This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Flash memory operations while using the CSM

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

  • Simon,

    You don't need to run Configctrl_CSMUnlock & configctrl_CSMlock function from RAM. You should be able to run these function from flash. Also, if these two functions are executed from unsecure RAM memory, ECSL logic in CSM will disconnect JTAG access.

    You can find controlsuite example "flash_programming" useful. Please refer to this example before proceeding with your debug.

    Regards,
    Manoj
  • The problem was that those functions were indeed in unsecured memory. I removed them from ramfuncts and everything is now working well.

    Thanks for the tip!

    Simon