Part Number: TMS320F28069M
Other Parts Discussed in Thread: MOTORWARE
I am using Motorware 18 proj_lab09a for this.
I am trying to use data saved in flash to initialize a struct on startup. I have created a const struct in flash that I initialize with a macro containing default parameters, which is then written when I program the board. Then when running the program, the data from the struct in flash gets copied to the struct in RAM. If I make any changes to the struct in RAM that I want to keep, I save the data to the struct in flash via Flash_Program() (flash api function).
The issue: when I start the board after writing data to flash that differs from what is defined in the macro, the program crashes to PIE_illegalIsr().
I assume that the problem stems from the program trying to initialize the flash struct with the macro, but the data does not match, and it cannot write to flash, so it crashes.
Is there any way to solve this? I want the default data to be written when flashing the board, but then be able to work with changed values if needed.
It currently looks something like this (not actual code, just to give you an idea about the sequence of actions):
#pragma DATA_SECTION(gUserParams_flash,"persistent_memory");
#define USER_Params_INIT {/*default params*/}
const USER_Params gUserParams_flash = USER_Params_INIT;
USER_Params gUserParams;
void main(void)
{
gUserParams = gUserParams_flash;
// Do stuff
Flash_Erase(SECTORH,&FlashStatus);
Flash_Program((Uint16*)&gUserParams_flash,(Uint16*)&gUserParams,sizeof(USER_Params),&FlashStatus);
}