MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mccibootloaderboard_stm32h7b3i_dk_systeminit.c
Go to the documentation of this file.
1/*
2
3Module: mccibootloaderboard_stm32h7b3i_dk_systeminit.c
4
5Function:
6 McciBootloaderBoard_Stm32h7b3iDk_systemInit() and system init logic for
7 STM32H7B3I_DK boards
8
9Copyright and License:
10 This file copyright (C) 2021 by
11
12 MCCI Corporation
13 3520 Krums Corners Road
14 Ithaca, NY 14850
15
16 See accompanying LICENSE file for copyright and license information.
17
18Author:
19 ChaeHee Won, MCCI Corporation June 2021
20
21*/
22
24
25#include "mcci_bootloader.h"
27#include "mcci_stm32h7xx.h"
28#include "mcci_arm_cm7.h"
29␌
30/****************************************************************************\
31|
32| Manifest constants & typedefs.
33|
34\****************************************************************************/
35
36#ifndef MCCI_BOOTLOADER_LED_GPIO /* PARAM */
37# define MCCI_BOOTLOADER_LED_GPIO MCCI_STM32H7_REG_GPIOI
38#endif
39
40#ifndef MCCI_BOOTLOADER_LED_GPIO_PIN /* PARAM */
41# define MCCI_BOOTLOADER_LED_GPIO_PIN 3
42#endif
43
45static void
48
49static void
50delayTick(void);
51
52/****************************************************************************\
53|
54| Read-only data.
55|
56\****************************************************************************/
57
58/****************************************************************************\
59|
60| Variables.
61|
62\****************************************************************************/
63
64/// the tick count for STM32h7b3i_dk platforms
65static volatile McciBootloader_Milliseconds_t s_tickCount;
66␌
67/*
68
69Name: McciBootloaderBoard_Stm32h7b3iDk_systemInit()
70
71Function:
72 Initialize STM32H7B3I_DK module for bootloader.
73
74Definition:
75 McciBootloaderPlatform_SystemInitFn_t
76 McciBootloaderBoard_Stm32h7b3iDk_systemInit;
77
78 void McciBootloaderBoard_Stm32h7b3iDk_systemInit(
79 void
80 );
81
82Description:
83 We set up the CPU for reset state.
84
85 We then enable GPIOs for the LED (pin PI3) and initialize SysTick.
86
87Returns:
88 No explicit result.
89
90Notes:
91
92
93*/
94
95void
97 void
98 )
99 {
101
102 // enable GPIO port I
106 );
107
108 // set up GPIO port I3 as low speed
115 )
116 );
117
118 // set up GPIO port I3 as an output type push-pull
125 )
126 );
127
128 // set up GPIO port I3 as no pull
135 )
136 );
137
138 // set up GPIO port I3 as output
145 )
146 );
147
148 // clear I3
152 );
153
154 // set I3 and clear it, so we can see things on a scope
158 );
162 );
163
164 // init SysTick
167 (64000000 / 1000) /* system clock is 64MHz */
168 );
175 );
179 );
180 }
181
182void
190
191void
199
200void
202 {
203 // TODO(tmm@mcci.com): this won't really work if clock interrupts
204 // are enabled. Condition this delay on "systick interrupts can happen";
205 // use the loop if they cannot, watch s_tickCount if they can.
206 for (++ms; ms > 0; --ms)
207 {
210 ;
211
212 ++s_tickCount;
213 }
214 }
215
216static void
221
222void
228
231 {
232 return s_tickCount;
233 }
234
235void
237 McciBootloaderError_t errorCode
238 )
239 {
241 {
243 }
244 else
245 {
246 unsigned timeToReboot;
247
248 McciArm_disableInterrupts();
249 timeToReboot = 60 * 1000;
250
252
253 for (; timeToReboot > 0; --timeToReboot)
254 {
255 delayTick();
257 }
258
259 McciArm_DataSynchBarrier();
260
267 );
268
269 McciArm_DataSynchBarrier();
270 while (true)
271 /* spin till reset */;
272 }
273 }
274
275static void fastBlinkForever(void)
276 {
277 uint32_t rOdr;
278
280 while (true)
281 {
282 // blink the led
283 rOdr ^= UINT32_C(1) << MCCI_BOOTLOADER_LED_GPIO_PIN;
286 rOdr
287 );
289 }
290 }
291
292/**** end of mccibootloaderboard_stm32h7b3i_dk_systeminit.c ****/
static uint32_t McciArm_putRegOr(uint32_t reg, uint32_t orVal)
or 32-bit values to a cm0plus register
static uint32_t McciArm_getReg(uint32_t reg)
read a 32-bit value from a cm0plus register
static uint32_t McciArm_putReg(uint32_t reg, uint32_t val)
write a 32-bit value to a cm0plus register
static uint32_t McciArm_putRegMasked(uint32_t reg, uint32_t maskVal, uint32_t modVal)
store to cm0plus register under mask
#define MCCI_CM7_SYSTICK_RVR
#define MCCI_CM7_SCB_AIRCR_SYSRESETREQ
System reset request.
#define MCCI_CM7_SCB_AIRCR_VECTKEY
Vector key.
#define MCCI_CM7_SCB_AIRCR
#define MCCI_CM7_SYSTICK_CSR_ENABLE
enable counter
#define MCCI_CM7_SYSTICK_CSR
#define MCCI_CM7_SYSTICK_CSR_TICKINT
enable tick exception
#define MCCI_CM7_SCB_AIRCR_VECTKEY_VALUE
Value to write to unlock register.
#define MCCI_CM7_SYSTICK_CSR_COUNTFLAG
timer has counted to zero
#define MCCI_CM7_SYSTICK_CVR
#define MCCI_CM7_SYSTICK_CSR_CLKSOURCE
use processor (not external) clock
@ McciBootloaderError_BootloaderNotValid
bootloader image isn't valid
#define MCCI_BOOTLOADER_FIELD_SET_VALUE(fmask, val)
McciBootloaderPlatform_DelayMsFn_t McciBootloaderBoard_Stm32h7b3iDk_delayMs
McciBootloaderPlatform_SystemInitFn_t McciBootloaderBoard_Stm32h7b3iDk_systemInit
McciBootloaderPlatform_AnnunciatorIndicateStateFn_t McciBootloaderBoard_Stm32h7b3iDk_annunciatorIndicateState
void McciBootloaderBoard_Stm32h7b3iDk_annunciatorHandleSysTick(void)
void McciBootloader_Stm32h7_systemInit(void)
#define MCCI_BOOTLOADER_NORETURN_SFX
uint32_t McciBootloader_Milliseconds_t
Time (in milliseconds)
uint32_t McciBootloaderError_t
error codes for the bootloader
#define MCCI_BOOTLOADER_NORETURN_PFX
#define MCCI_STM32H7_GPIO_OTYPE_PP
#define MCCI_STM32H7_GPIO_MODE_OUT
#define MCCI_STM32H7_GPIO_OSPEED_LOW
#define MCCI_STM32H7_REG_RCC_APB4ENR_SYSCFGEN
#define MCCI_STM32H7_GPIO_BSRR_BR_P(p)
compute port-bit reset mask for bit p.
#define MCCI_STM32H7_GPIO_BSRR
#define MCCI_STM32H7_GPIO_OSPEEDR
#define MCCI_STM32H7_GPIO_PUPD_NONE
#define MCCI_STM32H7_GPIO_OSPEED_P(p)
compute the mask for the mode bits for port bits 0..31
#define MCCI_STM32H7_REG_RCC_AHB4ENR_GPIOIEN
#define MCCI_STM32H7_GPIO_BSRR_BS_P(p)
compute port-bit set mask for bit p.
#define MCCI_STM32H7_GPIO_MODE_P(p)
compute the mask for the mode bits for port bits 0..31
#define MCCI_STM32H7_GPIO_PUPD_P(p)
compute the mask for the mode bits for port bits 0..31
#define MCCI_STM32H7_GPIO_PUPDR
#define MCCI_STM32H7_GPIO_MODER
#define MCCI_STM32H7_GPIO_ODR
#define MCCI_STM32H7_REG_RCC_AHB4ENR
AHB4 clock.
#define MCCI_STM32H7_REG_RCC_APB4ENR
APB4 clock.
#define MCCI_STM32H7_GPIO_OTYPE_P(p)
compute the mask for the mode bits for port bits 0..15
#define MCCI_STM32H7_GPIO_OTYPER
static MCCI_BOOTLOADER_NORETURN_PFX void fastBlinkForever(void)
void McciBootloaderBoard_Stm32h7b3iDk_setLed(void)
McciBootloader_Milliseconds_t McciBootloaderBoard_Stm32h7b3iDk_getMilliseconds(void)
void McciBootloaderBoard_Stm32h7b3iDk_fail(McciBootloaderError_t errorCode)
void McciBootloaderBoard_Stm32h7b3iDk_handleSysTick(void)
void McciBootloaderBoard_Stm32h7b3iDk_clearLed(void)