Tool/software: Code Composer Studio
Hi,
I'm programming flash with f021 flash api on tms570ls3137 demo board,I found two program example code in section 3.2 of the spna148.pdf,I have some questions about this.
1.For Programming a Single Byte,when the program address is located in the data segment,will the ecc be programmed to the corresponding ecc address?When the program address is located in the ecc segment,will the data be programmed to the corresponding data address?
2.For Programming 128-Bit Data and 16-Bit ECC,there is a line of code "FLASH_CONTROL_REGISTER->FemuAddr.u32Register = 0x0100;",what I found is the EEPROM Emulation Address Register,what is the purpose of this line of code?
Thanks.
3.2.1 Programming a Single Byte
FLASH_CONTROL_REGISTER->Fbprot.u32Register = 1U; /* Disable Level 1 Protection */ /* Enable all sectors of current bank for erase and program. For EEPROM banks with more than 16 sectors, this must be 0xFFFF */ FLASH_CONTROL_REGISTER->Fbse.u32Register = 0xFFFF; FLASH_CONTROL_REGISTER->Fbprot.u32Register = 0U; /* Enable Level 1 Protection */ /*Unlock FSM registers for writing */ FLASH_CONTROL_REGISTER->FsmWrEna.u32Register = 0x5U; /* Set command to "Clear the Status Register" */ FLASH_CONTROL_REGISTER->FsmCommand.FSM_COMMAND_BITS.FSMCMD = Fapi_ClearStatus; /* Execute the Clear Status command */ FLASH_CONTROL_REGISTER->FsmExecute.FSM_EXECUTE_BITS.FSMEXECUTE = 0x15U; /* Write address to FADDR register */ FLASH_CONTROL_REGISTER->Faddr.u32Register = 0x0100U; /* Placing byte at address 0x0102 */ oFwpWriteByteAccessor[2] = 0xA5; /* Set command to "Program" */ FLASH_CONTROL_REGISTER->FsmCommand.FSM_COMMAND_BITS.FSMCMD = Fapi_ProgramData; /* Execute the Program command */ FLASH_CONTROL_REGISTER->FsmExecute.FSM_EXECUTE_BITS.FSMEXECUTE = 0x15U; /* re-lock FSM registers to prevent writing */ FLASH_CONTROL_REGISTER->FsmWrEna.u32Register = 0x2U;
3.2.2 Programming 128-Bit Data and 16-Bit ECC
FLASH_CONTROL_REGISTER->Fbprot.u32Register = 1U; /* Disable Level 1 Protection */
/* Enable all sectors of current bank for erase and program. For EEPROM banks with more
than 16 sectors, this must be 0xFFFF */
FLASH_CONTROL_REGISTER->Fbse.u32Register = 0xFFFF;
FLASH_CONTROL_REGISTER->Fbprot.u32Register = 0U; /* Enable Level 1 Protection */
/*Unlock FSM registers for writing */
FLASH_CONTROL_REGISTER->FsmWrEna.u32Register = 0x5U;
/* Set command to "Clear the Status Register" */
FLASH_CONTROL_REGISTER->FsmCommand.FSM_COMMAND_BITS.FSMCMD = Fapi_ClearStatus;
/* Execute the Clear Status command */
FLASH_CONTROL_REGISTER->FsmExecute.FSM_EXECUTE_BITS.FSMEXECUTE = 0x15U;
/* Write address to FADDR register */
FLASH_CONTROL_REGISTER->Faddr.u32Register = 0x0100U;
/* Placing bytes at address 0x0100 - 0x010F */
for(u32Index=0;u32Index<16;u32Index++)
{
oFwpWriteByteAccessor[u32Index] = au8MainDataBuffer[u32Index];
}
/* Supply the address where ECC is being calculated */
FLASH_CONTROL_REGISTER->FemuAddr.u32Register = 0x0100;
#if defined(_LITTLE_ENDIAN)
/* Supply the lower 32bit word */
FLASH_CONTROL_REGISTER->FemuDlsw.u32Register = oFwpWriteDwordAccessor[1];
/* Supply the upper 32bit word */
FLASH_CONTROL_REGISTER->FemuDmsw.u32Register = oFwpWriteDwordAccessor[0];
#else
/* Supply the upper 32bit word */
FLASH_CONTROL_REGISTER->FemuDlsw.u32Register = oFwpWriteDwordAccessor[0];
/* Supply the lower 32bit word */
FLASH_CONTROL_REGISTER->FemuDmsw.u32Register = oFwpWriteDwordAccessor[1];
#endif
/* Place the Wrapper calculated ECC into FWPWRITE_ECC */
oFwpWriteEccByteAccessor[EI8(0)] = FLASH_CONTROL_REGISTER->FemuEcc.FEMU_ECC_BITS.EMU_ECC);
/* Supply the address where ECC is being calculated */
FLASH_CONTROL_REGISTER->FemuAddr.u32Register = 0x0108;
#if defined(_LITTLE_ENDIAN)
/* Supply the lower 32bit word */
FLASH_CONTROL_REGISTER->FemuDlsw.u32Register = oFwpWriteDwordAccessor[3];
/* Supply the upper 32bit word */
FLASH_CONTROL_REGISTER->FemuDmsw.u32Register = oFwpWriteDwordAccessor[2];
#else
/* Supply the upper 32bit word */
FLASH_CONTROL_REGISTER->FemuDlsw.u32Register = oFwpWriteDwordAccessor[2];
/* Supply the lower 32bit word */
FLASH_CONTROL_REGISTER->FemuDmsw.u32Register = oFwpWriteDwordAccessor[3];
#endif
/* Place the Wrapper calculated ECC into FWPWRITE_ECC */
oFwpWriteEccByteAccessor[EI8(1)] = FLASH_CONTROL_REGISTER->FemuEcc.FEMU_ECC_BITS.EMU_ECC);
/* Set command to "Program" */
FLASH_CONTROL_REGISTER->FsmCommand.FSM_COMMAND_BITS.FSMCMD = Fapi_ProgramData;
/* Execute the Program command */
FLASH_CONTROL_REGISTER->FsmExecute.FSM_EXECUTE_BITS.FSMEXECUTE = 0x15U;
/* re-lock FSM registers to prevent writing */
FLASH_CONTROL_REGISTER->FsmWrEna.u32Register = 0x2U;