HAL FLASH Functions

HAL FLASH Initialization and De-initialization functions

group FLASH_Exported_Functions_Group1

This subsection provides a set of functions to initialize and de-initialize the Flash peripheral:

  • Call HAL_FLASH_Init() to initialize the Flash handle and associate a physical instance. (Optionally, the Flash clock is enabled inside the function)

  • Call 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.

Functions

hal_status_t HAL_FLASH_Init ( hal_flash_handle_t * hflash , hal_flash_t instance )

Initialize the Flash handle and associate a physical Flash instance.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Invalid parameter when hflash pointer is NULL.

  • HAL_OK – Flash is successfully initialized.

void HAL_FLASH_DeInit ( hal_flash_handle_t * hflash )

De-initialize the Flash handle.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

HAL FLASH Configuration functions

group FLASH_Exported_Functions_Group2

This subsection provides a set of functions to configure the Flash programming mode:

Functions

hal_status_t HAL_FLASH_SetProgrammingMode ( hal_flash_handle_t * hflash , hal_flash_program_mode_t programming_mode )

Set the Flash programming mode.

Parameters :
Return values :

HAL_OK – Programming mode is successfully configured.

hal_flash_program_mode_t HAL_FLASH_GetProgrammingMode ( const hal_flash_handle_t * hflash )

Get the Flash programming mode.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :

hal_flash_program_mode_t – Programming mode.

HAL FLASH Process Operations functions

group FLASH_Exported_Functions_Group3

This subsection provides a set of functions to program and erase any Flash main user memory area:

Functions

hal_status_t HAL_FLASH_ProgramByAddr ( hal_flash_handle_t * hflash , uint32_t flash_addr , const uint32_t * p_data , uint32_t size_byte , uint32_t timeout_msec )

Program any Flash memory User area in polling mode using flash address according to selected programming mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of the programming operation.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

  • timeout_msec – Timeout value for the programming operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Returned when internal processing exceeded the timeout.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t HAL_FLASH_ProgramByAddrAdapt ( hal_flash_handle_t * hflash , uint32_t flash_addr , const uint32_t * p_data , uint32_t size_byte , uint32_t timeout_msec )

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.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of the programming operation.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

  • timeout_msec – Timeout value for the programming operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Returned when internal processing exceeded the timeout.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t HAL_FLASH_ProgramByAddr_IT ( hal_flash_handle_t * hflash , uint32_t flash_addr , const uint32_t * p_data , uint32_t size_byte )

Program any Flash memory User area in interrupt mode using flash address according to selected programming mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of the programming operation.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t HAL_FLASH_ProgramByAddrAdapt_IT ( hal_flash_handle_t * hflash , uint32_t flash_addr , const uint32_t * p_data , uint32_t size_byte )

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.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of the programming operation.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t HAL_FLASH_EraseByAddr ( hal_flash_handle_t * hflash , uint32_t flash_addr , uint32_t size_byte , uint32_t timeout_msec )

Erase any Flash memory User area in polling mode using flash address.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of the erase operation.

  • size_byte – Size of the data to be erased (in bytes).

  • timeout_msec – Timeout value for the erasing by address operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Returned when internal processing exceeded the timeout.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_EraseByAddr_IT ( hal_flash_handle_t * hflash , uint32_t flash_addr , uint32_t size_byte )

Erase any Flash memory User area in interrupt mode using flash address.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of the erase operation.

  • size_byte – Size of the data to be erased (in bytes).

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_ErasePage ( hal_flash_handle_t * hflash , hal_flash_bank_t bank , uint32_t page , uint32_t page_nbr , uint32_t timeout_msec )

Erase by page any Flash memory User area in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • bank – This parameter is one element of hal_flash_bank_t enumeration.

  • page – First page to be erased.

  • page_nbr – Number of page(s) to be erased.

  • timeout_msec – Timeout value for the page erasing operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Internal processing exceeded the timeout.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_ErasePage_IT ( hal_flash_handle_t * hflash , hal_flash_bank_t bank , uint32_t page , uint32_t page_nbr )

