Set fuses on ATmega4809

Hello

I am trying to change the oscillator frequency of a Nano Every. I can change it from the Arduino Ide modifying the fuse byte in board.txt, now it is set at 20MHz (Fuse2 0x02).

When i Try to set the fuses from PlatformIO I receive this:

> Executing task: platformio run --target fuses --environment nano_every <

Processing nano_every (platform: atmelmegaavr; board: nano_every)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/nano_every.html
PLATFORM: Atmel megaAVR (1.5.0) > Arduino Nano Every
HARDWARE: ATMEGA4809 16MHz, 6KB RAM, 47.50KB Flash
PACKAGES: 
 - tool-avrdude-megaavr 1.60300.191015 (6.3.0) 
 - toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode

Selected fuses:
------------------------
[fuse2 / OSCCFG  = 0x01]
[fuse5 / SYSCFG0 = 0xC9]
[fuse8 / BOOTEND = 0x00]
[lfuse / LOCKBIT = 0xC5]
------------------------

Setting fuses...

avrdude done.  Thank you.

*** [fuses] Error 1

I did not change the configuration, so OSCCFG=0x01 (16MHz). It says avrdude done, but it also gives an Error 1.
The clock frequency after that is still 20MHz, so the fuses were not reprogrammed.

There is another thing that puzzles me, when i download the hex file on the 4809 I receive this message:

avrdude: 202 bytes of flash written

avrdude: safemode: Fuses OK (E:FF, H:FF, L:FF)

avrdude done.  Thank you.

It gives me the value of Extended, High and Low fuses (like e.g. for ATmega328) but the 4809 has 8 fuse bytes, so what are these E:FF, H:FF, L:FF?

What does it say when you open a CLI and execute

pio run -t fuses -v 

?

Here is the output

reto@sputnik:~/Documenti/SynologyDrive/platformIO/every$ pio run -t fuses -v
Processing nano_every (platform: atmelmegaavr; board: nano_every; extra_scripts:
no_startfiles.py)
--------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/nano_every.h
tml
PLATFORM: Atmel megaAVR (1.5.0) > Arduino Nano Every
HARDWARE: ATMEGA4809 16MHz, 6KB RAM, 47.50KB Flash
PACKAGES:
- tool-avrdude-megaavr 1.60300.191015 (6.3.0)
- toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode

Selected fuses:
------------------------
[fuse2 / OSCCFG  = 0x01]
[fuse5 / SYSCFG0 = 0xC9]
[fuse8 / BOOTEND = 0x00]
[lfuse / LOCKBIT = 0xC5]
------------------------

avrdude -p atmega4809 -C /home/reto/.platformio/packages/tool-avrdude-megaavr/av
rdude.conf -v -P usb -c jtag2updi -Ufuse2:w:0x01:m -Ufuse5:w:0xC9:m -Ufuse8:w:0x
00:m -Ulock:w:0xC5:m

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 "/home/reto/.platformio/packages/tool
-avrdude-megaavr/avrdude.conf"                                                   
        User configuration file is "/home/reto/.avrduderc"                      
        User configuration file does not exist or is not a regular file, skippi
ng                                                                               
                                                                                
        Using Port                    : usb                                     
        Using Programmer              : jtag2updi                               
avrdude: usbdev_open(): did not find any USB device "usb" (0x03eb:0x2103)        
                                                                                
avrdude done.  Thank you.                                                        
                                                                                
*** [fuses] Error 1                                                              
========================== [FAILED] Took 0.33 seconds ==========================

It also says “avrdude done.”, but it gives the same *** [fuses] Error 1

Hm okay so the invocation with regards to the fuses looks good, but it seems to choke on the -P usb part and it does not find a fitting USB device – likely PlatformIO invokes it in a wrong way.

What I can see when I do “Advanced → Verbose Upload” is that it does

Auto-detected: COM11
Forcing reset using 1200bps open/close on port COM11
avrdude -v -p atmega4809 -C C:\Users\Max\.platformio\packages\tool-avrdude-megaavr@1.60300.191015\avrdude.conf -c jtag2updi -b 115200 -V -e -D -P "COM11" -U flash:w:.pio\build\nano_every\firmware.hex:i

So here it does a reset-into-bootloader (?) and then uses -P "COM11".

This is likely a bug on the PlatformIO side, I’ll open an issue about it.

This is now tracked in Fuse programming doesn't work · Issue #34 · platformio/platform-atmelmegaavr · GitHub.

1 Like

The Nano Every was connected and working, I can download the program and it works.
What do you think about the :

Fuses OK (E:FF, H:FF, L:FF)

when I download the program?
This also looks a bit weird…