|
| 1 | +/* |
| 2 | + * Copyright (c) 2026, Niklas Hauser |
| 3 | + * |
| 4 | + * This file is part of the modm project. |
| 5 | + * |
| 6 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 7 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 | + */ |
| 10 | +// ---------------------------------------------------------------------------- |
| 11 | + |
| 12 | +#pragma once |
| 13 | + |
| 14 | +#include <modm/platform.hpp> |
| 15 | +#include <modm/architecture.hpp> |
| 16 | +#include <modm/debug.hpp> |
| 17 | + |
| 18 | +using namespace modm::platform; |
| 19 | + |
| 20 | +/// @ingroup modm_board_nucleo_h533re |
| 21 | +#define MODM_BOARD_HAS_LOGGER |
| 22 | + |
| 23 | +namespace Board |
| 24 | +{ |
| 25 | +/// @ingroup modm_board_nucleo_h533re |
| 26 | +/// @{ |
| 27 | +using namespace modm::literals; |
| 28 | + |
| 29 | +/// STM32H533RE running at 250MHz from PLL clock generated from 24 MHz HSE |
| 30 | +struct SystemClock |
| 31 | +{ |
| 32 | + static constexpr uint32_t Hse = 24_MHz; |
| 33 | + static constexpr uint32_t Lse = 32.768_kHz; |
| 34 | + |
| 35 | + static constexpr Rcc::PllConfig pll1 |
| 36 | + { |
| 37 | + .range = Rcc::PllInputRange::MHz2_4, |
| 38 | + .M = 12, // 24 MHz / 12 = 2 MHz |
| 39 | + .N = 250, // 2 MHz * 120 = 500 MHz |
| 40 | + .P = 2, // 500 MHz / 2 = 250 MHz = F_cpu |
| 41 | + }; |
| 42 | + static constexpr uint32_t Pll1P = Hse / pll1.M * pll1.N / pll1.P; |
| 43 | + static_assert(Pll1P == Rcc::MaxFrequency); |
| 44 | + |
| 45 | + static constexpr Rcc::PllConfig pll3 |
| 46 | + { |
| 47 | + .range = Rcc::PllInputRange::MHz8_16, |
| 48 | + .M = 3, // 24 MHz / 3 = 8 MHz |
| 49 | + .N = 18, // 8 MHz * 18 = 144 MHz |
| 50 | + .Q = 3, // 144 MHz / 3 = 48 MHz = F_usb |
| 51 | + }; |
| 52 | + static constexpr uint32_t Pll3Q = Hse / pll3.M * pll3.N / pll3.Q; |
| 53 | + |
| 54 | + static constexpr uint32_t SysClk = Pll1P; |
| 55 | + static constexpr uint32_t Frequency = SysClk; |
| 56 | + |
| 57 | + // AHB Bus - Max 250MHz |
| 58 | + static constexpr uint32_t Hclk = SysClk / 1; |
| 59 | + static constexpr uint32_t Ahb = Hclk; |
| 60 | + |
| 61 | + // APB Buses - Max 250MHz |
| 62 | + static constexpr uint32_t Apb1 = Hclk / 1; |
| 63 | + static constexpr uint32_t Apb2 = Hclk / 1; |
| 64 | + static constexpr uint32_t Apb3 = Hclk / 1; |
| 65 | + |
| 66 | + // Peripherals on AHB2 |
| 67 | + static constexpr uint32_t Adc1 = Hclk; |
| 68 | + static constexpr uint32_t Dac1 = Hclk; |
| 69 | + |
| 70 | + // Peripherals on APB2 |
| 71 | + static constexpr uint32_t Spi1 = Apb2; |
| 72 | + static constexpr uint32_t Usart1 = Apb2; |
| 73 | + |
| 74 | + // Peripherals on APB1 |
| 75 | + static constexpr uint32_t Spi2 = Apb1; |
| 76 | + static constexpr uint32_t Spi3 = Apb1; |
| 77 | + static constexpr uint32_t Usart2 = Apb1; |
| 78 | + static constexpr uint32_t Usart3 = Apb1; |
| 79 | + static constexpr uint32_t Fdcan1 = Apb1; |
| 80 | + |
| 81 | + // Peripherals on APB3 |
| 82 | + static constexpr uint32_t LpUart1 = Apb3; |
| 83 | + |
| 84 | + // Timer Clocks |
| 85 | + static constexpr uint32_t Apb1Timer = Apb1 * 1; |
| 86 | + static constexpr uint32_t Apb2Timer = Apb2 * 1; |
| 87 | + |
| 88 | + static constexpr uint32_t Timer1 = Apb2Timer; |
| 89 | + static constexpr uint32_t Timer2 = Apb1Timer; |
| 90 | + static constexpr uint32_t Timer3 = Apb1Timer; |
| 91 | + static constexpr uint32_t Timer6 = Apb1Timer; |
| 92 | + static constexpr uint32_t Timer7 = Apb1Timer; |
| 93 | + |
| 94 | + static constexpr uint32_t Rtc = Lse; |
| 95 | + static constexpr uint32_t Usb = Pll3Q; |
| 96 | + static constexpr uint32_t Iwdg = Rcc::LsiFrequency; |
| 97 | + |
| 98 | + static bool inline |
| 99 | + enable() |
| 100 | + { |
| 101 | + Rcc::enableLseCrystal(); |
| 102 | + Rcc::enableHseCrystal(); |
| 103 | + |
| 104 | + Rcc::setVoltageScaling(Rcc::VoltageScaling::Scale0); |
| 105 | + Rcc::setFlashLatency<Frequency>(); |
| 106 | + |
| 107 | + Rcc::enablePll1(Rcc::PllSource::Hse, pll1); |
| 108 | + Rcc::enablePll3(Rcc::PllSource::Hse, pll3); |
| 109 | + |
| 110 | + Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1); |
| 111 | + Rcc::setApb1Prescaler(Rcc::ApbPrescaler::Div1); |
| 112 | + Rcc::setApb2Prescaler(Rcc::ApbPrescaler::Div1); |
| 113 | + Rcc::setApb3Prescaler(Rcc::ApbPrescaler::Div1); |
| 114 | + |
| 115 | + Rcc::updateCoreFrequency<Frequency>(); |
| 116 | + |
| 117 | + Rcc::enableSystemClock(Rcc::SystemClockSource::Pll1P); |
| 118 | + Rcc::setUsbClockSource(Rcc::UsbClockSource::Pll3Q); |
| 119 | + Rcc::setRealTimeClockSource(Rcc::RealTimeClockSource::Lse); |
| 120 | + |
| 121 | + return true; |
| 122 | + } |
| 123 | +}; |
| 124 | + |
| 125 | +using A0 = GpioA0; |
| 126 | +using A1 = GpioA1; |
| 127 | +using A2 = GpioB1; |
| 128 | +using A3 = GpioB0; |
| 129 | +using A4 = GpioC1; |
| 130 | +using A5 = GpioC0; |
| 131 | + |
| 132 | +using D0 = GpioB15; |
| 133 | +using D1 = GpioB14; |
| 134 | +using D2 = GpioC8; |
| 135 | +using D3 = GpioB3; |
| 136 | +using D4 = GpioB5; |
| 137 | +using D5 = GpioB4; |
| 138 | +using D6 = GpioB10; |
| 139 | +using D7 = GpioA8; |
| 140 | +using D8 = GpioC7; |
| 141 | +using D9 = GpioC6; |
| 142 | +using D10 = GpioC9; |
| 143 | +using D11 = GpioA7; |
| 144 | +using D12 = GpioA6; |
| 145 | +using D13 = GpioA5; |
| 146 | +using D14 = GpioB7; |
| 147 | +using D15 = GpioB6; |
| 148 | + |
| 149 | +using Button = GpioInputC13; |
| 150 | + |
| 151 | +using Led = GpioOutputA5; |
| 152 | +using Leds = SoftwareGpioPort< Led >; |
| 153 | +/// @} |
| 154 | + |
| 155 | +namespace usb |
| 156 | +{ |
| 157 | +/// @ingroup modm_board_nucleo_h533re |
| 158 | +/// @{ |
| 159 | +using Dm = GpioA11; |
| 160 | +using Dp = GpioA12; |
| 161 | + |
| 162 | +using Device = UsbFs; |
| 163 | +/// @} |
| 164 | +} |
| 165 | + |
| 166 | +namespace stlink |
| 167 | +{ |
| 168 | +/// @ingroup modm_board_nucleo_h533re |
| 169 | +/// @{ |
| 170 | +using Tx = GpioOutputA2; |
| 171 | +using Rx = GpioInputA3; |
| 172 | +using Uart = BufferedUart<UsartHal2, UartTxBuffer<2048>>; |
| 173 | +/// @} |
| 174 | +} |
| 175 | + |
| 176 | +/// @ingroup modm_board_nucleo_h533re |
| 177 | +/// @{ |
| 178 | +using LoggerDevice = modm::IODeviceWrapper< stlink::Uart, modm::IOBuffer::BlockIfFull >; |
| 179 | + |
| 180 | +inline void |
| 181 | +initialize() |
| 182 | +{ |
| 183 | + SystemClock::enable(); |
| 184 | + SysTickTimer::initialize<SystemClock>(); |
| 185 | + |
| 186 | + stlink::Uart::connect<stlink::Tx::Tx, stlink::Rx::Rx>(); |
| 187 | + stlink::Uart::initialize<SystemClock, 115200_Bd>(); |
| 188 | + |
| 189 | + Led::setOutput(modm::Gpio::Low); |
| 190 | + Button::setInput(); |
| 191 | +} |
| 192 | + |
| 193 | +inline void |
| 194 | +initializeUsb(uint8_t priority=3) |
| 195 | +{ |
| 196 | + usb::Device::initialize<SystemClock>(priority); |
| 197 | + usb::Device::connect<usb::Dm::Dm, usb::Dp::Dp>(); |
| 198 | +} |
| 199 | +/// @} |
| 200 | + |
| 201 | +} |
0 commit comments