Erase by page any Flash memory User area in interrupt mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • bank – This parameter is one element of hal_flash_bank_t enumeration.

  • page – First page to be erased.

  • page_nbr – Number of page(s) to be erased.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_EraseBank ( hal_flash_handle_t * hflash , hal_flash_bank_t bank , uint32_t timeout_msec )

Erase by bank any Flash memory User area in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • bank – Bank to be erased.

  • timeout_msec – Timeout value for the bank erasing operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Internal processing exceeded the timeout.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_EraseBank_IT ( hal_flash_handle_t * hflash , hal_flash_bank_t bank )

Erase by bank any Flash memory User area in interrupt mode.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_MassErase ( hal_flash_handle_t * hflash , uint32_t timeout_msec )

Mass erase the entire Flash memory User area in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • timeout_msec – Timeout value for the mass erasing operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Internal processing exceeded the timeout.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_MassErase_IT ( hal_flash_handle_t * hflash )

Mass erase the entire Flash memory User area in interrupt mode.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Returned when the erasing operation is completed successfully.

void HAL_FLASH_IRQHandler ( hal_flash_handle_t * hflash )

Handle the Flash interrupt requests.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_ProgramByAddr_IRQHandler ( hal_flash_handle_t * hflash )

Handle the Flash program by address interrupt request.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_EraseByAddr_IRQHandler ( hal_flash_handle_t * hflash )

Handle the Flash erase by address interrupt request.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_ErasePage_IRQHandler ( hal_flash_handle_t * hflash )

Handle the Flash erase by page interrupt request.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_EraseBank_IRQHandler ( hal_flash_handle_t * hflash )

Handle the Flash erase by bank interrupt request.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_MassErase_IRQHandler ( hal_flash_handle_t * hflash )

Handle the Flash mass erase interrupt request.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_ECC_IRQHandler ( hal_flash_handle_t * hflash )

Handle the Flash ECC single error detection correction interrupt request.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

hal_status_t HAL_FLASH_NMI_IRQHandler ( hal_flash_handle_t * hflash )

Handle the Flash NMI interrupt request.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :

cb_status – Return of ECC error callback status

hal_status_t HAL_FLASH_NS_ProgramByAddr ( hal_flash_handle_t * hflash , uint32_t flash_addr , const uint32_t * p_data , uint32_t size_byte , uint32_t timeout_msec )

Program the NSecure Flash memory area at a specified address in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of the NSecure Flash memory to be programmed.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

  • timeout_msec – Timeout value for the programming operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Returned when internal processing exceeded the timeout.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t HAL_FLASH_NS_ProgramByAddrAdapt ( hal_flash_handle_t * hflash , uint32_t flash_addr , const uint32_t * p_data , uint32_t size_byte , uint32_t timeout_msec )

Program the NSecure Flash memory area at a specified address using adaptive width in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of the NSecure Flash memory to be programmed.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

  • timeout_msec – Timeout value for the programming operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Returned when internal processing exceeded the timeout.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t HAL_FLASH_NS_ProgramByAddr_IT ( hal_flash_handle_t * hflash , uint32_t flash_addr , const uint32_t * p_data , uint32_t size_byte )

Program the NSecure Flash memory area at a specified address in interrupt mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of the NSecure programming operation.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t HAL_FLASH_NS_ProgramByAddrAdapt_IT ( hal_flash_handle_t * hflash , uint32_t flash_addr , const uint32_t * p_data , uint32_t size_byte )

Program the NSecure Flash memory area at a specified address using adaptive width in interrupt mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of the NSecure programming operation.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t HAL_FLASH_NS_OTP_ProgramByAddr ( hal_flash_handle_t * hflash , uint32_t otp_addr , const uint32_t * p_data , uint32_t size_byte , uint32_t timeout_msec )

