Other Parts Discussed in Thread: CONTROLSUITE
I am working on software that need to write in flash while using the CSM.
The approach I used to allow the software to momentary be able to use the flash api, is to wrap the function call with an unlock and a locking function.
the functions are define as the following:
#pragma CODE_SECTION(configctrl_CSMUnlock, "ramfuncs"); Uint16 configctrl_CSMUnlock(); #pragma CODE_SECTION(configctrl_CSMlock, "ramfuncs"); void configctrl_CSMlock();
Uint16 configctrl_CSMUnlock()
{
volatile Uint16 temp;
// Load the key registers with the current password
// These are defined in Example_Flash2803x_CsmKeys.asm
EALLOW;
CsmRegs.KEY0 = PRG_key0;
CsmRegs.KEY1 = PRG_key1;
CsmRegs.KEY2 = PRG_key2;
CsmRegs.KEY3 = PRG_key3;
CsmRegs.KEY4 = PRG_key4;
CsmRegs.KEY5 = PRG_key5;
CsmRegs.KEY6 = PRG_key6;
CsmRegs.KEY7 = PRG_key7;
EDIS;
// Perform a dummy read of the password locations
// if they match the key values, the CSM will unlock
temp = CsmPwl.PSWD0;
temp = CsmPwl.PSWD1;
temp = CsmPwl.PSWD2;
temp = CsmPwl.PSWD3;
temp = CsmPwl.PSWD4;
temp = CsmPwl.PSWD5;
temp = CsmPwl.PSWD6;
temp = CsmPwl.PSWD7;
// If the CSM unlocked, return succes, otherwise return
// failure.
if ( (CsmRegs.CSMSCR.all & 0x0001) == 0)
{
return STATUS_SUCCESS;
}
else
{
return STATUS_FAIL_CSM_LOCKED;
}
}
//----------------------------------------------------------------------------------
void configctrl_CSMlock()
{
EALLOW;
CsmRegs.CSMSCR.bit.FORCESEC=1;
EDIS;
}
Although, theses functions seems not to be always effective and the flash api return csm related errors.
Is there something wrong with the approach I used? Is there any timing specification to take into account while enabling/disabling the CSM?
Thanks,
Simon