1616
1717#include < modm/platform.hpp>
1818#include < modm/architecture/interface/clock.hpp>
19+ #include < modm/debug/logger.hpp>
1920
2021using namespace modm ::platform;
2122
23+ // / @ingroup modm_board_disco_f429zi
24+ #define MODM_BOARD_HAS_LOGGER
25+
2226namespace Board
2327{
2428// / @ingroup modm_board_disco_f429zi
2529// / @{
2630using namespace modm ::literals;
2731
28- // / STM32F429 running at 180MHz from the external 8MHz crystal
32+ // / STM32F429 running at 168MHz from the external 8MHz crystal
2933struct SystemClock
3034{
31- static constexpr uint32_t Frequency = 180_MHz ;
35+ static constexpr uint32_t Frequency = 168_MHz ;
3236 static constexpr uint32_t Apb1 = Frequency / 4 ;
3337 static constexpr uint32_t Apb2 = Frequency / 2 ;
3438
@@ -74,14 +78,17 @@ struct SystemClock
7478 static constexpr uint32_t Timer13 = Apb1Timer;
7579 static constexpr uint32_t Timer14 = Apb1Timer;
7680
81+ static constexpr uint32_t Usb = 48_MHz;
82+
7783 static bool inline
7884 enable ()
7985 {
8086 Rcc::enableExternalCrystal (); // 8 MHz
8187 const Rcc::PllFactors pllFactors{
82- .pllM = 4 , // 8MHz / M=4 -> 2MHz
83- .pllN = 180 , // 2MHz * N=180 -> 360MHz
84- .pllP = 2 // 360MHz / P=2 -> 180MHz = F_cpu
88+ .pllM = 4 , // 8MHz / M -> 2MHz
89+ .pllN = 168 , // 2MHz * N -> 336MHz
90+ .pllP = 2 , // 336MHz / P -> 168MHz = F_cpu
91+ .pllQ = 7 // 336MHz / Q -> 48MHz = F_usb
8592 };
8693 Rcc::enablePll (Rcc::PllSource::ExternalCrystal, pllFactors);
8794 // Required for 180 MHz clock
@@ -222,20 +229,37 @@ using Id = GpioOutputB12; // OTG_FS_ID: USB_OTG_HS_ID
222229
223230using Overcurrent = GpioC5; // OTG_FS_OC [OTG_FS_OverCurrent]: GPXTI5
224231using Power = GpioOutputC4; // OTG_FS_PSO [OTG_FS_PowerSwitchOn]
225- using VBus = GpioB13; // VBUS_FS: USB_OTG_HS_VBUS
226- // using Device = UsbFs;
232+ using Vbus = GpioB13; // VBUS_FS: USB_OTG_HS_VBUS
233+
234+ using Device = UsbHs;
235+ // / @}
236+ }
237+
238+ namespace stlink
239+ {
240+ // / @ingroup modm_board_nucleo_h743zi
241+ // / @{
242+ using Tx = GpioOutputA9;
243+ using Rx = GpioInputA10;
244+ using Uart = Usart1;
227245// / @}
228246}
229247
230248
249+
231250// / @ingroup modm_board_disco_f429zi
232251// / @{
252+ using LoggerDevice = modm::IODeviceWrapper< stlink::Uart, modm::IOBuffer::BlockIfFull >;
253+
233254inline void
234255initialize ()
235256{
236257 SystemClock::enable ();
237258 SysTickTimer::initialize<SystemClock>();
238259
260+ stlink::Uart::connect<stlink::Tx::Tx, stlink::Rx::Rx>();
261+ stlink::Uart::initialize<SystemClock, 115200_Bd>();
262+
239263 LedGreen::setOutput (modm::Gpio::Low);
240264 LedRed::setOutput (modm::Gpio::Low);
241265
@@ -250,9 +274,23 @@ initializeL3g()
250274 l3g::Cs::setOutput (modm::Gpio::High);
251275
252276 l3g::SpiMaster::connect<l3g::Sck::Sck, l3g::Mosi::Mosi, l3g::Miso::Miso>();
253- l3g::SpiMaster::initialize<SystemClock, 11 .25_MHz >();
277+ l3g::SpiMaster::initialize<SystemClock, 10 .5_MHz >();
254278 l3g::SpiMaster::setDataMode (l3g::SpiMaster::DataMode::Mode3);
255279}
280+
281+ inline void
282+ initializeUsbFs (uint8_t priority=3 )
283+ {
284+ Rcc::enable<Peripheral::Usbotgfs>();
285+ usb::Device::initialize<SystemClock>(priority);
286+ usb::Device::connect<usb::Dm::Dm, usb::Dp::Dp, usb::Id::Id>();
287+
288+ usb::Overcurrent::setInput ();
289+ usb::Vbus::setInput ();
290+ // Enable VBUS sense (B device) via pin PA9
291+ USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
292+ USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
293+ }
256294// / @}
257295
258296}
0 commit comments