Merge branch 'master' of https://gitlab.psi.ch/coldbox/tec
This commit is contained in:
@ -61,7 +61,12 @@
|
|||||||
// Description: Definition of local constants (visible by this module only).
|
// Description: Definition of local constants (visible by this module only).
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
|
|
||||||
|
#define USERFLASHSIZE (2000/4) // Bytes -> 64 Bits
|
||||||
|
#define USERFLASHPAGE (63)
|
||||||
|
|
||||||
|
#define STARTDEF 0xAA01F055
|
||||||
|
|
||||||
|
#define VARDEF 0xABCDEF00
|
||||||
|
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
// Section: MACROS
|
// Section: MACROS
|
||||||
@ -82,7 +87,12 @@
|
|||||||
// Description: Definition of local Structures (visible by this module only).
|
// Description: Definition of local Structures (visible by this module only).
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
|
|
||||||
|
FLASH_EraseInitTypeDef stEreaseInit = {
|
||||||
|
FLASH_TYPEERASE_PAGES,
|
||||||
|
FLASH_BANK_1,
|
||||||
|
UserFlashPage,
|
||||||
|
1
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
@ -97,28 +107,14 @@
|
|||||||
// Description: Definition of local constants (visible by this module only).
|
// Description: Definition of local constants (visible by this module only).
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
|
|
||||||
__attribute__((__section__(".user_data"))) const uint8_t userConfig[8];
|
__attribute__((__section__(".user_data"))) const U64 UserFlash[UserFlashSize];
|
||||||
|
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
// Section: LOCAL FUNCTIONS (PROTOTYPES)
|
||||||
// Description: Definition of local functions (visible by this module only).
|
// Description: Definition of local functions (visible by this module only).
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
|
|
||||||
|
void vEreaseUserFlash( void );
|
||||||
|
|
||||||
//=================================================================================================
|
|
||||||
// Section: EXTERNAL FUNCTIONS
|
|
||||||
// Description: Definition of external (global) functions.
|
|
||||||
//=================================================================================================
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=================================================================================================
|
|
||||||
// Section: EXTERNAL VARIABLES
|
|
||||||
// Description: Definition of external (global) variables.
|
|
||||||
//=================================================================================================
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
// Section: GLOBAL FUNCTIONS
|
// Section: GLOBAL FUNCTIONS
|
||||||
@ -126,7 +122,7 @@ __attribute__((__section__(".user_data"))) const uint8_t userConfig[8];
|
|||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------
|
||||||
// Function: TMPL_boInitializeModule
|
// Function: USFL_boInitializeModule
|
||||||
// Description: Initializes the module. Function must be called once immediately after power-up.
|
// Description: Initializes the module. Function must be called once immediately after power-up.
|
||||||
// Parameters: None
|
// Parameters: None
|
||||||
// Returns: Boolean TRUE if successful
|
// Returns: Boolean TRUE if successful
|
||||||
@ -134,9 +130,15 @@ __attribute__((__section__(".user_data"))) const uint8_t userConfig[8];
|
|||||||
|
|
||||||
BOOL USFL_boInitializeModule( VOID )
|
BOOL USFL_boInitializeModule( VOID )
|
||||||
{
|
{
|
||||||
|
BOOL boOK = TRUE;
|
||||||
|
|
||||||
// TODO: notes
|
if( UserFlash[0] != StartDef ){
|
||||||
return( TRUE );
|
boOK &= vEreaseUserFlash();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return( boOK );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -145,3 +147,55 @@ BOOL USFL_boInitializeModule( VOID )
|
|||||||
// Section: LOCAL FUNCTIONS
|
// Section: LOCAL FUNCTIONS
|
||||||
// Descriptionn: Definition (implementation) of local functions.
|
// Descriptionn: Definition (implementation) of local functions.
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: vEreaseUserFlash
|
||||||
|
// Description: Ereases the User Flash Sector
|
||||||
|
// Parameters: None
|
||||||
|
// Returns: Boolean TRUE if successful
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
U32 vFindNextFreePointer( void ){
|
||||||
|
|
||||||
|
BOOL boFound = FALSE;
|
||||||
|
U32 u32Pointer = 1; // 0 is StartDef
|
||||||
|
|
||||||
|
while(!boFound){
|
||||||
|
|
||||||
|
if( (UserFlash[u32Pointer] & 0xFFFFFF00) == VARDEF ){
|
||||||
|
U8 u8Size = UserFlash[u32Pointer] & 0xFF;
|
||||||
|
if( u8Size == 0 ){
|
||||||
|
boFound = TRUE;
|
||||||
|
} else {
|
||||||
|
u32Pointer += u8Size + 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( u32Pointer >= USERFLASHSIZE ){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return u32Pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
// Function: vEreaseUserFlash
|
||||||
|
// Description: Ereases the User Flash Sector
|
||||||
|
// Parameters: None
|
||||||
|
// Returns: Boolean TRUE if successful
|
||||||
|
//-------------------------------------------------------------------------------------------------
|
||||||
|
BOOL vEreaseUserFlash( void ){
|
||||||
|
uint32_t u32PageError = 0;
|
||||||
|
|
||||||
|
if( HAL_FLASHEx_Erase(&stEreaseInit, &u32PageError) != HAL_OK ){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user