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.
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;
Hello,
I strongly recommend you to use the flash API to write data to flash: Fapi_issueProgrammingCommand()
This function sets up the programming registers of the Flash State Machine based on the supplied parameters. This function has one option of calculating and programming the ECC. ECC is calculated on 64-bit aligned addresses up to the data width of the bank (144 bit for LS3137). Data not supplied is treated as 0xFF. For example, on a device with a 144-bit wide bank width, if data is written only to bytes 0x0-0x7 (or 0x8-0xF), then the ECC will only be calculated for those 64 bits. If the data supplied crosses a 64-bit boundary, ECC will be calculated for both 64-bit words. For example, on a device with a 144-bit wide bank width, data is written to bytes 0x4 - 0xB, the 2 bytes of ECC data will be calculated. The data restrictions for Fapi_DataOnly also exist for this option.
What is "data segment" and "ECC segment" in your message?
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?
QJ> As I mentioned in my last post, ECC is calculated on 64-bit aligned addresses up to the data width of the bank. Data not supplied is treated as 0xFF. If you write 1 byte data (e.g 0x5A) to the location at 0x103, the API will calculate the ECC of data 0xFF, 0xFF, 0xFF, 0x5A, 0xFF, 0xFF, 0xFF, 0xFF from address 0x100 to 0x107. The 1 byte ECC value will be write to 0xF040_0020.
You can not write ECC value directly to ECC location (for example 0xF0200020).
Please use Flash API instead of writing your own code.
Hi QJ Wang,
Thanks for your quick reply,in Programming a Single Byte example code,I didn't see the code to calculate ECC,why is ECC not calculated?
Thanks.
Hello,
The flash API Fapi_issueProgrammingCommand() is able to program both data the ECC.