HAL FLASH How to Use

group FLASH_How_To_Use

The Flash memory interface manages CPU AHB C-Bus accesses to the Flash memory. It implements the erase and program Flash memory operations and the read and write protection mechanisms.

FLASH main features

The FLASH memory organization is based on a main area, an EDATA area and an information block.

  • The main flash memory block organized as two banks of up to 512 Kbytes each containing up to 64 pages of 8 Kbytes.

  • The EDATA memory block can be configured

    • to extend the user area, with two banks of 32 Kbytes each containing 16 pages of 2 Kbytes.

    • or to offer data flash area, with two banks of 24 Kbytes each containing 16 pages of 1.5 Kbytes.

  • The information block contains:

    • 32 Kbytes for system memory. It contains the bootloader that is used to reprogram the flash memory.

    • 32 Kbytes immutable secure area containing the root security services (RSS and RSS library).

    • 512 bytes OTP (one-time programmable). The OTP data cannot be erased and can be written only once.

    • Option bytes for user configuration. The FLASH_ITF module provides option bytes configuration functions.

Programming operation

  • The flash memory program operation can be performed 128, 64, 32, 16 or 8 bits at a time within the flash user memory areas.

  • The flash memory program operation can be performed 32 or 16 bits at a time within the flash data and OTP memory areas.

  • Programming in a previously programmed address is not allowed except if the data to write is full zero.

Erasing operation

  • The flash memory erase operation can be performed at page level.

  • The flash memory erase operation can be performed at bank level.

  • The flash memory erase operation can be performed on the whole flash memory.

How to use the FLASH HAL module driver

Initialization and De-initialization functions

  • For a given instance, use the HAL_FLASH_Init() function to initialize the FLASH handle and associate the physical instance.

  • Use the HAL_FLASH_DeInit() function to de-initialize FLASH. When called, the FLASH must be in reset.

Configuration functions

Process operation functions

Polling mode operations

Interrupt mode operations

Callback registration

When the compilation flag USE_HAL_FLASH_REGISTER_CALLBACKS is set to 1, the following functions allow to register the different FLASH callbacks:

When the compilation flag USE_HAL_FLASH_REGISTER_CALLBACKS is undefined or set to 0, the callback registration feature is not available and all callbacks are set to the following weak functions:

These weak functions can be redefined within user application if the callbacks are needed.

Status functions