2014-07-28 11:32 PM
I have come across the following ST application note and sample.
I guess this works for STM32F4x family too, am I correct ? #eeprom-emulation2014-07-29 06:19 AM
http://www.st.com/web/en/catalog/tools/PF257902
2014-07-29 05:08 PM
Did they fix the issue discussed
?2014-07-29 05:22 PM
No idea, if you understand the issues/limitations of the STM32 Flash memory you'd be better off not using an abstraction to make it function like an awkward EEPROM
2014-07-29 10:56 PM
I have created a new IAR project & writing 3 variables with virtual addresses 0x5555, 0x6666 and 0x7777 respectively. The sample code uses 2 pages (page0, page1) in sectors 2 & 3 of FLASH memory ( STM32F4-Discovery board with STM32F407VG mcu).
Here is simple code which writesfirst variable 10 timesat 0x5555, second variable 20 timesat 0x6666 and the third variable 40 times at 0x77
/* Virtual address defined by the user: 0xFFFF value is prohibited */
uint16_t VirtAddVarTab[NB_OF_VAR] = {0x5555, 0x6666, 0x7777};
uint16_t VarDataTab[NB_OF_VAR] = {0, 0, 0};
uint16_t VarValue = 0;
int
main(
void
)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f4xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f4xx.c file
*/
/* Unlock the Flash Program Erase controller */
FLASH_Unlock();
/* EEPROM Init */
EE_Init();
/* --- Store successively many values of the three variables in the EEPROM ---*/
/* Store 10 values of Variable1 in EEPROM */
for
(VarValue = 1; VarValue <= 10; VarValue++)
{
EE_WriteVariable(VirtAddVarTab[0], VarValue);
}
/* read the last stored variables data*/
EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
/* Store 20 values of Variable2 in EEPROM */
for
(VarValue = 1; VarValue <= 20; VarValue++)
{
EE_WriteVariable(VirtAddVarTab[1], VarValue);
}
/* read the last stored variables data*/
EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]);
/* Store 40 values of Variable3 in EEPROM */
for
(VarValue = 1; VarValue <= 40; VarValue++)
{
EE_WriteVariable(VirtAddVarTab[2], VarValue);
}
/* read the last stored variables data*/
EE_ReadVariable(VirtAddVarTab[0], &VarDataTab[0]);
EE_ReadVariable(VirtAddVarTab[1], &VarDataTab[1]);
EE_ReadVariable(VirtAddVarTab[2], &VarDataTab[2]);
while
(1);
}
With this code, I was trying to test reliability & correctness when there is overflow from page0 to page1 and page1 to page0. page size is 16kb or 0x4000. page0 start address is
0x08008000& page1 start address is
0x0800C000.
Case 1:page0 to page1
Case 2:page1 to page0
I use ST-Link Utility tool to see the FLASH memory contents. I found Case 1 is working fine.
But not Case 2.
Here is properly written elements for verification.
Case 1:
The following image shows the contents of page1 ( page0 now erased). The latest values of 0x5555 & 0x6666 are retained properly from page0. We can see the continuation of variables in page1 of virtual address 0x77
Case 2:
The following image shows the contents of page0 ( page 1 now erased). The latest values of 0x5555 & 0x6666 are retained properly from page1.We can see 2 retained variables 555000A and 66660014, 39th written variable 77770 After them, we should have 40th variable 77770 But it has not been written. I guess there is some coding issue.
I tested Case 1 and Case 2 again once more, I found Case 2 exhibits the same problem described here.Where is it going wrong ?
@clive1: I understand the problems with this emulation stuff, but I desperately need it in my project.
2014-07-30 11:01 PM
I have observed several times, the for loop is getting terminated in Case 2.
For example, lets say, now we are in third for loop, found that page1 is full when trying to write 38th variable, The page transfer should happen.During this page transfer, first page0 header is written with REVEIVE_DATA, then 38th variable is written to page0. And finally copies the updated values of variables from page1. Then erase the page1, set the page status VALID_PAGE.At this point we will return back to for loop, and we should still be in the for loop to write the rest of variables ( 39th and 40th), but its getting terminated due to some reason, Don't know why ?2014-07-31 12:13 AM
Replying for myself.
I did step by step debug in IAR, watched flash memory for Case 2. There was no problem, everything works ok. But WHY there is problem when running stand alone ?Do we need any delay after the sector erase ? too confused !2014-07-31 03:39 AM
I cleared the SER, MER and MER, PG bits in FLASH_ProgramHalfWord and FLASH_EraseSector function respectively as proposed
. But I started getting a new problem. The remaining data values of for loop are being written in the old page, i.e. page1 after erase.2014-07-31 07:48 PM
Did little more debugging, actually the loop is not getting terminated. But the values are being written to the erased page ( page1) though the page0 marked as VALID_PAGE and page1 ERASED.
Here is FLASH memory contents of Case 2;See page0See page1I found this behavior is repeatable. As we can see the page1 has ERASED page status, when application runs next time, the page will be erased by EE_Init(); functional call at start.I'm updating this forum post with care & hoping that someone will reply and suggest any fix.I'm waiting for EEPROM Emulation application based on STM32Cube package library. Hope that may fix this bug.Please help, our project has tight schedule.2014-08-01 08:01 AM
I'm updating this forum post with care & hoping that someone will reply and suggest any fix. I'm waiting for EEPROM Emulation application based on STM32Cube package library. Hope that may fix this bug. Please help, our project has tight schedule.
While your presentation is thorough I think you're talking to the wrong audience. I would suggest you push your support concerns through your local ST reps or FAE. You have all the source to the driver code, you'd perhaps want to dig into that. As I suggested much earlier, it would be more effective for you to manage the Flash yourself, rather than rely on something coded by an intern. If you need technical staffing to meethttp://www.catb.org/esr/faqs/smart-questions.html#urgent
you might want to seek support from thehttp://www.st.com/web/en/support/mcu_design_consultants.html
ST catalogues?