ParaLib 2.0.15-master SHA: 2e03d68caa
PARA_Flash_STM32H5.c File Reference

Flash parameter storage for STMicroelectronics SMT32H5 Series. More...

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "Error/Error_ID_System.h"
#include "Error/Error.h"
#include "Para/SYS_Type.h"
#include "Math/MATH_Crc.h"
#include "Para/PARA_Lib.h"
#include "Para/PARA_ID_System.h"
#include "Error/LogMessage.h"
#include "basicModules/Para/PARA_Backup.h"
#include "PARA_Flash_STM32H5.h"
#include "stm32h5xx_hal.h"
#include "stm32h5xx_hal_conf.h"
#include "MemoryOrganization.h"
#include "FreeRTOS.h"
#include "task.h"
#include "gitRevision.h"
#include "PARA_Identifikation.h"
#include "state_machine.h"

Data Structures

struct  tFlashInformation
 Information stored in flash about the contents of the flash page. More...
 
struct  t_ParaFlashDataset
 Datastructure of one flash block. More...
 

Macros

#define MEMBER_SIZEOF(t, f)   (sizeof(((t*)0)->f))
 
#define PARA_FLASH_SIZE_DATA   24
 Size of data stored in one flash block. In the block some meta-information is stored besides the data. More...
 
#define PARA_FLASH_SIZE_HALFWORD   2
 
#define PARA_FLASH_SIZE_BLOCK   32
 Total size of one flash block. More...
 
#define MAXIMUM_PARAMETER_DATAPOINTER   ((PARAMETER_FLASH_MAX_SIZE - PARA_FLASH_SIZE_BLOCK) /PARA_FLASH_SIZE_BLOCK)
 Maximum address of valid flash blocks. More...
 
#define PARAMETER_FLASH_VERSION   1
 Version of the flash library. More...
 
#define PARA_FLASH_FLAG_READ_ACTIVE   (1<<0)
 
#define PARA_FLASH_FLAG_DECC_ACTIVE   (1<<1)
 
#define FlashData1   (*(tFlashInformation*)PARAMETER_FLASH_BASE_BLOCK1)
 
#define FlashData2   (*(tFlashInformation*)PARAMETER_FLASH_BASE_BLOCK2)
 

Functions

static bool FlashErrorReset (void)
 Error-reset definition which is called after error-reset in if a flash error is present. More...
 
 DefineOnErrorResetReaction (DefineErrorData(FlashErrorReset, "Flash Error Reset", "DOC_D Parameter überprüfen und im Flash speichern zum zurückzusetzen.\DOC_E Review Parameters and save to Flash to reset.")
 Function which is called after error-reset in if a flash error is present. More...
 
void PARA_FlashInit (void)
 Initialization of parameter flash interface needs to be called before: More...
 
void PARA_FlashReadFromBackup (uint16_t location, ParameterAccessSource Access, uint8_t AccessLevel)
 Reads backup-values from flash and stores them into parameter values. More...
 
static void WriteToBackupThread (void *argument)
 Writes backup-values into flash. More...
 
bool PARA_FlashWriteToBackup (uint16_t location)
 Writes backup-values into flash All parameters with storage-location selected in parameter location are processed, all others are ignored. More...
 
static bool VerifyBackupArea (tFlashInformation *FlashDataLocation)
 The Backup-Area in flash is verified. More...
 
static HAL_StatusTypeDef FlashEraseParaBank (uint32_t bank)
 Erase the complete user data area in Flash in the specified bank. More...
 
bool ParaFlashNMIHandler (void)
 NMI is called in case of a double ECC Error. More...
 
int32_t ReadFunction_FlashSize (Parameter *ptThis, uint16_t ui16SubId, void *pData, int32_t ui32MaxCount, uint32_t ui32Offset, ParameterAccessSource tAccessSource, uint8_t ui8AccessLevel)
 Read-function for accessing the flash-information. More...
 
 ParameterU16 (0, PARA_ID_FlashSize, GROUP_ID_System, "FlashSize", "{0} Bytes", "Size of parameter backup memory", "Size of the actual uses Parameter-Falsh. Maximum is "DEFINE_VAL(PARAMETER_FLASH_MAX_SIZE)" Bytes.", "Größe des Parameter Flash Bereiches. Maximal sind "DEFINE_VAL(PARAMETER_FLASH_MAX_SIZE)" Bytes möglich.", "", 1, 0, MAX_uint16, 0, ReadFunction_FlashSize, WriteFunction_STD_Const, SetToDefaultFunction_STD_Const, VIEWER_READ|USER_READ|PROFESSIONAL_READ|DEVELOPER_READ, NOT_STORED, FLAG_NONE) int32_t ReadFunction_WriteCycle(Parameter *ptThis
 
 if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)||((*(tFlashInformation *) PARAMETER_FLASH_BASE_BLOCK1) .Size==0xFFFF))
 
 memcpy (pData, &(*(tFlashInformation *) PARAMETER_FLASH_BASE_BLOCK1) .WriteCycleCount, 4)
 
