2017-12-04 06:10 AM
Hello,
I'm working with SPC570S-DISP discovery kit and SPC5Studio v5.6, and I'm trying to use EEPROM emulation in order to save some data for my application.
I'm not using the flash drivers downloadable from ST site, so I'm trying to write my own code following the indications in RM0349 reference manual.
What I try to do is:
1) erase only the 4 8KB sectors placed in high memory (used for data memory)
2) write 0xAA55AA55 at the start of data memory (0x00800000)
The erase operation seems to be completed successfully (after operation, PEG bit in MCR register equals to 1), but write operation doesn't work (PEG = 0).
Here is my code:
#define FLASH_TEST_ADDR_0 ( uint32_t *) (0x00800000UL)
uint32_t temp;
uint32_t status_erase;
uint32_t status_write;
uint32_t *address;
// erase
FLASH_0.LOCK1.R = 0xFFFFFFF0; //unlock 4 8KB high memory sectors used for EEPROM emulation
FLASH_0.MCR.R = 0x00000004; //activate ERASE bit
FLASH_0.SEL0.R = 0x00000000;
FLASH_0.SEL1.R = 0x0000000F; //select only 4 8KB high memory sectors for erasing
FLASH_0.SEL2.R = 0x00000000;
FLASH_0.MCR.R = 0x00000005; //activate High Voltage bit in order to start erasing
do {
temp = FLASH_0.MCR.R;
} while ( !(temp & 0x00000400) ); //wait for operation to be completed
status_erase = FLASH_0.MCR.R & 0x00000200; //check for operation result and store it in status_erase variable
FLASH_0.MCR.R = 0x00000004; //High Voltage bit deactivated
FLASH_0.MCR.R = 0x00000000; //ERASE bit deactivated
//status_erase value at this point equals to 0x00000200, that means that the operation has been succesfully completed
//write
address = FLASH_TEST_ADDR_0; //initialize address pointer to first address of emulated EEPROM
FLASH_0.MCR.R = 0x00000010; //activate PGM bit
*address = 0xAA55AA55; //set the data value to be written
FLASH_0.MCR.R = 0x00000011; //activate High Voltage bit in order to start programming
do {
temp = FLASH_0.MCR.R;
} while ( !(temp & 0x00000400) ); //wait for operation to be completed
status_write = FLASH_0.MCR.R & 0x00000200; //check for operation result and store it in status_write variable
FLASH_0.MCR.R = 0x00000010; //High Voltage bit deactivated
FLASH_0.MCR.R = 0x00000000; //PGM bit deactivated
//status_write value at this point equals to 0x00000000, that means that the operation went wrong
Could you please help me to find what is wrong? Probably it's a stupid issue due to my inexperience about this microcontroller that I'm exploring just now.
Thanks in advance,
kind regards.
Daniel
2017-12-06 12:44 AM
Hello Daniel ,
Did you try EEPROM Emulation Software coming from SPC5Studio Marketplace ?
There are some examples in Application repository example.
Best regards
Erwan
2018-01-08 03:11 AM
Hello Erwan,
I was out of office for a while and found now your reply.
Thanks for your suggestion, sounds very good! Actually I didn't consider to check in market place for additional drivers, this seems to be what I was looking for.
Thanks a lot for your help.
With kind regards,
Daniel