|
| 1 | +/* |
| 2 | + * Copyright (c) 2015-2018, Niklas Hauser |
| 3 | + * Copyright (c) 2016, Fabian Greif |
| 4 | + * Copyright (c) 2016-2017, Sascha Schade |
| 5 | + * Copyright (c) 2018, Antal Szabó |
| 6 | + * |
| 7 | + * This file is part of the modm project. |
| 8 | + * |
| 9 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 10 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 11 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 12 | + */ |
| 13 | +// ---------------------------------------------------------------------------- |
| 14 | + |
| 15 | +#pragma once |
| 16 | + |
| 17 | +#include <modm/platform.hpp> |
| 18 | +#include <modm/architecture/interface/clock.hpp> |
| 19 | +#include <modm/debug/logger.hpp> |
| 20 | + |
| 21 | +/// @ingroup modm_board_disco_f723ie |
| 22 | +#define MODM_BOARD_HAS_LOGGER |
| 23 | + |
| 24 | +using namespace modm::platform; |
| 25 | + |
| 26 | +namespace Board |
| 27 | +{ |
| 28 | +/// @ingroup modm_board_disco_f723ie |
| 29 | +/// @{ |
| 30 | +using namespace modm::literals; |
| 31 | + |
| 32 | +/// STM32F7 running at 216MHz from the external 25MHz clock |
| 33 | +struct SystemClock |
| 34 | +{ |
| 35 | + static constexpr uint32_t Frequency = 216_MHz; |
| 36 | + static constexpr uint32_t Apb1 = Frequency / 4; |
| 37 | + static constexpr uint32_t Apb2 = Frequency / 2; |
| 38 | + |
| 39 | + static constexpr uint32_t Adc1 = Apb2; |
| 40 | + static constexpr uint32_t Adc2 = Apb2; |
| 41 | + static constexpr uint32_t Adc3 = Apb2; |
| 42 | + |
| 43 | + static constexpr uint32_t Spi1 = Apb2; |
| 44 | + static constexpr uint32_t Spi2 = Apb1; |
| 45 | + static constexpr uint32_t Spi3 = Apb1; |
| 46 | + static constexpr uint32_t Spi4 = Apb2; |
| 47 | + |
| 48 | + static constexpr uint32_t Usart1 = Apb2; |
| 49 | + static constexpr uint32_t Usart2 = Apb1; |
| 50 | + static constexpr uint32_t Usart3 = Apb1; |
| 51 | + static constexpr uint32_t Uart4 = Apb1; |
| 52 | + static constexpr uint32_t Uart5 = Apb1; |
| 53 | + static constexpr uint32_t Usart6 = Apb2; |
| 54 | + static constexpr uint32_t Uart7 = Apb1; |
| 55 | + static constexpr uint32_t Uart8 = Apb1; |
| 56 | + |
| 57 | + static constexpr uint32_t Can1 = Apb1; |
| 58 | + static constexpr uint32_t Can2 = Apb1; |
| 59 | + |
| 60 | + static constexpr uint32_t I2c1 = Apb1; |
| 61 | + static constexpr uint32_t I2c2 = Apb1; |
| 62 | + static constexpr uint32_t I2c3 = Apb1; |
| 63 | + static constexpr uint32_t I2c4 = Apb1; |
| 64 | + |
| 65 | + static constexpr uint32_t Apb1Timer = Apb1 * 2; |
| 66 | + static constexpr uint32_t Apb2Timer = Apb2 * 2; |
| 67 | + static constexpr uint32_t Timer1 = Apb2Timer; |
| 68 | + static constexpr uint32_t Timer2 = Apb1Timer; |
| 69 | + static constexpr uint32_t Timer3 = Apb1Timer; |
| 70 | + static constexpr uint32_t Timer4 = Apb1Timer; |
| 71 | + static constexpr uint32_t Timer5 = Apb1Timer; |
| 72 | + static constexpr uint32_t Timer6 = Apb1Timer; |
| 73 | + static constexpr uint32_t Timer7 = Apb1Timer; |
| 74 | + static constexpr uint32_t Timer8 = Apb2Timer; |
| 75 | + static constexpr uint32_t Timer10 = Apb2Timer; |
| 76 | + static constexpr uint32_t Timer11 = Apb2Timer; |
| 77 | + static constexpr uint32_t Timer12 = Apb1Timer; |
| 78 | + static constexpr uint32_t Timer13 = Apb1Timer; |
| 79 | + static constexpr uint32_t Timer14 = Apb1Timer; |
| 80 | + |
| 81 | + static constexpr uint32_t Usb = 48_MHz; |
| 82 | + static constexpr uint32_t Iwdg = Rcc::LsiFrequency; |
| 83 | + static constexpr uint32_t Rtc = 32.768_kHz; |
| 84 | + |
| 85 | + static bool inline |
| 86 | + enable() |
| 87 | + { |
| 88 | + Rcc::enableLowSpeedExternalCrystal(); |
| 89 | + Rcc::enableRealTimeClock(Rcc::RealTimeClockSource::LowSpeedExternalCrystal); |
| 90 | + |
| 91 | + Rcc::enableExternalClock(); // 25 MHz |
| 92 | + const Rcc::PllFactors pllFactors{ |
| 93 | + .pllM = 25, // 25MHz / M=25 -> 1MHz |
| 94 | + .pllN = 432, // 1MHz * N=432 -> 432MHz |
| 95 | + .pllP = 2, // 432MHz / P=2 -> 216MHz = F_cpu |
| 96 | + .pllQ = 9 // 432MHz / Q=9 -> 48MHz = F_usb |
| 97 | + }; |
| 98 | + Rcc::enablePll(Rcc::PllSource::ExternalClock, pllFactors); |
| 99 | + // Required for 216 MHz clock |
| 100 | + Rcc::enableOverdriveMode(); |
| 101 | + |
| 102 | + Rcc::setFlashLatency<Frequency>(); |
| 103 | + Rcc::enableSystemClock(Rcc::SystemClockSource::Pll); |
| 104 | + // APB1 is running at 54MHz |
| 105 | + Rcc::setApb1Prescaler(Rcc::Apb1Prescaler::Div4); |
| 106 | + // APB2 is running at 108MHz |
| 107 | + Rcc::setApb2Prescaler(Rcc::Apb2Prescaler::Div2); |
| 108 | + Rcc::updateCoreFrequency<Frequency>(); |
| 109 | + |
| 110 | + return true; |
| 111 | + } |
| 112 | +}; |
| 113 | + |
| 114 | +// Arduino footprint |
| 115 | +using A0 = GpioA6; |
| 116 | +using A1 = GpioA4; |
| 117 | +using A2 = GpioC4; |
| 118 | +using A3 = GpioF10; |
| 119 | +using A4 = GpioC0; |
| 120 | +using A5 = GpioC1; |
| 121 | + |
| 122 | +using D0 = GpioA3; |
| 123 | +using D1 = GpioA2; |
| 124 | +using D2 = GpioC5; |
| 125 | +using D3 = GpioE5; |
| 126 | +using D4 = GpioH3; |
| 127 | +using D5 = GpioB0; |
| 128 | +using D6 = GpioE6; |
| 129 | +using D7 = GpioE3; |
| 130 | +using D8 = GpioE4; |
| 131 | +using D9 = GpioH6; |
| 132 | +using D10 = GpioA1; |
| 133 | +using D11 = GpioB5; |
| 134 | +using D12 = GpioB4; |
| 135 | +using D13 = GpioOutputA5; |
| 136 | +using D14 = GpioH5; |
| 137 | +using D15 = GpioH4; |
| 138 | + |
| 139 | +using Button = GpioInputA0; // User Button |
| 140 | +using LedRed = GpioOutputA7; // User Red LED |
| 141 | +using LedGreen = GpioOutputB1; // User Green LED |
| 142 | +using LedD13 = D13; // User Blue LED (Arduino D13) |
| 143 | + |
| 144 | +using Leds = SoftwareGpioPort< LedD13, LedGreen, LedRed >; |
| 145 | +/// @} |
| 146 | + |
| 147 | +namespace usb_fs |
| 148 | +{ |
| 149 | +/// @ingroup modm_board_disco_f723ie |
| 150 | +/// @{ |
| 151 | +using Vbus = GpioA9; |
| 152 | +using Id = GpioA10; |
| 153 | +using Dm = GpioA11; |
| 154 | +using Dp = GpioA12; |
| 155 | +using Overcurrent = GpioB10; |
| 156 | +using Power = GpioG8; |
| 157 | + |
| 158 | +using Device = UsbFs; |
| 159 | +/// @} |
| 160 | +} |
| 161 | + |
| 162 | +namespace usb_hs |
| 163 | +{ |
| 164 | +/// @ingroup modm_board_disco_f723ie |
| 165 | +/// @{ |
| 166 | + |
| 167 | +using Vbus = GpioB13; |
| 168 | +using Id = GpioB12; |
| 169 | +using Dm = GpioB14; |
| 170 | +using Dp = GpioB15; |
| 171 | +using Overcurrent = GpioH10; |
| 172 | +using Power = GpioH12; |
| 173 | + |
| 174 | +using Device = UsbHs; |
| 175 | +/// @} |
| 176 | +} |
| 177 | + |
| 178 | +namespace stlink |
| 179 | +{ |
| 180 | +/// @ingroup modm_board_disco_f723ie |
| 181 | +/// @{ |
| 182 | +using Tx = GpioOutputC6; |
| 183 | +using Rx = GpioInputC7; |
| 184 | +using Uart = BufferedUart<UsartHal6, UartTxBuffer<2048>>; |
| 185 | +/// @} |
| 186 | +} |
| 187 | + |
| 188 | +/// @ingroup modm_board_disco_f723ie |
| 189 | +/// @{ |
| 190 | +using LoggerDevice = modm::IODeviceWrapper< stlink::Uart, modm::IOBuffer::BlockIfFull >; |
| 191 | + |
| 192 | +inline void |
| 193 | +initialize() |
| 194 | +{ |
| 195 | + SystemClock::enable(); |
| 196 | + SysTickTimer::initialize<SystemClock>(); |
| 197 | + |
| 198 | + stlink::Uart::connect<stlink::Tx::Tx, stlink::Rx::Rx>(); |
| 199 | + stlink::Uart::initialize<SystemClock, 115200_Bd>(); |
| 200 | + |
| 201 | + Button::setInput(); |
| 202 | +} |
| 203 | + |
| 204 | +inline void |
| 205 | +initializeUsb(uint8_t priority=3) |
| 206 | +{ |
| 207 | + // Full-speed USB port |
| 208 | + usb_fs::Device::initialize<SystemClock>(priority); |
| 209 | + usb_fs::Device::connect<usb_fs::Dm::Dm, usb_fs::Dp::Dp, usb_fs::Id::Id>(); |
| 210 | + usb_fs::Overcurrent::setInput(); |
| 211 | + |
| 212 | + // Enable VBUS Sensing B |
| 213 | + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN; |
| 214 | + |
| 215 | + // High-speed USB port |
| 216 | + usb_hs::Device::initialize<SystemClock>(priority); |
| 217 | + usb_hs::Device::connect<usb_hs::Dm::Dm, usb_hs::Dp::Dp, usb_hs::Id::Id>(); |
| 218 | + usb_hs::Overcurrent::setInput(); |
| 219 | + |
| 220 | + // Enable VBUS Sensing B |
| 221 | + USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBDEN; |
| 222 | +} |
| 223 | +/// @} |
| 224 | + |
| 225 | +} |
0 commit comments