|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-2017, Sascha Schade |
| 3 | + * Copyright (c) 2016-2018, Niklas Hauser |
| 4 | + * |
| 5 | + * This file is part of the modm project. |
| 6 | + * |
| 7 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 8 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 9 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 10 | + */ |
| 11 | +// ---------------------------------------------------------------------------- |
| 12 | + |
| 13 | +#pragma once |
| 14 | + |
| 15 | +#include <modm/platform.hpp> |
| 16 | +#include <modm/architecture/interface/clock.hpp> |
| 17 | +#include <modm/debug/logger.hpp> |
| 18 | + |
| 19 | +using namespace modm::platform; |
| 20 | + |
| 21 | +/// @ingroup modm_board_nucleo_f207zg |
| 22 | +#define MODM_BOARD_HAS_LOGGER |
| 23 | + |
| 24 | +namespace Board |
| 25 | +{ |
| 26 | +/// @ingroup modm_board_nucleo_f207zg |
| 27 | +/// @{ |
| 28 | +using namespace modm::literals; |
| 29 | + |
| 30 | +/// STM32F207ZG running at 120MHz from the ST-LINK 8 MHz MCO |
| 31 | +struct SystemClock |
| 32 | +{ |
| 33 | + static constexpr uint32_t Hse = 8_MHz; |
| 34 | + static constexpr Rcc::PllConfig pll |
| 35 | + { |
| 36 | + .M = 4, // 8 MHz / 4 = 2 MHz |
| 37 | + .N = 240, // 2 MHz * 240 = 480 MHz |
| 38 | + .P = 4, // 480 MHz / 4 = 120 MHz = F_cpu |
| 39 | + .Q = 10, // 480 MHz / 10 = 48 MHz = F_usb |
| 40 | + }; |
| 41 | + static constexpr uint32_t PllP = Hse / pll.M * pll.N / pll.P; |
| 42 | + static constexpr uint32_t PllQ = Hse / pll.M * pll.N / pll.Q; |
| 43 | + |
| 44 | + static constexpr uint32_t Frequency = PllP; |
| 45 | + static_assert(Frequency == Rcc::MaxFrequency); |
| 46 | + |
| 47 | + static constexpr uint32_t Ahb = Frequency; |
| 48 | + static constexpr uint32_t Apb1 = Frequency / 4; |
| 49 | + static constexpr uint32_t Apb2 = Frequency / 2; |
| 50 | + static constexpr uint32_t Ahb1 = Ahb; |
| 51 | + static constexpr uint32_t Ahb2 = Ahb; |
| 52 | + |
| 53 | + static constexpr uint32_t Crc = Ahb1; |
| 54 | + static constexpr uint32_t Flash = Ahb1; |
| 55 | + static constexpr uint32_t Dma1 = Ahb1; |
| 56 | + static constexpr uint32_t Dma2 = Ahb1; |
| 57 | + static constexpr uint32_t Eth = Ahb1; |
| 58 | + |
| 59 | + static constexpr uint32_t Dcmi = Ahb2; |
| 60 | + static constexpr uint32_t Rng = Ahb2; |
| 61 | + |
| 62 | + static constexpr uint32_t Spi2 = Apb1; |
| 63 | + static constexpr uint32_t Spi3 = Apb1; |
| 64 | + static constexpr uint32_t Usart2 = Apb1; |
| 65 | + static constexpr uint32_t Usart3 = Apb1; |
| 66 | + static constexpr uint32_t Uart4 = Apb1; |
| 67 | + static constexpr uint32_t Uart5 = Apb1; |
| 68 | + static constexpr uint32_t I2c1 = Apb1; |
| 69 | + static constexpr uint32_t I2c2 = Apb1; |
| 70 | + static constexpr uint32_t I2c3 = Apb1; |
| 71 | + static constexpr uint32_t Can1 = Apb1; |
| 72 | + static constexpr uint32_t Can2 = Apb1; |
| 73 | + static constexpr uint32_t Pwr = Apb1; |
| 74 | + static constexpr uint32_t Dac = Apb1; |
| 75 | + static constexpr uint32_t Wwdg = Apb1; |
| 76 | + |
| 77 | + // APB2 domain |
| 78 | + static constexpr uint32_t Spi1 = Apb2; |
| 79 | + static constexpr uint32_t Usart1 = Apb2; |
| 80 | + static constexpr uint32_t Usart6 = Apb2; |
| 81 | + static constexpr uint32_t Adc = Apb2; |
| 82 | + static constexpr uint32_t Sdio = Apb2; |
| 83 | + static constexpr uint32_t Syscfg = Apb2; |
| 84 | + |
| 85 | + static constexpr uint32_t Apb1Timer = Apb1 * 2; |
| 86 | + static constexpr uint32_t Apb2Timer = Apb2 * 2; |
| 87 | + static constexpr uint32_t Timer1 = Apb2Timer; |
| 88 | + static constexpr uint32_t Timer2 = Apb1Timer; |
| 89 | + static constexpr uint32_t Timer3 = Apb1Timer; |
| 90 | + static constexpr uint32_t Timer4 = Apb1Timer; |
| 91 | + static constexpr uint32_t Timer5 = Apb1Timer; |
| 92 | + static constexpr uint32_t Timer6 = Apb1Timer; |
| 93 | + static constexpr uint32_t Timer7 = Apb1Timer; |
| 94 | + static constexpr uint32_t Timer8 = Apb2Timer; |
| 95 | + static constexpr uint32_t Timer9 = Apb2Timer; |
| 96 | + static constexpr uint32_t Timer10 = Apb2Timer; |
| 97 | + static constexpr uint32_t Timer11 = Apb2Timer; |
| 98 | + static constexpr uint32_t Timer12 = Apb1Timer; |
| 99 | + static constexpr uint32_t Timer13 = Apb1Timer; |
| 100 | + static constexpr uint32_t Timer14 = Apb1Timer; |
| 101 | + |
| 102 | + static constexpr uint32_t Usb = PllQ; |
| 103 | + static constexpr uint32_t Iwdg = Rcc::LsiFrequency; |
| 104 | + static constexpr uint32_t Rtc = 32.768_kHz; |
| 105 | + |
| 106 | + static bool inline |
| 107 | + enable() |
| 108 | + { |
| 109 | + Rcc::enableLseCrystal(); |
| 110 | + Rcc::enableHseClock(); |
| 111 | + |
| 112 | + Rcc::setFlashLatency<Frequency>(); |
| 113 | + Rcc::updateCoreFrequency<Frequency>(); |
| 114 | + |
| 115 | + Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1); |
| 116 | + Rcc::setApb1Prescaler(Rcc::ApbPrescaler::Div4); |
| 117 | + Rcc::setApb2Prescaler(Rcc::ApbPrescaler::Div2); |
| 118 | + |
| 119 | + Rcc::enablePll(Rcc::PllSource::Hse, pll); |
| 120 | + Rcc::enableSystemClock(Rcc::SystemClockSource::Pll); |
| 121 | + Rcc::setRealTimeClockSource(Rcc::RealTimeClockSource::Lse); |
| 122 | + |
| 123 | + return true; |
| 124 | + } |
| 125 | +}; |
| 126 | + |
| 127 | +// Arduino Footprint |
| 128 | +#include "nucleo144_arduino.hpp" |
| 129 | + |
| 130 | +using Button = GpioInputC13; |
| 131 | + |
| 132 | +using LedGreen = GpioOutputB0; // LED1 [Green] |
| 133 | +using LedBlue = GpioOutputB7; // LED2 [Blue] |
| 134 | +using LedRed = GpioOutputB14; // LED3 [Red] |
| 135 | +using Leds = SoftwareGpioPort< LedRed, LedBlue, LedGreen >; |
| 136 | +/// @} |
| 137 | + |
| 138 | +namespace usb |
| 139 | +{ |
| 140 | +/// @ingroup modm_board_nucleo_f207zg |
| 141 | +/// @{ |
| 142 | +using Vbus = GpioA9; |
| 143 | +using Id = GpioA10; |
| 144 | +using Dm = GpioA11; |
| 145 | +using Dp = GpioA12; |
| 146 | + |
| 147 | +using Overcurrent = GpioInputG7; // OTG_FS_OverCurrent |
| 148 | +using Power = GpioOutputG6; // OTG_FS_PowerSwitchOn |
| 149 | + |
| 150 | +using Device = UsbFs; |
| 151 | +/// @} |
| 152 | +} |
| 153 | + |
| 154 | +namespace stlink |
| 155 | +{ |
| 156 | +/// @ingroup modm_board_nucleo_f207zg |
| 157 | +/// @{ |
| 158 | +using Tx = GpioOutputD8; |
| 159 | +using Rx = GpioInputD9; |
| 160 | +using Uart = BufferedUart<UsartHal3, UartTxBuffer<2048>>; |
| 161 | +/// @} |
| 162 | +} |
| 163 | + |
| 164 | +/// @ingroup modm_board_nucleo_f207zg |
| 165 | +/// @{ |
| 166 | +using LoggerDevice = modm::IODeviceWrapper< stlink::Uart, modm::IOBuffer::BlockIfFull >; |
| 167 | + |
| 168 | +inline void |
| 169 | +initialize() |
| 170 | +{ |
| 171 | + SystemClock::enable(); |
| 172 | + SysTickTimer::initialize<SystemClock>(); |
| 173 | + |
| 174 | + stlink::Uart::connect<stlink::Tx::Tx, stlink::Rx::Rx>(); |
| 175 | + stlink::Uart::initialize<SystemClock, 115200_Bd>(); |
| 176 | + |
| 177 | + Leds::setOutput(modm::Gpio::Low); |
| 178 | + |
| 179 | + Button::setInput(); |
| 180 | +} |
| 181 | + |
| 182 | +inline void |
| 183 | +initializeUsb(uint8_t priority=3) |
| 184 | +{ |
| 185 | + usb::Device::initialize<SystemClock>(priority); |
| 186 | + usb::Device::connect<usb::Dm::Dm, usb::Dp::Dp, usb::Id::Id>(); |
| 187 | + |
| 188 | + usb::Overcurrent::setInput(); |
| 189 | + usb::Vbus::setInput(); |
| 190 | + // // Enable VBUS sense (B device) via pin PA9 |
| 191 | + // USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; |
| 192 | + // USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; |
| 193 | +} |
| 194 | +/// @} |
| 195 | + |
| 196 | +} |
0 commit comments