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.

group FLASH_ITF_Introduction

The FLASH ITF Hardware Abstraction Layer (HAL) provides high-level, user-friendly interface APIs for managing non-volatile memory (FLASH) configuration and control on STM32 microcontrollers.

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

  • Lock and unlock management.

  • Control operations.

  • Option byte configuration.

  • Option byte process interrupt handling.

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
top to bottom direction
hide stereotype
skinparam DefaultFontName Arial
skinparam linetype polyline
skinparam nodesep 45
skinparam ranksep 55

' Corporate color chart
!$C_DARK_BLUE = "#03234B"
!$C_DARK_BLUE_75 = "#425A78"
!$C_DARK_BLUE_50 = "#8191A5"
!$C_DARK_BLUE_25 = "#C0C8D2"
!$C_LIGHT_BLUE = "#3CB4E6"
!$C_LIGHT_BLUE_75 = "#6DC6ED"
!$C_LIGHT_BLUE_50 = "#9EDAF3"
!$C_LIGHT_BLUE_25 = "#CEEDF9"
!$C_YELLOW = "#FFD200"
!$C_PINK = "#E6007E"
!$C_DARK_GREY = "#525A63"

!$USE_COLOR = 0

' Default mapping
' - outside boxes (packages): dark blue
' - inside boxes/components/interfaces: light blue
' - highlight boxes: <<highlight>> stereotype (yellow)
' - primary connectors: pink
' - secondary connectors: use explicit color -[#525A63]->
!if ($USE_COLOR == 1)
skinparam PackageBackgroundColor $C_LIGHT_BLUE_25
skinparam PackageBorderColor $C_DARK_BLUE_50
skinparam PackageFontColor $C_DARK_BLUE

skinparam DefaultFontColor $C_DARK_BLUE
skinparam TitleFontColor $C_DARK_BLUE
skinparam LegendFontColor $C_DARK_BLUE
skinparam NoteFontColor $C_DARK_BLUE

skinparam ComponentBackgroundColor $C_LIGHT_BLUE
skinparam ComponentBorderColor $C_LIGHT_BLUE_25
skinparam ComponentFontColor $C_LIGHT_BLUE_25

skinparam InterfaceBackgroundColor $C_LIGHT_BLUE
skinparam InterfaceBorderColor $C_LIGHT_BLUE_25
skinparam InterfaceFontColor $C_DARK_BLUE

skinparam ArrowColor $C_PINK
skinparam ArrowFontColor $C_DARK_BLUE

skinparam component<<highlight>> {
BackgroundColor $C_YELLOW
BorderColor $C_DARK_BLUE
FontColor $C_DARK_BLUE
}
!endif
' The Driver name to be customized according to the driver
' Example CRC, I2C, NVM, FLASH, ....
!$ppp = "FLASH"

' The HAL driver use a core driver - default value 0
!$use_ppp_core = 0

' When using a core driver : the core driver name
!$core = "XXX" + "_CORE"

' enable/disable LL RCC interfaces depandencies - default value 0
!$use_ll_rcc = 0

' the driver provide an LL layer : default value 1
' Set to 0 if core is set to 1
!if ($use_ppp_core == 1)
!$use_ppp_ll = 0
!else
!$use_ppp_ll = 1
!endif
' the driver provide a HAL Layer : default value 1
!$use_ppp_hal = 1

' the HAL driver use HAL services : default value 1
!$use_hal_service = 1

' the HAL driver use HAL RCC services : default value 1
!$use_hal_rcc = 0

' the HAL driver use HAL DMA services : default value 1
!$use_hal_dma = 0

' The driver use HAL_RCC_PPP_GetClockFreq()
!$use_kernel_clock = 1

' HAL driver use depandencies with generic instead of interfaces
!$use_hal_generic_dep = 0

' The driver use interrupts : default value 1
' Example CCB --> no interrupts
!$use_ppp_isr = 1

' The driver use an extented file : default value 0
' Example of Usage NVM, FLASH
!$use_hal_ppp_extend = 1

' The HAL Driver extension name
!$ppp_extend = "ITF"

' The HAL Driver interface
!$hal_api_itf = "HAL " + $ppp + " IO API"

' The HAL Driver extended interface
!$hal_api_ext_itf = "\n\tHAL " + $ppp + " " + $ppp_extend + " API"

' The Use Application Interface
!$appli_itf = $ppp+ " IO User Callback"
!$appli_ext_itf = "\n" + $ppp+ " " + $ppp_extend + " User Callback"

' The HAL PPP name
!$ppp_name = "HAL_" + $ppp
!$ppp_ext_name = "HAL_" + $ppp+ "_" + $ppp_extend

