HAL FLASH How to Use ¶
- group FLASH_How_To_Use
-
This file provides firmware functions to manage the following functionalities of the Flash memory area
-
Initialization and De-initialization functions
-
Configuration functions
-
Process operation functions
-
IRQHandler functions
-
Callback functions
-
Status functions
Flash main features ¶
The flash memory interface manages accesses to flash memory, maximizing throughput to CPU, instruction cache and DMAs. It implements the flash memory erase and program operations as well as the read and write protection mechanisms. It also implements the security and privilege access control features. It is optimized in terms of power consumption with dedicated modes when the MCU is in low-power modes.
Up to 4 Mbytes of flash memory supporting read-while-write capability (RWW).
-
Dual bank architecture (bank 1 and bank 2)
-
Main memory: up to 2 Mbytes per bank
-
Information block: 64.5 Kbytes in bank 1 128-bit wide data read with prefetch
-
Standard and burst programming modes
-
Read, program and erase operations in all voltage ranges
-
10 kcycles endurance on all flash memory. 100 kcycles on up to 256 Kbytes per bank
-
Page erase, bank erase and mass erase (both banks)
-
Bank swapping: the user flash memory address mapping of each bank can be swapped.
-
Product security activated by TrustZone option bit (TZEN)
-
Device life cycle managed by readout protection option byte (RDP)
-
Four write protection areas (two per bank)
-
TrustZone support:
-
Two secure areas (1 per bank)
-
Two secure HDP (hide protection) areas part of the secure areas (one per bank)
-
Configurable protection against unprivileged accesses with flash page granularity
-
Error code correction: 9-bit ECC per 128-bit quad-word allowing two bits error detection and one bit error correction
-
Option-byte loader
-
Advanced low-power modes (low-power read mode, bank power-down mode)
Flash memory organization ¶
The flash memory has the following main features:
-
Capacity up to 4 Mbytes
-
Dual-bank mode:
-
up to 2 Mbytes per bank for main memory
-
8 Kbytes page size
-
137 bits wide data read and write (128 effective bits plus 9 ECC bits)
-
Page, bank and mass erase
-
Support read-while-write feature
-
Support bank shutdown feature for power consumption saving The flash memory is organized as follows:
-
Main memory block organized as two banks of up to 2 Mbytes each containing up to 256 pages of 8 Kbytes
-
An information block containing:
-
32 Kbytes for system memory. This area is immutable and reserved for use by STMicroelectronics. It contains the bootloader that is used to reprogram the flash memory through one of the user communication interfaces such as USB (DFU). The system memory is programmed by STMicroelectronics when the device is manufactured. For further details, refer to the application note STM32 microcontroller system memory boot mode (AN2606).
-
32 Kbytes immutable secure area containing the root security services (RSS and RSS library) developed by ST.
-
512 bytes OTP (one-time programmable) bytes for user data (32 quad-words). The OTP data cannot be erased and can be written only once.
-
option bytes for user configuration. Unlike user flash memory and system memory, it is not mapped to any memory address and can be accessed only through the flash register interface
How to use the Flash HAL module driver ¶
Initialization and De-initialization functions : ¶
-
Use HAL_FLASH_Init() to initialize the Flash handle and associate the physical instance.
-
Use HAL_FLASH_DeInit() to de-initialize the Flash instance, When called, the API wait for end of ongoing process and put the Flash state machine in idle state.
Configuration functions : ¶
-
Use HAL_FLASH_SetProgrammingMode() to set the programming mode. (After reset the Quad-word programming is selected).
-
Use HAL_FLASH_GetProgrammingMode() to get the programming mode.
Process operation functions : ¶
Polling mode operations : ¶
-
Use HAL_FLASH_ProgramByAddr() to program any Flash memory User area in polling mode using flash address according to selected programming mode.
-
Use HAL_FLASH_ProgramByAddrAdapt() to program any Flash memory User area in polling mode using flash address with adaptive programming mode. The adaptive mode allows to optimize Flash programming access versus remaining data size with ignoring Flash programming mode selected by HAL_FLASH_SetProgrammingMode() API.
-
Use HAL_FLASH_OTP_ProgramByAddr() to program any Flash memory OTP area in polling mode using flash OTP address according to selected programming mode.
-
Use HAL_FLASH_OTP_ProgramByAddrAdapt() to program any Flash memory OTP area in polling mode using flash OTP address with adaptive programming mode. The adaptive mode allows to optimize Flash programming access versus remaining data size with ignoring Flash programming mode selected by HAL_FLASH_SetProgrammingMode() API.
-
Use HAL_FLASH_EraseByAddr() to erase by address any Flash memory area in polling mode.
-
Use HAL_FLASH_ErasePage() to erase by page any Flash memory area in polling mode.
-
Use HAL_FLASH_EraseBank() to erase by bank any Flash memory area in polling mode.
-
Use HAL_FLASH_MassErase() to mass erase the entire Flash memory area in polling mode.
-
Use HAL_FLASH_NS_ProgramByAddr() to program any NSecure Flash memory User area from Secure context in polling mode using flash address according to selected programming mode.
-
Use HAL_FLASH_NS_ProgramByAddrAdapt() to program any NSecure Flash memory User area from Secure context in polling mode using flash address with adaptive programming mode. The adaptive mode allows to optimize Flash programming access versus remaining data size with ignoring Flash programming mode selected by HAL_FLASH_SetProgrammingMode() API.
-
Use HAL_FLASH_NS_OTP_ProgramByAddr() to program any Flash memory OTP area from Secure context in polling mode using flash OTP address according to selected programming mode.
-
Use HAL_FLASH_NS_OTP_ProgramByAddrAdapt() to program any Flash memory OTP area from Secure context in polling mode using flash OTP address with adaptive programming mode. The adaptive mode allows to optimize Flash programming access versus remaining data size with ignoring Flash programming mode selected by HAL_FLASH_SetProgrammingMode() API.
-
Use HAL_FLASH_NS_EraseByAddr() to erase by address any NSecure Flash memory area from Secure context in polling mode.
-
Use HAL_FLASH_NS_ErasePage() to erase by page any NSecure Flash memory area from Secure context in polling mode.
-
Use HAL_FLASH_NS_EraseBank() to erase by bank any NSecure Flash memory area from Secure context in polling mode.
-
Use HAL_FLASH_NS_MassErase() to mass erase the entire NSecure Flash memory area from Secure context in polling mode.
Interrupt mode operations : ¶
-
Configure the Flash interrupt priority using HAL_CORTEX_NVIC_SetPriority() function
-
Enable the Flash IRQ handler using HAL_CORTEX_NVIC_EnableIRQ() function
-
Use HAL_FLASH_RegisterProgramCpltCallback() to register the Flash program by address complete callback.
-
Use HAL_FLASH_RegisterEraseByAddrCpltCallback() to register the Flash erase by address complete callback.
-
Use HAL_FLASH_RegisterErasePageCpltCallback() to register the Flash erase by page complete callback.
-
Use HAL_FLASH_RegisterEraseBankCpltCallback() to register the Flash erase by bank complete callback.
-
Use HAL_FLASH_RegisterMassEraseCpltCallback() to register the Flash mass erase complete callback.
-
Use HAL_FLASH_RegisterErrorCallback() to register the Flash error callback.
-
Use HAL_FLASH_RegisterECCErrorCallback() to register the Flash ECC error callback.
-
Use HAL_FLASH_ProgramByAddr_IT() to program any Flash memory User area in interrupt mode using flash address according to selected programming mode.
-
Use HAL_FLASH_ProgramByAddrAdapt_IT() to program any Flash memory User area in interrupt mode using flash address with adaptive programming mode. The adaptive mode allows to optimize Flash programming access versus remaining data size with ignoring Flash programming mode selected by HAL_FLASH_SetProgrammingMode() API.
-
Use HAL_FLASH_OTP_ProgramByAddr_IT() to program any Flash memory OTP area in interrupt mode using flash OTP address according to selected programming mode.
-
Use HAL_FLASH_OTP_ProgramByAddrAdapt_IT() to program any Flash memory OTP area in interrupt mode using flash OTP address with adaptive programming mode. The adaptive mode allows to optimize Flash programming access versus remaining data size with ignoring Flash programming mode selected by HAL_FLASH_SetProgrammingMode() API.
-
Use HAL_FLASH_EraseByAddr_IT() to erase by address any Flash memory area in interrupt mode.
-
Use HAL_FLASH_ErasePage_IT() to erase by page any Flash memory area in interrupt mode.
-
Use HAL_FLASH_EraseBank_IT() to erase by bank any Flash memory area in interrupt mode.
-
Use HAL_FLASH_MassErase_IT() to mass erase the entire Flash memory area in interrupt mode.
-
Use HAL_FLASH_NS_ProgramByAddr_IT() to program any NSecure Flash memory User area from Secure context in interrupt mode using flash address according to selected programming mode.
-
Use HAL_FLASH_NS_ProgramByAddrAdapt_IT() to program any Flash memory User area from Secure context in interrupt mode using flash address with adaptive programming mode. The adaptive mode allows to optimize Flash programming access versus remaining data size with ignoring Flash programming mode selected by HAL_FLASH_SetProgrammingMode() API.
-
Use HAL_FLASH_NS_OTP_ProgramByAddr_IT() to program any Flash memory OTP area from Secure context in interrupt mode using flash OTP address according to selected programming mode.
-
Use HAL_FLASH_NS_OTP_ProgramByAddrAdapt_IT() to program any Flash memory OTP area from Secure context in interrupt mode using flash OTP address with adaptive programming mode. The adaptive mode allows to optimize Flash programming access versus remaining data size with ignoring Flash programming mode selected by HAL_FLASH_SetProgrammingMode() API.
-
Use HAL_FLASH_NS_EraseByAddr_IT() to erase by address any NSecure Flash memory area from Secure context in interrupt mode.
-
Use HAL_FLASH_NS_ErasePage() _IT() to erase by page any NSecure Flash memory area from Secure context in interrupt mode.
-
Use HAL_FLASH_NS_EraseBank() _IT() to erase by bank any NSecure Flash memory area from Secure context in interrupt mode.
-
Use HAL_FLASH_NS_MassErase() _IT() to mass erase the entire NSecure Flash memory area from Secure context in interrupt mode.
-
Use HAL_FLASH_IRQHandler() to handle any Flash interrupt.
-
Use HAL_FLASH_ProgramByAddr_IRQHandler() to handle any Flash program by address interrupt.
-
Use HAL_FLASH_EraseByAddr_IRQHandler() to handle any Flash erase by address interrupt.
-
Use HAL_FLASH_ErasePage_IRQHandler() to handle any Flash page erase interrupt.
-
Use HAL_FLASH_EraseBank_IRQHandler() to handle any Flash bank erase interrupt.
-
Use HAL_FLASH_MassErase_IRQHandler() to handle any Flash mass erase interrupt.
-
Use HAL_FLASH_ECC_IRQHandler() interrupt subroutines to handle any Flash ECC single error correction interrupt.
-
Use HAL_FLASH_NMI_IRQHandler() interrupt subroutine to handle any Flash NMI interrupt.
-
Use HAL_FLASH_NS_IRQHandler() to handle any NSecure Flash interrupt from Secure context.
-
Use HAL_FLASH_NS_ProgramByAddr_IRQHandler() to handle any NSecure Flash program by address interrupt from Secure context.
-
Use HAL_FLASH_NS_EraseByAddr_IRQHandler() to handle any NSecure Flash erase by address interrupt from Secure context.
-
Use HAL_FLASH_NS_ErasePage_IRQHandler() to handle any NSecure Flash page erase interrupt from Secure context.
-
Use HAL_FLASH_NS_EraseBank_IRQHandler() to handle any NSecure Flash bank erase interrupt from Secure context.
-
Use HAL_FLASH_NS_MassErase_IRQHandler() to handle any NSecure Flash mass erase interrupt from Secure context.
Status functions : ¶
-
Use HAL_FLASH_GetOperation() to get the last Flash ongoing operation.
-
Use HAL_FLASH_GetProgramOperationInfo() to get the last Flash programming operation information.
-
Use HAL_FLASH_GetEraseByAddrOperationInfo() to get the last Flash erase by address operation information.
-
Use HAL_FLASH_GetErasePageOperationInfo() to get the last Flash erase by page operation information.
-
Use HAL_FLASH_GetEraseBankOperationInfo() to get the last Flash erase by bank operation information.
-
Use HAL_FLASH_GetInterruptedByResetOperationInfo() to get the Flash interrupted by reset operation information.
-
Use HAL_FLASH_GetInfo() to get the Flash memory organization information.
-
Use HAL_FLASH_ECC_GetFailInfo() to get Flash ECC fail information.
-
Use HAL_FLASH_GetSizeByte() to get the total Flash size in bytes.
-
Use HAL_FLASH_GetBankNbr() to get the total Flash number of banks.
-
Use HAL_FLASH_GetBankSizeByte() to get the total Flash size per bank.
-
Use HAL_FLASH_GetUserFlashSizeByte() to get the User Flash size in bytes of any given bank.
-
Use HAL_FLASH_GetUserFlashPageNbr() to get the User Flash number of pages per bank.
-
Use HAL_FLASH_GetUserFlashPageSizeByte() to get the User Flash size of any given page.
-
Use HAL_FLASH_GetUserFlashAddrOffset() to get the User Flash offset address of any given page.
-
Use HAL_FLASH_GetState() to get the Flash current global state.
-
Use HAL_FLASH_GetLastErrorCodes() to get the Flash last error codes.
-
Use HAL_FLASH_SetUserData() to set the Flash User data within the handle.
-
Use HAL_FLASH_GetUserData() to get the Flash User data from the handle.
-