cancel
Showing results for 
Search instead for 
Did you mean: 

SPC560B writing data to DFLASH

Patriks
Senior
Posted on December 01, 2014 at 15:14

Hello,

I would like to store data in the DFLASH of my SPC560B. Therefore, I wrote the following function, according to the reference manual page 693:

void
DFO_WriteFlashDoubleWord(uint32_t dataWordHigh, uint32_t dataWordLow){ 


uint32_t tmp, status; 


/* STEP 1 - UNLOCK FLASH REGION: BOTH REGISTERS LML and SLL have to be enabled*/

UnlockDFlash(); 


/* STEP2 - SELECT DESIRED OPERATION - double word program */

DFLASH.MCR.R = 0x00000010; 
/* Set PGM in MCR: Select Operation */


/* STEP3 - DEFINITION OF OPERANDS: ADRESS AND DATA (double word data which should be write to flash) */

DFLASH_TARGET_PHASE_X = dataWordHigh; 
/* Latch Address and 32 LSB data */

DFLASH_TARGET_PHASE_Y = dataWordLow; 
/* Latch 32 MSB data */


/* STEP4 - START OPERATION */

DFLASH.MCR.R = 0x00000011; 
/* Set EHV in MCR: Operation Start */


/* STEP5 - WAIT UNTIL PROCESS FINISHED */

do
{ 

tmp = DFLASH.MCR.R; 
/* Read MCR */

} 
while
( !(tmp & 0x00000400) ); 


//status = DFLASH.MCR.R & 0x00000200; /* Check PEG(Program/Erase Good) flag */ 


/* END OF OPERATION */

LockDFlash(); 

}

My function seems to have an error and I hope someone can tell me what I am doing wrong. With this function, I was able to write to an empty address of DFLASH at 0x00800000 and 0x00800 But sometimes, when I try to write a new value to the same addresses, the FLASH memory gets corrupted at theses adresses. Means, when I reset the controller and start the software again, it always halts at a specific adress when I try to read the written DFLASH memory addresses. In that case, I have to perform a total flash erase and flash the software to the controller again. Can anyone tell me what the error in my function is and how I can prevent the flash from getting corrupted during the write process? Best regards, Patrik
This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
0 REPLIES 0