AnsweredAssumed Answered

FLASH1_LDD unexpected behavior

Question asked by David McClung on Jan 23, 2018
Latest reply on Jan 25, 2018 by David McClung

I have noticed a few strange things happen when trying to modify flash with Flash_LDD functions. I tried using the interrupt enabled, then polling, and got the same results.

 

Write:

It appears as though I can only write to each address one time. Attempting another write to the same location twice will cause "DataWrittenFlg" to never clear, and the processor gets stuck in an infinite loop.

 

Erase:

I have an instruction to clear 0x1FE28 (size 0x1C bytes). I have found that this wipes out data that I've written to 0x1FE14 - 0x1FE27. This is strange because I have another command that seems to work elsewhere, that erases 0x1FE00 - 0x1FEA0.

 

 

I wrote "write" and "erase" functions that use a self written macro called "wait_for_flash()". These are pasted below. The only way I could get write and erase to work was to disable the watchdog because it couldn't be fed long enough to get through the erase step.

 

LDD_TError flash_write(LDD_TDeviceData *DeviceDataPtr, LDD_TData *FromPtr, LDD_FLASH_TAddress ToAddress, LDD_FLASH_TDataSize Size) {
DataWrittenFlg = FALSE;
WDog1_Disable(MyWDog1Ptr);
Error = FLASH1_Write(DeviceDataPtr, FromPtr, ToAddress, Size);
if(Error == ERR_OK) {
wait_for_flash();
}
WDog1_Enable(MyWDog1Ptr);
return Error;
}

 

LDD_TError flash_erase(LDD_TDeviceData *DeviceDataPtr, LDD_FLASH_TAddress FromAddress, LDD_FLASH_TDataSize Size) {
WDog1_Disable(MyWDog1Ptr);
DataWrittenFlg = FALSE;
Error = FLASH1_Erase(DeviceDataPtr, FromAddress, Size);
if(Error == ERR_OK) {
wait_for_flash();
}
WDog1_Enable(MyWDog1Ptr);
return Error;

 

 

void wait_for_flash(void) {
while(!DataWrittenFlg) {
FLASH1_Main(MyFLASH_Ptr);
}
flashOpStatus = FLASH1_GetOperationStatus(MyFLASH_Ptr);
if ((flashOpStatus == LDD_FLASH_FAILED)) {
Error = ERR_FAILED;
error_code_6205 = 0x6205;
}
}

 

Using KDS 3.2 (although condition persists in other versions.) for a KEA128 processor.

Outcomes