MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mccibootloader_stm32h7_systeminit.c
Go to the documentation of this file.
1/*
2
3Module: mccibootloader_stm32h7_systeminit.c
4
5Function:
6 McciBootloader_Stm32h7_systemInit()
7
8Copyright and License:
9 This file copyright (C) 2021 by
10
11 MCCI Corporation
12 3520 Krums Corners Road
13 Ithaca, NY 14850
14
15 See accompanying LICENSE file for copyright and license information.
16
17Author:
18 ChaeHee Won, MCCI Corporation July 2021
19
20*/
21
23
24#include "mcci_bootloader.h"
26#include "mcci_stm32h7xx.h"
27
28/****************************************************************************\
29|
30| Manifest constants & typedefs.
31|
32\****************************************************************************/
33
34
35
36/****************************************************************************\
37|
38| Read-only data.
39|
40\****************************************************************************/
41
42
43
44/****************************************************************************\
45|
46| Variables.
47|
48\****************************************************************************/
49
50
51/*
52
53Name: McciBootloader_Stm32h7_systemInit()
54
55Function:
56 Configure STM32H7 core for MCCI bootloader
57
58Definition:
59 void McciBootloader_Stm32h7_systemInit(
60 void
61 );
62
63Description:
64 Configure the STM32H7 core to run at 32 MHz, with the other
65 clocks configured in a suitable default way. Set up SYSTICK
66 to roll over every MS. Enable HSI16 clock, PLL, LSE.
67
68Returns:
69 No explicit result.
70
71Notes:
72 Assumes we have a 32 kHz crystal for the LSE clock.
73
74*/
75
76#define FUNCTION "McciBootloader_Stm32h7_systemInit"
77
78#define MCCI_STM32H7_PWR_SUPPLY_CONFIG_MASK \
79 (MCCI_STM32H7_REG_PWR_CR3_SMPSLEVEL | \
80 MCCI_STM32H7_REG_PWR_CR3_SMPSEXTHP | \
81 MCCI_STM32H7_REG_PWR_CR3_SMPSEN | \
82 MCCI_STM32H7_REG_PWR_CR3_LDOEN | \
83 MCCI_STM32H7_REG_PWR_CR3_BYPASS)
84
85#define MCCI_STM32H7_PWR_SUPPLY_LDO MCCI_STM32H7_REG_PWR_CR3_LDOEN
86#define MCCI_STM32H7_PWR_SUPPLY_DIRECT_SMPS MCCI_STM32H7_REG_PWR_CR3_SMPSEN
87#define MCCI_STM32H7_PWR_SUPPLY_SMPS_1V8_LDO (MCCI_STM32H7_REG_PWR_CR3_SMPSLEVEL_1_8V | \
88 MCCI_STM32H7_REG_PWR_CR3_SMPSEN | \
89 MCCI_STM32H7_REG_PWR_CR3_LDOEN)
90#define MCCI_STM32H7_PWR_SUPPLY_SMPS_2V5_LDO (MCCI_STM32H7_REG_PWR_CR3_SMPSLEVEL_2_5V | \
91 MCCI_STM32H7_REG_PWR_CR3_SMPSEN | \
92 MCCI_STM32H7_REG_PWR_CR3_LDOEN)
93#define MCCI_STM32H7_PWR_SUPPLY_SMPS_1V8_EXT (MCCI_STM32H7_REG_PWR_CR3_SMPSLEVEL_1_8V | \
94 MCCI_STM32H7_REG_PWR_CR3_SMPSEN | \
95 MCCI_STM32H7_REG_PWR_CR3_SMPSEXTHP | \
96 MCCI_STM32H7_REG_PWR_CR3_BYPASS)
97#define MCCI_STM32H7_PWR_SUPPLY_SMPS_2V5_EXT (MCCI_STM32H7_REG_PWR_CR3_SMPSLEVEL_2_5V | \
98 MCCI_STM32H7_REG_PWR_CR3_SMPSEN | \
99 MCCI_STM32H7_REG_PWR_CR3_SMPSEXTHP | \
100 MCCI_STM32H7_REG_PWR_CR3_BYPASS)
101#define MCCI_STM32H7_PWR_SUPPLY_SMPS_1V8_EXTLDO (MCCI_STM32H7_REG_PWR_CR3_SMPSLEVEL_1_8V | \
102 MCCI_STM32H7_REG_PWR_CR3_SMPSEN | \
103 MCCI_STM32H7_REG_PWR_CR3_SMPSEXTHP | \
104 MCCI_STM32H7_REG_PWR_CR3_LDOEN)
105#define MCCI_STM32H7_PWR_SUPPLY_SMPS_2V5_EXTLDO (MCCI_STM32H7_REG_PWR_CR3_SMPSLEVEL_2_5V | \
106 MCCI_STM32H7_REG_PWR_CR3_SMPSEN | \
107 MCCI_STM32H7_REG_PWR_CR3_SMPSEXTHP | \
108 MCCI_STM32H7_REG_PWR_CR3_LDOEN)
109#define MCCI_STM32H7_PWR_SUPPLY_EXTERNAL_SOURCE MCCI_STM32H7_REG_PWR_CR3_BYPASS
110
111#ifndef MCCI_STM32H7_PWR_SUPPLY_CONFIG /* PARAM */
112# define MCCI_STM32H7_PWR_SUPPLY_CONFIG MCCI_STM32H7_PWR_SUPPLY_LDO
113#endif
114
115void
117 {
118 // mask off interrupts, discarding prior state.
119 (void) McciArm_disableInterrupts();
120
121 // presumably we got here via the boot vector, but load the
122 // vector table anyway
126 );
127
128 // use reset things to defaults
129 uint32_t r;
130
131 /* Increase flash wait states */
135 {
140 );
141 }
142
143 /* Set HSION */
147 );
148
149 /* Reset CFGR register */
151
152 /* Reset HSEON, HSECSSON, CSION, HSI48ON, CSIKERON, PLL1ON, PLL2ON and PLL3ON */
154 McciArm_putReg(MCCI_STM32H7_REG_RCC_CR, r & 0xEAF6ED7FU);
155
156 /* Decrease flash wait states */
160 {
165 );
166 }
167
168 /* Reset CDCFGR1, CDCFGR2 and SRDCFGR register */
172
173 /* Reset PLLCKSELR register */
175
176 /* Reset PLLCFGR register */
178
179 /* Reset PLL1DIVR register */
181
182 /* Reset PLL1FRACR register */
184
185 /* Reset PLL2DIVR register */
187
188 /* Reset PLL2FRACR register */
190
191 /* Reset PLL3DIVR register */
193
194 /* Reset PLL3FRACR register */
196
197 /* Reset HSEBYP bit */
199 McciArm_putReg(MCCI_STM32H7_REG_RCC_CR, r & 0xFFFBFFFFU);
200
201 /* Disable all interrupts */
203
204#ifdef MCCI_STM32H7_INIT_POWER_SUPPLY
211 {
214 {
215 /* can't apply new supply config */
216 }
217 else
218 {
219 /* matched supply config */
220 }
221 }
222 else
223 {
228 );
229
230 do {
232 } while ((r & MCCI_STM32H7_REG_PWR_CSR1_ACTVOSRDY) == 0);
233
238 {
239 do {
241 } while ((r & MCCI_STM32H7_REG_PWR_CR3_SMPSEXTRDY) == 0);
242 }
243 }
244
250 );
251
252 do {
254 } while ((r & MCCI_STM32H7_REG_PWR_SRDCR_VOSRDY) == 0);
255#endif /* MCCI_STM32H7_INIT_POWER_SUPPLY */
256 }
257
258#undef FUNCTION
259
260/**** end of mccibootloader_stm32h7_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
#define MCCI_CM7_SCB_VTOR
const McciBootloader_CortexPageZero_t gk_McciBootloader_CortexVectors
the CortexM0 vectors for the boot loader.
#define MCCI_STM32H7_REG_RCC_CDCFGR1
CPU domain clock configuration.
#define MCCI_STM32H7_REG_PWR_SRDCR_VOS_SCALE1
scale 1
#define MCCI_STM32H7_REG_PWR_CR3_LDOEN
low drop-out regulator enable
#define MCCI_STM32H7_REG_PWR_SRDCR
SmartRun domain control.
#define MCCI_STM32H7_REG_RCC_PLL1DIVR
PLL1 dividers configuration.
#define MCCI_STM32H7_REG_PWR_CR3_SMPSEXTRDY
SMPS step-down converter external supply ready.
#define MCCI_STM32H7_REG_PWR_CSR1
control status
#define MCCI_STM32H7_REG_RCC_PLL2FRACR
PLL2 fractional divider.
#define MCCI_STM32H7_REG_RCC_CIER
clock source interrupt enable
#define MCCI_STM32H7_REG_RCC_CR_HSION
#define MCCI_STM32H7_REG_FLASH_ACR_LATENCY
Read latency:
#define MCCI_STM32H7_REG_PWR_CSR1_ACTVOSRDY
Regulator low-power flag.
#define MCCI_STM32H7_REG_RCC_PLL1FRACR
PLL1 fractional divider.
#define MCCI_STM32H7_REG_FLASH_ACR_LATENCY_V(n)
Read latency: n wait state.
#define MCCI_STM32H7_REG_RCC_PLL3FRACR
PLL4 fractional divider.
#define MCCI_STM32H7_REG_FLASH_ACR
Flash access control register.
#define MCCI_STM32H7_REG_RCC_CDCFGR2
CPU domain clock configuration.
#define MCCI_STM32H7_REG_RCC_PLLCFGR
PLLs configuration.
#define MCCI_STM32H7_REG_RCC_PLL3DIVR
PLL3 dividers configuration.
#define MCCI_STM32H7_REG_PWR_SRDCR_VOS
voltage scaling selection according to performance
#define MCCI_STM32H7_REG_PWR_CR3
control 3
#define MCCI_STM32H7_REG_PWR_CR3_BYPASS
power management unit bypass
#define MCCI_STM32H7_REG_RCC_CFGR
Clock configuration.
#define MCCI_STM32H7_REG_PWR_SRDCR_VOSRDY
VOS ready bit for VCORE voltage scaling output selection.
#define MCCI_STM32H7_REG_RCC_SRDCFGR
SmartRun domain clock configuration.
#define MCCI_STM32H7_REG_RCC_PLLCKSELR
PLLs clock source selection.
#define MCCI_STM32H7_REG_PWR_CR3_SMPSEN
SMPS step-down converter enable.
#define MCCI_STM32H7_REG_RCC_PLL2DIVR
PLL2 dividers configuration.
#define MCCI_STM32H7_REG_RCC_CR
source control
#define MCCI_STM32H7_PWR_SUPPLY_SMPS_1V8_EXTLDO
#define MCCI_STM32H7_PWR_SUPPLY_CONFIG_MASK
void McciBootloader_Stm32h7_systemInit(void)
#define MCCI_STM32H7_PWR_SUPPLY_SMPS_1V8_EXT
#define MCCI_STM32H7_PWR_SUPPLY_SMPS_2V5_EXTLDO
#define MCCI_STM32H7_PWR_SUPPLY_CONFIG
#define MCCI_STM32H7_PWR_SUPPLY_SMPS_2V5_EXT