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

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

#include <stdbool.h>
#include <stdint.h>
#include "project_config.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 "basicModules/Network/ptp_timestamp.h"
#include "PARA_Flash_STM32H7.h"
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_conf.h"
#include "MemoryOrganization.h"
#include "FreeRTOS.h"
#include "task.h"
#include "gitRevision.h"
#include "PARA_Identifikation.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_BLOCK   FLASH_NB_32BITWORD_IN_FLASHWORD*4
 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 BSY_FLAG   FLASH_FLAG_QW_BANK1
 

Functions

static bool FlashErrorReset (void)
 Error-reset definition which is called after error-reset in if a flash error is present. More...
 
 DefineOnErrorResetReaction (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 (const 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 FlashEraseParaSector (uint32_t sector)
 Erase one complete sector in flash. More...
 
int32_t ReadFunction_FlashInfo_U16 (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...
 
int32_t ReadFunction_FlashInfo_U32 (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...
 
int32_t ReadFunction_FlashInfo_STR (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 FlashData1 ParameterU32 FlashData1 ParameterSTR ((char *)&FlashData1.SoftwareVersion, PARA_ID_FlashSoftwareVersion, GROUP_ID_System, "Parameter Flash Softwareversion", "", "Software Version which saved the Parameters", "", "", "", 1, 30, "unknown", ReadFunction_FlashInfo_STR, WriteFunction_STD_Const, SetToDefaultFunction_STD_Const, VIEWER_READ|USER_READ|PROFESSIONAL_READ|DEVELOPER_READ, NOT_STORED, FLAG_NONE) ParameterU32(&FlashData1.WriteTimestamp
 

Variables

ParameterU16 FlashData1 ParameterU32 FlashData1 PARA_ID_FlashTimestamp
 
ParameterU16 FlashData1 ParameterU32 FlashData1 GROUP_ID_System
 
ParameterU16 FlashData1 ParameterU32 FlashData1 Parameter Write Timestamp
 

Detailed Description

Flash parameter storage for STMicroelectronics SMT32H7 Series.


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

Macro Definition Documentation

◆ BSY_FLAG

#define BSY_FLAG   FLASH_FLAG_QW_BANK1

◆ 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_SIZE_BLOCK

#define PARA_FLASH_SIZE_BLOCK   FLASH_NB_32BITWORD_IN_FLASHWORD*4

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.

◆ PARAMETER_FLASH_VERSION

#define PARAMETER_FLASH_VERSION   1

Version of the flash library.

Function Documentation

◆ DefineOnErrorResetReaction()

DefineOnErrorResetReaction ( 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

◆ FlashEraseParaSector()

static HAL_StatusTypeDef FlashEraseParaSector ( uint32_t  sector)
static

Erase one complete sector in flash.

Parameters
sectorNumber of the sector to be erased.
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.

◆ 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.

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.

◆ ParameterSTR()

ParameterU16 FlashData1 ParameterU32 FlashData1 ParameterSTR ( (char *)&FlashData1.  SoftwareVersion,
PARA_ID_FlashSoftwareVersion  ,
GROUP_ID_System  ,
"Parameter Flash Softwareversion"  ,
""  ,
"Software Version which saved the Parameters"  ,
""  ,
""  ,
""  ,
,
30  ,
"unknown"  ,
ReadFunction_FlashInfo_STR  ,
WriteFunction_STD_Const  ,
SetToDefaultFunction_STD_Const  ,
VIEWER_READ|USER_READ|PROFESSIONAL_READ DEVELOPER_READ,
NOT_STORED  ,
FLAG_NONE   
) &

◆ ReadFunction_FlashInfo_STR()

int32_t ReadFunction_FlashInfo_STR ( 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.

◆ ReadFunction_FlashInfo_U16()

int32_t ReadFunction_FlashInfo_U16 ( 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.

◆ ReadFunction_FlashInfo_U32()

int32_t ReadFunction_FlashInfo_U32 ( 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 ( const 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

◆ GROUP_ID_System

◆ PARA_ID_FlashTimestamp

◆ Timestamp