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.
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.
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.
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.
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.
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.
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