' The PPP isr
!$ppp_ISR = $ppp + " ISR"
!$ppp_ext_ISR = $ppp+ "\n " + $ppp_extend + " ISR"

' The LL Driver name
!$ll_ppp = "LL_" + $ppp

!$hal_dma_itf = "HAL_DMA_StartDirectXfer_IT_Opt()\nHAL_DMA_Abort_IT"
!if ($use_kernel_clock == 1)
!$hal_rcc_itf = "\t\t\tHAL_RCC_"+$ppp+"_GetClockFreq()\n\t\t\tHAL_RCC_"+$ppp+"_EnableClock()"
!else
!$hal_rcc_itf = "\t\t\tHAL_RCC_"+$ppp+"_EnableClock()"
!endif

!$hal_ppp_itf = "Half transfer complete\nTransfer complete\nError callback\nAbort callback"

' HAL Generic interface for the PPP driver
!$hal_generic_itf = "HAL_GetTick()"

!$ll_ppp_itf = "LL " + $ppp +" API"

' HW
!$ppp_xIRQ = $ppp+"x_IRQ"

<style>
componentDiagram {
arrow {
FontSize 8
}
interface {
FontSize 8
}
}
</style>

title $ppp Software Component Diagram

Package "Application Layer" {

component [Appli]
!if ($use_ppp_isr == 1)
interface "$appli_itf" as APPLI_Interface
[Appli] -r- APPLI_Interface
!if ($use_hal_ppp_extend == 1)
interface "$appli_ext_itf" as APPLI_EXT_Interface
[Appli] -l- APPLI_EXT_Interface
!endif
!endif
}