g_ui32ParaFlashFlags &return GetDataTypeSize (TYPE_uint32) = ~( (1<<0) | (1<<1) )
 
 ParameterU32 (0, PARA_ID_FlashWriteCycleCount, GROUP_ID_System, "FlashWriteCycleCount", "{0}", "Count of parameter write operations in Flash", "Counter of Parameter write cycles.", "Zähler der Parameterschreibvorgänge in das Flash.", "", 1, 0, MAX_uint32, 0, ReadFunction_WriteCycle, WriteFunction_STD_Const, SetToDefaultFunction_STD_Const, VIEWER_READ|USER_READ|PROFESSIONAL_READ|DEVELOPER_READ, NOT_STORED, FLAG_NONE) int32_t ReadFunction_FlashInfo_STR(Parameter *ptThis
 
 if (IsValidForRead(ptThis, ui16SubId, pData, ui32MaxCount, ui32Offset, tAccessSource, ui8AccessLevel)==false)
 
memcpylocalInf (*(tFlashInformation *) PARAMETER_FLASH_BASE_BLOCK1), sizeof(tFlashInformation)
 
 if (i8len=len, len=14)
 
 if (len,(ui32MaxCount - destoffset))
 
 ParameterSTR (0, PARA_ID_FlashSoftwareVersion, GROUP_ID_System, "Parameter Flash Softwareversion", "{0}", "Software Version which saved the Parameters", "", "", "", 1, 14, "unknown", ReadFunction_FlashInfo_STR, WriteFunction_STD_Const, SetToDefaultFunction_STD_Const, VIEWER_READ|USER_READ|PROFESSIONAL_READ|DEVELOPER_READ, NOT_STORED, FLAG_NONE) int32_t ReadFunction_WriteTimestamp(Parameter *ptThis
 

Variables

uint16_t ui16SubId
 
uint16_t void * pData
 
uint16_t void int32_t ui32MaxCount
 
uint16_t void int32_t uint32_t ui32Offset
 
uint16_t void int32_t uint32_t ParameterAccessSource tAccessSource
 
uint16_t void int32_t uint32_t ParameterAccessSource uint8_t ui8AccessLevel
 
 g_ui32ParaFlashFlags = (1<<0)
 
uint8_t i8len
 
uint8_t destoffset =0
 
tFlashInformation localInf
 
g_ui32ParaFlashFlagslen = strlen(localInf.SoftwareVersion)
 
 else
 

Detailed Description

Flash parameter storage for STMicroelectronics SMT32H5 Series.

Uses the high-cycle data area


© Copyright 2017-2022 Copyright: Retostronik GmbH Stütingstraße 30 58285 Gevelsberg

Macro Definition Documentation

◆ FlashData1

#define FlashData1   (*(tFlashInformation*)PARAMETER_FLASH_BASE_BLOCK1)

◆ FlashData2

#define FlashData2   (*(tFlashInformation*)PARAMETER_FLASH_BASE_BLOCK2)

◆ MAXIMUM_PARAMETER_DATAPOINTER

#define MAXIMUM_PARAMETER_DATAPOINTER   ((PARAMETER_FLASH_MAX_SIZE - PARA_FLASH_SIZE_BLOCK) /PARA_FLASH_SIZE_BLOCK)

Maximum address of valid flash blocks.

◆ MEMBER_SIZEOF

#define MEMBER_SIZEOF (   t,
 
)    (sizeof(((t*)0)->f))

◆ PARA_FLASH_FLAG_DECC_ACTIVE

#define PARA_FLASH_FLAG_DECC_ACTIVE   (1<<1)

◆ PARA_FLASH_FLAG_READ_ACTIVE

#define PARA_FLASH_FLAG_READ_ACTIVE   (1<<0)

◆ PARA_FLASH_SIZE_BLOCK

#define PARA_FLASH_SIZE_BLOCK   32

Total size of one flash block.

◆ PARA_FLASH_SIZE_DATA

#define PARA_FLASH_SIZE_DATA   24

Size of data stored in one flash block. In the block some meta-information is stored besides the data.

◆ PARA_FLASH_SIZE_HALFWORD

#define PARA_FLASH_SIZE_HALFWORD   2

◆ PARAMETER_FLASH_VERSION

#define PARAMETER_FLASH_VERSION   1

Version of the flash library.

Function Documentation

◆ DefineOnErrorResetReaction()

DefineOnErrorResetReaction ( DefineErrorData(  FlashErrorReset,
"Flash Error Reset"  ,
"DOC_D Parameter überprüfen und im Flash speichern zum zurückzusetzen.\DOC_E Review Parameters and save to Flash to reset."   
)

Function which is called after error-reset in if a flash error is present.

Return values
trueif ErrorReset was successful
falseif ErrorReset was not successful

◆ FlashEraseParaBank()

static HAL_StatusTypeDef FlashEraseParaBank ( uint32_t  bank)
static

Erase the complete user data area in Flash in the specified bank.

Parameters
bankNumber of the bank to be erased (1 or 2).
Returns
HAL Error code. Err_OK if successfull.

◆ FlashErrorReset()

static bool FlashErrorReset ( void  )
static

Error-reset definition which is called after error-reset in if a flash error is present.

◆ GetDataTypeSize()

g_ui32ParaFlashFlags &return GetDataTypeSize ( TYPE_uint32  ) = ~( (1<<0) | (1<<1) )

◆ if() [1/4]

if ( __HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)||((*(tFlashInformation *) PARAMETER_FLASH_BASE_BLOCK1) .Size==0xFFFF)  )

◆ if() [2/4]

if ( i8len len,
len 14 
)

◆ if() [3/4]

◆ if() [4/4]

if ( len  ,
(ui32MaxCount - destoffset  
)

◆ localInf()

memcpy & localInf ( *(tFlashInformation *)  PARAMETER_FLASH_BASE_BLOCK1)

◆ memcpy()

memcpy ( pData  ,
&(*(tFlashInformation *) PARAMETER_FLASH_BASE_BLOCK1) .  WriteCycleCount,
 
)

◆ PARA_FlashInit()

void PARA_FlashInit ( void  )

Initialization of parameter flash interface needs to be called before:

  • HAL Init
  • PARA_Init
  • Error_Init
  • SystemMessage_Init
  • PARA_Backup_Init

◆ PARA_FlashReadFromBackup()

void PARA_FlashReadFromBackup ( uint16_t  location,
ParameterAccessSource  Access,
uint8_t  AccessLevel 
)

Reads backup-values from flash and stores them into parameter values.

All parameters with storage-location selected in parameter location are processed, all others are ignored. The parameter values are written with the OnWrite-function defined in the parameter itself. In case of an error, the default value is set. Flash must be unlocked!

Parameters
locationselects the storage location
AccessSource of access (see Access restrictions).
AccessLevelActual AccessLevel (see Access restrictions).

◆ PARA_FlashWriteToBackup()

bool PARA_FlashWriteToBackup ( uint16_t  location)

Writes backup-values into flash All parameters with storage-location selected in parameter location are processed, all others are ignored.

Parameters
locationselects the storage location
Return values
Trueif successfull.

◆ ParaFlashNMIHandler()

bool ParaFlashNMIHandler ( void  )

NMI is called in case of a double ECC Error.

If this occures while reading Parameter flash, set flag and return from NMI.

◆ ParameterSTR()

ParameterSTR ( ,
PARA_ID_FlashSoftwareVersion  ,
GROUP_ID_System  ,
"Parameter Flash Softwareversion"  ,
"{0}"  ,
"Software Version which saved the Parameters"  ,
""  ,
""  ,
""  ,
,
14  ,
"unknown"  ,
ReadFunction_FlashInfo_STR  ,
WriteFunction_STD_Const  ,
SetToDefaultFunction_STD_Const  ,
VIEWER_READ|USER_READ|PROFESSIONAL_READ DEVELOPER_READ,
NOT_STORED  ,
FLAG_NONE   
)

◆ ParameterU16()

ParameterU16 ( ,
PARA_ID_FlashSize  ,
GROUP_ID_System  ,
"FlashSize"  ,
"{0} Bytes"  ,
"Size of parameter backup memory"  ,
"Size of the actual uses Parameter-Falsh. Maximum is "DEFINE_VAL(PARAMETER_FLASH_MAX_SIZE)" Bytes."  ,
"Größe des Parameter Flash Bereiches. Maximal sind "DEFINE_VAL(PARAMETER_FLASH_MAX_SIZE)" Bytes möglich."  ,
""  ,
,
,
MAX_uint16  ,
,
ReadFunction_FlashSize  ,
WriteFunction_STD_Const  ,
SetToDefaultFunction_STD_Const  ,
VIEWER_READ|USER_READ|PROFESSIONAL_READ DEVELOPER_READ,
NOT_STORED  ,
FLAG_NONE   
)

◆ ParameterU32()

ParameterU32 ( ,
PARA_ID_FlashWriteCycleCount  ,
GROUP_ID_System  ,
"FlashWriteCycleCount"  ,
"{0}"  ,
"Count of parameter write operations in Flash"  ,
"Counter of Parameter write cycles."  ,
"Zähler der Parameterschreibvorgänge in das Flash."  ,
""  ,
,
,
MAX_uint32  ,
,
ReadFunction_WriteCycle  ,
WriteFunction_STD_Const  ,
SetToDefaultFunction_STD_Const  ,
VIEWER_READ|USER_READ|PROFESSIONAL_READ DEVELOPER_READ,
NOT_STORED  ,
FLAG_NONE   
)

◆ ReadFunction_FlashSize()

int32_t ReadFunction_FlashSize ( Parameter ptThis,
uint16_t  ui16SubId,
void *  pData,
int32_t  ui32MaxCount,
uint32_t  ui32Offset,
ParameterAccessSource  tAccessSource,
uint8_t  ui8AccessLevel 
)

Read-function for accessing the flash-information.

This function is neccessary, because during erase operation, every access of the flash bank stalls the processor. During erase the access is trapped to prevent a processor stall.

Parameters
ptThisPointer to the Parameter.
ui16SubIdSubID to read.
[out]pDataOutputbuffer to store the parametervalue.
ui32MaxCountBuffer size. If smaller than data size, return 0
ui32OffsetStart-offset to read from. If bigger than data-size return 0
tAccessSourceSource of access (see Access restrictions).
ui8AccessLevelActual AccessLevel (see Access restrictions).
Returns
Size in bytes of the used buffer.

◆ VerifyBackupArea()

static bool VerifyBackupArea ( tFlashInformation FlashDataLocation)
static

The Backup-Area in flash is verified.

A 32-Bit CRC is calculated and compared to the stored value in zhe stored flashInformation. If CRC is matching, true is returned.

Parameters
FlashDataLocationPointer to the flash-information stored in flash.
Return values
Trueif successfull.

◆ WriteToBackupThread()

static void WriteToBackupThread ( void *  argument)
static

Writes backup-values into flash.

All parameters with storage-location PARA_FLASH are processed, all others are ignored. This function is realized as a task. It has to be called as following:

BaseType_t result = xTaskCreate((TaskFunction_t)WriteToBackupThread, "Flash", 100, NULL, TASK_PRIORITY_FlashSave, NULL);
if(result != pdPASS ) {...}
static void WriteToBackupThread(void *argument)
Writes backup-values into flash.
Definition: PARA_Flash_STM32H5.c:429
Parameters
argumentnot used. Set NULL as argument.

Variable Documentation

◆ destoffset

return len destoffset =0

◆ else

else
Initial value:
{
uint16_t void int32_t uint32_t ui32Offset
Definition: PARA_Flash_STM32H5.c:981

◆ g_ui32ParaFlashFlags

g_ui32ParaFlashFlags = (1<<0)

◆ i8len

uint8_t i8len

◆ len

g_ui32ParaFlashFlags& len = strlen(localInf.SoftwareVersion)

◆ localInf

◆ pData

uint16_t void * pData

◆ tAccessSource

uint16_t void int32_t uint32_t ParameterAccessSource tAccessSource

◆ ui16SubId

uint16_t ui16SubId

◆ ui32MaxCount

uint16_t void int32_t ui32MaxCount

◆ ui32Offset

uint16_t void int32_t uint32_t ui32Offset

◆ ui8AccessLevel

uint16_t void int32_t uint32_t ParameterAccessSource uint8_t ui8AccessLevel
Initial value:
{
return 0
bool IsValidForRead(Parameter *ptThis, uint16_t ui16SubId, void *pData, int32_t ui32MaxCount, uint32_t ui32Offset, ParameterAccessSource tAccessSource, uint8_t ui8AccessLevel)
Check if the actual access-right is sufficient to read the parameter.
Definition: PARA_Data.c:770
uint16_t void int32_t uint32_t ParameterAccessSource tAccessSource
Definition: PARA_Flash_STM32H5.c:981
uint16_t void int32_t ui32MaxCount
Definition: PARA_Flash_STM32H5.c:981
uint16_t void * pData
Definition: PARA_Flash_STM32H5.c:981
uint16_t void int32_t uint32_t ParameterAccessSource uint8_t ui8AccessLevel
Definition: PARA_Flash_STM32H5.c:982
uint16_t ui16SubId
Definition: PARA_Flash_STM32H5.c:981