Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

STM32F103C8 EEPROM FLASH_BASE_ADDRESS has wrong value #1500

Open
mczerski opened this issue Sep 20, 2021 · 14 comments
Open

STM32F103C8 EEPROM FLASH_BASE_ADDRESS has wrong value #1500

mczerski opened this issue Sep 20, 2021 · 14 comments

Comments

@mczerski
Copy link

mczerski commented Sep 20, 2021

For STM32F103C8 device the FLASH_BASE_ADDRESS in libraries/EEPROM/src/utility/stm32_eeprom.c is calculated as (line 84):

((uint32_t)((FLASH_END + 1) - FLASH_PAGE_SIZE))

where FLASH_END is defined as FLASH_BANK1_END (line 64) which in turn is defined as 0x0801FFFFUL (system/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h:574) which is outside of the declared flash size for the STM32F103C8 device which is 64k not 128k.

I guess this works for genuine STM32 chips which usually have 128k despite the declared 64k. I found this issue while using fake CH32F103C8 chips (due to f... COVID 19 genuine stm32 are priced as gold) and those actually have 64k of flash :(

version:
Arduino_Core_STM32 current master

@fpistm
Copy link
Member

fpistm commented Sep 21, 2021

HI @mczerski
Yes you're right.
Those definitions are generic and based on CMSIS input for all series. That's why it is possible to redefine all.
You can simply define FLASH_END to the value you want.

@fpistm fpistm added this to To do in STM32 core based on ST HAL via automation Sep 21, 2021
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>
@alextrical
Copy link
Contributor

You can simply define FLASH_END to the value you want.

Where is best to define this value for a Board/Variant?

@fpistm
Copy link
Member

fpistm commented Nov 10, 2022

You can simply define FLASH_END to the value you want.

Where is best to define this value for a Board/Variant?

Variant_*.h

@muhkuhgh
Copy link

Could this maybe be related to my problem? STMicroelectronics/OpenOCD#23

@fpistm
Copy link
Member

fpistm commented Oct 17, 2023

Could this maybe be related to my problem? STMicroelectronics/OpenOCD#23

No, this issue is related to EEPROM library usage, which emulate an eeprom in flash.

@gregbarski
Copy link

gregbarski commented Jan 9, 2024

HI @mczerski Yes you're right. Those definitions are generic and based on CMSIS input for all series. That's why it is possible to redefine all. You can simply define FLASH_END to the value you want.

Maybe that's a very basic question, but how should those values be actually calculated?
I'm facing probably the same issue now using STM32G030K8T6 and STM32G030C8T6. Committing a value to flash works fine before the RAM memory is filled with other bigger objects. But after all defined objects are initialized and filled with data, commit any value to the flash makes the program crash (overriding the code I guess).

If defining correct values would help, is there any good way to calculate / verifiy them?

@fpistm
Copy link
Member

fpistm commented Jan 9, 2024

Hi @gregbarski
The EEPROM emulation used the latest page of the Flash, for your case:
image

So only 2k should be used by default. So if your project is lesser that flash size - 2k, it should work if not then you should not use the EEPROM emulation.

@gregbarski
Copy link

gregbarski commented Jan 9, 2024

@fpistm Thank you. I try to base on the same datasheet.

My device has 31 pages of main memory.
I just tried to fix the configuration values for FLASH_PAGE_SIZE, E2END or number of pages with values calculated from the datasheet but with no luck.

The project takes:
RAM: [===== ] 50.5% (used 4140 bytes from 8192 bytes)
Flash: [===== ] 49.5% (used 32460 bytes from 65536 bytes)
so I assume there shouldn't be any problems of overriding the last page.

I'll keep searching.

@fpistm
Copy link
Member

fpistm commented Jan 9, 2024

Right, normally, it should be ok.
Did you test eeprom_put anf eeprom_get examples?

@gregbarski
Copy link

Yes, I did. Considering "empty" project, it's possible to write/update each single flash "cell" inside of setup() function. The problem occurs, when program is "fully initialised" and all objects are created. I know it smell like getting out of RAM memory. I've checked it against memory leaks, but it seems fine. So may assumption is, that there is attemption to override the program's memory area. In the same time it seems stupid, as I know that it's being checked by the library code.

@alextrical
Copy link
Contributor

@fpistm Is it possible to change the program memory size dynamically when Virtual EEPROM is enabled?
It's quite easy for an end user to accidentally add enough code to use the last 2k block, and not know that the Virtual EEPROM will then break.

@fpistm
Copy link
Member

fpistm commented Jan 10, 2024

@fpistm Is it possible to change the program memory size dynamically when Virtual EEPROM is enabled?

No.

@fpistm
Copy link
Member

fpistm commented Jan 10, 2024

Yes, I did. Considering "empty" project, it's possible to write/update each single flash "cell" inside of setup() function. The problem occurs, when program is "fully initialised" and all objects are created. I know it smell like getting out of RAM memory. I've checked it against memory leaks, but it seems fine. So may assumption is, that there is attemption to override the program's memory area. In the same time it seems stupid, as I know that it's being checked by the library code.

I've tested with a Disco G031 the ut and get examples and it works as expected. My guess is the RAM is too small for your use case.

@gregbarski
Copy link

Thank you for this investigation. I'll be testing it according to this path and will share the results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

5 participants