Program the OTP area at a specified address in polling mode.

Warning

This API must be used only through NSecure world when TrustZone is enabled.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • otp_addr – OTP address.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

  • timeout_msec – Timeout value for the programming operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked or when TrustZone is disabled.

  • HAL_TIMEOUT – Returned when internal processing exceeded the timeout.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t HAL_FLASH_NS_OTP_ProgramByAddrAdapt ( hal_flash_handle_t * hflash , uint32_t otp_addr , const uint32_t * p_data , uint32_t size_byte , uint32_t timeout_msec )

Program the OTP area at a specified address using adaptive width in polling mode.

Warning

This API must be used only through NSecure world when TrustZone is enabled.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • otp_addr – OTP address.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

  • timeout_msec – Timeout value for the programming operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked or when TrustZone is disabled.

  • HAL_TIMEOUT – Returned when internal processing exceeded the timeout.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t HAL_FLASH_NS_OTP_ProgramByAddr_IT ( hal_flash_handle_t * hflash , uint32_t otp_addr , const uint32_t * p_data , uint32_t size_byte )

Program the OTP area at a specified address in interrupt mode.

Warning

This API must be used only through NSecure access when TrustZone is enabled.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • otp_addr – OTP address.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked or when TrustZone is disabled.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t HAL_FLASH_NS_OTP_ProgramByAddrAdapt_IT ( hal_flash_handle_t * hflash , uint32_t otp_addr , const uint32_t * p_data , uint32_t size_byte )

Program the OTP area at a specified address using adaptive width in interrupt mode.

Warning

This API must be used only through NSecure access when TrustZone is enabled.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • otp_addr – OTP address.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked or when TrustZone is disabled.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t HAL_FLASH_NS_EraseByAddr ( hal_flash_handle_t * hflash , uint32_t flash_addr , uint32_t size_byte , uint32_t timeout_msec )

Erase the Flash memory area at a specified address in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of the erase operation.

  • size_byte – Size of the data to be erased (in bytes).

  • timeout_msec – Timeout value for the erasing by address operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Internal processing exceeded the timeout.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_NS_EraseByAddr_IT ( hal_flash_handle_t * hflash , uint32_t flash_addr , uint32_t size_byte )

Erase the Flash memory area at a specified address in interrupt mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of the erase operation.

  • size_byte – Size of the data to be erased (in bytes).

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_NS_ErasePage ( hal_flash_handle_t * hflash , hal_flash_bank_t bank , uint32_t page , uint32_t page_nbr , uint32_t timeout_msec )

Erase by page the NSecure Flash memory area in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • bank – This parameter is one element of hal_flash_bank_t enumeration.

  • page – First page to be erased.

  • page_nbr – Number of page(s) to be erased.

  • timeout_msec – Timeout value for the page(s) erase operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Internal processing exceeded the timeout.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_NS_ErasePage_IT ( hal_flash_handle_t * hflash , hal_flash_bank_t bank , uint32_t page , uint32_t page_nbr )

Erase by page the NSecure Flash memory area in interrupt mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • bank – This parameter is one element of hal_flash_bank_t enumeration.

  • page – First page to be erased.

  • page_nbr – Number of pages to be erased.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_NS_EraseBank ( hal_flash_handle_t * hflash , hal_flash_bank_t bank , uint32_t timeout_msec )

Erase by bank the NSecure Flash memory area in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • bank – Bank to be erased.

  • timeout_msec – Timeout value for the bank erasing operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Internal processing exceeded the timeout.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_NS_EraseBank_IT ( hal_flash_handle_t * hflash , hal_flash_bank_t bank )

Erase by bank the NSecure Flash memory area in interrupt mode.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter selected.

  • HAL_ERROR – Returned when the control registers access locked.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_NS_MassErase ( hal_flash_handle_t * hflash , uint32_t timeout_msec )

