STM32 Bootloader
Customizable Bootloader for STM32 microcontrollers
|
This file contains the bootloader configuration parameters, function prototypes and other required macros and definitions. More...
#include "stm32l4xx.h"
Go to the source code of this file.
Macros | |
#define | STM32L4 |
#define | USE_CHECKSUM 0 |
#define | USE_WRITE_PROTECTION 0 |
#define | SET_VECTOR_TABLE 1 |
#define | CLEAR_RESET_FLAGS 1 |
#define | APP_ADDRESS (uint32_t)0x08008000 |
#define | END_ADDRESS (uint32_t)0x080FFFFB |
#define | CRC_ADDRESS (uint32_t)0x080FFFFC |
#define | SYSMEM_ADDRESS (uint32_t)0x1FFF0000 |
#define | APP_SIZE (uint32_t)(((END_ADDRESS - APP_ADDRESS) + 3) / 4) |
#define | FLASH_PAGE_NBPERBANK (256) |
#define | RAM_BASE SRAM1_BASE |
#define | RAM_SIZE SRAM1_SIZE_MAX |
Enumerations | |
enum | eBootloaderErrorCodes { BL_OK = 0, BL_NO_APP, BL_SIZE_ERROR, BL_CHKS_ERROR, BL_ERASE_ERROR, BL_WRITE_ERROR, BL_OBP_ERROR } |
enum | eFlashProtectionTypes { BL_PROTECTION_NONE = 0, BL_PROTECTION_WRP = 0x1, BL_PROTECTION_RDP = 0x2, BL_PROTECTION_PCROP = 0x4 } |
Functions | |
uint8_t | Bootloader_Init (void) |
This function initializes bootloader and flash. More... | |
uint8_t | Bootloader_Erase (void) |
This function erases the user application area in flash. More... | |
uint8_t | Bootloader_FlashBegin (void) |
Begin flash programming: this function unlocks the flash and sets the data pointer to the start of application flash area. More... | |
uint8_t | Bootloader_FlashNext (uint64_t data) |
Program 64bit data into flash: this function writes an 8byte (64bit) data chunk into the flash and increments the data pointer. More... | |
uint8_t | Bootloader_FlashEnd (void) |
Finish flash programming: this function finalizes the flash programming by locking the flash. More... | |
uint8_t | Bootloader_GetProtectionStatus (void) |
This function returns the protection status of flash. More... | |
uint8_t | Bootloader_ConfigProtection (uint32_t protection) |
This function configures the wirte protection of flash. More... | |
uint8_t | Bootloader_CheckSize (uint32_t appsize) |
This function checks whether the new application fits into flash. More... | |
uint8_t | Bootloader_VerifyChecksum (void) |
This function verifies the checksum of application located in flash. If USE_CHECKSUM configuration parameter is disabled then the function always returns an error code. More... | |
uint8_t | Bootloader_CheckForApplication (void) |
This function checks whether a valid application exists in flash. The check is performed by checking the very first DWORD (4 bytes) of the application firmware. In case of a valid application, this DWORD must represent the initialization location of stack pointer - which must be within the boundaries of RAM. More... | |
void | Bootloader_JumpToApplication (void) |
This function performs the jump to the user application in flash. More... | |
void | Bootloader_JumpToSysMem (void) |
This function performs the jump to the MCU System Memory (ST Bootloader). More... | |
uint32_t | Bootloader_GetVersion (void) |
This function returns the version number of the bootloader library. Semantic versioning is used for numbering. More... | |
This file contains the bootloader configuration parameters, function prototypes and other required macros and definitions.
STM32 Bootloader Header
Definition in file bootloader.h.
#define APP_SIZE (uint32_t)(((END_ADDRESS - APP_ADDRESS) + 3) / 4) |
Size of application in DWORD (32bits or 4bytes)
Definition at line 71 of file bootloader.h.
#define FLASH_PAGE_NBPERBANK (256) |
Number of pages per bank in flash
Definition at line 74 of file bootloader.h.
#define RAM_BASE SRAM1_BASE |
Start address of RAM
Definition at line 77 of file bootloader.h.
#define RAM_SIZE SRAM1_SIZE_MAX |
RAM size in bytes
Definition at line 78 of file bootloader.h.
Bootloader error codes
Definition at line 82 of file bootloader.h.
Flash Protection Types
Enumerator | |
---|---|
BL_PROTECTION_NONE | No flash protection |
BL_PROTECTION_WRP | Flash write protection |
BL_PROTECTION_RDP | Flash read protection |
BL_PROTECTION_PCROP | Flash propietary code readout protection |
Definition at line 94 of file bootloader.h.
uint8_t Bootloader_CheckForApplication | ( | void | ) |
This function checks whether a valid application exists in flash. The check is performed by checking the very first DWORD (4 bytes) of the application firmware. In case of a valid application, this DWORD must represent the initialization location of stack pointer - which must be within the boundaries of RAM.
BL_OK | if first DWORD represents a valid stack pointer location |
BL_NO_APP | first DWORD value is out of RAM boundaries |
Definition at line 395 of file bootloader.c.
uint8_t Bootloader_CheckSize | ( | uint32_t | appsize | ) |
This function checks whether the new application fits into flash.
appsize | size of application |
BL_OK | if application fits into flash |
BL_SIZE_ERROR | if application does not fit into flash |
Definition at line 338 of file bootloader.c.
uint8_t Bootloader_ConfigProtection | ( | uint32_t | protection | ) |
This function configures the wirte protection of flash.
protection | protection type eFlashProtectionTypes |
BL_OK | upon success |
BL_OBP_ERROR | upon failure |
Definition at line 263 of file bootloader.c.
uint8_t Bootloader_Erase | ( | void | ) |
This function erases the user application area in flash.
BL_OK | upon success |
BL_ERR | upon failure |
Definition at line 56 of file bootloader.c.
uint8_t Bootloader_FlashBegin | ( | void | ) |
Begin flash programming: this function unlocks the flash and sets the data pointer to the start of application flash area.
BL_OK | is returned in every case |
Definition at line 100 of file bootloader.c.
uint8_t Bootloader_FlashEnd | ( | void | ) |
Finish flash programming: this function finalizes the flash programming by locking the flash.
BL_OK | is returned in every case |
Definition at line 159 of file bootloader.c.
uint8_t Bootloader_FlashNext | ( | uint64_t | data | ) |
Program 64bit data into flash: this function writes an 8byte (64bit) data chunk into the flash and increments the data pointer.
data | 64bit data chunk to be written into flash |
BL_OK | upon success |
BL_WRITE_ERROR | upon failure |
Definition at line 120 of file bootloader.c.
uint8_t Bootloader_GetProtectionStatus | ( | void | ) |
This function returns the protection status of flash.
Definition at line 171 of file bootloader.c.
uint32_t Bootloader_GetVersion | ( | void | ) |
This function returns the version number of the bootloader library. Semantic versioning is used for numbering.
Definition at line 471 of file bootloader.c.
uint8_t Bootloader_Init | ( | void | ) |
This function initializes bootloader and flash.
BL_OK | is returned in every case |
Definition at line 37 of file bootloader.c.
void Bootloader_JumpToApplication | ( | void | ) |
This function performs the jump to the user application in flash.
The function carries out the following operations:
Definition at line 410 of file bootloader.c.
void Bootloader_JumpToSysMem | ( | void | ) |
This function performs the jump to the MCU System Memory (ST Bootloader).
The function carries out the following operations:
Definition at line 439 of file bootloader.c.
uint8_t Bootloader_VerifyChecksum | ( | void | ) |
This function verifies the checksum of application located in flash. If USE_CHECKSUM configuration parameter is disabled then the function always returns an error code.
BL_OK | if calculated checksum matches the application checksum |
BL_CHKS_ERROR | upon checksum mismatch or when USE_CHECKSUM is disabled |
Definition at line 353 of file bootloader.c.