Upload and Debug for ATmega328P with Atmel ICE

As said above, with the avr-stub method for example, this just requires a serial port device but in turn you can’t use the hardware UART in the debugged firmware / must disable it (How to debug on Arduino mega 2560 - #2 by maxgerhardt). dwire would be another thing for debugging, unsure if it’s for uploading too. Programming can be done with a multitude of devices, basically everything AVRdude supports, as see per docs Atmel AVR — PlatformIO latest documentation.

Hi @maxgerhardt,

after reading the link you posted, I understand that if I use the debug with avr-stub is not possible to use the USART module into the code. This could be a problem because my code uses the USART to communicate with another MCU and the communication must be in place in order to execute the code.

I’m sorry for my many questions but I always work on a different kind of MCU (usually STM32 with other IDE) and the debug is supported natively by the IDE and by the programmer.

In this particular project, I switched to ATmega238P but I looking to find a way to debug in a way similar to other MCU.

Unfortunately Atmel Studio works only on Windows.

So I think the only way to debug in a similar way is to change the programmer/debugger. Am I right?
Or there is not a programmer/debugger to debug that without using avr-stub?

UPDATE: I tried the debugging functionality on my Arduino UNO board (same ATmega328P) and everything works with ‘avr-stub’. And it was very simple.

I need to figure out how to debug my system in a simular way.

Thanks for your time!

Best regards.

It’s also about hardware USART here. When working with e.g. Arduino, the SoftwareSerial library is available (with some baud rate and format restrictions though), so one can move the original Serial output to a software serial pretty easily and thus enable hardware debugging – or, one could also think about moving the GDB serial interface to a software serial and freeing up the original software serial that way.

Hello @maxgerhardt,

now it is clear. I will try it.

Just an update (another): I tried to debug my project on ArduinoUNO board with ‘avr-dude’ but I get this error when I start a debug session:

immagine

I think the code inside my project (developed from another person) interfers with GBD.

Thank you.

If the blinky-code from the topic I’ve linked above works avr-gdb but your firmware code not, that should be the reason.

Yes, exactly. Your blink code works bwith avr-gdb, but my code not!

So since debugging with ‘avr-gdb’ doesn’t work the only thing I can do is to use Atmel Studio.

Thank you for your time and help!

BR,
Federico

Hi @maxgerhardt,

I try again to upload the firmware on Windows.

Now I get this error:

avrdude: jtag3_edbg_prepare(): unexpected response 0x81, 0x11
avrdude: jtag3_edbg_prepare(): unexpected response 0x02, 0x01
avrdude: jtag3_edbg_send(): Unexpected response 0x01, 0x00
avrdude: jtag3_edbg_recv(): Unexpected response 0x80
avrdude: failed to sync with the JTAGICE3 in ISP mode

I installed the WinUSB driver with Zading and tried to upload the firmware with this platformio.ini

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

Do you have any suggestions?

Thanks fro your time!

Best regards

I’ve seen the post AVR Debuggen met Atmel-ICE en MPLAB X IDE onder Linux which says this error can occur if debugWire has been enabled or is in use.

What does it say when you open a PIO CLI and do

C:\Users\<user>\.platformio\packages\tool-avrdude\avrdude -v  -C "C:\Users\<user>\.platformio\packages\tool-avrdude\avrdude.conf"  -c atmelice_isp  -p m328p

?

Other generic trouble-shooting methods would be:

Hi,

thanks for the reply.

The output is

avrdude.exe: Version 6.3, compiled on Sep 12 2016 at 17:24:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Federico\.platformio\packages\tool-avrdude\avrdude.conf"

         Using Port                    : usb
         Using Programmer              : atmelice_isp

avrdude.exe: usbdev_open(): Found Atmel-ICE CMSIS-DAP, serno: J41800043393
avrdude.exe: Found CMSIS-DAP compliant device, using EDBG protocol
avrdude.exe: jtag3_edbg_prepare(): unexpected response 0x81, 0x11
avrdude.exe: jtag3_edbg_prepare(): unexpected response 0x02, 0x01
avrdude.exe: jtag3_edbg_send(): Unexpected response 0x01, 0x00
avrdude.exe: jtag3_edbg_recv(): Unexpected response 0x80
avrdude.exe: failed to sync with the JTAGICE3 in ISP mode

avrdude.exe done. Thank you.

Now, I remember that my target could be in debugWire because yesterday I try to debug with Microchip studio.

Since I change the Atmel-ICE driver, so Microchip Studio did not recognize the programmer, can I disable the debugWire writing the DWEN fuse from platformio?

Thank you so much!