Mass erase the entire NSecure Flash memory in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • timeout_msec – Timeout value for the mass erasing operation.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Internal processing exceeded the timeout.

  • HAL_OK – Returned when the erasing operation is completed successfully.

hal_status_t HAL_FLASH_NS_MassErase_IT ( hal_flash_handle_t * hflash )

Mass erase the entire NSecure Flash memory in interrupt mode.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Returned when the erasing operation is completed successfully.

void HAL_FLASH_NS_IRQHandler ( hal_flash_handle_t * hflash )

Handle the NSecure Flash interrupt requests.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_NS_ProgramByAddr_IRQHandler ( hal_flash_handle_t * hflash )

Handle the NSecure Flash standard and adaptive program by address interrupt request.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_NS_EraseByAddr_IRQHandler ( hal_flash_handle_t * hflash )

Handle the NSecure Flash erase by address interrupt request.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_NS_ErasePage_IRQHandler ( hal_flash_handle_t * hflash )

Handle the NSecure Flash erase by page interrupt request.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_NS_EraseBank_IRQHandler ( hal_flash_handle_t * hflash )

Handle the NSecure Flash erase by bank interrupt request.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_NS_MassErase_IRQHandler ( hal_flash_handle_t * hflash )

Handle the NSecure Flash mass erase interrupt request.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

HAL FLASH Callback functions

group FLASH_Exported_Functions_Group4

This subsection provides a set of functions allowing to register the Flash callbacks:

Functions

void HAL_FLASH_ProgramCpltCallback ( hal_flash_handle_t * hflash )

Flash program by address complete callback.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_EraseByAddrCpltCallback ( hal_flash_handle_t * hflash , uint32_t flash_addr , uint32_t size_byte )

Flash erase by address complete callback.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Erased address.

  • size_byte – Erased size in byte.

void HAL_FLASH_ErasePageCpltCallback ( hal_flash_handle_t * hflash , hal_flash_bank_t bank , uint32_t page , uint32_t page_nbr )

Flash erase by page complete callback.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • bank – This parameter is one element of hal_flash_bank_t enumeration.

  • page – Index of the erased page(s).

  • page_nbr – Number of the erased page(s).

void HAL_FLASH_EraseBankCpltCallback ( hal_flash_handle_t * hflash , hal_flash_bank_t bank )

Flash erase by bank complete callback.

Parameters :
void HAL_FLASH_MassEraseCpltCallback ( hal_flash_handle_t * hflash )

Flash mass erase complete callback.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void HAL_FLASH_ErrorCallback ( hal_flash_handle_t * hflash )

Flash error callback.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

hal_status_t HAL_FLASH_ECC_ErrorCallback ( hal_flash_handle_t * hflash )

Flash ECC error callback.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :

HAL_ERROR – Returned when an ECC error occurred.

hal_status_t HAL_FLASH_RegisterProgramCpltCallback ( hal_flash_handle_t * hflash , hal_flash_program_cplt_cb_t callback )

Register the Flash program by address complete callback.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • callback – Specifies the program complete callback.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_OK – Returned when the registration of the callback is completed successfully.

hal_status_t HAL_FLASH_RegisterEraseByAddrCpltCallback ( hal_flash_handle_t * hflash , hal_flash_erase_by_addr_cplt_cb_t callback )

Register the Flash erase by address complete callback.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • callback – Specifies the erase by address complete callback.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_OK – Returned when the registration of the callback is completed successfully.

hal_status_t HAL_FLASH_RegisterErasePageCpltCallback ( hal_flash_handle_t * hflash , hal_flash_erase_page_cplt_cb_t callback )

Register the Flash erase by page complete callback.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • callback – Specifies the erase by page complete callback.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is selected.

  • HAL_OK – Returned when the registration of the callback is completed successfully.

hal_status_t HAL_FLASH_RegisterEraseBankCpltCallback ( hal_flash_handle_t * hflash , hal_flash_erase_bank_cplt_cb_t callback )

