AVR: Uploading EEPROM also erases chip

Hi,
I’m doing some pure AVR assembler stuff in Platform.IO and I noticed, that the task “Upload EEPROM” seems to include a chip erase. Is there any possibility to disable the chip erase on this task?

avrdude: Device signature = 0x1e9207 (probably t44)
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as FF
avrdude: erasing chip
avrdude: set SCK frequency to 8000 Hz
avrdude: reading input file ".pio/build/attiny13/firmware.eep"
[...]

Thanks

When I read the responsible code for creating the avrdude command, I don’t see an erase flag (-e).

Can you open a PIO CLI and execute pio run -v -t uploadeep. What’s the output?

This is the complete output:

user@mac Senso Game v2 % pio run -v -t uploadeep
Processing attiny13 (platform: atmelavr; board: attiny44; upload_protocol: usbasp; board_build.f_cpu: 1000000L; upload_flags: -v, -B 70)
--------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/attiny44.html
PLATFORM: Atmel AVR (3.0.0) > Generic ATtiny44
HARDWARE: ATTINY44 1MHz, 256B RAM, 4KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES: 
 - tool-avrdude 1.60300.200527 (6.3.0) 
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
BeforeUpload(["uploadeep"], [".pio/build/attiny13/firmware.eep"])
avrdude -v "-B 70" -v -p attiny44 -C /Users/user/.platformio/packages/tool-avrdude/avrdude.conf -c usbasp -e -D -U eeprom:w:.pio/build/attiny13/firmware.eep:i

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/Users/user/.platformio/packages/tool-avrdude/avrdude.conf"
         User configuration file is "/Users/user/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         Setting bit clk period        : 70.0
avrdude: seen device from vendor ->www.fischl.de<-
avrdude: seen product ->USBasp<-
         AVR Part                      : ATtiny44
         Chip Erase delay              : 4500 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     6     4    0 no        256    4      0  4000  4500 0xff 0xff
           flash         65     6    32    0 yes      4096   64     64  4500  4500 0xff 0xff
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: try to set SCK period to 7e-05 s (= 14285 Hz)
avrdude: set SCK frequency to 8000 Hz
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9207 (probably t44)
avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as FF
avrdude: erasing chip
avrdude: try to set SCK period to 7e-05 s (= 14285 Hz)
avrdude: set SCK frequency to 8000 Hz
avrdude: reading input file ".pio/build/attiny13/firmware.eep"
avrdude: writing eeprom (1 bytes):

Writing | ################################################## | 100% 0.06s

avrdude: 1 bytes of eeprom written
avrdude: verifying eeprom memory against .pio/build/attiny13/firmware.eep:
avrdude: load data eeprom data from input file .pio/build/attiny13/firmware.eep:
avrdude: input file .pio/build/attiny13/firmware.eep contains 1 bytes
avrdude: reading on-chip eeprom data:

Reading | ################################################## | 100% 0.02s

avrdude: verifying ...
avrdude: 1 bytes of eeprom verified

avrdude: safemode: lfuse reads as 62
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (E:FF, H:DF, L:62)

avrdude done.  Thank you.

============================================== [SUCCESS] Took 0.74 seconds ==============================================

Hm okay it really does a -e. Did you put this in your platformio.ini? What’s the full content of it?

I did not put the erase command into my ini. Here is the full content of my platformio.ini:

[env:attiny13]
platform = atmelavr
board = attiny44
upload_protocol = usbasp
board_build.f_cpu = 1000000L
upload_flags =
  -v
  -B 70

I see. The board definition says

So that is where -e is coming from. You can disable this by writing

board_upload.extra_flags = 

to override it to an empty value.

Changes the invocation to (e.g.)

avrdude -v “-B 70” -v -p attiny44 -C C:\Users\Max.platformio\packages\tool-avrdude\avrdude.conf -c usbasp -D -U eeprom:w:.pio\build\attiny13\firmware.eep:i

The question is whether that makes sense. Shouldn’t the EEPROM be erased before reprogramming it? Maybe it only erases the EEPROM and not the entire flash.

You can try and see yourself it that works.

Yeah, that seems to work, thanks. The disadvantage is, that for uploading the firmware, I need to perform the chip erase, therefore I need to enable and disable it based on the task to be executed.

Is there any way to only define these extra flags for that specific “Upload EEPROM” task?

Yes with a custom piece of python code, as generally explained in the docs. Modifying the platformio.ini to

[env:attiny13]
platform = atmelavr
board = attiny44
upload_protocol = usbasp
board_build.f_cpu = 1000000L
upload_flags =
  -v
  -B 70
board_upload.extra_flags = 
extra_scripts = post:fix_uploadflags.py

and adding the file fix_uploadflags.py to the project with the content

Import("env", "projenv")

def before_upload(source, target, env):
    if "upload" == str(target[0]):
        env.Append(UPLOADERFLAGS=["-e"])

env.AddPreAction("upload", before_upload)
env.AddPreAction("uploadeep", before_upload)

will cause the Upload (firmware) command to include -e (added by script) but the upload EEPROM command not.

In my case the pio run -v -t upload (upload firmware) gives

avrdude -v “-B 70” -v -p attiny44 -C C:\Users\Max.platformio\packages\tool-avrdude\avrdude.conf -c usbasp -e -D -U flash:w:.pio\build\attiny13\firmware.hex:i

And pio run -v -t uploadeep gives

avrdude -v “-B 70” -v -p attiny44 -C C:\Users\Max.platformio\packages\tool-avrdude\avrdude.conf -c usbasp -D -U eeprom:w:.pio\build\attiny13\firmware.eep:i

2 Likes

That works perfectly. Thank you very much for your support! Awesome!!