16
16
17
17
#include < modm/platform.hpp>
18
18
#include < modm/architecture/interface/clock.hpp>
19
+ #include < modm/debug/logger.hpp>
19
20
20
21
using namespace modm ::platform;
21
22
23
+ // / @ingroup modm_board_disco_f429zi
24
+ #define MODM_BOARD_HAS_LOGGER
25
+
22
26
namespace Board
23
27
{
24
28
// / @ingroup modm_board_disco_f429zi
25
29
// / @{
26
30
using namespace modm ::literals;
27
31
28
- // / STM32F429 running at 180MHz from the external 8MHz crystal
32
+ // / STM32F429 running at 168MHz from the external 8MHz crystal
29
33
struct SystemClock
30
34
{
31
- static constexpr uint32_t Frequency = 180_MHz ;
35
+ static constexpr uint32_t Frequency = 168_MHz ;
32
36
static constexpr uint32_t Apb1 = Frequency / 4 ;
33
37
static constexpr uint32_t Apb2 = Frequency / 2 ;
34
38
@@ -74,14 +78,17 @@ struct SystemClock
74
78
static constexpr uint32_t Timer13 = Apb1Timer;
75
79
static constexpr uint32_t Timer14 = Apb1Timer;
76
80
81
+ static constexpr uint32_t Usb = 48_MHz;
82
+
77
83
static bool inline
78
84
enable ()
79
85
{
80
86
Rcc::enableExternalCrystal (); // 8 MHz
81
87
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
85
92
};
86
93
Rcc::enablePll (Rcc::PllSource::ExternalCrystal, pllFactors);
87
94
// Required for 180 MHz clock
@@ -222,20 +229,37 @@ using Id = GpioOutputB12; // OTG_FS_ID: USB_OTG_HS_ID
222
229
223
230
using Overcurrent = GpioC5; // OTG_FS_OC [OTG_FS_OverCurrent]: GPXTI5
224
231
using 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;
227
245
// / @}
228
246
}
229
247
230
248
249
+
231
250
// / @ingroup modm_board_disco_f429zi
232
251
// / @{
252
+ using LoggerDevice = modm::IODeviceWrapper< stlink::Uart, modm::IOBuffer::BlockIfFull >;
253
+
233
254
inline void
234
255
initialize ()
235
256
{
236
257
SystemClock::enable ();
237
258
SysTickTimer::initialize<SystemClock>();
238
259
260
+ stlink::Uart::connect<stlink::Tx::Tx, stlink::Rx::Rx>();
261
+ stlink::Uart::initialize<SystemClock, 115200_Bd>();
262
+
239
263
LedGreen::setOutput (modm::Gpio::Low);
240
264
LedRed::setOutput (modm::Gpio::Low);
241
265
@@ -250,9 +274,23 @@ initializeL3g()
250
274
l3g::Cs::setOutput (modm::Gpio::High);
251
275
252
276
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 >();
254
278
l3g::SpiMaster::setDataMode (l3g::SpiMaster::DataMode::Mode3);
255
279
}
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
+ }
256
294
// / @}
257
295
258
296
}
0 commit comments