Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
board.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2021 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24/*
25 * Copyright (c) 2015-2018, Niklas Hauser
26 * Copyright (c) 2017, Sascha Schade
27 * Copyright (c) 2018, Antal Szabó
28 *
29 * This file is part of the modm project.
30 *
31 * This Source Code Form is subject to the terms of the Mozilla Public
32 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
34 */
35// ----------------------------------------------------------------------------
36
37#ifndef TAPROOT_BOARD_HPP_
38#define TAPROOT_BOARD_HPP_
39
40#ifndef PLATFORM_HOSTED
41#include "modm/architecture/interface/clock.hpp"
42#include "modm/platform.hpp"
43
44using namespace modm::platform;
45#else
46#include "modm/math/units.hpp"
47#endif
48
49namespace Board
50{
51using namespace modm::literals;
52
57{
58 static constexpr uint32_t Frequency = 168_MHz;
59 static constexpr uint32_t Ahb = Frequency;
60 static constexpr uint32_t Apb1 = Frequency / 4;
61 static constexpr uint32_t Apb2 = Frequency / 2;
62
63 static constexpr uint32_t Adc = Apb2;
64
65 static constexpr uint32_t Spi1 = Apb2;
66 static constexpr uint32_t Spi2 = Apb1;
67 static constexpr uint32_t Spi3 = Apb1;
68 static constexpr uint32_t Spi4 = Apb2;
69 static constexpr uint32_t Spi5 = Apb2;
70 static constexpr uint32_t Spi6 = Apb2;
71
72 static constexpr uint32_t Usart1 = Apb2;
73 static constexpr uint32_t Usart2 = Apb1;
74 static constexpr uint32_t Usart3 = Apb1;
75 static constexpr uint32_t Uart4 = Apb1;
76 static constexpr uint32_t Uart5 = Apb1;
77 static constexpr uint32_t Usart6 = Apb2;
78 static constexpr uint32_t Uart7 = Apb1;
79 static constexpr uint32_t Uart8 = Apb1;
80
81 static constexpr uint32_t Can1 = Apb1;
82 static constexpr uint32_t Can2 = Apb1;
83
84 static constexpr uint32_t I2c1 = Apb1;
85 static constexpr uint32_t I2c2 = Apb1;
86 static constexpr uint32_t I2c3 = Apb1;
87
88 static constexpr uint32_t Apb1Timer = Apb1 * 2;
89 static constexpr uint32_t Apb2Timer = Apb2 * 2;
90 static constexpr uint32_t Timer1 = Apb2Timer;
91 static constexpr uint32_t Timer2 = Apb1Timer;
92 static constexpr uint32_t Timer3 = Apb1Timer;
93 static constexpr uint32_t Timer4 = Apb1Timer;
94 static constexpr uint32_t Timer5 = Apb1Timer;
95 static constexpr uint32_t Timer6 = Apb1Timer;
96 static constexpr uint32_t Timer7 = Apb1Timer;
97 static constexpr uint32_t Timer8 = Apb2Timer;
98 static constexpr uint32_t Timer9 = Apb2Timer;
99 static constexpr uint32_t Timer10 = Apb2Timer;
100 static constexpr uint32_t Timer11 = Apb2Timer;
101 static constexpr uint32_t Timer12 = Apb1Timer;
102 static constexpr uint32_t Timer13 = Apb1Timer;
103 static constexpr uint32_t Timer14 = Apb1Timer;
104
105 static bool inline enable()
106 {
107#ifndef PLATFORM_HOSTED
108 Rcc::enableExternalCrystal(); // 12 MHz
109 Rcc::PllFactors pllF = {
110 6, // 12MHz / M=6 -> 2MHz
111 168, // 2MHz * N=168 -> 336MHz
112 2 // 336MHz / P=2 -> 168MHz = F_cpu
113 };
114 Rcc::enablePll(Rcc::PllSource::ExternalCrystal, pllF);
115
116 Rcc::setFlashLatency<Frequency>();
117 Rcc::enableSystemClock(Rcc::SystemClockSource::Pll);
118 Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div1);
119 Rcc::setApb1Prescaler(Rcc::Apb1Prescaler::Div4);
120 Rcc::setApb2Prescaler(Rcc::Apb2Prescaler::Div2);
121 Rcc::updateCoreFrequency<Frequency>();
122#endif
123
124 return true;
125 }
126};
127
128#ifndef PLATFORM_HOSTED
129
130// Initialize leds
131
132using LedRed = GpioOutputH12;
133using LedGreen = GpioOutputH11;
134using LedBlue = GpioOutputH10;
135using LedsPort = SoftwareGpioPort<GpioOutputH12, GpioOutputH11, GpioOutputH10>;
136
137
138// Initialize PWM pins
139
140using PWMOutPinC1 = GpioE9;
141using PWMOutPinC2 = GpioE11;
142using PWMOutPinC3 = GpioE13;
143using PWMOutPinC4 = GpioE14;
144using PWMOutPinC5 = GpioC6;
145using PWMOutPinC6 = GpioI6;
146using PWMOutPinC7 = GpioI7;
147using PWMOutPinBuzzer = GpioD14;
148using PWMOutPinImuHeater = GpioF6;
149
150using PWMOutPins = SoftwareGpioPort<PWMOutPinC1, PWMOutPinC2, PWMOutPinC3, PWMOutPinC4, PWMOutPinC5, PWMOutPinC6, PWMOutPinC7, PWMOutPinBuzzer, PWMOutPinImuHeater>;
151
152// Initialize digital input pins
153
154using DigitalInPinPF1 = GpioF1;
155using DigitalInPinPF0 = GpioF0;
156using DigitalInPinB12 = GpioB12;
157
158using DigitalInPins = SoftwareGpioPort<DigitalInPinPF1, DigitalInPinPF0, DigitalInPinB12>;
159
160// Initialize digital output pins
161
162using DigitalOutPinB13 = GpioB13;
163using DigitalOutPinB14 = GpioB14;
164using DigitalOutPinB15 = GpioB15;
165using DigitalOutPinLaser = GpioC8;
166
167using DigitalOutPins = SoftwareGpioPort<DigitalOutPinB13, DigitalOutPinB14, DigitalOutPinB15, DigitalOutPinLaser>;
168
169// gpio pins used for SPI communication to the onboard BMI088 IMU
170
171using ImuSck = GpioB3;
172using ImuMiso = GpioB4;
173using ImuMosi = GpioA7;
174using ImuCS1Accel = GpioA4;
175using ImuCS1Gyro = GpioB0;
176using ImuInt1Accel = GpioC4;
177using ImuInt1Gyro = GpioC5;
178using ImuHeater = GpioF6;
179using ImuSpiMaster = SpiMaster1;
180
181#endif
182
183inline void initialize()
184{
185 // init clock
187#ifndef PLATFORM_HOSTED
188 SysTickTimer::initialize<SystemClock>();
189#endif
190}
191
192} // namespace Board
193
194#endif // TAPROOT_BOARD_HPP_
Definition board.hpp:50
GpioOutputH12 LedRed
Definition board.hpp:132
GpioB3 ImuSck
Definition board.hpp:171
GpioA4 ImuCS1Accel
Definition board.hpp:174
SoftwareGpioPort< DigitalOutPinB13, DigitalOutPinB14, DigitalOutPinB15, DigitalOutPinLaser > DigitalOutPins
Definition board.hpp:167
GpioF0 DigitalInPinPF0
Definition board.hpp:155
SpiMaster1 ImuSpiMaster
Definition board.hpp:179
GpioC6 PWMOutPinC5
Definition board.hpp:144
GpioE13 PWMOutPinC3
Definition board.hpp:142
GpioF6 ImuHeater
Definition board.hpp:178
GpioOutputH10 LedBlue
Definition board.hpp:134
SoftwareGpioPort< DigitalInPinPF1, DigitalInPinPF0, DigitalInPinB12 > DigitalInPins
Definition board.hpp:158
GpioOutputH11 LedGreen
Definition board.hpp:133
GpioI7 PWMOutPinC7
Definition board.hpp:146
GpioE11 PWMOutPinC2
Definition board.hpp:141
SoftwareGpioPort< PWMOutPinC1, PWMOutPinC2, PWMOutPinC3, PWMOutPinC4, PWMOutPinC5, PWMOutPinC6, PWMOutPinC7, PWMOutPinBuzzer, PWMOutPinImuHeater > PWMOutPins
Definition board.hpp:150
void initialize()
Definition board.hpp:183
GpioE14 PWMOutPinC4
Definition board.hpp:143
GpioF1 DigitalInPinPF1
Definition board.hpp:154
GpioB12 DigitalInPinB12
Definition board.hpp:156
GpioA7 ImuMosi
Definition board.hpp:173
GpioF6 PWMOutPinImuHeater
Definition board.hpp:148
GpioB13 DigitalOutPinB13
Definition board.hpp:162
GpioD14 PWMOutPinBuzzer
Definition board.hpp:147
GpioC5 ImuInt1Gyro
Definition board.hpp:177
GpioI6 PWMOutPinC6
Definition board.hpp:145
GpioB4 ImuMiso
Definition board.hpp:172
GpioC4 ImuInt1Accel
Definition board.hpp:176
GpioB14 DigitalOutPinB14
Definition board.hpp:163
GpioB0 ImuCS1Gyro
Definition board.hpp:175
GpioE9 PWMOutPinC1
Definition board.hpp:140
SoftwareGpioPort< GpioOutputH12, GpioOutputH11, GpioOutputH10 > LedsPort
Definition board.hpp:135
GpioC8 DigitalOutPinLaser
Definition board.hpp:165
GpioB15 DigitalOutPinB15
Definition board.hpp:164
Definition board.hpp:57
static constexpr uint32_t Timer14
Definition board.hpp:103
static constexpr uint32_t Uart5
Definition board.hpp:76
static constexpr uint32_t Spi6
Definition board.hpp:70
static constexpr uint32_t Usart3
Definition board.hpp:74
static constexpr uint32_t Spi2
Definition board.hpp:66
static constexpr uint32_t Spi5
Definition board.hpp:69
static constexpr uint32_t Timer7
Definition board.hpp:96
static constexpr uint32_t Uart8
Definition board.hpp:79
static constexpr uint32_t Apb1
Definition board.hpp:60
static constexpr uint32_t Timer13
Definition board.hpp:102
static constexpr uint32_t I2c2
Definition board.hpp:85
static constexpr uint32_t Timer3
Definition board.hpp:92
static constexpr uint32_t Apb2
Definition board.hpp:61
static constexpr uint32_t Timer9
Definition board.hpp:98
static constexpr uint32_t Uart7
Definition board.hpp:78
static constexpr uint32_t Uart4
Definition board.hpp:75
static constexpr uint32_t Timer10
Definition board.hpp:99
static constexpr uint32_t Timer4
Definition board.hpp:93
static constexpr uint32_t I2c1
Definition board.hpp:84
static constexpr uint32_t Timer2
Definition board.hpp:91
static constexpr uint32_t Usart2
Definition board.hpp:73
static constexpr uint32_t Spi1
Definition board.hpp:65
static constexpr uint32_t Frequency
Definition board.hpp:58
static constexpr uint32_t Usart6
Definition board.hpp:77
static bool enable()
Definition board.hpp:105
static constexpr uint32_t Spi4
Definition board.hpp:68
static constexpr uint32_t Usart1
Definition board.hpp:72
static constexpr uint32_t Timer5
Definition board.hpp:94
static constexpr uint32_t Ahb
Definition board.hpp:59
static constexpr uint32_t Timer12
Definition board.hpp:101
static constexpr uint32_t Apb1Timer
Definition board.hpp:88
static constexpr uint32_t Adc
Definition board.hpp:63
static constexpr uint32_t Timer8
Definition board.hpp:97
static constexpr uint32_t Timer11
Definition board.hpp:100
static constexpr uint32_t Timer6
Definition board.hpp:95
static constexpr uint32_t Spi3
Definition board.hpp:67
static constexpr uint32_t Timer1
Definition board.hpp:90
static constexpr uint32_t Can2
Definition board.hpp:82
static constexpr uint32_t Can1
Definition board.hpp:81
static constexpr uint32_t I2c3
Definition board.hpp:86
static constexpr uint32_t Apb2Timer
Definition board.hpp:89