|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, Raphael Lehmann |
| 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 | +#ifndef MODM_STM32_NUCLEO_F334R8_HPP |
| 13 | +#define MODM_STM32_NUCLEO_F334R8_HPP |
| 14 | + |
| 15 | +#include <modm/platform.hpp> |
| 16 | +#include <modm/architecture/interface/clock.hpp> |
| 17 | +#include <modm/debug/logger.hpp> |
| 18 | +/// @ingroup modm_board_nucleo_f334r8 |
| 19 | +#define MODM_BOARD_HAS_LOGGER |
| 20 | + |
| 21 | +using namespace modm::platform; |
| 22 | + |
| 23 | +/// @ingroup modm_board_nucleo_f334r8 |
| 24 | +namespace Board |
| 25 | +{ |
| 26 | + using namespace modm::literals; |
| 27 | + |
| 28 | +/// STM32F334R8 running at 64MHz generated from the internal 8MHz clock |
| 29 | +// Dummy clock for devices |
| 30 | +struct SystemClock { |
| 31 | + static constexpr uint32_t Frequency = 64_MHz; |
| 32 | + static constexpr uint32_t Ahb = Frequency; |
| 33 | + static constexpr uint32_t Apb1 = Frequency / 2; |
| 34 | + static constexpr uint32_t Apb2 = Frequency; |
| 35 | + |
| 36 | + static constexpr uint32_t Adc1 = Apb2; |
| 37 | + static constexpr uint32_t Adc2 = Apb2; |
| 38 | + |
| 39 | + static constexpr uint32_t Can = Apb1; |
| 40 | + |
| 41 | + static constexpr uint32_t Spi1 = Apb2; |
| 42 | + |
| 43 | + // USART1 is on APB2 bus, but default clock is PCLK1 |
| 44 | + static constexpr uint32_t Usart1 = Apb1; |
| 45 | + static constexpr uint32_t Usart2 = Apb1; |
| 46 | + static constexpr uint32_t Usart3 = Apb1; |
| 47 | + |
| 48 | + // I2C1 clock source is HSI per default |
| 49 | + static constexpr uint32_t I2c1 = 8_MHz; |
| 50 | + |
| 51 | + static constexpr uint32_t Apb1Timer = Apb1 * 2; |
| 52 | + static constexpr uint32_t Apb2Timer = Apb2 * 1; |
| 53 | + static constexpr uint32_t Timer1 = Apb2Timer; |
| 54 | + static constexpr uint32_t Timer2 = Apb1Timer; |
| 55 | + static constexpr uint32_t Timer3 = Apb1Timer; |
| 56 | + static constexpr uint32_t Timer6 = Apb1Timer; |
| 57 | + static constexpr uint32_t Timer7 = Apb1Timer; |
| 58 | + static constexpr uint32_t Timer15 = Apb2Timer; |
| 59 | + static constexpr uint32_t Timer16 = Apb2Timer; |
| 60 | + static constexpr uint32_t Timer17 = Apb2Timer; |
| 61 | + |
| 62 | + static bool inline |
| 63 | + enable() |
| 64 | + { |
| 65 | + Rcc::enableInternalClock(); // 8MHz |
| 66 | + // 8MHz / 2 * 16 = 64MHz |
| 67 | + const Rcc::PllFactors pllFactors{ |
| 68 | + .pllMul = 16, |
| 69 | + .pllPrediv = 2, // fixed (/2) for Hsi |
| 70 | + }; |
| 71 | + Rcc::enablePll(Rcc::PllSource::HsiDiv2, pllFactors); |
| 72 | + // set flash latency for 64MHz |
| 73 | + Rcc::setFlashLatency<Frequency>(); |
| 74 | + // switch system clock to PLL output |
| 75 | + Rcc::enableSystemClock(Rcc::SystemClockSource::Pll); |
| 76 | + Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1); |
| 77 | + // APB1 has max. 36MHz |
| 78 | + Rcc::setApb1Prescaler(Rcc::Apb1Prescaler::Div2); |
| 79 | + Rcc::setApb2Prescaler(Rcc::Apb2Prescaler::Div1); |
| 80 | + // update frequencies for busy-wait delay functions |
| 81 | + Rcc::updateCoreFrequency<Frequency>(); |
| 82 | + |
| 83 | + return true; |
| 84 | + } |
| 85 | +}; |
| 86 | + |
| 87 | +// Arduino Footprint |
| 88 | +#include "nucleo64_arduino.hpp" |
| 89 | + |
| 90 | +using Button = GpioInverted<GpioInputC13>; |
| 91 | +using LedD13 = D13; |
| 92 | + |
| 93 | +using Leds = SoftwareGpioPort< LedD13 >; |
| 94 | + |
| 95 | + |
| 96 | +namespace stlink |
| 97 | +{ |
| 98 | +using Rx = GpioInputA15; |
| 99 | +using Tx = GpioOutputA2; |
| 100 | +using Uart = Usart2; |
| 101 | +} |
| 102 | + |
| 103 | +using LoggerDevice = modm::IODeviceWrapper< stlink::Uart, modm::IOBuffer::BlockIfFull >; |
| 104 | + |
| 105 | + |
| 106 | +inline void |
| 107 | +initialize() |
| 108 | +{ |
| 109 | + SystemClock::enable(); |
| 110 | + SysTickTimer::initialize<SystemClock>(); |
| 111 | + |
| 112 | + stlink::Uart::connect<stlink::Tx::Tx, stlink::Rx::Rx>(); |
| 113 | + stlink::Uart::initialize<SystemClock, 115200_Bd>(); |
| 114 | +} |
| 115 | + |
| 116 | +} |
| 117 | + |
| 118 | +#endif // MODM_STM32_NUCLEO_F334R8_HPP |
0 commit comments