Skip to content

EEPROM is erased on uploading new sketch #428

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

Closed
arihantdaga opened this issue Feb 8, 2019 · 6 comments
Closed

EEPROM is erased on uploading new sketch #428

arihantdaga opened this issue Feb 8, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@arihantdaga
Copy link

Is your feature request/improvement related to a problem? Please describe.
EEPROM is erased on uploading new sketch.

Describe the solution you'd like
Can we give an option in upload menu for users to chose to clear only sketch or entire flash.

@AnHardt
Copy link
Contributor

AnHardt commented Feb 8, 2019

The STM32 processors don't have native EEPROM. EEPROM is simulated in flash, where also the program resides. The usual location of the simulated EEPROM in flash is at its end.

/* Be able to change FLASH_BASE_ADDRESS to use */
#ifndef FLASH_BASE_ADDRESS
/*
* By default, Use the last page of the flash to store data
* in order to prevent overwritting
* program data
*/
#if defined(STM32L0xx)
#define FLASH_BASE_ADDRESS ((uint32_t)(DATA_EEPROM_BASE))
#else
#define FLASH_BASE_ADDRESS ((uint32_t)((FLASH_END + 1) - FLASH_PAGE_SIZE))
#endif
#ifndef FLASH_BASE_ADDRESS
#error "FLASH_BASE_ADDRESS could not be defined"
#endif
#endif /* FLASH_BASE_ADDRESS */

That means, if your program is to large it will erase the EEPROM. Likely redefining a smaller FLASH_PAGE_SIZE will not work.
#ifndef FLASH_PAGE_SIZE
/*
* FLASH_PAGE_SIZE is not defined for STM32F2xx, STM32F4xx and STM32F7xx
* Could be redefined in variant.h or using build_opt.h
* Warning: This is not the sector size, only the size used for EEPROM
* emulation. Anyway, all the sector size will be erased.
* So pay attention to not use this sector for other stuff.
*/
#define FLASH_PAGE_SIZE ((uint32_t)(16*1024)) /* 16kB page */
#endif
#define E2END (FLASH_PAGE_SIZE - 1)

@arihantdaga
Copy link
Author

@AnHardt I understand that, but what if sketch size is very well limited within the bounds and not reaching till the last sector, Lets say there is still 20kb space in flash and EEPROM is only last 1kb. Then we need not delete the EEPROM Content. If that can be given as an option to users in Arduino ide Menu, i think it'll be great.
Currently Even if there is space left in Flash its deleting entire flash before uploading the code.
Sketch uses 60116 bytes (91%) of program storage space. Maximum is 65536 bytes.
I tested with even smaller sketch also.

@BennehBoy
Copy link
Contributor

Assuming you are on windows, you will need to edit stlink_upload.bat in the tools folder.

You need to change the line:
echo "" | stlink\ST-LINK_CLI.exe -c SWD -P %str% 0x8000000 -Rst -Run

to read:
echo "" | stlink\ST-LINK_CLI.exe -c SWD -P %str% 0x8000000 ske -Rst -Run

The 'ske' parameter for the -P switch skips flash erase.

@fpistm
Copy link
Member

fpistm commented Feb 21, 2019

Probably could be added as a request for #445.

@arihantdaga
Copy link
Author

Cool thank you @BennehBoy . Its been long , but i finally went with this-
stm32flash cli support deleting only specific number of pages,
so i modified on macOs my serial_upload file to this-
$(dirname $0)/stm32flash/stm32flash -g 0x8000000 -e 124 -b 115200 -w "$4" /dev/"$1"

Just added -e 124 to erase only first 124 pages(Note that i am using bluepill with 128kb flash) and emulated eeprom is in last sector.

But as suggested by @fpistm maybe in #445 we can give an option in arduino ide to select what to erase(Only Sketch or Sketch plus EEPROM).

@fpistm
Copy link
Member

fpistm commented May 24, 2019

Since #514, by default there is no full erase (which is also required to not erase bootloader if any)
As I do not want add again an extra menu, user can use platform.local.txt and add:
tools.stm32CubeProg.upload.pattern="{path}/{cmd}" 1{upload.protocol} "{build.path}/{build.project_name}.bin" {upload.options}

This is the same line except the '1' prefixing {upload.protocol} , this enable the full erase.

See stm32duino/Arduino_Tools@00caaeb

@fpistm fpistm closed this as completed May 24, 2019
@fpistm fpistm added enhancement New feature or request and removed Request labels Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants