L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
flash_if.c File Reference

This file provides set of firmware functions to manage Flash Interface functionalities. More...

#include "flash_if.h"
#include "stm32_mem.h"
Include dependency graph for flash_if.c:

Go to the source code of this file.

Macros

#define PAGE_INDEX(__ADDRESS__)
 Get internal flash page index from page address.

Enumerations

enum  { FLASH_IF_MEM_EMPTY = 0 , FLASH_IF_MEM_NOT_EMPTY = 1 }
 Flash empty status enumeration. More...

Functions

static FLASH_IF_StatusTypedef FLASH_IF_INT_Write (void *pDestination, const void *pSource, uint32_t uLength)
 This function writes a data buffer in flash (data are 64-bit aligned).
static FLASH_IF_StatusTypedef FLASH_IF_INT_Read (void *pDestination, const void *pSource, uint32_t uLength)
 This function reads flash.
static FLASH_IF_StatusTypedef FLASH_IF_INT_Erase (void *pStart, uint32_t uLength)
 This function does an erase of n (depends on Length) pages in user flash area.
static FLASH_IF_StatusTypedef FLASH_IF_INT_Clear_Error (void)
 Clear error flags raised during previous operation.
FLASH_IF_StatusTypedef FLASH_IF_Init (void *pAllocRamBuffer)
 This function initializes the internal and external flash interface.
FLASH_IF_StatusTypedef FLASH_IF_DeInit (void)
 This function de-initializes the internal and external flash interface.
FLASH_IF_StatusTypedef FLASH_IF_Write (void *pDestination, const void *pSource, uint32_t uLength)
 This function writes a data buffer in internal or external flash.
FLASH_IF_StatusTypedef FLASH_IF_Read (void *pDestination, const void *pSource, uint32_t uLength)
 This function reads a amount of data from flash and copy into the output data buffer.
FLASH_IF_StatusTypedef FLASH_IF_Erase (void *pStart, uint32_t uLength)
 This function erases a amount of internal or external flash pages depending of the length.
void HAL_FLASH_EndOfOperationCallback (uint32_t ReturnValue)
void HAL_FLASH_OperationErrorCallback (uint32_t ReturnValue)

Variables

static uint8_t * pAllocatedBuffer = NULL

Detailed Description

This file provides set of firmware functions to manage Flash Interface functionalities.

Author
MCD Application Team
Attention

Copyright (c) 2026 STMicroelectronics. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.

Definition in file flash_if.c.

Macro Definition Documentation

◆ PAGE_INDEX

#define PAGE_INDEX ( __ADDRESS__)
Value:
(uint32_t)((((__ADDRESS__) - FLASH_BASE) % FLASH_BANK_SIZE) / FLASH_PAGE_SIZE)

Get internal flash page index from page address.

Definition at line 58 of file flash_if.c.

Referenced by FLASH_IF_INT_Erase(), and FLASH_IF_INT_Write().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Flash empty status enumeration.

Enumerator
FLASH_IF_MEM_EMPTY 
FLASH_IF_MEM_NOT_EMPTY 

Definition at line 44 of file flash_if.c.

Function Documentation

◆ FLASH_IF_DeInit()

FLASH_IF_StatusTypedef FLASH_IF_DeInit ( void )

This function de-initializes the internal and external flash interface.

Returns
FLASH_IF_StatusTypedef status

Definition at line 129 of file flash_if.c.

References FLASH_IF_OK, and pAllocatedBuffer.

◆ FLASH_IF_Erase()

FLASH_IF_StatusTypedef FLASH_IF_Erase ( void * pStart,
uint32_t uLength )

This function erases a amount of internal or external flash pages depending of the length.

Parameters
pStartpointer of flash address to erase
uLengthnumber of bytes to erase
Returns
FLASH_IF_StatusTypedef status

Definition at line 175 of file flash_if.c.

References FLASH_IF_ERROR, and FLASH_IF_INT_Erase().

Here is the call graph for this function:

◆ FLASH_IF_Init()

FLASH_IF_StatusTypedef FLASH_IF_Init ( void * pAllocRamBuffer)

This function initializes the internal and external flash interface.

Parameters
pAllocRamBufferpointer used to store a FLASH page in RAM when partial replacement is needed
Returns
FLASH_IF_StatusTypedef status

Definition at line 115 of file flash_if.c.

References FLASH_IF_OK, and pAllocatedBuffer.

◆ FLASH_IF_INT_Clear_Error()

FLASH_IF_StatusTypedef FLASH_IF_INT_Clear_Error ( void )
static

Clear error flags raised during previous operation.

Return values
FLASH_IF_StatusTypedefstatus

