[SOLVED] Record variables??

Timoteo
Sun Sep 16, 2018 11:31 am
Hello all,

Once again I am here searching for some help.
As the STM32 does not have an internal EEPROM like the ATMEGA328 is there anyway to record a variable that can be changed and record again to keep the track of it changes?
My idea is to use a external flash(w25n01) to be used as datalogger but in order not to read it all every time I would like to use an incremental variable that let me know what was the last page written to.
Another option a bit more complex is to use the first page of the flash and write that value in a variable, but for this I need to read it, clear the page and write the new value again, but because I have a high rate of samples and the number of read and write are limited I am afraid it reaches the maximum and the flash would be no longer good.
Thanks for your help.

Tim


stevestrong
Sun Sep 16, 2018 11:43 am
Look for MRAM or FRAM.

mrburnette
Sun Sep 16, 2018 1:50 pm
As you are data logging anyway, you could just use one of the cheap DS3231 RTC realtime clock modules with on board EEPROM, most have something like a 24C02 chip.

Ray


Timoteo
Sun Sep 16, 2018 3:00 pm
hello,

@stevestrong this memories needs some space and I would like to use the STM32 full potential so maybe some trick to write to flash…

@Ray as explained before my idea is to use the minimum external components beside the stm32 already have an RTC.

Probably the only option is to use an external eeprom, i2c

Will continue to search.

Thanks

Tim


EntropyWizard
Sun Sep 16, 2018 3:51 pm
Since you indicate you will be using the RTC, I assume you plan to power VBAT to keep the RTC running when you are otherwise shutdown. If you look at chapter 6 of the reference manual, there are some backup registers for user applications. They are not EEPROM, but they might work for you, as long as you keep the RTC running.

fredbox
Sun Sep 16, 2018 4:31 pm
@Ray as explained before my idea is to use the minimum external components beside the stm32 already have an RTC.

Ray gave you some good advice. A DS3231 module with EEPROM is one external component. Four wires are needed to make it work. This gives you 4K of EEPROM (usually a 24C32) that you can rewrite millions of times along with a fairly accurate RTC (a few seconds per month). I have a couple of these that have been running for a couple of years and I have yet to reset the time. They are presently about 10 seconds ahead of actual time.

When you try to use the built in RTC, you’ll find that it doesn’t keep very accurate time and needs to be synced with an external source.

These modules are readily available for pocket change. You might need to remove one component if you use a standard 2032 battery, as these modules are generally designed for rechargeable cells.


Timoteo
Sun Sep 16, 2018 5:50 pm
@EntropyWizard this seems to me a very good approach!
It looks there are 42 BKR with 16bits this is very good for what I need.
Now just need to understand how to reach it to read and record values, do you have any idea how to access them?

@fredbox I do understand perfectly the idea but in order to keep the device very small I will try to understand how to implement the @EntropyWizard idea.
The RTC are in fact not very precise but because the device is just to log data for a week this is not such a big problem.

Thanks all.

Tim


flyboy74
Sun Sep 16, 2018 8:11 pm
A noob question here.

Is it not possible to use the flash to store varibles?? I mean the program occupies a certain amount of flash but can any unused flash be used as storage. I mean this is what Micro-Python does and MicroPython firmware is written in C


Timoteo
Sun Sep 16, 2018 8:46 pm
@flyboy74 that was what I was looking for…
But the option with the backup registers are also valid.
If you know how to implement your suggestion, you are more then welcome to share :D
Thanks
Tim

mrburnette
Sun Sep 16, 2018 10:44 pm
[flyboy74 – Sun Sep 16, 2018 8:11 pm] –
A noob question here.

Is it not possible to use the flash to store varibles?? I mean the program occupies a certain amount of flash but can any unused flash be used as storage. I mean this is what Micro-Python does and MicroPython firmware is written in C

A very often used library is called SPIFFS. http://stm32duino.com/viewtopic.php?t=1187

I am not aware of a blue-pill implementation.

On the ESP8266, I was able to store a rather large database, 800KB
https://www.hackster.io/rayburne/oui-ou … on-esp8266


flyboy74
Mon Sep 17, 2018 3:19 am
Ok again a noob question and I ask because it is how I learn.

If you know the base address where the bin file is being written to and you know the size of your bin file is it possible just to make a pointer to the address = base_adress + bin_size then make an array or struct then write it to the pointer???

If I look at the below clip from the manual does this mean flash is accessible between 0x4002 2000 – 0x4002 23FF

RAM map.JPG
RAM map.JPG (57.3 KiB) Viewed 345 times

edogaldo
Mon Sep 17, 2018 6:51 am
Maybe this can help:

Both implementations use part of the MCU flash as an EEPROM.


racemaniac
Mon Sep 17, 2018 12:07 pm
[flyboy74 – Mon Sep 17, 2018 3:19 am] –
Ok again a noob question and I ask because it is how I learn.

If you know the base address where the bin file is being written to and you know the size of your bin file is it possible just to make a pointer to the address = base_adress + bin_size then make an array or struct then write it to the pointer???

If I look at the below clip from the manual does this mean flash is accessible between 0x4002 2000 – 0x4002 23FF

RAM map.JPG

to elaborate a bit: you’re indeed right, however… those memory locations thus refer to the flash memory and… you can’t just write to flash like you can write to RAM. Look at the links edogaldo provided, people have written libraries to use the flash, but it’s not just writing to those addresses, flash is a bit more complex in usage.


MoDu
Mon Sep 17, 2018 1:25 pm
Have you considered a SPI Flash Memory Module, or an FRAM module?

mrburnette
Mon Sep 17, 2018 4:51 pm
[MoDu – Mon Sep 17, 2018 1:25 pm] –
Have you considered a SPI Flash Memory Module, or an FRAM module?

… it was suggested earlier but Op wants to explore non-physical additions.


mrburnette
Mon Sep 17, 2018 5:09 pm
[Timoteo – Sun Sep 16, 2018 5:50 pm] –
@EntropyWizard this seems to me a very good approach!
It looks there are 42 BKR with 16bits this is very good for what I need.
Now just need to understand how to reach it to read and record values, do you have any idea how to access them?

@fredbox I do understand perfectly the idea but in order to keep the device very small I will try to understand how to implement the @EntropyWizard idea.
The RTC are in fact not very precise but because the device is just to log data for a week this is not such a big problem.

Thanks all.

Tim

You may wish to look at this thread; https://www.stm32duino.com/viewtopic.ph … t=30#p1495
It seems Andy was successful in writing & reading.

Ray


Timoteo
Fri Sep 21, 2018 9:16 am
Hello all,

@mrburnette thanks for pointing me in that direction it works fine for my tests.
It seems that C8 only have 10 available registers but as they are 16bits, is more then I need.

Tim


edogaldo
Fri Sep 21, 2018 9:37 am
If using Roger’s core and particularly Roger’s bootloader, consider that the 10th register is used by the bootloader..

Leave a Reply

Your email address will not be published. Required fields are marked *