Hi guys,
I'm running a setup where an RM42 configured as SPI-slave gets a firmware image from the SPI-master. I'm writing the bootloader for the slave, and I'm using the F021 Flash API v. 1.51 on an RM42L43 platform. I've made some code that transfers an image through SPI and tries to write it to flash. I've used the bootloader examples from the wiki as my starting poing.
Sometimes however, what I try to write is not what ends up on the flash chip. When I receive a firmware-image, my program flow is like this:
1) Erase the area containing application code (only done once and for all relevant sectors)
2) Check that the erased area is all 1-bits
3) Write the transferred payload to the flash chip 16 bytes at a time
4) Read the written data from the flash 16 bytes at a time, compare the read-buffer to the write-buffer
Now what I see is, sporadically the write will go awry. What ends up on the flash chip is not what was in the buffer passed to Fapi_BlockProgram - I will typically see this error after a couple of writes and I see the first error quicker if I write to the chip with shorter intervals (transfer smaller chunks through SPI).
I'm using the API like QJ Wang describes in this post: http://e2e.ti.com/support/microcontrollers/hercules/f/312/t/277379.aspx
For Flash Erase:
Fapi_initializeAPI((Fapi_FmcRegistersType *)F021_CPU0_REGISTER_ADDRESS, Freq_In_MHz);
Fapi_setActiveFlashBank((Fapi_FlashBankType)ucBank);
Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, eraseStartAddr);
status = Fapi_getFsmStatus();
status = Flash_Erase_Check((uint32_t)eraseStartAddr0, Size_In_Bytes);
For flash program:
Fapi_initializeAPI((Fapi_FmcRegistersType *)F021_CPU0_REGISTER_ADDRESS, Freq_In_MHz);
Fapi_setActiveFlashBank((Fapi_FlashBankType)Bank);
Fapi_issueProgrammingCommand((uint32_t *)dst,
status = Flash_Program_Check(Flash_Start_Address, Data_Start_Address, Size_In_Bytes);
I've sprinkled my code with assertions and error checks to narrow in on the source of the error. I am always succesful in erasing the chip and it is only the writing part that fails.
I'm running the code without an OS, in privilege mode, interrupts are disabled while writing/erasing and I'm running the Fapi-object code and the code that calls it from SRAM. System clock frequency is 100MHz (Freq_In_MHz) and I'm writing to flash address 0x10000 and forward (bank 0, sectors 8-14).
Any more info I should provide ?
Kind regards
/Mikkel