MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mccibootloaderboard_catenaabz_systeminit.c
Go to the documentation of this file.
1/*
2
3Module: mccibootloaderboard_catenaabz_systeminit.c
4
5Function:
6 McciBootloaderBoard_CatenaABZ_SystemInit() and system init logic for
7 MCCI Catenas based on Murata type-ABZ modules.
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 Terry Moore, MCCI Corporation March 2021
20
21*/
22
24
26#include "mcci_bootloader.h"
28#include "mcci_stm32l0xx.h"
29#include "mcci_arm_cm0plus.h"
30␌
31/****************************************************************************\
32|
33| Manifest constants & typedefs.
34|
35\****************************************************************************/
36
38static void
41
42static void
43delayTick(void);
44
45/****************************************************************************\
46|
47| Read-only data.
48|
49\****************************************************************************/
50
51/****************************************************************************\
52|
53| Variables.
54|
55\****************************************************************************/
56
57/// the tick count for ABZ platforms
58static volatile McciBootloader_Milliseconds_t s_tickCount;
59␌
60/*
61
62Name: McciBootloaderBoard_CatenaAbz_systemInit()
63
64Function:
65 Initialize MCCI Catena based on Murata ABZ module for bootloader.
66
67Definition:
68 McciBootloaderPlatform_SystemInitFn_t
69 McciBootloaderBoard_CatenaAbz_systemInit;
70
71 void McciBootloaderBoard_CatenaAbz_systemInit(
72 void
73 );
74
75Description:
76 We set up the CPU for 32 MHz operation (using stm32l0 initialization).
77
78 We then enable GPIOs for the LED (pin PB2).
79
80Returns:
81 No explicit result.
82
83Notes:
84
85
86*/
87
88void
90 void
91 )
92 {
94
95 // enable GPIO port B
99 );
100
101 // set up GPIO port B2 as an output
108 )
109 );
110
111 // clear B2
114 UINT32_C(1) << 2
115 );
116
117 // set B2 and clear it, so we can see things on a scope
120 UINT32_C(1) << 2
121 );
124 UINT32_C(1) << 2
125 );
126 }
127
128void
136
137void
145
146void
148 {
149 // TODO(tmm@mcci.com): this won't really work if clock interrupts
150 // are enabled. Condition this delay on "systick interrupts can happen";
151 // use the loop if they cannot, watch s_tickCount if they can.
152 for (++ms; ms > 0; --ms)
153 {
155 ;
156
157 ++s_tickCount;
158 }
159 }
160
161/// legacy routine to delay for one ms
162static void
167
168void
174
177 {
178 return s_tickCount;
179 }
180
181void
183 McciBootloaderError_t errorCode
184 )
185 {
188 else
189 {
190 unsigned timeToReboot;
191
192 McciArm_disableInterrupts();
193 timeToReboot = 60 * 1000;
194
196
197 for (; timeToReboot > 0; --timeToReboot)
198 {
199 delayTick();
201 }
202
203 McciArm_DataSynchBarrier();
204
211 );
212
213 McciArm_DataSynchBarrier();
214 while (true)
215 /* spin till reset */;
216 }
217 }
218
219static void fastBlinkForever(void)
220 {
222
223 while (true)
224 {
225 // blink the led
226 rOdr ^= UINT32_C(1) << 2;
229 }
230 }
231
232/**** end of mccibootloaderboard_catenaabz_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_CM0PLUS_SCB_AIRCR_SYSRESETREQ
#define MCCI_CM0PLUS_SYSTICK_CSR
#define MCCI_CM0PLUS_SCB_AIRCR
#define MCCI_CM0PLUS_SCB_AIRCR_VECTKEY_VALUE
Value to write to unlock regster.
static uint32_t McciArm_putRegMasked(uint32_t reg, uint32_t maskVal, uint32_t modVal)
store to cm0plus register under mask
#define MCCI_CM0PLUS_SYSTICK_CSR_COUNTFLAG
timer has counted to zero
#define MCCI_CM0PLUS_SCB_AIRCR_VECTKEY
Vector key.
@ McciBootloaderError_BootloaderNotValid
bootloader image isn't valid
#define MCCI_BOOTLOADER_FIELD_SET_VALUE(fmask, val)
McciBootloaderPlatform_DelayMsFn_t McciBootloaderBoard_CatenaAbz_delayMs
McciBootloaderPlatform_AnnunciatorIndicateStateFn_t McciBootloaderBoard_CatenaAbz_annunciatorIndicateState
void McciBootloaderBoard_CatenaAbz_annunciatorHandleSysTick(void)
McciBootloaderPlatform_SystemInitFn_t McciBootloaderBoard_CatenaAbz_systemInit
MCCI_BOOTLOADER_BEGIN_DECLS void McciBootloader_Stm32L0_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_STM32L0_GPIO_BSRR
#define MCCI_STM32L0_REG_RCC_IOPENR_IOPBEN
#define MCCI_STM32L0_REG_GPIOB
Section 9.4.12: GPIO register map (1K)
#define MCCI_STM32L0_GPIO_ODR
#define MCCI_STM32L0_GPIO_MODER
#define MCCI_STM32L0_REG_RCC_IOPENR
GPIO clock enable.
#define MCCI_STM32L0_GPIO_BRR
#define MCCI_STM32L0_GPIO_MODE_OUT
#define MCCI_STM32L0_GPIO_MODE_P(p)
compute the mask for the mode bits for port bits 0..15
static MCCI_BOOTLOADER_NORETURN_PFX void fastBlinkForever(void)
void McciBootloaderBoard_CatenaAbz_fail(McciBootloaderError_t errorCode)
void McciBootloaderBoard_CatenaAbz_clearLed(void)
static void delayTick(void)
legacy routine to delay for one ms
void McciBootloaderBoard_CatenaAbz_handleSysTick(void)
void McciBootloaderBoard_CatenaAbz_setLed(void)
McciBootloader_Milliseconds_t McciBootloaderBoard_CatenaAbz_getMilliseconds(void)