HAL FLASH Overview

Introducing FLASH

group FLASH_Introduction

The FLASH IO Hardware Abstraction Layer (HAL) provides high-level, user-friendly APIs for managing non-volatile memory (FLASH) operations on STM32 microcontrollers.

This layer offers firmware functions to handle key FLASH functionalities, including:

  • Initialization and de-initialization of FLASH handling.

  • Programming operations across different FLASH memory areas.

  • Management of operation completion and error interrupt requests.

  • Retrieval of FLASH memory topology and configuration information.

The abstraction provided by this layer ensures portability and simplifies application development across various STM32 microcontroller series.

Module and files

The following diagram illustrates the FLASH module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the FLASH module. It shows the interactions between the user application, HAL drivers, low-level drivers, and the hardware components.


@startuml
<style>
componentDiagram {
   arrow {
      FontSize 8
   }
}
</style>

title FLASH IO Software Component Diagram

package "HAL" {
    [HAL_SERVICE]
    [HAL_FLASH]
}

package "Low Layer" {
    [LL_FLASH]
    [DFP]
    [FLASH IO Interrupt service routine]
}

package "HW" {
    [STM32_HW]
}

[Application] --> [HAL_FLASH] : HAL FLASH IO API
[Application] <-- [HAL_FLASH] : HAL FLASH IO callback

[HAL_FLASH] --> [LL_FLASH] : LL FLASH API
[HAL_FLASH] <-- [FLASH IO Interrupt service routine]
[HAL_FLASH] -l->  [HAL_SERVICE] : HAL_GetTick

[LL_FLASH] -->   [DFP]: FLASH registers definition
[STM32_HW] -u--> [FLASH IO Interrupt service routine] : FLASH_IRQHandler
[STM32_HW] <-u-  [LL_FLASH] : FLASH registers R/W
@enduml


@startuml
<style>
componentDiagram {
   arrow {
      FontSize 8
   }
}
</style>

title FLASH Interface Software Component Diagram

package "HAL" {
    [HAL_SERVICE]
    [HAL_FLASH_ITF]
}

package "Low Layer" {
    [LL_FLASH]
    [DFP]
    [FLASH ITF Interrupt service routine]
}

package "HW" {
    [STM32_HW]
}

[Application] --> [HAL_FLASH_ITF] : HAL FLASH ITF API
[Application] <-- [HAL_FLASH_ITF] : HAL FLASH ITF callback

[HAL_FLASH_ITF] --> [LL_FLASH] : LL FLASH API
[HAL_FLASH_ITF] <-- [FLASH ITF Interrupt service routine]
[HAL_FLASH_ITF] -l->  [HAL_SERVICE] : HAL_GetTick

[LL_FLASH] -->   [DFP]: FLASH registers definition
[STM32_HW] <-u-  [LL_FLASH] : FLASH registers R/W
[STM32_HW] -u--> [FLASH ITF Interrupt service routine] : FLASH_ITF_IRQHandler
@enduml

Configuration table

The following table lists the configuration defines for the HAL FLASH module, specifying their locations, default values, and descriptions:

group FLASH_Configuration_Table

Configuration inside the FLASH driver

Configuration defines

Description

Default value

Note

PRODUCT

from IDE

NA

The selected device (ex STM32C5xx).

USE_HAL_FLASH_MODULE

from hal_conf.h

1

Enables the HAL FLASH module.

USE_ASSERT_DBG_PARAM

from IDE

None

Enables assert check parameters.

USE_ASSERT_DBG_STATE

from IDE

None

Enables assert check states.

USE_HAL_CHECK_PARAM

from hal_conf.h

0

Enables run-time parameter checks.

USE_HAL_CHECK_PROCESS_STATE

from hal_conf.h

0

Enables load and store exclusive checks.

USE_HAL_FLASH_REGISTER_CALLBACKS

from hal_conf.h

0

Enables callback registration for FLASH.

USE_HAL_FLASH_CLK_ENABLE_MODEL

from hal_conf.h

HAL_CLK_ENABLE_NO

Enables the clock model for the FLASH.

USE_HAL_FLASH_GET_LAST_ERRORS

from hal_conf.h

0

Enables the error code mechanism.

USE_HAL_FLASH_USER_DATA

from hal_conf.h

0

Enables user data.

USE_HAL_FLASH_PROGRAM_BY_ADDR

from hal_conf.h

1

Enables program by address feature APIs.

USE_HAL_FLASH_ERASE_BY_ADDR

from hal_conf.h

1

Enables erase by address feature APIs.

USE_HAL_FLASH_ERASE_PAGE

from hal_conf.h

1

Enables erase by page feature APIs.

USE_HAL_FLASH_ERASE_BANK

from hal_conf.h

1

Enables erase by bank feature APIs.

USE_HAL_FLASH_MASS_ERASE

from hal_conf.h

1

Enables mass erase feature APIs.

USE_HAL_FLASH_ECC

from hal_conf.h

1

Enables ECC error handling APIs.

USE_HAL_FLASH_OB_EDATA

from hal_conf.h

0

Enables EDATA APIs. Value must be equal to EDATA_EN OB.

group FLASH_ITF_Configuration_Table

Configuration inside the FLASH ITF driver

Configuration defines

Description

Default value

Note

PRODUCT

from IDE

NA

The selected device (ex STM32C5xx).

USE_HAL_FLASH_MODULE

from hal_conf.h

1

Enables the HAL FLASH module.

USE_ASSERT_DBG_PARAM

from IDE

None

Enables assert check parameters.