MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mccibootloaderboard_catena1sj_eeprom.c
Go to the documentation of this file.
1/*
2
3Module: mccibootloaderboard_catena1sj_eeprom.c
4
5Function:
6 EEPROM variables and accessors for bootloader for Catenas based on 1SJ
7 and STM32L0.
8
9Copyright and License:
10 This file copyright (C) 2026 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 2026
20
21*/
22
24#include "mcci_stm32l0xx.h"
25␌
26/****************************************************************************\
27|
28| Manifest constants & typedefs.
29|
30\****************************************************************************/
31
32
33/****************************************************************************\
34|
35| Read-only data.
36|
37\****************************************************************************/
38
39
40
41/****************************************************************************\
42|
43| Variables.
44|
45\****************************************************************************/
46
47McciBootloaderBoard_Catena1sj_Eeprom_t *
49 {
50 ///
51 /// \brief base address of the bootloader EEPROM region (linker-defined).
52 ///
53 /// \details
54 /// This is hidden in this function because linker-defined symbols
55 /// are not really type-safe; so we use an accessor.
56 ///
57 extern volatile uint8_t g_McciBootloaderBoard_Catena1sj_EepromBase[];
58
59 /* convert to a pointer to the eeprom */
60 return (McciBootloaderBoard_Catena1sj_Eeprom_t *)
61 &g_McciBootloaderBoard_Catena1sj_EepromBase[0];
62 }
63
64bool
66 {
67 const McciBootloaderBoard_Catena1sj_Eeprom_t * const pEeprom = McciBootloaderBoard_Catena1sj_getEepromPointer();
68
69 if (pEeprom->fUpdateRequest == MCCI_BOOTLOADER_CATENA_1SJ_EEPROM_UPDATE_REQUEST)
70 return true;
71 else
72 return false;
73 }
74
75void
77 {
78 const McciBootloaderBoard_Catena1sj_Eeprom_t * const pEeprom = McciBootloaderBoard_Catena1sj_getEepromPointer();
79 uint32_t dwValue = fRequest ? MCCI_BOOTLOADER_CATENA_1SJ_EEPROM_UPDATE_REQUEST
80 : 0;
81
82 // if it's already set to the right value, just return.
83 if (pEeprom->fUpdateRequest == dwValue)
84 return;
85
86 // spin waiting for an operation
88 /* loop */;
89
90 // unlock
93
94 // the EEPROM should erase first, if needed.
95 // write data
96 McciArm_putReg((uint32_t)&pEeprom->fUpdateRequest, dwValue);
97
98 // wait for operation to complete
100 /* loop */;
101
102 // re-lock
106 );
107 }
108
109/**** end of mccibootloaderboard_catena1sj_eeprom.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
McciBootloaderPlatform_SetUpdateFlagFn_t McciBootloaderBoard_Catena1sj_setUpdate
#define MCCI_BOOTLOADER_CATENA_1SJ_EEPROM_UPDATE_REQUEST
the distinguished "update request" value
#define MCCI_STM32L0_REG_FLASH_PECR
Flash program and erase control register.
#define MCCI_STM32L0_REG_FLASH_PEKEYR_UNLOCK2
unlock word 2 for PECR
#define MCCI_STM32L0_REG_FLASH_PEKEYR
Flash PECR unlock key register.
#define MCCI_STM32L0_REG_FLASH_SR
Flash status register.
#define MCCI_STM32L0_REG_FLASH_PEKEYR_UNLOCK1
unlock word 1 for PECR
#define MCCI_STM32L0_REG_FLASH_SR_BSY
Busy doing write/erase.
#define MCCI_STM32L0_REG_FLASH_PECR_PELOCK
Lock the FLASH_PECR register.
McciBootloaderBoard_Catena1sj_Eeprom_t * McciBootloaderBoard_Catena1sj_getEepromPointer()
bool McciBootloaderBoard_Catena1sj_getUpdate(void)