|
| 1 | +/* |
| 2 | + * Copyright (c) 2016-2018, 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 | +#ifndef MODM_STM32_NUCLEO_F072RB_HPP |
| 14 | +#define MODM_STM32_NUCLEO_F072RB_HPP |
| 15 | + |
| 16 | +#include <modm/platform.hpp> |
| 17 | +#include <modm/architecture/interface/clock.hpp> |
| 18 | +#include <modm/debug/logger.hpp> |
| 19 | +/// @ingroup modm_board_nucleo_f072rb |
| 20 | +#define MODM_BOARD_HAS_LOGGER |
| 21 | + |
| 22 | +using namespace modm::platform; |
| 23 | + |
| 24 | +/// @ingroup modm_board_nucleo_f072rb |
| 25 | +namespace Board |
| 26 | +{ |
| 27 | + using namespace modm::literals; |
| 28 | + |
| 29 | +/// STM32f072rb running at 48MHz generated from the internal 8MHz crystal |
| 30 | +// Dummy clock for devices |
| 31 | +struct SystemClock |
| 32 | +{ |
| 33 | + static constexpr int Frequency = 48_MHz; |
| 34 | + static constexpr uint32_t Ahb = Frequency; |
| 35 | + static constexpr uint32_t Apb = Frequency; |
| 36 | + |
| 37 | + static constexpr uint32_t Adc = Apb; |
| 38 | + static constexpr uint32_t Can = Apb; |
| 39 | + |
| 40 | + static constexpr uint32_t Spi1 = Apb; |
| 41 | + static constexpr uint32_t Spi2 = Apb; |
| 42 | + |
| 43 | + static constexpr uint32_t Usart1 = Apb; |
| 44 | + static constexpr uint32_t Usart2 = Apb; |
| 45 | + static constexpr uint32_t Usart3 = Apb; |
| 46 | + static constexpr uint32_t Usart4 = Apb; |
| 47 | + |
| 48 | + static constexpr uint32_t I2c1 = Apb; |
| 49 | + static constexpr uint32_t I2c2 = Apb; |
| 50 | + |
| 51 | + static constexpr uint32_t Timer1 = Apb; |
| 52 | + static constexpr uint32_t Timer2 = Apb; |
| 53 | + static constexpr uint32_t Timer3 = Apb; |
| 54 | + static constexpr uint32_t Timer6 = Apb; |
| 55 | + static constexpr uint32_t Timer7 = Apb; |
| 56 | + static constexpr uint32_t Timer14 = Apb; |
| 57 | + static constexpr uint32_t Timer15 = Apb; |
| 58 | + static constexpr uint32_t Timer16 = Apb; |
| 59 | + static constexpr uint32_t Timer17 = Apb; |
| 60 | + |
| 61 | + static constexpr uint32_t Usb = 48_MHz; |
| 62 | + |
| 63 | + static bool inline |
| 64 | + enable() |
| 65 | + { |
| 66 | + // Enable the internal 48MHz clock |
| 67 | + Rcc::enableInternalClockMHz48(); |
| 68 | + // set flash latency for 48MHz |
| 69 | + Rcc::setFlashLatency<Frequency>(); |
| 70 | + // Switch to the 48MHz clock |
| 71 | + Rcc::enableSystemClock(Rcc::SystemClockSource::InternalClockMHz48); |
| 72 | + // update frequencies for busy-wait delay functions |
| 73 | + Rcc::updateCoreFrequency<Frequency>(); |
| 74 | + |
| 75 | + return true; |
| 76 | + } |
| 77 | +}; |
| 78 | + |
| 79 | +// Arduino Uno Footprint |
| 80 | +#include "nucleo64_arduino.hpp" |
| 81 | + |
| 82 | +using Button = GpioInverted<GpioInputC13>; |
| 83 | +using LedD13 = D13; |
| 84 | + |
| 85 | +using Leds = SoftwareGpioPort< LedD13 >; |
| 86 | + |
| 87 | + |
| 88 | +namespace stlink |
| 89 | +{ |
| 90 | +using Rx = GpioInputA3; |
| 91 | +using Tx = GpioOutputA2; |
| 92 | +using Uart = Usart2; |
| 93 | +} |
| 94 | + |
| 95 | +using LoggerDevice = modm::IODeviceWrapper< stlink::Uart, modm::IOBuffer::BlockIfFull >; |
| 96 | + |
| 97 | + |
| 98 | +inline void |
| 99 | +initialize() |
| 100 | +{ |
| 101 | + SystemClock::enable(); |
| 102 | + SysTickTimer::initialize<SystemClock>(); |
| 103 | + |
| 104 | + stlink::Uart::connect<stlink::Tx::Tx, stlink::Rx::Rx>(); |
| 105 | + stlink::Uart::initialize<SystemClock, 115200_Bd>(); |
| 106 | +} |
| 107 | + |
| 108 | +} |
| 109 | + |
| 110 | +#endif // MODM_STM32_NUCLEO_F072RB_HPP |
0 commit comments