MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mccibootloader_stm32l0_prepareforlaunch.c
Go to the documentation of this file.
1/*
2
3Module: mccibootloader_stm32l0_prepareforlaunch.c
4
5Function:
6 McciBootloader_Stm32l0_prepareForLaunch()
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 Terry Moore, MCCI Corporation March 2021
19
20*/
21
23
24#include "mcci_stm32l0xx.h"
25
26/****************************************************************************\
27|
28| Manifest constants & typedefs.
29|
30\****************************************************************************/
31
32
33
34/****************************************************************************\
35|
36| Read-only data.
37|
38\****************************************************************************/
39
40
41
42/****************************************************************************\
43|
44| Variables.
45|
46\****************************************************************************/
47
48
49/*
50
51Name: McciBootloader_Stm32L0_prepareForLaunch()
52
53Function:
54 Return the STM32L0 to suitable config prior to launching app.
55
56Definition:
57 void McciBootloader_Stm32L0_prepareForLaunch(
58 void
59 );
60
61Description:
62 Reset all the peripherals, and switch back to default MSI clock.
63
64Returns:
65 No explicit result.
66
67Notes:
68 We don't scrub every possible bit.
69
70*/
71
72void
74 void
75 )
76 {
77 // reset the low-level peripherals (just in case)
80
83
86
89
90 // stop systick
95 );
96
97 // reset things to defaults
98 // scale MSI to 4194k
103 );
104
105 // make sure MSI is on
109 );
110
111 // wait for it to come up.
113 ;
114
115 // switch to MSI
119 );
120
121 /// wait for clock to switch
123 /* loop */;
124
125 // turn off other oscillators
133 );
134
135 // turn off HSI, HSE, PLL, etc.
143 );
144
145 // turn off HSI48
149 );
150
151 // now HSE is off so we can turn off HSEBYP
155 );
156
157 // clear out the PLL stuff
163 );
164
167 0
168 );
169
170 // Set ACR back to reset state: pre-read disabled, read buf enable,
171 // run mode == IDLE, RUN_PD == IDLE SLEEP_PD == IDLE, prefetch disabled,
172 // zero wait state. And this also locks the RUN_PD bit.
181 );
182 }
183
184/**** end of mccibootloader_stm32l0_prepareforlaunch.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_putRegClear(uint32_t reg, uint32_t clearVal)
clear out 32-bit values to a cm0plus register
#define MCCI_CM0PLUS_SYSTICK_CSR
#define MCCI_CM0PLUS_SYSTICK_CSR_ENABLE
enable counter
#define MCCI_CM0PLUS_SYSTICK_CSR_TICKINT
enable tick exception
static uint32_t McciArm_putRegMasked(uint32_t reg, uint32_t maskVal, uint32_t modVal)
store to cm0plus register under mask
#define MCCI_STM32L0_REG_RCC_CR_PLLON
#define MCCI_STM32L0_REG_RCC_CR
Clock control.
#define MCCI_STM32L0_REG_FLASH_ACR_DISAB_BUF
Disable read buffer.
#define MCCI_STM32L0_REG_RCC_CFGR_MCOSEL
#define MCCI_STM32L0_REG_FLASH_ACR_RUN_PD
power-down in run mode
#define MCCI_STM32L0_REG_RCC_CRRCR_HSI48ON
#define MCCI_STM32L0_REG_FLASH_ACR_PRFTEN
prefetch enable
#define MCCI_STM32L0_REG_RCC_AHBRSTR
AHB peripheral reset.
#define MCCI_STM32L0_REG_FLASH_ACR
Flash access control register.
#define MCCI_STM32L0_REG_RCC_CFGR_PLLSRC
#define MCCI_STM32L0_REG_RCC_CFGR_SWS
#define MCCI_STM32L0_REG_RCC_CFGR_PLLDIV
#define MCCI_STM32L0_REG_RCC_CR_MSIRDY
#define MCCI_STM32L0_REG_RCC_CFGR_HPRE
#define MCCI_STM32L0_REG_RCC_CFGR_PLLMUL
#define MCCI_STM32L0_REG_RCC_CFGR
Clock configuration.
#define MCCI_STM32L0_REG_RCC_APB2RSTR
APB2 peripheral reset.
#define MCCI_STM32L0_REG_RCC_ICSCR
Internal clock sources calibration.
#define MCCI_STM32L0_REG_RCC_APB1RSTR
APB1 peripheral reset.
#define MCCI_STM32L0_REG_RCC_CFGR_SWS_MSI
#define MCCI_STM32L0_REG_RCC_ICSCR_MSIRANGE
#define MCCI_STM32L0_REG_RCC_CFGR_PPRE2
#define MCCI_STM32L0_REG_RCC_CR_MSION
#define MCCI_STM32L0_REG_RCC_CR_HSI16DIVEN
#define MCCI_STM32L0_REG_RCC_CR_HSEBYP
#define MCCI_STM32L0_REG_RCC_CIER
Clock interrupt enable.
#define MCCI_STM32L0_REG_RCC_CFGR_MCOPRE
#define MCCI_STM32L0_REG_RCC_CRRCR
Clock recovery RC.
#define MCCI_STM32L0_REG_RCC_CFGR_SW
#define MCCI_STM32L0_REG_RCC_CR_CSSHSEON
#define MCCI_STM32L0_REG_FLASH_ACR_LATENCY
NVM latency: 1 wait state (not zero wait state)
#define MCCI_STM32L0_REG_RCC_ICSCR_MSIRANGE_4194k
#define MCCI_STM32L0_REG_RCC_CR_HSEON
#define MCCI_STM32L0_REG_FLASH_ACR_SLEEP_PD
power-down in sleep mode
#define MCCI_STM32L0_REG_RCC_CFGR_PPRE1
#define MCCI_STM32L0_REG_FLASH_ACR_PRE_READ
Enable pre-read.
#define MCCI_STM32L0_REG_RCC_IOPRSTR
GPIO reset.
#define MCCI_STM32L0_REG_RCC_CR_HSI16ON
void McciBootloader_Stm32L0_prepareForLaunch(void)