Hi Renesas team,
I am using rl78 r5f102aa microcontroller and its data flash to store some settings in it.
In my product I am using 3.7v battery backup (2400mah), when power interruption happens, the mcu should run with battery backup.
Now, the problem is, the stored settings in data flash is erasing sometimes. I thought the issue is because of the writing/reading happens during battery powered. So I stopped memory operations during power interruption (battery time). Still the same issue observed.
Now, I started writing the settings in two different banks in data flash as extra data backup. I am not sure whether it will resolve the issue.
I want to know the reason for erasing and if the erase happens, will it erase complete data flash (second block) too, which I am using as extra second back up.
In reply to Sai:
In reply to manju:
The data-flash cannot be erased without initiating a self-programming operation on the block. Are you using the Tiny / T02 EEL or just FDL in your code? EEL is designed to be reset resistant and implement wear-leveling. If using only FDL you must implement your own strategy for both concepts to maintain data integrity.
Do you have the documentation for the Renesas FDL and the EEL?
The users manual for the FDL shows examples of how to use the FDL, I don't understand why you would be executing fixed timing delays, when the library can notify you of the completion of the operation. For some reason, I don't see the RL78/G12 flash programming times specified in the documentation. But for other devices which use the same flash process, a block erase operation takes 5ms while a write operation takes 10us.
Example code for the T02/Tiny FDL can be found in section 4.7 of the FDL U/M R01US0061ED. The library can be polled for busy status, calling the handler while busy.
Note that the RL78 data-flash is not like byte-erasable EEPROM. The erase block size is 1KB while a write unit is 1-byte. The EEPROM Emulation Library (EEL) uses an approach to implement wear-leveling by performing multiple write operations in a single block, before an erase operation is required. Reset resistance means that a specific flow is used to ensure the data integrity (e.g. a start marker is first written, followed by the data, followed by an end marker). Reset resistance also ensures that data is not lost during a block erase operation by duplicating the data in another block before the erase operation is done (Renesas EEL refers to this concept as a "refresh" operation).
Please refer to the T02/Tiny EEL U/M for more information on the wear-leveling techniques and reset resistant features of the Renesas EEL.
I would not generally recommend that a user implement their own EEPROM emulation unless they are a very experienced programmer. If your application has the memory resources available to use the Renesas EEL I would highly recommend that you consider using this off the shelf library.
Can you please elaborate on the statement, "But in FDL library, there is no abort API."? If you are using the "Tiny" / T02 FDL this command exists. Or are you using the "Pico" / T04 FDL type? The Pico FDL does not support the abort command.
Please refer to the Data Flash Access LibraryType T04 (Pico), European Release for the Pico / T04 FDL U/M.
Perhaps your battery is not able to sustain the power required to perform the erase operation? If the abort needs to be supported you would have to use the Tiny / T02 FDL.
In reply to JB:
I found the tiny / t02 fdl library and started integrating into my code. One more doubt is, I have middle layer for pico fdl library which is generated one. (r_cg_pfdl.c and .h) - CS+ CC-RL
Do we have middle layer for tiny t02 fdl also? How can I get it? Please elaborate the steps if it tool generates..
Files named "r_cg_*.c,h" are typically code-generated files from the Renesas Applilet, for your G12 device this is the Applilet3 (latest version is 1.18.00): https://www.renesas.com/en-eu/software/D4001290.html
Unfortunately it appears that only the Pico / T04 data-flash library is supported by the Applilet tool. In this case you would need to manually edit the middle layer to support the Tiny / T02 library, or remove that layer altogether.
I don't really understand the logic in your code, the handler is going to have to be called many times for the erase operation to complete, aborting after only two calls doesn't make sense to me.
If you look at section 5.2.2. of the Tiny FDL U/M, you will see the command execution times, and the erase can be ~5.8ms typical to over 265ms max.
To be honest my experience with the automotive RL78 devices (F1x), which typically have a battery voltage monitor circuit with a small reserve power and can be triggered by falling voltage to take action before the reserve runs out.
Are you using the LVD to ensure proper operation of the device? If you battery is unable to provide the required power to program the data-flash, I'm not sure what you can do if anything until the battery is refreshed, so maybe a simple reset would make sense, or at least an interrupt for the device to take some action.