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.
Dear Support,
I tried to write a single byte into the flash (as it was described in SPNA148). I executed this from RAM also I couldn't see any issue juts the flash hasn't been updated. I also tried to update the EEPROM but I got the same result.
void flash_write_byte(uint32_t address) { Fapi_StatusType oReturnCheck = Fapi_Status_FsmReady; FwpWriteByteAccessorType * oFwpWriteByteAccessor = FWPWRITE_BYTE_ACCESSOR_ADDRESS; oReturnCheck = Fapi_initializeFlashBanks(160); /* Example code is assuming operating frequency of 180 MHz */ if ((oReturnCheck == Fapi_Status_Success) && (FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY != Fapi_Status_FsmBusy)) { oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank7); 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 = 0xF0000111; /* Placing byte at address 0x0102 */ oFwpWriteByteAccessor[2] = 0xBB; /* 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; /* Wait for FSM to finish */ while (FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY == Fapi_Status_FsmBusy) ; /* Check the FSM Status to see if there were no errors */ if (FLASH_CONTROL_REGISTER->FmStat.u32Register != 0) { /* Put Error handling code here */ } } }
Also I found other implementation on the forum, I tried the following, but I got the same result:
void flash_write_byte(uint32_t address) { Fapi_StatusType oReturnCheck = Fapi_Status_FsmReady; FwpWriteByteAccessorType * oFwpWriteByteAccessor = FWPWRITE_BYTE_ACCESSOR_ADDRESS; uint8_t au8MainDataBuffer[16] = {0xAA, 0x17, 0x19, 0x2E, 0x0A, 0xB9, 0x11, 0x70, 0x5F, 0xC1, 0x9C, 0xFD, 0x54, 0x51, 0xED, 0x86}; uint8_t au8EccDataBuffer[16]; uint32_t *pu32StartAddress = (uint32_t *)(0xF0000111); uint8_t *p1; uint8_t *eccp1; p1 = au8MainDataBuffer; eccp1 = au8EccDataBuffer; oReturnCheck = Fapi_initializeFlashBanks(160); /* Example code is assuming operating frequency of 180 MHz */ if ((oReturnCheck == Fapi_Status_Success) && (FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY != Fapi_Status_FsmBusy)) { oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank7); oReturnCheck = Fapi_enableEepromBankSectors(0xF, 0); while (Fapi_checkFsmForReady() == Fapi_Status_FsmBusy) ; if ((oReturnCheck == Fapi_Status_Success) && (Fapi_checkFsmForReady() != Fapi_Status_FsmBusy)) { oReturnCheck = Fapi_issueProgrammingCommand(&pu32StartAddress, p1, 16, NULL, 0, Fapi_AutoEccGeneration); /* Wait for FSM to finish */ while (Fapi_checkFsmForReady() == Fapi_Status_FsmBusy) ; if ((oReturnCheck == Fapi_Status_Success) && (Fapi_checkFsmForReady() != Fapi_Status_FsmBusy)) { /* Check the FSM Status to see if there were no errors */ if (FLASH_CONTROL_REGISTER->FmStat.u32Register != 0) { /* Put Error handling code here */ } } } } }
Can you help me please? Thank you!
Kind regards,
Keno
Hi Keno,
I recreated the code from SPNA148.pdf and it works. Bank7 starts from 0xF020 0000. Please check it! In your code you are trying to write to 0xF0000111.
Best regards
Miro
Hi Keno,
The code is as spna148.pdf.
Attached also is print screen of "memory browser" where two consecutive writes are done.
int main(void) { /* USER CODE BEGIN (3) */ Fapi_StatusType oReturnCheck = Fapi_Status_Success; FwpWriteByteAccessorType * oFwpWriteByteAccessor = FWPWRITE_BYTE_ACCESSOR_ADDRESS; FwpWriteByteAccessorType * oFwpWriteEccByteAccessor = FWPWRITE_ECC_BYTE_ACCESSOR_ADDRESS; FwpWriteDWordAccessorType * oFwpWriteDWordAccessor = FWPWRITE_DWORD_ACCESSOR_ADDRESS; uint8 au8MainDataBuffer[16] ={0x78, 0x17, 0x19, 0x2E, 0x0A, 0xB9, 0x11, 0x70, 0x5F, 0xC1, 0x9C, 0xFD, 0x54, 0x51, 0xED,0x86}; uint32 u32Index; /* For proper initialization of the device prior to any Flash operations, see the device-specific initialization document. Assumes, unless otherwise noted, device has 144bit wide Flash Banks. */ oReturnCheck = Fapi_initializeFlashBanks(180); /* Example code is assuming operating frequency of 180 MHz */ if((oReturnCheck == Fapi_Status_Success) && (FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY != Fapi_Status_FsmBusy)) { oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank7); /* Place specific example code here */ 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 = 0xF0200000U; /* Placing byte at address 0x0102 */ oFwpWriteByteAccessor[0] = 0x13; /* 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; /* Wait for FSM to finish */ while(FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY == Fapi_Status_FsmBusy); /* Check the FSM Status to see if there were no errors */ if (FLASH_CONTROL_REGISTER->FmStat.u32Register != 0) { /* Put Error handling code here */ } } while(1); /* USER CODE END */ return 0; }
Hi Miro,
I'm using the same processor. I'm using v2.01.01. F021 Flash API (F021_API_CortexR4_BE.lib). Also I'd like to mention again if I erase the hole sector then I can write the flash. Thank you!
Kind regards,
Keno
Hi Miro,
I checked your project settings and I found you erase the hole flash every time when you flash TMS570 chip. If I set writing the necessary sectors only then your project has the same problem as mine -> I'm not able to rewrite a single byte without erase the sector.
Also I tried the following code (I tried to write several bytes into flash continuously, but result was very different):
int main(void) { /* USER CODE BEGIN (3) */ uint8_t i=0; Fapi_StatusType oReturnCheck = Fapi_Status_Success; FwpWriteByteAccessorType * oFwpWriteByteAccessor = FWPWRITE_BYTE_ACCESSOR_ADDRESS; FwpWriteByteAccessorType * oFwpWriteEccByteAccessor = FWPWRITE_ECC_BYTE_ACCESSOR_ADDRESS; FwpWriteDWordAccessorType * oFwpWriteDWordAccessor = FWPWRITE_DWORD_ACCESSOR_ADDRESS; uint8 au8MainDataBuffer[16] ={0x78, 0x17, 0x19, 0x2E, 0x0A, 0xB9, 0x11, 0x70, 0x5F, 0xC1, 0x9C, 0xFD, 0x54, 0x51, 0xED,0x86}; uint32 u32Index; /* For proper initialization of the device prior to any Flash operations, see the device-specific initialization document. Assumes, unless otherwise noted, device has 144bit wide Flash Banks. */ for(i = 0; i< 0xCC; i++) { oReturnCheck = Fapi_initializeFlashBanks(180); /* Example code is assuming operating frequency of 180 MHz */ if((oReturnCheck == Fapi_Status_Success) && (FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY != Fapi_Status_FsmBusy)) { oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank7); /* Place specific example code here */ 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 = 0xF0200000U + i; /* Placing byte at address 0x0102 */ oFwpWriteByteAccessor[0] = 0x00 + i; /* 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; /* Wait for FSM to finish */ while(FLASH_CONTROL_REGISTER->FmStat.FMSTAT_BITS.BUSY == Fapi_Status_FsmBusy); /* Check the FSM Status to see if there were no errors */ if (FLASH_CONTROL_REGISTER->FmStat.u32Register != 0) { /* Put Error handling code here */ } } } while(1); /* USER CODE END */ return 0; }
The result was the following:
Only every 16th bytes have been modified. Why? Thank you!
Kind regards,
Keno
Hi Keno,
In this way you are accessing FEE using Flash API directly. In that case you should take care about sectors management. When using FEE API for read/write user need not take care of management of the sectors.
You can take a look at TI FEE Driver User Guide.pdf under c:\ti\Hercules\HALCoGen\v04.07.00\Docs directory.
Also, there is an example how to read /write FEE under c:\ti\Hercules\HALCoGen\v04.07.00\examples\ directory
Best regards
Miro