Register the Flash erase by bank complete callback.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • callback – Specifies the bank erase complete callback.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is provided.

  • HAL_OK – Returned when the registration of the callback is successful.

hal_status_t HAL_FLASH_RegisterMassEraseCpltCallback ( hal_flash_handle_t * hflash , hal_flash_mass_erase_cplt_cb_t callback )

Register the Flash mass erase complete callback.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • callback – Specifies the mass erase complete callback.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is provided.

  • HAL_OK – Returned when the registration of the callback is successful.

hal_status_t HAL_FLASH_RegisterErrorCallback ( hal_flash_handle_t * hflash , hal_flash_error_cb_t callback )

Register the Flash error callback.

Parameters :
Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is provided.

  • HAL_OK – Returned when the registration of the callback is successful.

hal_status_t HAL_FLASH_RegisterECCErrorCallback ( hal_flash_handle_t * hflash , hal_flash_ecc_error_cb_t callback )

Register the Flash ECC error callback.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • callback – Specifies the ECC error callback.

Return values :
  • HAL_INVALID_PARAM – Returned when an invalid input parameter is provided.

  • HAL_OK – Returned when the registration of the callback is successful.

HAL FLASH Status functions

group FLASH_Exported_Functions_Group5

This subsection provides functions to get Flash general data information and status:

Functions

hal_flash_operation_t HAL_FLASH_GetOperation ( const hal_flash_handle_t * hflash )

Get the last Flash operation.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :

hal_flash_operation_t – The last operation performed.

void HAL_FLASH_GetProgramOperationInfo ( const hal_flash_handle_t * hflash , uint32_t * prog_flash_addr , uint32_t * prog_data_addr , uint32_t * programmed_data_byte )

Get the last programming operation information.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • prog_data_addr – Address of the data to be programmed.

  • prog_flash_addr – Address in the Flash where the data is programmed

  • programmed_data_byte – Size in bytes of the programmed data.

void HAL_FLASH_GetEraseByAddrOperationInfo ( const hal_flash_handle_t * hflash , uint32_t * flash_addr , uint32_t * erased_size_byte )

Get the last address erase operation information.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Address of the first page erased.

  • erased_size_byte – Size in bytes of the erased page.

void HAL_FLASH_GetErasePageOperationInfo ( const hal_flash_handle_t * hflash , hal_flash_bank_t * bank , uint32_t * page , uint32_t * erased_page_nbr )

Get the last page erase operation information.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • bank – Erased bank.

  • page – Index of the first page erased.

  • erased_page_nbr – Number of page(s) erased.

hal_flash_bank_t HAL_FLASH_GetEraseBankOperationInfo ( const hal_flash_handle_t * hflash )

Get the last bank erase operation information.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :

hal_flash_bank_t – Index of the erased bank.

void HAL_FLASH_GetInterruptedByResetOperationInfo ( const hal_flash_handle_t * hflash , hal_flash_interrupted_by_reset_operation_info_t * p_info )

Get the interrupted Flash operation information.

Parameters :
void HAL_FLASH_GetInfo ( const hal_flash_handle_t * hflash , hal_flash_info_t * p_info )

Get the Flash general information (size, number and size of banks, number and size of pages).

Parameters :
void HAL_FLASH_ECC_GetFailInfo ( hal_flash_handle_t * hflash , hal_flash_ecc_fail_info_t * p_info )

Get the Flash ECC fail information.

Parameters :
uint32_t HAL_FLASH_GetSizeByte ( const hal_flash_handle_t * hflash )

Get the total Flash size (in bytes).

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :

uint32_t – Total Flash size (in bytes).

uint8_t HAL_FLASH_GetBankNbr ( const hal_flash_handle_t * hflash )

Get the total Flash number of banks.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :

uint32_t – Total Flash number of banks.

uint32_t HAL_FLASH_GetBankSizeByte ( const hal_flash_handle_t * hflash , hal_flash_bank_t bank )

