Page 1 of 2

EEPROM.put - where does it stores data?

Posted: Tue Apr 07, 2020 6:35 pm
by kvv213
Hi EveryGuruAtTheForum!

I use EEPROM lib with my STM32F103 in my solution. It writes and reads some data from the flash memory of my chip.

The usage of the lib is very simple just use EEPROM.put(int address, obj) and it does everything for you. But I'd like to understand where exactly at the flash memory my data is stored? How to find out? int as address is not very obviuous.

Thank you for the answers.

Re: EEPROM.put - where does it stores data?

Posted: Tue Apr 07, 2020 7:04 pm
by mrburnette
From https://github.com/redbear/STM32-Arduin ... mulation.h
/* EEPROM Emulation using Flash memory
*
* EEPROM provides reads and writes for single bytes, with a default
* value of 0xFF for unprogrammed cells.
*
* Two pages (sectors) of Flash memory with potentially different sizes
* are used to store records each containing the value of 1 byte of
* emulated EEPROM.
*
* Each record contain an index (EEPROM cell virtual address), a data
* byte and a status byte (valid/erased).
*
* The maximum number of bytes that can be written is the smallest page
* size divided by the record size.
*
* Since erased Flash starts at 0xFF and bits can only be written as 0,
* writing a new value of an EEPROM byte involves appending a new record
* to the list of current records in the active page.
*
* Reading involves going through the list of valid records in the
* active page looking for the last record with a specified index.

Re: EEPROM.put - where does it stores data?

Posted: Tue Apr 07, 2020 7:19 pm
by kvv213
That is strange:

1. "Two pages (sectors) of Flash memory " and where are they located in Chip Flash?
2. I use different EEPROM lib, that is called EEPROM.h not emulated_EEPROM.

Re: EEPROM.put - where does it stores data?

Posted: Tue Apr 07, 2020 7:33 pm
by mrburnette
kvv213 wrote: Tue Apr 07, 2020 7:19 pm That is strange:

1. "Two pages (sectors) of Flash memory " and where are they located in Chip Flash?
2. I use different EEPROM lib, that is called EEPROM.h not emulated_EEPROM.
In Arduino 16-bit AVR, most of those uC's have dedicated EEPROM affixed to the uC die ... that is completely separate component than the flash memory that stores the compiled sketch. (Ex: Uno, Mega, Micro, Nano...)

STM32 ARM uC's like STM32F103 do not have EEPROM, so it is emulated by a software library. There are various libraries, the internals may be written differently, but they all work the same at the sketch level. Essentially, the library stores data in program flash ... so, there is some wear on that flash memory and one should not cycle writes too often; therefore not a great way to datalog fast changing info.

Re: EEPROM.put - where does it stores data?

Posted: Tue Apr 07, 2020 7:54 pm
by fpiSTM
For the STM32 core, this is stored in the last page/sector of the flash.

Re: EEPROM.put - where does it stores data?

Posted: Wed Apr 08, 2020 5:18 pm
by kvv213
mrburnette wrote: Tue Apr 07, 2020 7:33 pm
kvv213 wrote: Tue Apr 07, 2020 7:19 pm That is strange:

1. "Two pages (sectors) of Flash memory " and where are they located in Chip Flash?
2. I use different EEPROM lib, that is called EEPROM.h not emulated_EEPROM.
In Arduino 16-bit AVR, most of those uC's have dedicated EEPROM affixed to the uC die ... that is completely separate component than the flash memory that stores the compiled sketch. (Ex: Uno, Mega, Micro, Nano...)

STM32 ARM uC's like STM32F103 do not have EEPROM, so it is emulated by a software library. There are various libraries, the internals may be written differently, but they all work the same at the sketch level. Essentially, the library stores data in program flash ... so, there is some wear on that flash memory and one should not cycle writes too often; therefore not a great way to datalog fast changing info.
That is for configuration storing only. So, not very often update (even not often update at all) :)

Re: EEPROM.put - where does it stores data?

Posted: Wed Apr 08, 2020 5:20 pm
by kvv213
fpiSTM wrote: Tue Apr 07, 2020 7:54 pm For the STM32 core, this is stored in the last page/sector of the flash.
Thank you, yes, for STM32 Core.

I found out a strange behaviour of put method of EEPROM lib. If I write an object with size around 0,5 kb then a part of my sketch memory is ruined. Variables values are destroyed... So, was like to find out where it is written.

Re: EEPROM.put - where does it stores data?

Posted: Tue Apr 14, 2020 1:48 am
by mrburnette
kvv213 wrote: Wed Apr 08, 2020 5:20 pm
fpiSTM wrote: Tue Apr 07, 2020 7:54 pm For the STM32 core, this is stored in the last page/sector of the flash.
Thank you, yes, for STM32 Core.

I found out a strange behaviour of put method of EEPROM lib. If I write an object with size around 0,5 kb then a part of my sketch memory is ruined. Variables values are destroyed... So, was like to find out where it is written.
Flash can hold the bootloader, your sketch, and simulated EEPROM ... flash is finite. You must use an STM32 aware lib for EEPROM, using an AVR library is not supported.

Re: EEPROM.put - where does it stores data?

Posted: Tue Apr 14, 2020 5:39 am
by kvv213
mrburnette wrote: Tue Apr 14, 2020 1:48 am Flash can hold the bootloader, your sketch, and simulated EEPROM ... flash is finite. You must use an STM32 aware lib for EEPROM, using an AVR library is not supported.
Yep, it is. But how to check the lib to be STM32 compliant? I took the lib from STM32 Arduino Core and it stores values at flash due to absence of EEPROM at the board.
I agree that it seems that if I try to store large values (like 500-600 bytes) it goes to symbols area of my RAM (due to flat dressing of entire memory). So that is why I started this thread.

Re: EEPROM.put - where does it stores data?

Posted: Tue Apr 14, 2020 7:08 am
by stas2z
No, bytes you put to flash cant reach your ram
flash area start address is 800 0000 (hex), when SRAM is starting at 2000 0000 (hex)
in decimals it will be 134 217 728 and 536 870 912, hundreds of millions bytes difference