AnsweredAssumed Answered

SPC560B writing data to DFLASH

Question asked by Patrik Schantl on Dec 1, 2014

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){
02.
03.uint32_t tmp, status;
04.
05./* STEP 1 - UNLOCK FLASH REGION: BOTH REGISTERS LML and SLL have to be enabled*/
06.UnlockDFlash();
07.
08./* STEP2 - SELECT DESIRED OPERATION - double word program */
09.DFLASH.MCR.R = 0x00000010; /* Set PGM in MCR: Select Operation */
10.
11./* STEP3 - DEFINITION OF OPERANDS: ADRESS AND DATA (double word data which should be write to flash) */
12.DFLASH_TARGET_PHASE_X = dataWordHigh; /* Latch Address and 32 LSB data */
13.DFLASH_TARGET_PHASE_Y = dataWordLow; /* Latch 32 MSB data */
14.
15./* STEP4 - START OPERATION */
16.DFLASH.MCR.R = 0x00000011; /* Set EHV in MCR: Operation Start */
17.
18./* STEP5 - WAIT UNTIL PROCESS FINISHED */
19.do{
20.tmp = DFLASH.MCR.R; /* Read MCR */
21.} while ( !(tmp & 0x00000400) );
22.
23.//status = DFLASH.MCR.R & 0x00000200; /* Check PEG(Program/Erase Good) flag */
24.
25./* END OF OPERATION */
26.LockDFlash();
27.}

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 0x00800004. 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

Outcomes