2016-07-12 02:19 AM
Hi,
I am working with an external flash and I wanted to store the lastest memory address after the power cut off and fetch back the stored memory address when power on. So, how should I do it ? Is it done by write into the EEPROM of the chip or is there any ways to do it?Is there any EEPROM example code provided by ST? Because I am using STM32CubeL0 to learn, but I did not find any example code related to EEPROM.2016-07-12 03:26 AM
Hi,
You can refer to the EEPROM examples in other firmware package which can help you as an implementation example and get inspiration to achieve you goal.For example, you find under the package an EEPROM application:STM32Cube_FW_L4_V1.5.0\Projects\STM32L476G_EVAL\Applications\EEPROM\EEPROM_EmulationYou can take this example as start point to make required updates in the project generated and look at this manual in the section 3 ''Flash program memory and data EEPROM (FLASH) '' and code examples.Regards2016-07-12 11:38 AM
You can enable PVD (Programmable Voltage Detector) and set it to the highest value - 2.9 V. At power off, when Vdd drops below 2.9 V, PVD interrupt occurs and then you have still some time to program a half-word or two into the embedded flash. You have time until Vdd drops below 2 V. If you want to extend this time, you could also give one larger capacitor (e.g. 100 uF) to the power supply.
2016-07-12 09:03 PM
Thanks for the reply. I found the eeprom function inside the STM32CubeL0 hal_flash_ex.c file but without the read function.For now I need to figure out how to read.
Besides, is there any method to let the code know where was the lastest eeprom address to read when restart?2016-07-12 09:07 PM
Thanks for reply. Is the whole process can complete writing before the power totally cut off? For now I still working on write and read on the eeprom and probably with a push button to save before power off. Will try this out afterward. Thanks for the suggestions!
2016-07-12 09:37 PM
2016-07-12 10:03 PM
I see. But I did not understand how did u find the last written data by looking at last not equal to 0xFFFF. Do you mean using a for-loop to check all the eeprom address data during the power on until it find out the unwritten slot?
2016-07-13 10:52 AM
2016-07-13 04:02 PM
I think the mindset with the L series parts is that they are constantly powered by a battery, or if you have a power supply you fork that with a battery and a pair of diodes, and recognize when the primary power is removed and enter a very low power state where you can hold values in RAM for prolonged periods.
2016-07-13 07:20 PM
I think the check half method, it is fast and easy to implement for me. But another question will be when will you erase the old data?
The next thing is currently I will record down some data into an external Flash and to access back the last written address in Flash after restart,I will store the last Flash address in eeprom and do the empty check to find back the last written Flash address. Is this the correct way to doing it?Because directly do a for-loop check in the Flash is very time consuming if the last written address is at the very last address.