Get the total Flash size per bank (in bytes).

Parameters :
Return values :

uint32_t – Total Flash size per bank (in bytes).

uint32_t HAL_FLASH_GetUserFlashSizeByte ( const hal_flash_handle_t * hflash , hal_flash_bank_t bank )

Get the User Flash size of the specified bank (in bytes).

Parameters :
Return values :

uint32_t – User Flash size of the specified bank (in bytes).

uint16_t HAL_FLASH_GetUserFlashPageNbr ( const hal_flash_handle_t * hflash , hal_flash_bank_t bank )

Get the User Flash number of pages per bank.

Parameters :
Return values :

uint32_t – User Flash number of pages per bank.

uint32_t HAL_FLASH_GetUserFlashPageSizeByte ( const hal_flash_handle_t * hflash , hal_flash_bank_t bank , uint32_t page )

Get the User Flash size of the specified page (in bytes).

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • bank – Selected bank.

  • page – Selected page.

Return values :

uint32_t – User Flash size of the specified page (in bytes).

uint32_t HAL_FLASH_GetUserFlashAddrOffset ( const hal_flash_handle_t * hflash , hal_flash_bank_t bank , uint32_t page )

Get the User Flash offset address of the specified page.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • bank – Selected bank.

  • page – Selected page within the specified bank.

Return values :

uint32_t – Offset address of the specified page.

hal_flash_state_t HAL_FLASH_GetState ( const hal_flash_handle_t * hflash )

Get the current Flash global state.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :

hal_flash_state_t – Current global state of the Flash.

uint32_t HAL_FLASH_GetLastErrorCodes ( const hal_flash_handle_t * hflash )

Get the current Flash last error codes.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :

uint32_t – Flash last error codes.

void HAL_FLASH_SetUserData ( hal_flash_handle_t * hflash , const void * p_user_data )

Store the User data pointer within the Flash handle.

Parameters :
const void * HAL_FLASH_GetUserData ( const hal_flash_handle_t * hflash )

Retrieve the User data pointer from the Flash handle.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :

void* – Pointer to the user data.

FLASH Private Functions

group FLASH_Private_Functions

This subsection provides a set of functions intrinsically called to manage various Flash operations:

Functions

hal_status_t FLASH_WaitForEndOfOperation ( hal_flash_handle_t * hflash , uint32_t timeout_msec )

Wait for an ongoing Flash operation to be completed.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • timeout_msec – Maximum Flash operation timeout.

Return values :
  • HAL_ERROR – There is an operation in progress.

  • HAL_OK – No operation is waiting.

hal_status_t FLASH_CheckEndOfOperation ( const hal_flash_handle_t * hflash )

Check the Flash last operation if completed.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :
  • HAL_ERROR – Returned when an error occurred.

  • HAL_OK – No operation is waiting.

void FLASH_HandleErrorIT ( hal_flash_handle_t * hflash )

Handle any Flash error interrupt.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

uint32_t FLASH_UpdateAdaptiveProgrammingMode ( const hal_flash_handle_t * hflash )

Automatically Adjust the right programming size depending on the given data size by the user.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :

count – Adapted data size count for each programming iteration.

hal_status_t FLASH_Program ( hal_flash_handle_t * hflash , uint32_t flash_addr , const uint32_t * p_data , uint32_t size_byte , uint32_t timeout_msec )

Program a quad-word (128-bit) or burst programming (8x quad-words) at a specified address in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of Flash to be programmed.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

  • timeout_msec – Timeout value for programming operation.

Return values :
  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Internal processing exceeded the timeout.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t FLASH_Program_IT ( hal_flash_handle_t * hflash , uint32_t flash_addr , const uint32_t * p_data , uint32_t size_byte )

Program a quad-word (128-bit) or burst programming (8x quad-words) at a specified address in interrupt mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Address in Flash memory to be programmed.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

Return values :
  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Operation completed successfully.

