Hi All,
I recently created a design with an embedded STM32F303RET6 chip with the understanding that there was no EEPROM unit in this controller. From looking online I see that EEPROM can be emulated on STM32 MCUs using the on-chip flash memory.
I intended to connect an external EEPROM chip so that I could use the Arduino EEPROM.h library instead of using the expansion for the STMCube IDE to reconfigure the flash memory. However when I uploaded the software to the chip with no external EEPROM connected, it carried out the read and write functions I had written. My only explanation for this is that the EEPROM library accessed the flash memory, is this correct and if so how does it do this?
I'm relatively new programming these devices so any information or ideas would be super helpful.
Thanks,
Phoebe
[SOLVED] How does Arduino EEPROM library work on STM32?
[SOLVED] How does Arduino EEPROM library work on STM32?
To start with - you cannot use built in EEPROM library with external EEPROM chips (arduino or stm32duino). It's for built-in (on chips with EEPROM) or emulated eeprom (STM32duino).
For external chips you need to use library for those chips, but most of them have same usage as built-it library, except for the object definition (you need to set interface and pins).
As to emulated eeprom - it uses flash memory (usually 2 smallest pages), if MCU has small pages on the beginning of flash, then those are used, so flashing a program without eeprom enabled will overwrite what was saved there.
How it works (eg for F40x, F41x):
https://www.st.com/resource/en/applicat ... ronics.pdf
Go to full postFor external chips you need to use library for those chips, but most of them have same usage as built-it library, except for the object definition (you need to set interface and pins).
As to emulated eeprom - it uses flash memory (usually 2 smallest pages), if MCU has small pages on the beginning of flash, then those are used, so flashing a program without eeprom enabled will overwrite what was saved there.
How it works (eg for F40x, F41x):
https://www.st.com/resource/en/applicat ... ronics.pdf
Last edited by phoebeK on Tue Jul 30, 2024 10:46 am, edited 1 time in total.
Re: How does Arduino EEPROM library work on STM32?
To start with - you cannot use built in EEPROM library with external EEPROM chips (arduino or stm32duino). It's for built-in (on chips with EEPROM) or emulated eeprom (STM32duino).
For external chips you need to use library for those chips, but most of them have same usage as built-it library, except for the object definition (you need to set interface and pins).
As to emulated eeprom - it uses flash memory (usually 2 smallest pages), if MCU has small pages on the beginning of flash, then those are used, so flashing a program without eeprom enabled will overwrite what was saved there.
How it works (eg for F40x, F41x):
https://www.st.com/resource/en/applicat ... ronics.pdf
For external chips you need to use library for those chips, but most of them have same usage as built-it library, except for the object definition (you need to set interface and pins).
As to emulated eeprom - it uses flash memory (usually 2 smallest pages), if MCU has small pages on the beginning of flash, then those are used, so flashing a program without eeprom enabled will overwrite what was saved there.
How it works (eg for F40x, F41x):
https://www.st.com/resource/en/applicat ... ronics.pdf
Re: How does Arduino EEPROM library work on STM32?
I think the 'EEPROM' library bundled in the core basically use part of the on chip flash memory as 'eeprom' storage.
one should review the library codes and the reference manual in particular the flash memory chapters prior to using it.
'blindly' using that may cause 'unexpected' behaviours, e.g. that it could erase flash where part of your code / binary is stored in the flash.
stm32 flash memories varies between devices and in various cases, erasing the 'upper memory' could erase a whole half of the full storage space.
e.g. with like 64k it erase a whole 32k of it, and for 128k it erase a whole 64k of it, then you try imagining that your binary / app is bigger than 32k or 64k and you are trying to use 'eeprom', your app may just crash and device non responding on erase.
it is better to understand how to work with on chip flash memory and possibly use it directly instead of 'blindly' using an 'eeprom' library.
those things are covered in the reference manual for each soc.
But that said on chip flash memory is convenient, sometimes saving extra wiring works and effort and simply use part of flash for data.
get a chip with adequate amount of flash for your purpose (e.g. 128k or more) if you want to do that
note also that flash memory has limited erasing / re-writing tolerance
more commonly, I used SPI flash
https://github.com/search?q=spi%20flash ... positories
and those chips like w25q128* sop8
https://www.aliexpress.com/w/wholesale-w25q128.html
https://www.winbond.com/hq/product/code ... =W25Q128FV
provides like 128 Mbit (16 MB) of flash storage
and if that seemed little, if you used SD cards these days, for a little larger footprint store gigabytes of data
one should review the library codes and the reference manual in particular the flash memory chapters prior to using it.
'blindly' using that may cause 'unexpected' behaviours, e.g. that it could erase flash where part of your code / binary is stored in the flash.
stm32 flash memories varies between devices and in various cases, erasing the 'upper memory' could erase a whole half of the full storage space.
e.g. with like 64k it erase a whole 32k of it, and for 128k it erase a whole 64k of it, then you try imagining that your binary / app is bigger than 32k or 64k and you are trying to use 'eeprom', your app may just crash and device non responding on erase.
it is better to understand how to work with on chip flash memory and possibly use it directly instead of 'blindly' using an 'eeprom' library.
those things are covered in the reference manual for each soc.
But that said on chip flash memory is convenient, sometimes saving extra wiring works and effort and simply use part of flash for data.
get a chip with adequate amount of flash for your purpose (e.g. 128k or more) if you want to do that
note also that flash memory has limited erasing / re-writing tolerance
more commonly, I used SPI flash
https://github.com/search?q=spi%20flash ... positories
and those chips like w25q128* sop8
https://www.aliexpress.com/w/wholesale-w25q128.html
https://www.winbond.com/hq/product/code ... =W25Q128FV
provides like 128 Mbit (16 MB) of flash storage
and if that seemed little, if you used SD cards these days, for a little larger footprint store gigabytes of data
Re: [SOLVED] How does Arduino EEPROM library work on STM32?
Thank you both!