Definition at line 394 of file flash_if.c.

References FLASH_IF_LOCK_ERROR, and FLASH_IF_OK.

Referenced by FLASH_IF_INT_Erase(), and FLASH_IF_INT_Write().

Here is the caller graph for this function:

◆ FLASH_IF_INT_Erase()

FLASH_IF_StatusTypedef FLASH_IF_INT_Erase ( void * pStart,
uint32_t uLength )
static

This function does an erase of n (depends on Length) pages in user flash area.

Parameters
pStartpointer of flash address to be erased
uLengthnumber of bytes
Returns
FLASH_IF_StatusTypedef status

Definition at line 342 of file flash_if.c.

References FLASH_IF_BUSY, FLASH_IF_ERASE_ERROR, FLASH_IF_INT_Clear_Error(), FLASH_IF_LOCK_ERROR, FLASH_IF_OK, FLASH_IF_PARAM_ERROR, and PAGE_INDEX.

Referenced by FLASH_IF_Erase(), and FLASH_IF_INT_Write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FLASH_IF_INT_Read()

FLASH_IF_StatusTypedef FLASH_IF_INT_Read ( void * pDestination,
const void * pSource,
uint32_t uLength )
static

This function reads flash.

Parameters
pDestinationStart address for target location
pSourceflash address to read
uLengthnumber of bytes
Returns
FLASH_IF_StatusTypedef status

Definition at line 324 of file flash_if.c.

References FLASH_IF_OK, and FLASH_IF_PARAM_ERROR.

Referenced by FLASH_IF_INT_Write(), and FLASH_IF_Read().

Here is the caller graph for this function:

◆ FLASH_IF_INT_Write()

FLASH_IF_StatusTypedef FLASH_IF_INT_Write ( void * pDestination,
const void * pSource,
uint32_t uLength )
static

This function writes a data buffer in flash (data are 64-bit aligned).

Note
After writing data buffer, the flash content is checked.
Parameters
pDestinationStart address for target location. It has to be 8 bytes aligned.
pSourcepointer on buffer with data to write
uLengthLength of data buffer in bytes. It has to be 8 bytes aligned.
Returns
FLASH_IF_StatusTypedef status

Definition at line 199 of file flash_if.c.

References FLASH_IF_ERASE_ERROR, FLASH_IF_INT_Clear_Error(), FLASH_IF_INT_Erase(), FLASH_IF_INT_Read(), FLASH_IF_LOCK_ERROR, FLASH_IF_OK, FLASH_IF_PARAM_ERROR, FLASH_IF_WRITE_ERROR, PAGE_INDEX, and pAllocatedBuffer.

Referenced by FLASH_IF_Write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FLASH_IF_Read()

FLASH_IF_StatusTypedef FLASH_IF_Read ( void * pDestination,
const void * pSource,
uint32_t uLength )

This function reads a amount of data from flash and copy into the output data buffer.

Parameters
pDestinationpointer of target location to copy the flash sector
pSourcepointer of flash address to read
uLengthnumber of bytes to read
Returns
FLASH_IF_StatusTypedef status

Definition at line 159 of file flash_if.c.

References FLASH_IF_ERROR, and FLASH_IF_INT_Read().

Referenced by OnRestoreContextRequest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FLASH_IF_Write()

FLASH_IF_StatusTypedef FLASH_IF_Write ( void * pDestination,
const void * pSource,
uint32_t uLength )

This function writes a data buffer in internal or external flash.

Parameters
pDestinationpointer of flash address to write. It has to be 8 bytes aligned.
pSourcepointer on buffer with data to write
uLengthlength of data buffer in bytes. It has to be 8 bytes aligned.
Returns
FLASH_IF_StatusTypedef status

Definition at line 143 of file flash_if.c.

References FLASH_IF_ERROR, and FLASH_IF_INT_Write().

Referenced by OnStoreContextRequest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HAL_FLASH_EndOfOperationCallback()

void HAL_FLASH_EndOfOperationCallback ( uint32_t ReturnValue)
Note
This function overwrites the __weak one from HAL

Definition at line 425 of file flash_if.c.

◆ HAL_FLASH_OperationErrorCallback()

void HAL_FLASH_OperationErrorCallback ( uint32_t ReturnValue)
Note
This function overwrites the __weak one from HAL

Definition at line 442 of file flash_if.c.

Variable Documentation

◆ pAllocatedBuffer

uint8_t* pAllocatedBuffer = NULL
static

Definition at line 65 of file flash_if.c.

Referenced by FLASH_IF_DeInit(), FLASH_IF_Init(), and FLASH_IF_INT_Write().