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
65/*
66
67Name: McciBootloaderBoard_Stm32h7b3iDk_systemInit()
68
69Function:
70 Initialize STM32H7B3I_DK module for bootloader.
71
72Definition:
73 McciBootloaderPlatform_SystemInitFn_t
74 McciBootloaderBoard_Stm32h7b3iDk_systemInit;
75
76 void McciBootloaderBoard_Stm32h7b3iDk_systemInit(
77 void
78 );
79
80Description:
81 We set up the CPU for reset state.
82
83 We then enable GPIOs for the LED (pin PI3) and initialize SysTick.
84
85Returns:
86 No explicit result.
87
88Notes:
89
90
91*/
92
93void
95 void
96 )
97 {
99
100 // enable GPIO port I
104 );
105
106 // set up GPIO port I3 as low speed
113 )
114 );
115
116 // set up GPIO port I3 as an output type push-pull
123 )
124 );
125
126 // set up GPIO port I3 as no pull
133 )
134 );
135
136 // set up GPIO port I3 as output
143 )
144 );
145
146 // clear I3
150 );
151
152 // set I3 and clear it, so we can see things on a scope
156 );
160 );
161
162 // init SysTick
165 (64000000 / 1000) /* system clock is 64MHz */
166 );
173 );
177 );
178 }
179
180void
188
189void
197
198void
200 {
201 for (++ms; ms > 0; --ms)
202 {
205 ;
206 }
207 }
208
209static void
211 {
214 ;
215 }
216
217void
219 McciBootloaderError_t errorCode
220 )
221 {
223 {
225 }
226 else
227 {
228 unsigned timeToReboot;
229
230 McciArm_disableInterrupts();
231 timeToReboot = 60 * 1000;
232
234
235 for (; timeToReboot > 0; --timeToReboot)
236 {
237 delayTick();
239 }
240
241 McciArm_DataSynchBarrier();
242
249 );
250
251 McciArm_DataSynchBarrier();
252 while (true)
253 /* spin till reset */;
254 }
255 }
256
257static void fastBlinkForever(void)
258 {
259 uint32_t rOdr;
260
262 while (true)
263 {
264 // blink the led
265 rOdr ^= UINT32_C(1) << MCCI_BOOTLOADER_LED_GPIO_PIN;
268 rOdr
269 );
271 }
272 }
273
274/**** 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
void McciBootloaderBoard_Stm32h7b3iDk_handleSysTick(void)
McciBootloaderPlatform_AnnunciatorIndicateStateFn_t McciBootloaderBoard_Stm32h7b3iDk_annunciatorIndicateState
void McciBootloader_Stm32h7_systemInit(void)
#define MCCI_BOOTLOADER_NORETURN_SFX
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)
void McciBootloaderBoard_Stm32h7b3iDk_fail(McciBootloaderError_t errorCode)
void McciBootloaderBoard_Stm32h7b3iDk_clearLed(void)