Skip to content

Commit 210226a

Browse files
committed
[board] Add NUCLEO-H743ZI BSP
1 parent a537775 commit 210226a

File tree

4 files changed

+275
-3
lines changed

4 files changed

+275
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,20 +509,21 @@ We have out-of-box support for many development boards including documentation.
509509
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-g431rb">NUCLEO-G431RB</a></td>
510510
</tr><tr>
511511
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-g474re">NUCLEO-G474RE</a></td>
512+
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-h743zi">NUCLEO-H743ZI</a></td>
512513
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l031k6">NUCLEO-L031K6</a></td>
513514
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l152re">NUCLEO-L152RE</a></td>
514-
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l432kc">NUCLEO-L432KC</a></td>
515515
</tr><tr>
516+
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l432kc">NUCLEO-L432KC</a></td>
516517
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l452re">NUCLEO-L452RE</a></td>
517518
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l476rg">NUCLEO-L476RG</a></td>
518519
<td align="center"><a href="https://modm.io/reference/module/modm-board-nucleo-l496zg-p">NUCLEO-L496ZG-P</a></td>
519-
<td align="center"><a href="https://modm.io/reference/module/modm-board-olimexino-stm32">OLIMEXINO-STM32</a></td>
520520
</tr><tr>
521+
<td align="center"><a href="https://modm.io/reference/module/modm-board-olimexino-stm32">OLIMEXINO-STM32</a></td>
521522
<td align="center"><a href="https://modm.io/reference/module/modm-board-raspberrypi">Raspberry Pi</a></td>
522523
<td align="center"><a href="https://modm.io/reference/module/modm-board-samd21-mini">SAMD21-MINI</a></td>
523524
<td align="center"><a href="https://modm.io/reference/module/modm-board-stm32_f4ve">STM32-F4VE</a></td>
524-
<td align="center"><a href="https://modm.io/reference/module/modm-board-stm32f030_demo">STM32F030-DEMO</a></td>
525525
</tr><tr>
526+
<td align="center"><a href="https://modm.io/reference/module/modm-board-stm32f030_demo">STM32F030-DEMO</a></td>
526527
</tr>
527528
</table>
528529
<!--/bsptable-->
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/*
2+
* Copyright (c) 2021, Niklas Hauser
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+
#pragma once
13+
14+
#include <modm/platform.hpp>
15+
#include <modm/architecture/interface/clock.hpp>
16+
#include <modm/debug/logger.hpp>
17+
18+
using namespace modm::platform;
19+
20+
/// @ingroup modm_board_nucleo_h743zi
21+
/// @{
22+
#define MODM_BOARD_HAS_LOGGER
23+
24+
namespace Board
25+
{
26+
using namespace modm::literals;
27+
28+
/// STM32H743 running at 400MHz from the external 8MHz HSE
29+
struct SystemClock
30+
{
31+
// NOTE: revision Y at 400MHz, only revision V runs at 480Mhz!!!
32+
static constexpr uint32_t SysClk = 400_MHz;
33+
// Max 400MHz or 480MHz
34+
static constexpr uint32_t Hclk = SysClk / 1; // D1CPRE
35+
static constexpr uint32_t Frequency = Hclk;
36+
// Max 200MHz or 240MHz
37+
static constexpr uint32_t Ahb = Hclk / 2; // HPRE
38+
static constexpr uint32_t Ahb1 = Ahb;
39+
static constexpr uint32_t Ahb2 = Ahb;
40+
static constexpr uint32_t Ahb3 = Ahb;
41+
static constexpr uint32_t Ahb4 = Ahb;
42+
// Max 100MHz or 120MHz
43+
static constexpr uint32_t Apb1 = Ahb / 2; // D2PPRE1
44+
static constexpr uint32_t Apb2 = Ahb / 2; // D2PPRE2
45+
static constexpr uint32_t Apb3 = Ahb / 2; // D1PPRE
46+
static constexpr uint32_t Apb4 = Ahb / 2; // D3PPRE
47+
48+
static constexpr uint32_t Adc1 = Ahb1;
49+
static constexpr uint32_t Adc2 = Ahb1;
50+
static constexpr uint32_t Adc3 = Ahb4;
51+
52+
static constexpr uint32_t Dac1 = Apb1;
53+
54+
static constexpr uint32_t Spi1 = Apb2;
55+
static constexpr uint32_t Spi2 = Apb1;
56+
static constexpr uint32_t Spi3 = Apb1;
57+
static constexpr uint32_t Spi4 = Apb2;
58+
static constexpr uint32_t Spi5 = Apb2;
59+
static constexpr uint32_t Spi6 = Apb4;
60+
61+
static constexpr uint32_t Usart1 = Apb2;
62+
static constexpr uint32_t Usart2 = Apb1;
63+
static constexpr uint32_t Usart3 = Apb1;
64+
static constexpr uint32_t Uart4 = Apb1;
65+
static constexpr uint32_t Uart5 = Apb1;
66+
static constexpr uint32_t Usart6 = Apb2;
67+
static constexpr uint32_t Uart7 = Apb1;
68+
static constexpr uint32_t Uart8 = Apb1;
69+
70+
static constexpr uint32_t LpUart1 = Apb4;
71+
72+
static constexpr uint32_t Can1 = Apb1;
73+
static constexpr uint32_t Can2 = Apb1;
74+
75+
static constexpr uint32_t I2c1 = Apb1;
76+
static constexpr uint32_t I2c2 = Apb1;
77+
static constexpr uint32_t I2c3 = Apb1;
78+
static constexpr uint32_t I2c4 = Apb4;
79+
80+
static constexpr uint32_t Apb1Timer = Apb1 * 2;
81+
static constexpr uint32_t Apb2Timer = Apb2 * 2;
82+
static constexpr uint32_t Timer1 = Apb2Timer;
83+
static constexpr uint32_t Timer2 = Apb1Timer;
84+
static constexpr uint32_t Timer3 = Apb1Timer;
85+
static constexpr uint32_t Timer4 = Apb1Timer;
86+
static constexpr uint32_t Timer5 = Apb1Timer;
87+
static constexpr uint32_t Timer6 = Apb1Timer;
88+
static constexpr uint32_t Timer7 = Apb1Timer;
89+
static constexpr uint32_t Timer8 = Apb2Timer;
90+
static constexpr uint32_t Timer12 = Apb1Timer;
91+
static constexpr uint32_t Timer13 = Apb1Timer;
92+
static constexpr uint32_t Timer14 = Apb1Timer;
93+
static constexpr uint32_t Timer15 = Apb2Timer;
94+
static constexpr uint32_t Timer16 = Apb2Timer;
95+
static constexpr uint32_t Timer17 = Apb2Timer;
96+
97+
static constexpr uint32_t Usb = 48_MHz; // From PLL3Q
98+
99+
static bool inline
100+
enable()
101+
{
102+
Rcc::enableExternalClock(); // 8 MHz
103+
Rcc::setVoltageScaling(Rcc::VoltageScaling::Scale0); // required for 400MHz/480MHz
104+
const Rcc::PllFactors pllFactors1{
105+
.range = Rcc::PllInputRange::MHz4_8,
106+
.pllM = 2, // 8MHz / M= 4MHz
107+
.pllN = 100, // 4MHz * N= 400MHz
108+
.pllP = 1, // 400MHz / P= 400MHz = F_cpu
109+
.pllQ = 10, // 400MHz / Q= 40MHz
110+
.pllR = 10, // 400MHz / R= 40MHz
111+
};
112+
Rcc::enablePll1(Rcc::PllSource::ExternalClock, pllFactors1);
113+
// Use PLL3 for USB 48MHz
114+
const Rcc::PllFactors pllFactors3{
115+
.range = Rcc::PllInputRange::MHz4_8,
116+
.pllM = 2, // 8MHz / M= 4MHz
117+
.pllN = 60, // 4MHz * N= 240MHz
118+
.pllP = 5, // 240MHz / P= 48MHz
119+
.pllQ = 5, // 240MHz / Q= 48MHz = F_usb
120+
.pllR = 5, // 240MHz / R= 48MHz
121+
};
122+
Rcc::enablePll3(Rcc::PllSource::ExternalClock, pllFactors3);
123+
Rcc::setFlashLatency<Ahb>();
124+
// max 240MHz on AHB
125+
Rcc::setAhbPrescaler(Rcc::AhbPrescaler::Div2);
126+
// max 120MHz on APB
127+
Rcc::setApb1Prescaler(Rcc::Apb1Prescaler::Div2);
128+
Rcc::setApb2Prescaler(Rcc::Apb2Prescaler::Div2);
129+
Rcc::setApb3Prescaler(Rcc::Apb3Prescaler::Div2);
130+
Rcc::setApb4Prescaler(Rcc::Apb4Prescaler::Div2);
131+
// update clock frequencies
132+
Rcc::updateCoreFrequency<Hclk>();
133+
Rcc::enableUsbClockSource(Rcc::UsbClockSource::Pll3Q);
134+
// Switch the main clock source to PLL
135+
Rcc::enableSystemClock(Rcc::SystemClockSource::Pll1P);
136+
137+
return true;
138+
}
139+
};
140+
141+
// Arduino Footprint
142+
#include "nucleo144_arduino.hpp"
143+
144+
using Button = GpioInputC13;
145+
146+
using LedGreen = GpioOutputB0;
147+
using LedBlue = GpioOutputB7;
148+
using LedRed = GpioOutputB14;
149+
using Leds = SoftwareGpioPort< LedRed, LedBlue, LedGreen >;
150+
151+
namespace usb
152+
{
153+
using Vbus = GpioA9;
154+
using Id = GpioA10;
155+
using Dm = GpioA11;
156+
using Dp = GpioA12;
157+
158+
using Overcurrent = GpioInputG7; // OTG_FS_OverCurrent
159+
using Power = GpioOutputG6; // OTG_FS_PowerSwitchOn
160+
161+
using Device = UsbFs;
162+
}
163+
164+
namespace stlink
165+
{
166+
using Tx = GpioOutputD8;
167+
using Rx = GpioInputD9;
168+
using Uart = Usart3;
169+
}
170+
171+
using LoggerDevice = modm::IODeviceWrapper< stlink::Uart, modm::IOBuffer::BlockIfFull >;
172+
173+
174+
inline void
175+
initialize()
176+
{
177+
SystemClock::enable();
178+
SysTickTimer::initialize<SystemClock>();
179+
180+
stlink::Uart::connect<stlink::Tx::Tx, stlink::Rx::Rx>();
181+
stlink::Uart::initialize<SystemClock, 115200_Bd>();
182+
183+
LedGreen::setOutput(modm::Gpio::Low);
184+
LedBlue::setOutput(modm::Gpio::Low);
185+
LedRed::setOutput(modm::Gpio::Low);
186+
187+
Button::setInput();
188+
Button::setInputTrigger(Gpio::InputTrigger::RisingEdge);
189+
Button::enableExternalInterrupt();
190+
// Button::enableExternalInterruptVector(12);
191+
}
192+
193+
/// FIXME: USB does not work on this board.
194+
inline void
195+
initializeUsbFs()
196+
{
197+
usb::Device::initialize<SystemClock>();
198+
usb::Device::connect<usb::Dm::Dm, usb::Dp::Dp, usb::Id::Id>();
199+
usb::Id::configure(Gpio::InputType::Floating);
200+
201+
usb::Overcurrent::setInput();
202+
usb::Vbus::setInput();
203+
// Enable VBUS sense (B device) via pin PA9
204+
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
205+
}
206+
207+
}
208+
/// @}
209+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<library>
2+
<repositories>
3+
<repository>
4+
<path>../../../../repo.lb</path>
5+
</repository>
6+
</repositories>
7+
8+
<options>
9+
<option name="modm:target">stm32h743zit6/revY</option>
10+
11+
<option name="modm:platform:uart:3:buffer.tx">2048</option>
12+
</options>
13+
<modules>
14+
<module>modm:board:nucleo-h743zi</module>
15+
</modules>
16+
</library>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2016-2018, Niklas Hauser
5+
# Copyright (c) 2017, Fabian Greif
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+
def init(module):
15+
module.name = ":board:nucleo-h743zi"
16+
module.description = """\
17+
# NUCLEO-H743ZI
18+
19+
[Nucleo kit for STM32H743ZI](https://www.st.com/en/evaluation-tools/nucleo-h743zi.html)
20+
"""
21+
22+
def prepare(module, options):
23+
if not options[":target"].partname.startswith("stm32h743zit"):
24+
return False
25+
26+
module.depends(
27+
":debug",
28+
":architecture:clock",
29+
":platform:core",
30+
":platform:gpio",
31+
":platform:clock",
32+
":platform:uart:3",
33+
":platform:usb:fs")
34+
35+
return True
36+
37+
def build(env):
38+
env.outbasepath = "modm/src/modm/board"
39+
env.substitutions = {
40+
"with_logger": True,
41+
"with_assert": env.has_module(":architecture:assert")
42+
}
43+
env.template("../board.cpp.in", "board.cpp")
44+
env.copy('.')
45+
env.copy("../nucleo144_arduino.hpp", "nucleo144_arduino.hpp")
46+
env.collect(":build:openocd.source", "board/st_nucleo_h743zi.cfg");

0 commit comments

Comments
 (0)