/** ****************************************************************************** * STM32L4 Bootloader ****************************************************************************** * @author Akos Pasztor * @file bootloader.h * @brief Bootloader header * This file contains the bootloader configuration parameters, * function prototypes and other required macros and definitions. * @see Please refer to README for detailed information. ****************************************************************************** * Copyright (c) 2018 Akos Pasztor. https://akospasztor.com ****************************************************************************** **/ #ifndef __BOOTLOADER_H #define __BOOTLOADER_H /*** Bootloader Configuration *************************************************/ #define USE_CHECKSUM 0 /* Check application checksum on startup */ #define USE_WRITE_PROTECTION 0 /* Enable write protection after performing in-app-programming */ #define SET_VECTOR_TABLE 1 /* Automatically set vector table location before launching application */ #define CLEAR_RESET_FLAGS 1 /* If enabled: bootloader clears reset flags. (This occurs only when OBL RST flag is active.) If disabled: bootloader does not clear reset flags, not even when OBL RST is active. */ #define APP_ADDRESS ADDR_FLASH_SECTOR_3 /* Start address of application space in flash */ #define END_ADDRESS (uint32_t)0x080FFFFB /* End address of application space (addr. of last byte) */ #define CRC_ADDRESS (uint32_t)0x080FFFFC /* Start address of application checksum in flash */ #define SYSMEM_ADDRESS (uint32_t)0x1FFF0000 /* Address of System Memory (ST Bootloader) */ /* Defines -------------------------------------------------------------------*/ #define FLASH_PAGE_NBPERBANK 256 /* Number of pages per bank in flash */ #define APP_SIZE (uint32_t)(((END_ADDRESS - APP_ADDRESS) + 3) / 4) /* Size of application in DWORD (32bits or 4bytes) */ #define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */ #define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */ #define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */ #define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */ #define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */ #define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */ #define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */ #define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */ #define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbytes */ #define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbytes */ #define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbytes */ #define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbytes */ #define ADDR_FLASH_SECTOR_12 ((uint32_t)0x08100000) /* flash sector 12 - 16kb */ #define ADDR_FLASH_SECTOR_13 ((uint32_t)0x08104000) /* flash sector 13 - 16kb */ #define ADDR_FLASH_SECTOR_14 ((uint32_t)0x08108000) /* flash sector 14 - 16kb */ #define ADDR_FLASH_SECTOR_15 ((uint32_t)0x0810c000) /* flash sector 15 - 16kb */ #define ADDR_FLASH_SECTOR_16 ((uint32_t)0x08110000) /* flash sector 16 - 64kb */ #define ADDR_FLASH_SECTOR_17 ((uint32_t)0x08120000) /* flash sector 17 - 128kb */ #define ADDR_FLASH_SECTOR_18 ((uint32_t)0x08140000) /* flash sector 18 - 128kb */ #define ADDR_FLASH_SECTOR_19 ((uint32_t)0x08160000) /* flash sector 19 - 128kb */ #define ADDR_FLASH_SECTOR_20 ((uint32_t)0x08180000) /* flash sector 20 - 128kb */ #define ADDR_FLASH_SECTOR_21 ((uint32_t)0x081A0000) /* flash sector 21 - 128kb */ #define ADDR_FLASH_SECTOR_22 ((uint32_t)0x081C0000) /* flash sector 22 - 128kb */ #define ADDR_FLASH_SECTOR_23 ((uint32_t)0x081E0000) /* flash sector 23 - 128kb */ /* Bootloader Error Codes */ enum { BL_OK = 0, BL_NO_APP, BL_SIZE_ERROR, BL_CHKS_ERROR, BL_ERASE_ERROR, BL_WRITE_ERROR, BL_OBP_ERROR }; /* Flash Protection Types */ enum { BL_PROTECTION_NONE = 0, BL_PROTECTION_WRP = 0x1, BL_PROTECTION_RDP = 0x2, BL_PROTECTION_PCROP = 0x4, }; /* Functions -----------------------------------------------------------------*/ uint32_t GetSector(uint32_t Address); void Bootloader_Init(void); uint8_t Bootloader_Erase(void); void Bootloader_FlashBegin(void); uint8_t Bootloader_FlashNext(uint32_t data); void Bootloader_FlashEnd(void); uint8_t Bootloader_GetProtectionStatus(void); uint8_t Bootloader_ConfigProtection(uint32_t protection); uint8_t Bootloader_CheckSize(uint32_t appsize); uint8_t Bootloader_VerifyChecksum(void); uint8_t Bootloader_CheckForApplication(void); void Bootloader_JumpToApplication(void); void Bootloader_JumpToSysMem(void); typedef void (*pFunction)(void); #endif /* __BOOTLOADER_H */