Save data on Nucleo F334R8 when powered by battery

Hello ,

I am using Nucleo F334R8 on a mobile battery-powered robot and I want to save data from my Analog input in order to be able check these data offline (connect to PC via USB after every experiment).

My data are floating points from AnalogIn class with max. sampling frequency 100 (or less) Hz and my experiments will last maximum 30 seconds.

I tried connecting to PC after the experiment without removing battery source but even then when the platform connects with USB it resets .

What are the possible solutions from my problem?
I have read about EEPROM memory in Arduino platforms but in STM32 there is not .
All solutions are welcome but I am first searching for the one without an external card if possible.


Hello Giannis,

There is probably not much option left if you do not want to use an external memory. The SD card is probably best solution.
Maybe you can use rest of the on-chip Flash memory and try to use KVStore or Flash IAP but you need to found a limits.
The space can be your enemy 4bytes(float) * 100hz * 30s = 12000bytes and your target has only 64KB and also some space you need for your program.

About the EEPROM you need to check chip’s datasheet, however the Arduino also not have so large EEPROM, only 1-4KB I think.

BR, Jan

1 Like

Thanks for the immediate response.

I see what you say. I suppose I will start with learning to use Flash IAP.

What do you mean by “…but you need to found a limits” ?

I personally used the KVStore only for storing few words but not for a large amount of data.
And Flash IAP is usable only for pages/sectors of memory, If I remember correctly. Than can cause a problem when you will have not enough of memory.

However, let me know, how will you have any result.

BR, Jan

1 Like

Thanks again.

Hello Johnny K,

I tried using Flash IAP which has a pretty understandable documentation. For this reason I tried compiling a code mentioned in How can I provision a persistent array of int in flash memory and access it as an array of int from mbed C++? by hudakz-Zoltan Hudak but I get an Error: Identifier “FlashIAP” is undefined in “main.cpp”, Line: 4, Col: 2 . This is an error on simply defining an instance of the class FlashIAP although FlashIAP is part of the official embed library. I did not find a solution for this in any forum post.

For this reason I will start using KVStore. Do you have any example code about how to start with saving simple data like arrays in Flash memory with KVStore?
KVStore documentation is not so understandable to a beginner like me.

Best regards.

Hi again,

I saw your question and I already have an answer for you about FlashIAP.

In the target.json file in the “target_has_ add” section the “FLASH” is missing.
You can try to solve that when you will try to add that (see bellow) into the mbed_app.json of your project.

    "requires": ["bare-metal"],
        "target_overrides": {
        "*": {
            "target.device_has_add": ["FLASH"]

BR, Jan

Thanks for the immediate response.

I am using mbed online compiler so there is no .json file on my project.
If I try to create one on my project on the online compiler it is initialized as empty.
Do I have to copy all the code from target.json and also add the one you mentioned above in this new file?

Yes, you must create it manually and copy & paste it, but I feel a problem…
What version of Mbed you use?
Probably MbedOS2, but all things what we talked about is for latest MbedOS5 (currently 5.15). The problem is about your board, because your board can not use full MbedOS5, because it is low memory board. However a chance is MbedOS5 with bare metal profile.

BR, Jan

Well, you are right I am using Mbed OS2.

I may try the MbedOS5 bare metal profile and configuring the .json file you mentioned.

Thanks for the guidance until now.

I did a property storage for Arduino ESP32, D21 and Mbed-OS. It used the FlashIAP API on mbed-os. It will handle smaller writes than the flash sector size. I tested this with STM32L4, it should work on all Mbed devices, if something is wrong send me a fix.

The NVProperty project is available here:

Have a look to the API:

The best would be to write the data in blocks of 254 bytes, otherwise it will have more overhead. There are up to 256 Keys available.

Regards Helmut

I do not do Nucleo but will say how I did similar thing in one of the projects.
Each data is saved in blocks, first in ‘holding block’ then written to the secured structure at teh allocated memory block,
Once reset is applied I checked if ‘secured block’ is intact and then I was looking at where end of the data stored is. when secured block is failed (corrupted) then I clean it and start from scratch.
Simple solution - allocate huge blob at the end of the memory. That block wuld be subdivided to smaller blocks - each containing timestamp, fixed number of measurements (say 1024) and checkum (crc32 or MD1 for example). You allocate the block, set timestamp there, store measurements and when block is filled then do CRC and leave to another block. At startup u add checking of CRCs of all blocks - when CRC is failed you clean it and allocate to free blocks. If CRC is ok then u use it.
Simple as 123