How to store to DFlash/EFlash memory

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to store to DFlash/EFlash memory

1,457 Views
jay_montague
Contributor I

Hello,

I am new to using the S32K146 board and I'm trying to store some data in the D-Flash memory. I have used the following code from the "Example_S32K144-Flash_RW_simple-S32DS12" example to erase a sector and program some data, which looks like its storing in memory successfully.

But looking at the Memory Map for the S32K146 it looks like this is storing data into the PFlash memory (0x0 - 0x03FFFFFF) with the DFlash memory starting at 0x10000000. But below the FTFC->FCCOB register doesn't have a setting for the upper byte of the flash address (31:24) which would be needed to access the DFlash memory? 
Any help would be much appreciated, apologies if I'm missing something obvious.
void EraseAndProgram(void)
{
 //erase 4KB flash sector (the smallest entity that can be erased) at 0x0004_0000
 while((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0); //wait if operation in progress
 FTFC->FSTAT = FTFC_FSTAT_ACCERR_MASK | FTFC_FSTAT_FPVIOL_MASK; //clear flags if set
 FTFC->FCCOB[3] = 0x09; //Erase Flash Sector command (0x09)
 FTFC->FCCOB[2] = 0x04; //Flash address [23:16]
 FTFC->FCCOB[1] = 0x00; //Flash address [15:08]
 FTFC->FCCOB[0] = 0x00; //Flash address [7:0]
 FTFC->FSTAT = FTFC_FSTAT_CCIF_MASK; //launch command
 while((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0); //wait for done

 //program phrase at address 0x0004_0000
 while((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0); //wait if operation in progress
 FTFC->FSTAT = FTFC_FSTAT_ACCERR_MASK | FTFC_FSTAT_FPVIOL_MASK;
 FTFC->FCCOB[3] = 0x07; //Program Phrase command (0x07)
 FTFC->FCCOB[2] = 0x04; //Flash address [23:16]
 FTFC->FCCOB[1] = 0x00; //Flash address [15:08]
 FTFC->FCCOB[0] = 0x00; //Flash address [7:0]
 FTFC->FCCOB[7] = 0xFE; //data
 FTFC->FCCOB[6] = 0xED;
 FTFC->FCCOB[5] = 0xFA;
 FTFC->FCCOB[4] = 0xCE;
 FTFC->FCCOB[11] = 0xCA;
 FTFC->FCCOB[10] = 0xFE;
 FTFC->FCCOB[9] = 0xBE;
 FTFC->FCCOB[8] = 0xEF;
 FTFC->FSTAT = FTFC_FSTAT_CCIF_MASK; //launch command
 while((FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK) == 0); //wait for done
}
0 Kudos
2 Replies

1,084 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi Jay,

good question. There's a note in the RM which can be easily overlooked:

pastedImage_1.png

So, if you are going to program address 0x1000_0000 then write these values to FCCOB registers:

FCCOB[1] = 0x80

FCCOB[2] = 0x00

FCCOB[3] = 0x00

Regards,

Lukas

1,084 Views
jay_montague
Contributor I

Hi Lukas,

Thank you very much for your reply! I'm now able to successfully write to the D-Flash memory. I must of missed that paragraph when reading through the manual.

Thanks,

Jay

0 Kudos