STM32 Bootloader
Customizable Bootloader for STM32 microcontrollers
bootloader.h
Go to the documentation of this file.
1 
16 #ifndef __BOOTLOADER_H
17 #define __BOOTLOADER_H
18 
28 #define STM32L4
29 
31 #define USE_CHECKSUM 0
32 
34 #define USE_WRITE_PROTECTION 0
35 
37 #define SET_VECTOR_TABLE 1
38 
45 #define CLEAR_RESET_FLAGS 1
46 
48 #define APP_ADDRESS (uint32_t)0x08008000
49 
51 #define END_ADDRESS (uint32_t)0x080FFFFB
52 
54 #define CRC_ADDRESS (uint32_t)0x080FFFFC
55 
57 #define SYSMEM_ADDRESS (uint32_t)0x1FFF0000
58 
59 /* End of configuration ------------------------------------------------------*/
60 
61 /* Includes ------------------------------------------------------------------*/
62 /* Include the appropriate header file */
63 #if defined(STM32L4)
64 #include "stm32l4xx.h"
65 #else
66 #error "Target MCU header file is not defined or unsupported."
67 #endif
68 
69 /* Defines -------------------------------------------------------------------*/
71 #define APP_SIZE (uint32_t)(((END_ADDRESS - APP_ADDRESS) + 3) / 4)
72 
74 #define FLASH_PAGE_NBPERBANK (256)
75 
76 /* MCU RAM information (to check whether flash contains valid application) */
77 #define RAM_BASE SRAM1_BASE
78 #define RAM_SIZE SRAM1_SIZE_MAX
80 /* Enumerations --------------------------------------------------------------*/
81 
83 {
84  BL_OK = 0,
91 };
92 
95 {
100 };
101 
102 /* Functions -----------------------------------------------------------------*/
103 uint8_t Bootloader_Init(void);
104 uint8_t Bootloader_Erase(void);
105 
106 uint8_t Bootloader_FlashBegin(void);
107 uint8_t Bootloader_FlashNext(uint64_t data);
108 uint8_t Bootloader_FlashEnd(void);
109 
110 uint8_t Bootloader_GetProtectionStatus(void);
111 uint8_t Bootloader_ConfigProtection(uint32_t protection);
112 
113 uint8_t Bootloader_CheckSize(uint32_t appsize);
114 uint8_t Bootloader_VerifyChecksum(void);
115 uint8_t Bootloader_CheckForApplication(void);
117 void Bootloader_JumpToSysMem(void);
118 
119 uint32_t Bootloader_GetVersion(void);
120 
121 #endif /* __BOOTLOADER_H */
BL_OBP_ERROR
@ BL_OBP_ERROR
Definition: bootloader.h:90
eFlashProtectionTypes
eFlashProtectionTypes
Definition: bootloader.h:94
Bootloader_VerifyChecksum
uint8_t Bootloader_VerifyChecksum(void)
This function verifies the checksum of application located in flash. If USE_CHECKSUM configuration pa...
Definition: bootloader.c:353
Bootloader_JumpToSysMem
void Bootloader_JumpToSysMem(void)
This function performs the jump to the MCU System Memory (ST Bootloader).
Definition: bootloader.c:439
BL_PROTECTION_RDP
@ BL_PROTECTION_RDP
Definition: bootloader.h:98
BL_SIZE_ERROR
@ BL_SIZE_ERROR
Definition: bootloader.h:86
Bootloader_FlashBegin
uint8_t Bootloader_FlashBegin(void)
Begin flash programming: this function unlocks the flash and sets the data pointer to the start of ap...
Definition: bootloader.c:100
Bootloader_GetProtectionStatus
uint8_t Bootloader_GetProtectionStatus(void)
This function returns the protection status of flash.
Definition: bootloader.c:171
Bootloader_CheckSize
uint8_t Bootloader_CheckSize(uint32_t appsize)
This function checks whether the new application fits into flash.
Definition: bootloader.c:338
BL_OK
@ BL_OK
Definition: bootloader.h:84
Bootloader_FlashEnd
uint8_t Bootloader_FlashEnd(void)
Finish flash programming: this function finalizes the flash programming by locking the flash.
Definition: bootloader.c:159
BL_ERASE_ERROR
@ BL_ERASE_ERROR
Definition: bootloader.h:88
Bootloader_Init
uint8_t Bootloader_Init(void)
This function initializes bootloader and flash.
Definition: bootloader.c:37
Bootloader_JumpToApplication
void Bootloader_JumpToApplication(void)
This function performs the jump to the user application in flash.
Definition: bootloader.c:410
Bootloader_Erase
uint8_t Bootloader_Erase(void)
This function erases the user application area in flash.
Definition: bootloader.c:56
BL_PROTECTION_WRP
@ BL_PROTECTION_WRP
Definition: bootloader.h:97
Bootloader_FlashNext
uint8_t Bootloader_FlashNext(uint64_t data)
Program 64bit data into flash: this function writes an 8byte (64bit) data chunk into the flash and in...
Definition: bootloader.c:120
BL_PROTECTION_NONE
@ BL_PROTECTION_NONE
Definition: bootloader.h:96
BL_CHKS_ERROR
@ BL_CHKS_ERROR
Definition: bootloader.h:87
Bootloader_ConfigProtection
uint8_t Bootloader_ConfigProtection(uint32_t protection)
This function configures the wirte protection of flash.
Definition: bootloader.c:263
eBootloaderErrorCodes
eBootloaderErrorCodes
Definition: bootloader.h:82
BL_NO_APP
@ BL_NO_APP
Definition: bootloader.h:85
Bootloader_GetVersion
uint32_t Bootloader_GetVersion(void)
This function returns the version number of the bootloader library. Semantic versioning is used for n...
Definition: bootloader.c:471
Bootloader_CheckForApplication
uint8_t Bootloader_CheckForApplication(void)
This function checks whether a valid application exists in flash. The check is performed by checking ...
Definition: bootloader.c:395
BL_WRITE_ERROR
@ BL_WRITE_ERROR
Definition: bootloader.h:89
BL_PROTECTION_PCROP
@ BL_PROTECTION_PCROP
Definition: bootloader.h:99