|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-2018, 2024, Niklas Hauser |
| 3 | + * Copyright (c) 2017, Nick Sarten |
| 4 | + * Copyright (c) 2017, Sascha Schade |
| 5 | + * |
| 6 | + * This file is part of the modm project. |
| 7 | + * |
| 8 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 9 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 10 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 11 | + */ |
| 12 | + |
| 13 | +#pragma once |
| 14 | + |
| 15 | +#include <modm/architecture.hpp> |
| 16 | +#include <modm/platform.hpp> |
| 17 | + |
| 18 | +using namespace modm::platform; |
| 19 | + |
| 20 | +namespace Board |
| 21 | +{ |
| 22 | +/// @ingroup modm_board_nucleo_c011f6 |
| 23 | +/// @{ |
| 24 | +using namespace modm::literals; |
| 25 | + |
| 26 | +/// STM32C011F6 running at 48MHz generated from the internal clock |
| 27 | +struct SystemClock |
| 28 | +{ |
| 29 | + static constexpr uint32_t Frequency = Rcc::HsiFrequency; |
| 30 | + static constexpr uint32_t Ahb = Frequency; |
| 31 | + static constexpr uint32_t Apb = Frequency; |
| 32 | + |
| 33 | + static constexpr uint32_t Adc1 = Apb; |
| 34 | + |
| 35 | + static constexpr uint32_t Spi1 = Apb; |
| 36 | + |
| 37 | + static constexpr uint32_t Usart1 = Apb; |
| 38 | + static constexpr uint32_t Usart2 = Apb; |
| 39 | + |
| 40 | + static constexpr uint32_t I2c1 = Apb; |
| 41 | + |
| 42 | + static constexpr uint32_t Timer1 = Apb; |
| 43 | + static constexpr uint32_t Timer2 = Apb; |
| 44 | + static constexpr uint32_t Timer3 = Apb; |
| 45 | + static constexpr uint32_t Timer14 = Apb; |
| 46 | + static constexpr uint32_t Timer16 = Apb; |
| 47 | + static constexpr uint32_t Timer17 = Apb; |
| 48 | + static constexpr uint32_t Iwdg = Rcc::LsiFrequency; |
| 49 | + static constexpr uint32_t Rtc = 32.768_kHz; |
| 50 | + |
| 51 | + static bool inline |
| 52 | + enable() |
| 53 | + { |
| 54 | + Rcc::enableLowSpeedExternalCrystal(); |
| 55 | + Rcc::enableRealTimeClock(Rcc::RealTimeClockSource::LowSpeedExternalCrystal); |
| 56 | + |
| 57 | + // 48MHz generated from internal RC |
| 58 | + Rcc::enableInternalClock(); |
| 59 | + Rcc::setHsiSysDivider(Rcc::HsiSysDivider::Div1); |
| 60 | + // set flash latency for 48MHz |
| 61 | + Rcc::setFlashLatency<Frequency>(); |
| 62 | + // switch system clock to PLL output |
| 63 | + Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1); |
| 64 | + Rcc::setApbPrescaler(Rcc::ApbPrescaler::Div1); |
| 65 | + // update frequencies for busy-wait delay functions |
| 66 | + Rcc::updateCoreFrequency<Frequency>(); |
| 67 | + |
| 68 | + return true; |
| 69 | + } |
| 70 | +}; |
| 71 | + |
| 72 | +using Button = GpioInputA14; // SWDCLK! |
| 73 | +using LedA4 = GpioInverted<GpioOutputA4>; |
| 74 | + |
| 75 | +using Leds = SoftwareGpioPort< LedA4 >; |
| 76 | +/// @} |
| 77 | + |
| 78 | +/// @ingroup modm_board_nucleo_c011f6 |
| 79 | +/// @{ |
| 80 | + |
| 81 | +inline void |
| 82 | +initialize() |
| 83 | +{ |
| 84 | + SystemClock::enable(); |
| 85 | + SysTickTimer::initialize<SystemClock>(); |
| 86 | +} |
| 87 | +/// @} |
| 88 | + |
| 89 | +} |
0 commit comments