package "HAL" {
!if ($use_hal_ppp_extend == 1)
together {
component [$ppp_name] <<highlight>>
component [$ppp_ext_name] <<highlight>>
[$ppp_name] -[hidden]right- [$ppp_ext_name]
}
!if ($use_hal_service == 1)
[$ppp_name] -[hidden]d- [HAL_SERVICE]
[$ppp_ext_name] -[hidden]d- [HAL_SERVICE]
!endif
!if ($use_hal_dma == 1)
[$ppp_name] -[hidden]d- [HAL_DMA]
[$ppp_ext_name] -[hidden]d- [HAL_DMA]
!endif
!if ($use_hal_rcc == 1)
[$ppp_name] -[hidden]d- [HAL_RCC]
[$ppp_ext_name] -[hidden]d- [HAL_RCC]
!endif
!else
component [$ppp_name] <<highlight>>
!endif
!if ($use_hal_dma == 1)
interface "$hal_ppp_itf" as HAL_PPP_Interface
[$ppp_name] -d- HAL_PPP_Interface
!endif
!if ($use_hal_ppp_extend == 1)
together {
interface "$hal_api_itf" as HAL_PPP_APPLI_Interface
interface "$hal_api_ext_itf" as HAL_PPP_APPLI_EXT_Interface
HAL_PPP_APPLI_Interface -[hidden]right- HAL_PPP_APPLI_EXT_Interface
}
[$ppp_name] -u- HAL_PPP_APPLI_Interface
[$ppp_ext_name] -u- HAL_PPP_APPLI_EXT_Interface
'[$ppp_ext_name] -u-(
[$ppp_name] .r.> [$ppp_ext_name] : <<include>> / <<use>> \nShared types + common APIs
!else
interface "$hal_api_itf" as HAL_PPP_APPLI_Interface
[$ppp_name] -u- HAL_PPP_APPLI_Interface
!endif

!if ($use_hal_service == 1)
  component [HAL_SERVICE]
  interface "$hal_generic_itf" as HAL_Service_Interface
  [HAL_SERVICE] -u- HAL_Service_Interface
  !if ($use_hal_generic_dep == 0)
    [$ppp_name] --( HAL_Service_Interface
    !if ($use_hal_ppp_extend == 1)
      [$ppp_ext_name] --( HAL_Service_Interface
    !endif
  !else
      [$ppp_name] .d.> HAL_Service_Interface : <<use>>
      !if ($use_hal_ppp_extend == 1)
        [$ppp_ext_name] .r.> HAL_Service_Interface : <<use>>
  !endif
!endif
!if ($use_hal_dma == 1)
  component [HAL_DMA]
  interface "$hal_dma_itf" as HAL_DMA_Interface
  [HAL_DMA] -u- HAL_DMA_Interface
  !if ($use_hal_generic_dep == 0)
    [HAL_DMA] -u-( HAL_PPP_Interface
    [$ppp_name] --( HAL_DMA_Interface
  !else
    [HAL_DMA] .u.> HAL_PPP_Interface : <<use>>
    [$ppp_name] ..> HAL_DMA_Interface: <<use>>
  !endif
!endif
!if ($use_hal_rcc == 1)
  component [HAL_RCC]
  interface "$hal_rcc_itf" as HAL_RCC_Interface
  [HAL_RCC] -l- HAL_RCC_Interface
  !if ($use_hal_generic_dep == 0)
    [$ppp_name] -r-( HAL_RCC_Interface
  !else
    [$ppp_name] .r.> HAL_RCC_Interface: <<use>>
  !endif
!endif
}

[Appli] -d-( HAL_PPP_APPLI_Interface
!if ($use_hal_ppp_extend == 1)
[Appli] -d-( HAL_PPP_APPLI_EXT_Interface
!endif
!if ($use_ppp_isr == 1)
[$ppp_name] -u-( APPLI_Interface
!if ($use_hal_ppp_extend == 1)
[$ppp_ext_name] -u-( APPLI_EXT_Interface
!endif
!endif
!if ($use_ppp_core ==1)
Package "Core Layer" {
component [$core]
interface "core API" as Core_api_itf
[$core] -u- Core_api_itf
}
[$ppp_name] -d-( Core_api_itf
!endif
package "Low Layer" {
together {
!if ($use_ppp_ll == 1)
component [$ll_ppp]
!endif
component "CMSIS-Devices"
!if ($use_ppp_isr == 1)
component [$ppp_ISR]
!endif
!if ($use_hal_dma == 1)
component [DMA ISR]
!endif
!if ($use_ppp_ll == 1)
[$ll_ppp] -[hidden]right- [CMSIS-Devices]
!endif
!if ($use_ppp_isr == 1)
[CMSIS-Devices] -[hidden]right- [$ppp_ISR]
!endif
!if ($use_hal_dma == 1)
!if ($use_ppp_isr == 1)
[$ppp_ISR] -[hidden]right- [DMA ISR]
!else
[CMSIS-Devices] -[hidden]right- [DMA ISR]
!endif
!endif
}
!if ($use_ppp_ll == 1)
interface "$ll_ppp_itf" as LL_PPP_Interface
[$ll_ppp] -u- LL_PPP_Interface
LL_PPP_Interface -[hidden]d- [$ll_ppp]
!endif

!if ($use_ppp_isr == 1)
interface "$ppp_ISR" as PPP_ISR
[$ppp_ISR] -u- PPP_ISR
PPP_ISR -[hidden]d- [$ppp_ISR]
!if ($use_hal_ppp_extend == 1)
  interface "$ppp_ext_ISR" as PPP_EXT_ISR
  [$ppp_ISR] -u- PPP_EXT_ISR
  PPP_EXT_ISR -[hidden]d- [$ppp_ISR]
  [$ppp_ext_name] -d-( PPP_EXT_ISR
!endif
!endif


!if ($use_ll_rcc == 1)
  component [LL_RCC]
  interface "LL RCC API" as LL_RCC_API
  [LL_RCC] -u- LL_RCC_API
  [HAL_RCC] -d-(LL_RCC_API
!endif

!if ($use_hal_dma == 1)
  interface "DMA ISR" as DMA_ISR
  [DMA ISR] -u- DMA_ISR
  DMA_ISR -[hidden]d- [DMA ISR]
!endif
}

package "HW" {
component [STM32_HW]
!if ($use_ppp_isr == 1)
interface "$ppp_xIRQ" as PPPx_IRQ
[STM32_HW] -u- PPPx_IRQ
!endif
!if ($use_hal_dma == 1)
interface "DMAx_IRQ_Ch" as DMA_IRQ_CH
[STM32_HW] -u- DMA_IRQ_CH
[DMA ISR] -d-( DMA_IRQ_CH
[HAL_DMA] --( DMA_ISR
!endif
}

' Layout hints: packages top -> down, elements left -> right
[Appli] -[hidden]d- [$ppp_name]
!if ($use_hal_ppp_extend == 1)
[Appli] -[hidden]d- [$ppp_ext_name]
HAL_PPP_APPLI_Interface -[hidden]d- [$ppp_name]
HAL_PPP_APPLI_EXT_Interface -[hidden]d- [$ppp_ext_name]
HAL_PPP_APPLI_Interface -[hidden]right- HAL_PPP_APPLI_EXT_Interface
!endif
!if ($use_hal_ppp_extend == 1)
[$ppp_name] -[hidden]right- [$ppp_ext_name]
!endif
!if ($use_ppp_core == 1)
[$ppp_name] -[hidden]d- [$core]
!if ($use_hal_ppp_extend == 1)
[$ppp_ext_name] -[hidden]d- [$core]
!endif
[$core] -[hidden]d- [CMSIS-Devices]
!else
[$ppp_name] -[hidden]d- [CMSIS-Devices]
!if ($use_hal_ppp_extend == 1)
[$ppp_ext_name] -[hidden]d- [CMSIS-Devices]
!endif
!endif
!if ($use_hal_service == 1)
[HAL_SERVICE] -[hidden]d- [CMSIS-Devices]
!endif
!if ($use_hal_rcc == 1)
[HAL_RCC] -[hidden]d- [CMSIS-Devices]
!endif
!if ($use_hal_dma == 1)
[HAL_DMA] -[hidden]d- [DMA ISR]
!endif
[CMSIS-Devices] -[hidden]d- [STM32_HW]
!if ($use_ppp_isr == 1)
[$ppp_ISR] -[hidden]d- [STM32_HW]
!endif
!if ($use_hal_dma == 1)
[DMA ISR] -[hidden]d- [STM32_HW]
!endif

!if ($use_ppp_ll == 1)
!if ($use_hal_service == 1)
[HAL_SERVICE] -[hidden]d- LL_PPP_Interface
!endif
!if ($use_hal_generic_dep == 0)
!if ($use_hal_ppp_extend == 1)
[$ppp_name] -d-( LL_PPP_Interface
[$ppp_ext_name] -d-( LL_PPP_Interface
!else
[$ppp_name] -d-( LL_PPP_Interface
!endif
!else
!if ($use_hal_ppp_extend == 1)
[$ppp_name] .d.> LL_PPP_Interface:<<use>>
[$ppp_ext_name] .d.> LL_PPP_Interface:<<use>>
!else
[$ppp_name] .d.> LL_PPP_Interface : <<use>>
!endif
!endif
[$ll_ppp] .r.> [CMSIS-Devices]: $ppp register def
[STM32_HW] <.u. [$ll_ppp] : $ppp registers R/W
!else
!if ($use_ppp_core == 1)
[$core] .l.> [CMSIS-Devices]: $ppp register def
[STM32_HW] <.u. [$core] : $ppp registers R/W
!else
[$ppp_name] .d.> [CMSIS-Devices]: $ppp register def
[STM32_HW] <.l. [$ppp_name] : $ppp registers R/W
!endif
!endif
!if ($use_ppp_isr == 1)
[$ppp_ISR] -d-( PPPx_IRQ
[$ppp_name] -d-( PPP_ISR
!endif
!if ($use_ll_rcc == 1)
[STM32_HW] <.u. [LL_RCC] : RCC registers R/W
!endif

@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 STM32H7P5xx)

USE_HAL_FLASH_MODULE

from hal_conf.h

1

Allows to use HAL FLASH module.

USE_ASSERT_DBG_PARAM

from IDE

None

Allows to use the assert check parameters.

USE_ASSERT_DBG_STATE

from IDE

None

Allows to use the assert check states.

USE_HAL_CHECK_PARAM

from hal_conf.h

0

Allows to use the run-time checks parameters.

USE_HAL_CHECK_PROCESS_STATE

from hal_conf.h

0

Allows to use the load and store exclusive.

USE_HAL_FLASH_REGISTER_CALLBACKS

from hal_conf.h

0

Allows to use the register callbacks

USE_HAL_FLASH_GET_LAST_ERRORS

from hal_conf.h

0

Allows to use error code mechanism.

USE_HAL_FLASH_USER_DATA

from hal_conf.h

0

Allows to use user data.

USE_HAL_FLASH_PROGRAM_BY_ADDR

from hal_conf.h

1

Allows to use program by address feature APIs

USE_HAL_FLASH_ERASE_BY_ADDR

from hal_conf.h

1

Allows to use erase by address feature APIs

USE_HAL_FLASH_ERASE_PAGE

from hal_conf.h

1

Allows to use erase by page feature APIs

USE_HAL_FLASH_ERASE_BANK

from hal_conf.h

1

Allows to use erase by bank feature APIs

USE_HAL_FLASH_MASS_ERASE

from hal_conf.h

1

Allows to use mass erase feature APIs

USE_HAL_FLASH_CALCULATE_CRC

from hal_conf.h

1

Allows to use calculate CRC feature APIs

USE_HAL_FLASH_ECC

from hal_conf.h

1

Allows to use ECC errors handling APIs

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 STM32H7P75xx)

USE_HAL_FLASH_MODULE

from hal_conf.h

1

Allows to use HAL FLASH ITF module.

USE_ASSERT_DBG_PARAM

from IDE

None

Allows to use the assert check parameters.

USE_HAL_CHECK_PARAM

from hal_conf.h

0

Allows to use the run-time checks parameters.

USE_HAL_FLASH_ECC

from hal_conf.h

1

Allows to use ECC errors features APIs.