cancel
Showing results for 
Search instead for 
Did you mean: 

Using Data flash

ssk
Associate II
Posted on February 18, 2015 at 12:25

Hello Members,

I am using SPC560D030 for my product. I want to use the Data flash to store the device configuration i.e. I want to use Data flash as NVM. The configuration data is of 120 bytes. I tried reading the reference manual (CD00259063.pdf) on using the Data flash as NVM but may be I am unable to understand on reading/writing to Data flash. I don't find any APIs for it. How can I use the 'DFLASH' for reading or writing? Any example code or document reference will be helpful.

Thanks in advance for any help.

Mike.

#dflash #dataflash #dataflash #orhan-y?lmaz #data-flash
16 REPLIES 16
Erwan YVIN
ST Employee
Posted on April 29, 2015 at 16:06

Hello Orhan ,

yes but it is an offset from

SPC5_DFLASH_BASE.

bool
spc5_dflash_write_word(uint32_t address, uint32_t word) {
bool
result;
osalDbgAssert((address & 3) == 0, 
''unaligned write''
);
/* Marking for program.*/
DFLASH.MCR.R = 0x00000010; 
/* PGM */
/* Starting operation.*/
*((volatile uint32_t *)(SPC5_DFLASH_BASE + address)) = word;

Best regards Erwan
orhanyilmaz
Associate II
Posted on April 29, 2015 at 16:23 Hello Erwan, My test code

#define DFLASH_BASE_ADDR 0x00800000
...
Addr = DFLASH_BASE_ADDR;
..
DFLASH.MCR.R = 0x00000010;
(*(U_32 *)Addr) = data;
DFLASH.MCR.R = 0x00000011;
while(!(DFLASH.MCR.R & 0x00000400));
DFLASH.MCR.R = 0x00000010;
DFLASH.MCR.R = 0x00000000;

but not work! Thanks
Erwan YVIN
ST Employee
Posted on April 30, 2015 at 09:49

Hello Orhan ,

I have tested the code this morning. Your code is working well , you have just to erase the block before writing a word. Did you initialize correctly the driver before ? (Cf Giovanni's code)

/**
* @brief Initializes the driver.
*/
void
spc5_dflash_init(
void
) {
/* Fixes wrong initialization in HAL driver.*/
// CFLASH.PFCR1.R = 0x318D8081;
CFLASH.PFCR1.B.BK1_APC = 3;
CFLASH.PFCR1.B.BK1_RWSC = 6;
/* Unlock procedure.*/
DFLASH.LML.R = 0xA1A11111;
DFLASH.LML.B.LME = 1;
DFLASH.SLL.R = 0xC3C33333;
DFLASH.SLL.B.SLE = 1;
DFLASH.MCR.R = 0x0;
/* All blocks unlocked.*/
DFLASH.LML.B.LLK = 0;
DFLASH.SLL.B.SLK = 0;
}

Best regards Erwan
orhanyilmaz
Associate II
Posted on June 01, 2015 at 16:52

Thanks Erwan. It's work!

lizheng887
Associate II
Posted on February 26, 2016 at 06:49

Hi Erwan,

I am using data flash on SPC560P40L1, and the eemprom emulation driver is used provided by spc5studio v3.7.

There is something wrong when initialize, the return error code is 0x40(EE_ERROR_PE_OPT). However, the same code is running well on SPC560P50L5, and I need your help.

I donot know where the problem is?

Thanks.

  /* Init EEPROM.*/

  result = FSL_InitEeprom(&eepromConf, NULL_CALLBACK);

  if (result != EE_OK && result != EE_FIRST_TIME_INITIALIZATION) {

    //while (sd_lld_write(&SD1,(uint8_t*)''INIT ERROR\r\n'', 12) == SERIAL_MSG_WAIT);

    //return result;

  }

  /* Read dataID 0.*/

  result = FSL_ReadEeprom(&eepromConf, 0, (UINT32)(dtc_ram), NULL_CALLBACK);

procolo
Senior
Posted on February 26, 2016 at 10:19

Hello,

currently ee library only support SPC560P50 devices. We are introducing the support for SPC560P40/34 and this library will be available in the next version of SPC5Studio.

Meanwhile, you can use the zip attached to solve the problem.In your project for P40 please replace the following files:

- eed.a

- eed_emulation,h

Please not that

  • Every time you generate the project the eed.a files will be the old one , so you should replace again the library
  • this library only works for P if you want to use on P50 you should not use these files but the ones generated as usual.

In the next version, the eed.a library will support both devices.

Sorry for the inconvenience.

Regards

Procolo

________________

Attachments :

EEPROM.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0Rs&d=%2Fa%2F0X0000000bZ4%2FdiL1XG101T81E3TbslvnKv2nAr1swzYyty2.vN3pQ9Y&asPdf=false
lizheng887
Associate II
Posted on April 07, 2016 at 08:57

thanks.