![]() |
ParaLib 2.0.15-master SHA: 2e03d68caa
|
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) | |
| memcpy & | localInf (*(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_ui32ParaFlashFlags & | len = strlen(localInf.SoftwareVersion) |
| else | |
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
| #define FlashData1 (*(tFlashInformation*)PARAMETER_FLASH_BASE_BLOCK1) |
| #define FlashData2 (*(tFlashInformation*)PARAMETER_FLASH_BASE_BLOCK2) |
| #define MAXIMUM_PARAMETER_DATAPOINTER ((PARAMETER_FLASH_MAX_SIZE - PARA_FLASH_SIZE_BLOCK) /PARA_FLASH_SIZE_BLOCK) |
Maximum address of valid flash blocks.
| #define MEMBER_SIZEOF | ( | t, | |
| f | |||
| ) | (sizeof(((t*)0)->f)) |
| #define PARA_FLASH_FLAG_DECC_ACTIVE (1<<1) |
| #define PARA_FLASH_FLAG_READ_ACTIVE (1<<0) |
| #define PARA_FLASH_SIZE_BLOCK 32 |
Total size of one flash block.
| #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.
| #define PARA_FLASH_SIZE_HALFWORD 2 |
| #define PARAMETER_FLASH_VERSION 1 |
Version of the flash library.
| 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.
| true | if ErrorReset was successful |
| false | if ErrorReset was not successful |
|
static |
Erase the complete user data area in Flash in the specified bank.
| bank | Number of the bank to be erased (1 or 2). |
|
static |
Error-reset definition which is called after error-reset in if a flash error is present.
| g_ui32ParaFlashFlags &return GetDataTypeSize | ( | TYPE_uint32 | ) | = ~( (1<<0) | (1<<1) ) |
| if | ( | __HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)||((*(tFlashInformation *) PARAMETER_FLASH_BASE_BLOCK1) .Size==0xFFFF) | ) |
| if | ( | IsValidForRead(ptThis, ui16SubId, pData, ui32MaxCount, ui32Offset, tAccessSource, ui8AccessLevel) | = = false | ) |
| if | ( | len | , |
| (ui32MaxCount - destoffset) | |||
| ) |
| memcpy & localInf | ( | *(tFlashInformation *) | PARAMETER_FLASH_BASE_BLOCK1 | ) |
| memcpy | ( | pData | , |
| &(*(tFlashInformation *) PARAMETER_FLASH_BASE_BLOCK1) . | WriteCycleCount, | ||
| 4 | |||
| ) |
| void PARA_FlashInit | ( | void | ) |
Initialization of parameter flash interface needs to be called before:
| 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!
| location | selects the storage location |
| Access | Source of access (see Access restrictions). |
| AccessLevel | Actual AccessLevel (see Access restrictions). |
| 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.
| location | selects the storage location |
| True | if successfull. |
| 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 | ( | 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 | |||
| ) |
| 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 | |||
| ) |
| 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_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.
| ptThis | Pointer to the Parameter. | |
| ui16SubId | SubID to read. | |
| [out] | pData | Outputbuffer to store the parametervalue. |
| ui32MaxCount | Buffer size. If smaller than data size, return 0 | |
| ui32Offset | Start-offset to read from. If bigger than data-size return 0 | |
| tAccessSource | Source of access (see Access restrictions). | |
| ui8AccessLevel | Actual AccessLevel (see Access restrictions). |
|
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.
| FlashDataLocation | Pointer to the flash-information stored in flash. |
| True | if successfull. |
|
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:
| argument | not used. Set NULL as argument. |
| return len destoffset =0 |
| else |
| g_ui32ParaFlashFlags = (1<<0) |
| uint8_t i8len |
| g_ui32ParaFlashFlags& len = strlen(localInf.SoftwareVersion) |
| tFlashInformation localInf |
| uint16_t void * pData |
| uint16_t void int32_t uint32_t ParameterAccessSource tAccessSource |
| uint16_t ui16SubId |
| uint16_t void int32_t ui32MaxCount |
| uint16_t void int32_t uint32_t ui32Offset |
| uint16_t void int32_t uint32_t ParameterAccessSource uint8_t ui8AccessLevel |