Skip to content

Wrong flash size for eeprom emulation #1316

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
JyeSmith opened this issue Mar 7, 2021 · 6 comments · Fixed by #1445
Closed

Wrong flash size for eeprom emulation #1316

JyeSmith opened this issue Mar 7, 2021 · 6 comments · Fixed by #1445
Assignees
Labels
bug 🐛 Something isn't working

Comments

@JyeSmith
Copy link

JyeSmith commented Mar 7, 2021

Hey,

I am trying to use eeprom on the STM32L432. It should be pretty straight forward but I dont appear to be having any luck. Is someone able to confirm it works?

Cheers

@fpistm
Copy link
Member

fpistm commented Mar 7, 2021

Hi @JyeSmith
could you be more precise ?
Which board? Arduino IDE version? Core version ?
Which sketch?

Basically the EEPROM library is an emulation using last page flash.

@fpistm fpistm added the waiting feedback Further information is required label Mar 7, 2021
@fpistm
Copy link
Member

fpistm commented Mar 9, 2021

I've tested eeprom_put and eeprom_get default examples and it works fine on the Nucleo L432KC

@fpistm fpistm closed this as completed Mar 9, 2021
@fpistm fpistm added invalid This doesn't seem right and removed waiting feedback Further information is required labels Mar 9, 2021
@cruwaller
Copy link

cruwaller commented Mar 18, 2021

@fpistm this is not working as expected on L432 when flash size is smaller than max 256kB :)

We have used stm32l432kbu6 which has 128kB of FLASH.

Current code calculates flash page index:
#define FLASH_PAGE_NUMBER ((uint32_t)((FLASH_SIZE / FLASH_PAGE_SIZE) - 1))
=> FLASH_SIZE returns 0x20000 and page is 0x800 => page 63 (the address 0x0801F800).

Then EEPROM base address is defined:
#define FLASH_BASE_ADDRESS ((uint32_t)((FLASH_END + 1) - FLASH_PAGE_SIZE))
=> #define FLASH_END (0x0803FFFFUL) is defined in stm32l432xx.h => 0x0803FFFFUL => base address will be 0x803F800 which is actually page 127 :)

This means that EEPROM save will work just once after mass erase because wrong flash page is erased :)
This means that EEPROM will write data out of bounds :)

Could you reopen this error?

@fpistm
Copy link
Member

fpistm commented Mar 18, 2021

@ABOSTM could you have a look on this please? Thanks in advance.

@ABOSTM
Copy link
Contributor

ABOSTM commented Mar 18, 2021

@JyeSmith,
I agree with you, it is a real issue.
FLASH_END which is defined in CMSIS file doesn't take into account the real flash size of a the device,
(it is just the maximum possible within the productline).

But fix will be a real challenge, as other STM32 series are impacted, and it will be difficult to find generic implementation, taking into account single bank/dual bank, possible flash discontinuity between banks, ...
So as a workaround, I propose you to update, for now, stm32l432xx.h with the value you expected:
#define FLASH_END (0x0801FFFFUL)

@ABOSTM ABOSTM reopened this Mar 18, 2021
@ABOSTM ABOSTM self-assigned this Mar 18, 2021
@ABOSTM ABOSTM added bug 🐛 Something isn't working and removed invalid This doesn't seem right labels Mar 18, 2021
@fpistm fpistm changed the title STM32L432 eeprom working? Single bank vs dual bank for eeprom emulation May 7, 2021
@Kamoool
Copy link

Kamoool commented May 12, 2021

I cannot save to EEPROM as well on STM32L432KBU6 on latest version.
On 1.8.0 both EEPROM.put and EEPROM.get worked.

After changing flash end as suggested in #1316 (comment) It saves and reads as it should.

@fpistm fpistm changed the title Single bank vs dual bank for eeprom emulation Wrong flash size for eeprom emulation Jul 12, 2021
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Jul 13, 2021
FLASH_SIZE defined by the CMSIS Device Peripheral Access Layer Header File
is the maximum one of a product line.
So depending of the mcu this is not the correct one.

As an example, L432KC have 256 KB while L432Kb has 128 KB.

Using LL_GetFlashSize() allows to get the correct FLASH size.

Fixes stm32duino#1316

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Jul 13, 2021
FLASH_SIZE defined by the CMSIS Device Peripheral Access Layer Header File
is the maximum one of a product line.
So depending of the mcu this is not the correct one.

As an example, L432KC have 256 KB while L432Kb has 128 KB.

Using LL_GetFlashSize() allows to get the correct FLASH size.

Fixes stm32duino#1316

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm fpistm self-assigned this Jul 13, 2021
fpistm added a commit that referenced this issue Jul 13, 2021
FLASH_SIZE defined by the CMSIS Device Peripheral Access Layer Header File
is the maximum one of a product line.
So depending of the mcu this is not the correct one.

As an example, L432KC have 256 KB while L432Kb has 128 KB.

Using LL_GetFlashSize() allows to get the correct FLASH size.

Fixes #1316

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Sep 21, 2021
FLASH_END which is defined in CMSIS file doesn't take
into account the real flash size of a the device,
(it is just the maximum possible within the productline).

Fixes stm32duino#1316, fixes stm32duino#1500

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants