platformio / platform-atmelsam

Atmel SAM: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelsam
Apache License 2.0
78 stars 105 forks source link

Feature request: add option to not pass --erase to bossac #221

Closed runger1101001 closed 5 months ago

runger1101001 commented 6 months ago

Would you consider adding an option to control whether bossac is called with the --erase option or not in builder/main.py ?

At the moment, the entire flash is erased each time the device is re-programmed. I would like to disable this erasure.

Reasoning / Background:

I need to store motor calibration and tuning parameters from an initial calibration run, for use in subsequent motor control algorithms. These parameters are unique to each setup, and therefore have to be determined "in situ". Since calibration is "expensive", it should not happen again each time the device is reset.

SAMD permits writing to the flash memory from user code. A few SAMD devices integrate a separate RWWEE section of flash for storing user data, but most SAMD models don't have this feature.

All SAMD21s have an "EEPROM" fuse, to reserve a section at the top of the flash memory for user data storage. But it seems the --erase option of bossac does not respect this fuse setting, and erases this memory anyway.

By adding an option not to call bossac with --erase, the devices can still be programmed but the user data doesn't get zapped. This enables storing settings persistently in the normal flash memory. Of course users have to additionally set up their ldscripts and upload.maximum_size settings accordingly, but these things can be overridden with existing options.

valeros commented 5 months ago

Hi @runger1101001, you can remove any upload flag via an extra script, for example:

[env:mkrzero]
platform = atmelsam
board = mkrzero
framework = arduino
extra_scripts = skip_erase.py

skip_erase.py:

Import("env")

env.Replace(
  UPLOADERFLAGS=[f for f in env.get("UPLOADERFLAGS", []) if f != "--erase"]
)