stm32duino / Arduino_Core_STM32

STM32 core support for Arduino
https://github.com/stm32duino/Arduino_Core_STM32/wiki
Other
2.75k stars 960 forks source link

STM32L082 EEPROM Size #1016

Closed mhmayyan closed 4 years ago

mhmayyan commented 4 years ago

I am using a custom board with STM32L082, which should have 6KB EEPROM. When I use the function EEPROM.length() I get 128.

When I tested the same function on Nucleo L152RE, which should have 16KB EEPROM, I got 256.

ABOSTM commented 4 years ago

Hi @mhmayyan , Such kind of question should be asked on the forum: https://www.stm32duino.com/ The EEPROM library you used is in fact derived form Arduino EEPROM emulation. https://github.com/stm32duino/wiki/wiki/API#EEPROM-Emulation It uses part of the Flash to emulate EEPROM. It has the advantages to be available from all chips from all STM32 series, including those which don't have EEPROM. And this is the reason why you get different values than the real EEPROM you have.

There is no Arduino dedicated driver to access real EEPROM, but you can use STM32cube HAL API to do so (Reminder: HAL API can be used directly within Arduino sketch) https://github.com/stm32duino/Arduino_Core_STM32/blob/master/system/Drivers/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_flash.c https://github.com/stm32duino/Arduino_Core_STM32/blob/master/system/Drivers/STM32L1xx_HAL_Driver/Src/stm32l1xx_hal_flash_ex.c

lyusupov commented 4 years ago

I use AcSiP S76G system-in-package which has STM32L073RZ inside the chip. Arduino_Core_STM32 gives access to EEPROM over this built-in library , which actually transfers read/write requests through eeprom_read_byte() and eeprom_write_byte() toward this implementation in the Core.

Does it actually use an EEPROM area ? The answer depends on a particular STM32 chip. Say, on :

When I intentionally erase main flash memory on L073 - it's EEPROM area remains intact.

My L073 device has USB DFU access. I can separately erase entire 6K EEPROM area while using a DFU utility. EEPROM on L073 has a separate "Target Id":

FRASTM commented 4 years ago

in the STM32L082 , Data EEPROM 6 Kbytes

The stm32l082xx.h defines

#define DATA_EEPROM_BASE       (0x08080000UL) /*!< DATA_EEPROM base address in the alias region */
#define DATA_EEPROM_BANK2_BASE (0x08080C00UL) /*!< DATA EEPROM BANK2 base address in the alias region */
#define DATA_EEPROM_BANK1_END  (0x08080BFFUL) /*!< Program end DATA EEPROM BANK1 address */
#define DATA_EEPROM_BANK2_END  (0x080817FFUL) /*!< Program end DATA EEPROM BANK2 address */
FRASTM commented 4 years ago

For devices that have an embedded EEPROM (like stm32L0xx soc), there is no more need to have a buffered access to this memory. Word or half-word or byte read/erase/write is possible at each EEPROM address location. Moreover, the buffered access to the EEPROM with flush/fill is useless.

The EEPROM area is supposed to start at address 0 and end at address EEPROM.length()-1 Some devices have 2 banks, which are supposed contiguous (from DATA_EEPROM_BASE to DATA_EEPROM_BANK2_END)

FRASTM commented 4 years ago

rebase