Hello,
I try to write some data into the Flash, using the Flash API from C2000. When I want to verify the data which was written into the flash, I came across a strange phenomenon. Here is my code.
I have a global structure called blFlags with dummy data, which should be written into flash. (The structure is again in another structer, but I left it out for the sake of simplicity).
struct STRUCT_bootloaderFlags { uint16_t appFlag; // = 0xFFFF uint16_t backupFlag; // = 0xFFFF uint16_t flashError; // = 22 uint16_t RS485Error; // = 44 uint16_t rsvd_1; // = 1 uint16_t rsvd_2; // = 2 uint16_t rsvd_3; // = 3 uint16_t rsvd_4; // = 4 }; struct STRUCT_bootloaderFlags blFlags;
At first, I initialize the API as described in the Flash API Manual with Initializing the Flash Bank, Fapi_initializeAPI(), Fapi_setActiveFlashBank(). All functions are placed in the RAM.
Then I write the data with this code.
// Issue program command oReturnCheck = Fapi_issueProgrammingCommand((uint32_t *)BOOTLOADER_FLAGS_START_ADDRESS, (uint16_t *)&objFlash.blFlags, 8, 0, 0, Fapi_AutoEccGeneration); // Wait until the Flash program operation is over while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady) if(oReturnCheck != Fapi_Status_Success) { objFlash.error |= ERROR_FAPI_WRITEFLAG; }
If I do now a CPU-read of the flash-address, I can see that the values are correct. However, if I use the Fapi_doVerify() function, it gives me a failure. I tried some different settings and I was able to narrow the problem down to two function calls, where one works and the other does not.
Fapi_StatusType oReturnCheck; Fapi_FlashStatusWordType oFlashStatusWord_1, oFlashStatusWord_2; uint16_t tempDataBlock[8]; uint32_t *tempPtr; memcpy((uint16_t *)&tempDataBlock, (uint16_t *)&objFlash.blFlags, sizeof(tempDataBlock)); tempPtr = (uint32_t *)&tempDataBlock; // = 0x00000438 oReturnCheck = Fapi_doVerify((uint32_t *)startAddress, 4, tempPtr, &oFlashStatusWord_1); // Works tempPtr = (uint32_t *)&objFlash.blFlags; // = 0x0000A813 oReturnCheck = Fapi_doVerify((uint32_t *)startAddress, 4, tempPtr, &oFlashStatusWord_2); // Do not work
The return values in oFlashStatusWord of the function which is workung gives
oFlashStatusWord_1.au32StatusWord [0] 0x00000000 [1] 0x00100002 [2] 0x0005F8A0 [3] 0x0005F890
and the one which fails is
oFlashStatusWord_2.au32StatusWord [0] 0x00082000 // address of first non-blank location [1] 0xFFFFFFFF // data read at first verify failure location [2] 0xFFFF0000 // value of compare data [3] 0x00000000 // N/A
So as I interpret it, the function has problems reading from the global structure. Is this possible or have I another mistake?
Of cource I would like to avoid the memcpy() funcition and read directly from the structure, to speed things up.
I hope someone can help me with this. Thanks already in advance.
Best regards,
Simon