ATmega328P Enable DWEN to debug with Avarice

Hi,

I’m working with an ATmega328P and a Atmel-ICE for programming and debugging.

On Windows and with Microchip Studio everything works, I can program using SPI and debug using debugWire. Microchip studio takes care to enable the DWEN fuse.

On Linux Xubuntu, I use Platformio and I’m able to program usign the SPI but I’m tring to figure out how to enable DWEN in order to use Avarice.

Board: Arduino Uno
Fuses (from Microchip Studio):

BODLEVEL = 2V7
RSTDISBL =
DWEN =
SPIEN =
WDTON =
EESAVE =
BOOTSZ = 256W_3F00
BOOTRST =
CKDIV8 =
CKOUT =
SUT_CKSEL = EXTXOSC_8MHZ_XX_16KCK_14CK_65MS

EXTENDED = 0xFD (valid)
HIGH = 0xD6 (valid)
LOW = 0xFF (valid)

I want to switch to debugWire from platformio, and I tough to creare different project task for:

  • Upload
  • Enabled debugWire uploading new Fuses
  • Disable debugWire and enable SPI again

According to Fuses Calculator, in order to enable debugWire and disable SPI the corresponding fuses are:

immagine

According to these values, I create three diffrente platformio tasks:

[platformio]
;default_envs = uno

[env:uno]
platform = atmelavr
board = uno
framework = arduino
upload_protocol = atmelice_isp
upload_flags = -e
upload_port = usb
board_upload.require_upload_port = no
board_build.f_cpu = 8000000L

[env:uno_enable_debugWire]
platform = atmelavr
board = uno
framework = arduino
upload_protocol = atmelice_isp
upload_flags = -e
upload_port = usb
board_upload.require_upload_port = no
board_build.f_cpu = 8000000L
; Set Fuses
; Arduino Uno Atmega328 8Mhz
board_fuses.efuse = 0xFD
board_fuses.hfuse = 0xB6
board_fuses.lfuse = 0xFF
; Debug
debug_port = :4242
debug_load_cmds = 
debug_load_mode = manual
debug_tool = custom
debug_init_cmds =
  target remote $DEBUG_PORT
  file "$PROG_PATH"
  load /home/Documents/PlatformIO/Projects/210128-100826-uno/.pio/build/uno/firmware.elf
debug_server =
  avarice
  -1 
  -j/dev/ttyUSB0 
  --ignore-intr 
  :4242

[env:uno_disable_debugWire]
platform = atmelavr
board = uno
framework = arduino
upload_protocol = atmelice_isp
upload_flags = -e
upload_port = usb
board_upload.require_upload_port = no
board_build.f_cpu = 8000000L
; Set Fuses
; Arduino Uno Atmega328 8Mhz
board_fuses.efuse = 0xFD
board_fuses.hfuse = 0xD6
board_fuses.lfuse = 0xFF

Is this make sense?

Thank you and best regards.