void FLASH_ProgramByBurst ( const hal_flash_handle_t * hflash )

Perform a Burst programming granularity (8x quad-words).

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void FLASH_ProgramByQuadWord ( const hal_flash_handle_t * hflash )

Perform a Quad-word programming granularity (128-bit).

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

hal_status_t FLASH_EraseBank ( hal_flash_handle_t * hflash , uint32_t timeout_msec )

Erase by bank the Flash memory area in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • timeout_msec – Timeout value for erase operation.

Return values :
  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Internal processing exceeded the timeout.

  • HAL_OK – Returned when the erase operation is completed successfully.

void FLASH_EraseBank_IT ( hal_flash_handle_t * hflash )

Erase by bank the Flash memory area in interrupt mode.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void FLASH_FillErrorCode ( hal_flash_handle_t * hflash , uint32_t flags )

Fill the last error code within the handle.

Parameters :
hal_status_t FLASH_NS_WaitForEndOfOperation ( hal_flash_handle_t * hflash , uint32_t timeout_msec )

Wait for an ongoing NSecure Flash operation to be completed.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • timeout_msec – Maximum Flash operation timeout.

Return values :
  • HAL_ERROR – There is an operation in progress.

  • HAL_OK – No operation is waiting.

hal_status_t FLASH_NS_CheckEndOfOperation ( const hal_flash_handle_t * hflash )

Check the Flash last NSecure operation if completed.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

Return values :
  • HAL_ERROR – Returned when the control registers access is locked. Returned when there is already an ongoing Flash operation.

  • HAL_OK – No current ongoing Flash operation.

void FLASH_NS_HandleErrorIT ( hal_flash_handle_t * hflash )

Handle the Flash NSecure error interrupt.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

hal_status_t FLASH_NS_Program ( hal_flash_handle_t * hflash , uint32_t flash_addr , const uint32_t * p_data , uint32_t size_byte , uint32_t timeout_msec )

Program a quad-word (128-bit) or burst programming (8x quad-words) at a specified NSecure Flash address in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of Flash to be programmed.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

  • timeout_msec – Timeout value for programming operation.

Return values :
  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_TIMEOUT – Internal processing exceeded the timeout.

  • HAL_OK – Returned when the programming operation is completed successfully.

hal_status_t FLASH_NS_Program_IT ( hal_flash_handle_t * hflash , uint32_t flash_addr , const uint32_t * p_data , uint32_t size_byte )

Program a quad-word (128-bit) or burst programming (8x quad-words) at a specified NSecure Flash address in interrupt mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • flash_addr – Start address of Flash to be programmed.

  • p_data – Pointer to the data to be programmed.

  • size_byte – Size of the data to be programmed (in bytes).

Return values :
  • HAL_ERROR – Returned when the control registers access is locked.

  • HAL_OK – Returned when the programming operation is completed successfully.

void FLASH_NS_ProgramByBurst ( const hal_flash_handle_t * hflash )

Perform a NSecure Burst programming granularity (8x quad-words).

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void FLASH_NS_ProgramByQuadWord ( const hal_flash_handle_t * hflash )

Perform a NSecure Quad-word programming granularity (128-bit).

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

hal_status_t FLASH_NS_EraseBank ( hal_flash_handle_t * hflash , uint32_t timeout_msec )

Erase by bank the NSecure Flash memory area in polling mode.

Parameters :
  • hflash – Pointer to a hal_flash_handle_t structure.

  • timeout_msec – Timeout value for erase operation.

Return values :

status – Flash bank erase operation status.

void FLASH_NS_EraseBank_IT ( hal_flash_handle_t * hflash )

Erase by bank the NSecure Flash memory area in interrupt mode.

Parameters :

hflash – Pointer to a hal_flash_handle_t structure.

void FLASH_NS_FillErrorCode ( hal_flash_handle_t * hflash , uint32_t flags )

Fill the NSecure last error code within the handle.

Parameters :