Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable STM32U0 Support #1202

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ jobs:
if: always()
run: |
(cd examples && ../tools/scripts/examples_compile.py nucleo_l552ze-q)
- name: Examples STM32U0 Series
if: always()
run: |
(cd examples && ../tools/scripts/examples_compile.py stm32u083c_dk)
- name: Examples STM32U5 Series
if: always()
run: |
Expand Down
3 changes: 2 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
url = https://github.com/modm-io/cmsis-header-stm32.git
[submodule "ext/modm-devices"]
path = ext/modm-devices
url = https://github.com/modm-io/modm-devices.git
url = https://github.com/FranzForstmayr/modm-devices.git
branch = stm32u0
[submodule "ext/ros/ros-lib"]
path = ext/ros/ros-lib
url = https://github.com/modm-io/ros-lib
Expand Down
28 changes: 28 additions & 0 deletions examples/stm32u083c_dk/blink/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024, Franz Forstmayr
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <modm/board.hpp>

using namespace Board;

int
main()
{
Board::initialize();

LedGreen::set();
LedBlue::reset();

while (true) {
LedGreen::toggle();
LedBlue::toggle();
modm::delay(Board::Button::read() ? 0.5s : 1s);
}
}
9 changes: 9 additions & 0 deletions examples/stm32u083c_dk/blink/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<library>
<extends>modm:disco-u083c</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32u083c_dk/blink</option>
</options>
<modules>
<module>modm:build:scons</module>
</modules>
</library>
64 changes: 64 additions & 0 deletions examples/stm32u083c_dk/logger/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2024, Franz Forstmayr
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <modm/board.hpp>
#include <modm/debug/logger.hpp>
#include <modm/processing/timer.hpp>

// ----------------------------------------------------------------------------
// Set the log level
#undef MODM_LOG_LEVEL
#define MODM_LOG_LEVEL modm::log::INFO

// Create an IODeviceWrapper around the Uart Peripheral we want to use
using Usart1 = BufferedUart<UsartHal1, UartTxBuffer<1024>>;
modm::IODeviceWrapper< Usart1, modm::IOBuffer::BlockIfFull > loggerDevice;

// Set all four logger streams to use the UART
modm::log::Logger modm::log::debug(loggerDevice);
modm::log::Logger modm::log::info(loggerDevice);
modm::log::Logger modm::log::warning(loggerDevice);
modm::log::Logger modm::log::error(loggerDevice);

int
main()
{
Board::initialize();

// initialize Uart1 for MODM_LOG_*
Usart1::connect<GpioOutputA9::Tx, GpioInputA10::Rx>();
Usart1::initialize<Board::SystemClock, 115200_Bd>();

// Use the logging streams to print some messages.
// Change MODM_LOG_LEVEL above to enable or disable these messages
MODM_LOG_DEBUG << "debug" << modm::endl;
MODM_LOG_INFO << "info" << modm::endl;
MODM_LOG_WARNING << "warning" << modm::endl;
MODM_LOG_ERROR << "error" << modm::endl;

Board::LedBlue::reset();

uint32_t ii(1);
modm::Timeout timeout;

while (true) {
Board::LedBlue::set();
timeout.restart(100ms);
while(not timeout.isExpired())
{};

Board::LedBlue::reset();
timeout.restart(900ms);
while(not timeout.isExpired())
{};

MODM_LOG_INFO << "Seconds since reboot: " << ii++ << modm::endl;
}
}
13 changes: 13 additions & 0 deletions examples/stm32u083c_dk/logger/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<library>
<extends>modm:disco-u083c</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f0_discovery/logger</option>
</options>
<modules>
<module>modm:debug</module>
<module>modm:platform:gpio</module>
<module>modm:platform:uart:1</module>
<module>modm:processing:timer</module>
<module>modm:build:scons</module>
</modules>
</library>
2 changes: 1 addition & 1 deletion ext/modm-devices
Submodule modm-devices updated 37 files
+1 −0 .gitignore
+4 −4 README.md
+6 −6 devices/stm32/stm32g0-70_b0.xml
+51 −19 devices/stm32/stm32g4-31_41.xml
+22 −3 devices/stm32/stm32g4-73_83.xml
+19 −3 devices/stm32/stm32g4-91_a1.xml
+21 −2 devices/stm32/stm32h5-03.xml
+4 −6 devices/stm32/stm32h5-23-c-c.xml
+4 −0 devices/stm32/stm32h5-23-c-r.xml
+6 −0 devices/stm32/stm32h5-23-c-v.xml
+8 −0 devices/stm32/stm32h5-23-c-z.xml
+4 −6 devices/stm32/stm32h5-23-e-c.xml
+3 −23 devices/stm32/stm32h5-23-e-h.xml
+4 −0 devices/stm32/stm32h5-23-e-r.xml
+6 −0 devices/stm32/stm32h5-23-e-v.xml
+8 −0 devices/stm32/stm32h5-23-e-z.xml
+4 −6 devices/stm32/stm32h5-33-e-c.xml
+3 −23 devices/stm32/stm32h5-33-e-h.xml
+4 −0 devices/stm32/stm32h5-33-e-r.xml
+6 −0 devices/stm32/stm32h5-33-e-v.xml
+8 −0 devices/stm32/stm32h5-33-e-z.xml
+21 −0 devices/stm32/stm32h5-62.xml
+31 −0 devices/stm32/stm32h5-63_73.xml
+6 −6 devices/stm32/stm32h7-42.xml
+6 −6 devices/stm32/stm32h7-43_53.xml
+5 −5 devices/stm32/stm32h7-45_55.xml
+5 −5 devices/stm32/stm32h7-47_57.xml
+3 −3 devices/stm32/stm32h7-50.xml
+1,072 −0 devices/stm32/stm32u0-31.xml
+1,479 −0 devices/stm32/stm32u0-73.xml
+1,468 −0 devices/stm32/stm32u0-83.xml
+3 −3 tools/generator/Makefile
+28 −0 tools/generator/dfg/stm32/stm.py
+0 −1 tools/generator/dfg/stm32/stm_device_tree.py
+1 −1 tools/generator/dfg/stm32/stm_dmamux_requests.py
+14 −0 tools/generator/dfg/stm32/stm_groups.py
+2 −2 tools/generator/dfg/stm32/stm_peripherals.py
2 changes: 1 addition & 1 deletion repo.lb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class DevicesCache(dict):
"stm32g0", "stm32g4",
"stm32h7",
"stm32l0", "stm32l1", "stm32l4", "stm32l5",
"stm32u5",
"stm32u0", "stm32u5",
"at90", "attiny", "atmega",
"samd21", "samg55",
"same70", "sams70", "samv70", "samv71",
Expand Down
81 changes: 81 additions & 0 deletions src/modm/board/disco_u083c/board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// coding: utf-8
/*
* Copyright (c) 2024, Franz Forstmayr
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#ifndef MODM_STM32_U083_DK_HPP
#define MODM_STM32_U083_DK_HPP

#include <modm/platform.hpp>
#include <modm/architecture/interface/clock.hpp>

using namespace modm::platform;

namespace Board
{
/// @ingroup modm_board_stm32u83_dk
/// @{
using namespace modm::literals;

/// STM32F0 running at 48MHz generated from the internal 8MHz with PLL.
struct SystemClock
{
static constexpr int Frequency = 48_MHz;
static constexpr int Usart1 = Frequency;
static constexpr int Usart2 = Frequency;
static constexpr int Spi2 = Frequency;
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;

static bool inline
enable()
{
// enable internal 8 MHz HSI RC clock
Rcc::enableInternalClock();
// (internal clock / 2) * 12 = 48MHz
const Rcc::PllFactors pllFactors{
.pllM = 4,
};
Rcc::enablePll(Rcc::PllSource::Hse, pllFactors);
// set flash latency for 48MHz
Rcc::setFlashLatency<Frequency>();
// switch system clock to PLL output
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
Rcc::setApbPrescaler(Rcc::ApbPrescaler::Div1);
// update frequencies for busy-wait delay functions
Rcc::updateCoreFrequency<Frequency>();

return true;
}
};

using Button = GpioInputA0;

using LedGreen = GpioOutputC9;
using LedBlue = GpioOutputC8;

using Leds = SoftwareGpioPort< LedGreen, LedBlue >;

inline void
initialize()
{
SystemClock::enable();
SysTickTimer::initialize<SystemClock>();

LedGreen::setOutput(modm::Gpio::Low);
LedBlue::setOutput(modm::Gpio::Low);

Button::setInput();
}
/// @}

} // namespace Board

#endif // MODM_STM32_U083_DK_HPP
16 changes: 16 additions & 0 deletions src/modm/board/disco_u083c/board.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<library>
<repositories>
<repository>
<path>../../../../repo.lb</path>
</repository>
</repositories>

<options>
<option name="modm:target">stm32u083mct6</option>
<option name="modm:platform:cortex-m:main_stack_size">1Ki</option>
<option name="modm:build:openocd.cfg">openocd.cfg</option>
</options>
<modules>
<module>modm:board:disco-u083c</module>
</modules>
</library>
40 changes: 40 additions & 0 deletions src/modm/board/disco_u083c/module.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2024, Franz Forstmayr
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
module.name = ":board:disco-u083c"
module.description = """\
# STM32U083C-DK

[Discovery kit for STM32U083](https://www.st.com/en/evaluation-tools/stm32u083c-dk.html)
"""

def prepare(module, options):
if not options[":target"].partname.startswith("stm32u083mct"):
return False

module.depends(
":architecture:clock",
":platform:clock",
":platform:core",
":platform:gpio")
return True

def build(env):
env.outbasepath = "modm/src/modm/board"
env.substitutions = {
"with_logger": False,
"with_assert": env.has_module(":architecture:assert")
}
env.template("../board.cpp.in", "board.cpp")
env.copy('.')
env.collect(":build:openocd.source")
44 changes: 44 additions & 0 deletions src/modm/board/disco_u083c/openocd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This is an STM32U083C-DK board with a single STM32U083MCTx chip
#
# Generated by STM32CubeIDE
# Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s)

source [find interface/stlink-dap.cfg]


set WORKAREASIZE 0x8000

transport select "dapdirect_swd"

set CHIPNAME STM32U083MCTx
set BOARDNAME STM32U083C-DK

# Enable debug when in low power modes
set ENABLE_LOW_POWER 1

# Stop Watchdog counters when halt
set STOP_WATCHDOG 1

# STlink Debug clock frequency
set CLOCK_FREQ 8000

# Reset configuration
# use hardware reset, connect under reset
# connect_assert_srst needed if low power mode application running (WFI...)
reset_config srst_only srst_nogate connect_assert_srst
set CONNECT_UNDER_RESET 1
set CORE_RESET 0

# ACCESS PORT NUMBER
set AP_NUM 0
# GDB PORT
set GDB_PORT 3333





# BCTM CPU variables

source [find target/stm32u0x.cfg]

2 changes: 1 addition & 1 deletion src/modm/platform/adc/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def prepare(module, options):
if target["family"] in ["f2", "f4", "f7"]:
props["shared_irqs"] = {"ADC": listify([int(i) for i in device.get_driver("adc")["instance"]])}
props["shared_irq_ids"] = props["shared_irqs"]["ADC"]
elif target["family"] in ["u5"]:
elif target["family"] in ["u5", "u0"]:
# STM32U5 is not yet supported with any ADC implementation im modm
return False
else:
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/clock/stm32/rcc.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Rcc::enablePll{{id}}(PllSource source, const PllFactors& pllFactors, uint32_t wa
;

return tmp;
%% elif target.family in ["g0", "l4", "l5", "g4"]
%% elif target.family in ["g0", "l4", "l5", "g4", "u0"]
// Read reserved values and clear all other values
uint32_t tmp = RCC->PLLCFGR & ~(
RCC_PLLCFGR_PLLSRC | RCC_PLLCFGR_PLLM | RCC_PLLCFGR_PLLN |
Expand Down
Loading
Loading