avrdudes / avrdude

AVRDUDE is a utility to program AVR microcontrollers
GNU General Public License v2.0
728 stars 137 forks source link

megaAVR JTAG programming doesn't work for SNAP and PICkit4 #1052

Closed MCUdude closed 1 year ago

MCUdude commented 2 years ago

I added the following programmer to avrdude.conf to see if I could get JTAG programming to work. JTAG works just with both the PK4 and the SNAP in MPLAB X. I've enabled both the OCDEN and the JTAGEN fuse for good measure.

programmer
  id    = "pickit4";
  desc  = "MPLAB(R) PICkit 4 in JTAG mode";
  type  = "jtagice3";
  connection_type = usb;
  usbpid = 0x2177, 0x2178, 0x2179;
;

programmer
  id    = "snap";
  desc  = "MPLAB(R) SNAP in JTAG mode";
  type  = "jtagice3";
  connection_type = usb;
  usbpid = 0x217F, 0x2180, 0x2181;
  hvupdi_support = 1;
;

PICkit4

$ ./avrdude -cpickit4 -p atmega1284p -B8

         Vtarget                      : 5.07 V
         JTAG clock megaAVR/program   : 125 kHz
         JTAG clock megaAVR/debug     : 100 kHz
         PDI/UPDI clock Xmega/megaAVR : 100 kHz

avrdude: JTAGEN fuse disabled?
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.

SNAP:

$ ./avrdude -csnap -p atmega1284p -B8
avrdude: usbhid_open(): No device found

         Vtarget                      : 5.06 V
         JTAG clock megaAVR/program   : 125 kHz
         JTAG clock megaAVR/debug     : 100 kHz
         PDI/UPDI clock Xmega/megaAVR : 100 kHz

avrdude: JTAGEN fuse disabled?
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

(Note that the debugWire support for these programmers is also lacking, but I haven't checked to see if dW works with these or not)

bonidydy commented 2 years ago

Programming with SNAP over JTAG works with gdb and "Bloom" debug server https://github.com/bloombloombloom/Bloom.

MCUdude commented 1 year ago

I've tested a little more and can confirm that the SNAP and PICkit4 work with Xmega targets using JTAG. However, I'm still having issues communicating with "standard" 8-bit AVRs over JTAG. Really weird... Especially since other JTAG3/EDBG compatible programmers have no issues with JTAG.

$ ./avrdude -patxmega256a3bu -csnap -B10

         Vtarget                      : 3.30 V
         JTAG clock megaAVR/program   : 1000 kHz
         JTAG clock megaAVR/debug     : 100 kHz
         JTAG clock Xmega             : 100 kHz
         PDI/UPDI clock Xmega/megaAVR : 100 kHz
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: device signature = 0x1e9843 (probably x256a3bu)

avrdude done.  Thank you.

$ ./avrdude -patxmega256a3bu -cpickit4 -B1

         Vtarget                      : 3.31 V
         JTAG clock megaAVR/program   : 1000 kHz
         JTAG clock megaAVR/debug     : 100 kHz
         JTAG clock Xmega             : 1000 kHz
         PDI/UPDI clock Xmega/megaAVR : 100 kHz
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: device signature = 0x1e9843 (probably x256a3bu)

avrdude done.  Thank you.
mcuee commented 1 year ago

@bonidydy

Are you using the SNAP / PICKit 4 with class AVR in JTAG mode or with ATxmega parts? What is the issue you encounterd?

mcuee commented 1 year ago

I can reproduce the issue. Connection as per Page65 from PICKit 4 user guide. target is ATmega32A. OCDEN and JTAGEN are programmed (as 0). http://ww1.microchip.com/downloads/en/DeviceDoc/PICkit4%20In-Circuit%20DebuggerUG-DS50002751B.pdf

And I made sure that it works with Atmel Studio 7.0 first (JTAG programming works)

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c pickit4 -p m32a -B8

         Vtarget                      : 4.93 V
         JTAG clock megaAVR/program   : 125 kHz
         JTAG clock megaAVR/debug     : 100 kHz
         PDI/UPDI clock Xmega/megaAVR : 100 kHz
avrdude error: JTAGEN fuse disabled?
avrdude error: initialization failed, rc=-1
        - double check the connections and try again
        - use -B to set lower ISP clock frequency, e.g. -B 200kHz
        - use -F to override this check

avrdude done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c avrispmkii -p m32a -qq -t
avrdude> dump lfuse
>>> dump lfuse
0000  bf                                                |.               |

avrdude> dump hfuse
>>> dump hfuse
0000  06                                                |.               |

avrdude> dump lock
>>> dump lock
0000  ff                                                |.               |

avrdude> quit
>>> quit
avrdude>

Screenshot 2022-11-05 142828

mcuee commented 1 year ago

Need to learn how to use debugWire. It does not seem to work. But I need to check if it works with Microchip Studio or not first. Once I enable DW bit, I can not communicate with the ATmega328P with AVRISP mkii (reset pin is now DW pin), which is expected.

Edit: TO DO -- to check whether PICKit 4 supports DW or not under avrdude. By right it should work. Connection: https://microchipdeveloper.com/pickit4:interface-pinouts

#------------------------------------------------------------
# pickit4 in DW mode
#------------------------------------------------------------

programmer
  id    = "pickit4_dw";
  desc  = "MPLAB(R) PICkit 4 in debugWire mode";
  type  = "jtagice3_dw";
  prog_modes = PM_debugWIRE;
  connection_type = usb;
  usbpid = 0x2177, 0x2178, 0x2179;
;

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c pickit4_dw -p m328p

         Vtarget                      : 4.94 V
         JTAG clock megaAVR/program   : 1000 kHz
         JTAG clock megaAVR/debug     : 100 kHz
         PDI/UPDI clock Xmega/megaAVR : 100 kHz
avrdude error: initialization failed, rc=-1
        - double check the connections and try again
        - use -B to set lower ISP clock frequency, e.g. -B 200kHz
        - use -F to override this check

avrdude done.  Thank you.

Unfortunately I do not have JTAGICE mkii which supports the function to program the ATmega328P even with DW bits enabled. I have the AVR Dragon which is supposed to be able to disable DW and enable ISP again using Atmel Studio as per Page 19 of the user guide. https://ww1.microchip.com/downloads/en/devicedoc/atmel-42723-avr-dragon_userguide.pdf

Under MPLAB X 6.0 here is the output for PICKit 4.

*****************************************************

Connecting to MPLAB PICkit 4

Currently loaded versions:
Application version...........1.14.268 (0x01.0x0e.0x010c)
Boot version..................1.0.0 (0x01.0x00.0x00)
Tool pack version ............1.12.1384
Target voltage detected

Calculating memory ranges for operation...

Configuration Bits are not accessible over debugWIRE. 
Change communication interface to ISP in the project properties to read or write configurations bits.

Configuration Bits are not accessible over debugWIRE. 
Change communication interface to ISP in the project properties to read or write configurations bits.

Erasing...
The detected device ID is not valid. (58)
Programming did not complete.
mcuee commented 1 year ago

@MCUdude

I check under Microchip Studio, PICKit 4 will not support DW mode of ATmega328P, only ISP mode is supported.

Edit to add: Microchip Studio has never supported DW for programming, only for debugging.

As for ATmega32A, Microchip Studio supports ISP and JTAG using PICKit 4.

bonidydy commented 1 year ago

Again I would like to point out the project "Bloom" https://github.com/bloombloombloom/Bloom which is a debug server for gdb. It can not only debug with PICKit4 and SNAP over DebugWire but also program targets with the gdb's "load" command. The same applies to JTAG, PDI and UPDI.

mcuee commented 1 year ago

I will check out Bloom, as of now it seems to only support Linux, so it is probably not a solution for many avrdude users on Windows and macOS.

MCUdude commented 1 year ago

@xedbg you're probably busy right before Christmas, but do you know if something as trivial as a flag or state needs to be set on these gen 4 programmers in order to support megaAVR JTAG programming?

MCUdude commented 1 year ago

For reference, here are two verbose output logs. One for Atmel ICE (that works), and one for PICkit4 that fails. The PICkit4 fails at the sign-on command, and responds with a 0x33 error, even though the Atmel ICE and PICkit4 run the exact same initialization routine.

Atmel ICE JTAG init success (-vvv) ``` $ ./avrdude -catmelice -patmega16 -vvv executable_abspath = /Users/hans/Downloads/avrdude/src/avrdude executable_abspath_len = 41 executable_dirpath = /Users/hans/Downloads/avrdude/src executable_dirpath_len = 33 sys_config = /Users/hans/Downloads/avrdude/src/avrdude.conf sys_config_found = true avrdude: Version 7.0-20220508 Copyright the AVRDUDE authors; see https://github.com/avrdudes/avrdude/blob/main/AUTHORS System wide configuration file is /Users/hans/Downloads/avrdude/src/avrdude.conf User configuration file is /Users/hans/.avrduderc Using Port : usb Using Programmer : atmelice avrdude: jtag3_open() avrdude: usbhid_open(): probing for max packet size avrdude: usbhid_open(): setting max_xfer from DAP_Info response to 512 avrdude: found CMSIS-DAP compliant device, using EDBG protocol avrdude: jtag3_getsync() avrdude: jtag3_edbg_prepare() avrdude: jtag3_edbg_prepare(): connection status 0x01 avrdude: sending sign-on command: avrdude: jtag3_edbg_send(): sending 3 bytes avrdude: jtag3_recv(): Got message seqno 0 (command_sequence == 0) [general] OK AVR Part : ATmega16 Chip Erase delay : 9000 us PAGEL : PD7 BS2 : PA0 RESET disposition : possible i/o RETRY pulse : SCK Serial program mode : yes Parallel program mode : yes Timeout : 200 StabDelay : 100 CmdexeDelay : 25 SyncLoops : 32 PollIndex : 3 PollValue : 0x53 Memory Detail : Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- eeprom 4 10 128 0 no 512 4 0 9000 9000 0xff 0xff Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- flash 33 6 128 0 yes 16384 128 128 4500 4500 0xff 0xff Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- lfuse 0 0 0 0 no 1 1 0 9000 9000 0x00 0x00 Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- hfuse 0 0 0 0 no 1 1 0 9000 9000 0x00 0x00 Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- lock 0 0 0 0 no 1 1 0 9000 9000 0x00 0x00 Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- signature 0 0 0 0 no 3 1 0 0 0 0x00 0x00 Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- calibration 0 0 0 0 no 4 1 0 0 0 0x00 0x00 Programmer Type : JTAGICE3 Description : Atmel-ICE (ARM/AVR) in JTAG mode avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x01, section 0, parm 0) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 1 (command_sequence == 1) [general] Data returned: 0x01 0x00 0x01 0x2a 0xa1 0x00 0x00 ICE HW version : 0 ICE FW version : 1.42 (rel. 161) Serial number : J41800057131 avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x01, section 0, parm 1) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 2 (command_sequence == 2) [general] Data returned: 0x01 0x01 0x2a 0x00 parm0: 2 avrdude: jtag3_setparm() avrdude: sending set parameter (scope 0x12, section 0, parm 0) command: avrdude: jtag3_edbg_send(): sending 7 bytes avrdude: jtag3_recv(): Got message seqno 3 (command_sequence == 3) [AVR] OK avrdude: jtag3_setparm() avrdude: sending set parameter (scope 0x12, section 0, parm 1) command: avrdude: jtag3_edbg_send(): sending 7 bytes avrdude: jtag3_recv(): Got message seqno 4 (command_sequence == 4) [AVR] OK conn: 4 avrdude: jtag3_setparm() avrdude: sending set parameter (scope 0x12, section 1, parm 0) command: avrdude: jtag3_edbg_send(): sending 7 bytes avrdude: jtag3_recv(): Got message seqno 5 (command_sequence == 5) [AVR] OK avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x01, section 1, parm 0) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 6 (command_sequence == 6) [general] Data returned: 0x01 0xb3 0x13 0x00 Vtarget : 5.04 V avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x12, section 1, parm 32) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 7 (command_sequence == 7) [AVR] Data returned: 0x00 0xdc 0x05 0x00 JTAG clock megaAVR/program : 1500 kHz avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x12, section 1, parm 33) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 8 (command_sequence == 8) [AVR] Data returned: 0x00 0xc8 0x00 0x00 JTAG clock megaAVR/debug : 200 kHz avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x12, section 1, parm 48) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 9 (command_sequence == 9) [AVR] Data returned: 0x00 0xe8 0x03 0x00 JTAG clock Xmega : 1000 kHz avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x12, section 1, parm 49) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 10 (command_sequence == 10) [AVR] Data returned: 0x00 0xf4 0x01 0x00 PDI/UPDI clock Xmega/megaAVR : 500 kHz avrdude: jtag3_initialize(): trying to set JTAG daisy-chain info to 0,0,0,0 avrdude: jtag3_setparm() avrdude: sending set parameter (scope 0x12, section 1, parm 1) command: avrdude: jtag3_edbg_send(): sending 10 bytes avrdude: jtag3_recv(): Got message seqno 11 (command_sequence == 11) [AVR] OK avrdude: jtag3_setparm() avrdude: sending set parameter (scope 0x12, section 2, parm 0) command: avrdude: jtag3_edbg_send(): sending 37 bytes avrdude: jtag3_recv(): Got message seqno 12 (command_sequence == 12) [AVR] OK avrdude: sending AVR sign-on command: avrdude: jtag3_edbg_send(): sending 3 bytes avrdude: jtag3_recv(): Got message seqno 13 (command_sequence == 13) [AVR] Data returned: 0x00 0x3f 0x30 0x40 0x09 0x00 avrdude: JTAG ID returned: 0x3f 0x30 0x40 0x09 avrdude: AVR device initialized and ready to accept instructions Reading | | 0% 0.00 s avrdude: jtag3_read_byte(.., signature, 0x0, ...) avrdude: sending enter progmode command: avrdude: jtag3_edbg_send(): sending 3 bytes avrdude: jtag3_recv(): Got message seqno 14 (command_sequence == 14) [AVR] OK avrdude: sending read memory command: avrdude: jtag3_edbg_send(): sending 12 bytes avrdude: jtag3_recv(): Got message seqno 15 (command_sequence == 15) [AVR] Data returned: 0x00 0x1e 0x94 0x03 0x00 avrdude: jtag3_read_byte(.., signature, 0x1, ...) Reading | ################# | 33% 0.08 s avrdude: jtag3_read_byte(.., signature, 0x2, ...) Reading | ################################################## | 100% 0.08 s avrdude: device signature = 0x1e9403 (probably m16) avrdude: sending leave progmode command: avrdude: jtag3_edbg_send(): sending 3 bytes avrdude: jtag3_recv(): Got message seqno 16 (command_sequence == 16) [AVR] OK avrdude: jtag3_close() avrdude: sending AVR sign-off command: avrdude: jtag3_edbg_send(): sending 3 bytes avrdude: jtag3_recv(): Got message seqno 17 (command_sequence == 17) [AVR] OK avrdude: sending sign-off command: avrdude: jtag3_edbg_send(): sending 4 bytes avrdude: jtag3_recv(): Got message seqno 18 (command_sequence == 18) [general] OK avrdude: jtag3_edbg_signoff() avrdude done. Thank you. ```
PICkit4 init fail (-vvv) ``` $ ./avrdude -cpickit4 -patmega16 -vvv executable_abspath = /Users/hans/Downloads/avrdude/src/avrdude executable_abspath_len = 41 executable_dirpath = /Users/hans/Downloads/avrdude/src executable_dirpath_len = 33 sys_config = /Users/hans/Downloads/avrdude/src/avrdude.conf sys_config_found = true avrdude: Version 7.0-20220508 Copyright the AVRDUDE authors; see https://github.com/avrdudes/avrdude/blob/main/AUTHORS System wide configuration file is /Users/hans/Downloads/avrdude/src/avrdude.conf User configuration file is /Users/hans/.avrduderc Using Port : usb Using Programmer : pickit4 avrdude: jtag3_open() avrdude: usbhid_open(): probing for max packet size avrdude: usbhid_open(): setting max_xfer from DAP_Info response to 64 avrdude: found CMSIS-DAP compliant device, using EDBG protocol avrdude: jtag3_getsync() avrdude: jtag3_edbg_prepare() avrdude: jtag3_edbg_prepare(): connection status 0x01 avrdude: sending sign-on command: avrdude: jtag3_edbg_send(): sending 3 bytes avrdude: jtag3_recv(): Got message seqno 0 (command_sequence == 0) [general] OK AVR Part : ATmega16 Chip Erase delay : 9000 us PAGEL : PD7 BS2 : PA0 RESET disposition : possible i/o RETRY pulse : SCK Serial program mode : yes Parallel program mode : yes Timeout : 200 StabDelay : 100 CmdexeDelay : 25 SyncLoops : 32 PollIndex : 3 PollValue : 0x53 Memory Detail : Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- eeprom 4 10 128 0 no 512 4 0 9000 9000 0xff 0xff Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- flash 33 6 128 0 yes 16384 128 128 4500 4500 0xff 0xff Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- lfuse 0 0 0 0 no 1 1 0 9000 9000 0x00 0x00 Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- hfuse 0 0 0 0 no 1 1 0 9000 9000 0x00 0x00 Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- lock 0 0 0 0 no 1 1 0 9000 9000 0x00 0x00 Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- signature 0 0 0 0 no 3 1 0 0 0 0x00 0x00 Block Poll Page Polled Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- calibration 0 0 0 0 no 4 1 0 0 0 0x00 0x00 Programmer Type : JTAGICE3 Description : MPLAB(R) PICkit 4 in JTAG mode avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x01, section 0, parm 0) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 1 (command_sequence == 1) [general] Data returned: 0x01 0x04 0x01 0x0e 0x0c 0x01 0x00 ICE HW version : 4 ICE FW version : 1.14 (rel. 268) Serial number : BUR204071896 avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x01, section 0, parm 1) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 2 (command_sequence == 2) [general] Data returned: 0x01 0x01 0x0e 0x00 parm0: 2 avrdude: jtag3_setparm() avrdude: sending set parameter (scope 0x12, section 0, parm 0) command: avrdude: jtag3_edbg_send(): sending 7 bytes avrdude: jtag3_recv(): Got message seqno 3 (command_sequence == 3) [AVR] OK avrdude: jtag3_setparm() avrdude: sending set parameter (scope 0x12, section 0, parm 1) command: avrdude: jtag3_edbg_send(): sending 7 bytes avrdude: jtag3_recv(): Got message seqno 4 (command_sequence == 4) [AVR] OK conn: 4 avrdude: jtag3_setparm() avrdude: sending set parameter (scope 0x12, section 1, parm 0) command: avrdude: jtag3_edbg_send(): sending 7 bytes avrdude: jtag3_recv(): Got message seqno 5 (command_sequence == 5) [AVR] OK avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x01, section 1, parm 0) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 6 (command_sequence == 6) [general] Data returned: 0x01 0xcf 0x13 0x00 Vtarget : 5.07 V avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x12, section 1, parm 32) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 7 (command_sequence == 7) [AVR] Data returned: 0x00 0xe8 0x03 0x00 JTAG clock megaAVR/program : 1000 kHz avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x12, section 1, parm 33) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 8 (command_sequence == 8) [AVR] Data returned: 0x00 0x64 0x00 0x00 JTAG clock megaAVR/debug : 100 kHz avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x12, section 1, parm 48) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 9 (command_sequence == 9) [AVR] Data returned: 0x00 0x00 0x00 0x00 avrdude: jtag3_getparm() avrdude: sending get parameter (scope 0x12, section 1, parm 49) command: avrdude: jtag3_edbg_send(): sending 6 bytes avrdude: jtag3_recv(): Got message seqno 10 (command_sequence == 10) [AVR] Data returned: 0x00 0x64 0x00 0x00 PDI/UPDI clock Xmega/megaAVR : 100 kHz avrdude: jtag3_initialize(): trying to set JTAG daisy-chain info to 0,0,0,0 avrdude: jtag3_setparm() avrdude: sending set parameter (scope 0x12, section 1, parm 1) command: avrdude: jtag3_edbg_send(): sending 10 bytes avrdude: jtag3_recv(): Got message seqno 11 (command_sequence == 11) [AVR] OK avrdude: jtag3_setparm() avrdude: sending set parameter (scope 0x12, section 2, parm 0) command: avrdude: jtag3_edbg_send(): sending 37 bytes avrdude: jtag3_recv(): Got message seqno 12 (command_sequence == 12) [AVR] OK avrdude: sending AVR sign-on command: avrdude: jtag3_edbg_send(): sending 3 bytes avrdude: jtag3_recv(): Got message seqno 13 (command_sequence == 13) [AVR] FAILED, reason: 0x33 avrdude: bad response to AVR sign-on command: 0xa0 avrdude: retrying with external reset applied avrdude: sending AVR sign-on command: avrdude: jtag3_edbg_send(): sending 3 bytes avrdude: jtag3_recv(): Got message seqno 14 (command_sequence == 14) [AVR] FAILED, reason: 0x33 avrdude: bad response to AVR sign-on command: 0xa0 avrdude: retrying with external reset applied avrdude jtag3_initialize() [jtag3.c:1338] error: JTAGEN fuse disabled? avrdude main() [main.c:1244] error: initialization failed, rc=-1 - double check the connections and try again - use -B to set lower ISP clock frequency, e.g. -B 200kHz - use -F to override this check avrdude: jtag3_close() avrdude: sending AVR sign-off command: avrdude: jtag3_edbg_send(): sending 3 bytes avrdude: jtag3_recv(): Got message seqno 15 (command_sequence == 15) [AVR] OK avrdude: sending sign-off command: avrdude: jtag3_edbg_send(): sending 4 bytes avrdude: jtag3_recv(): Got message seqno 16 (command_sequence == 16) [general] OK avrdude: jtag3_edbg_signoff() avrdude done. Thank you. ```
MCUdude commented 1 year ago

My setup is also working, because I can ping the device over JTAG using pymcuprog:

$ pymcuprog ping -d atmega324pb
Connecting to anything possible
Connected to MPLAB PICkit 4 CMSIS-DAP from Microchip Technology Incorporated (serial number BUR2040xxxxx)
Debugger firmware version 1.14.268
Debugger hardware revision 4
pymcuprog.nvm - WARNING - 
pymcuprog.nvm - WARNING - megaAVR-JTAG stack is in Alpha state
pymcuprog.nvm - WARNING - Expect some features to be missing
pymcuprog.nvm - WARNING - 
Pinging device...
Ping response: 1E9403
Done.
xedbg commented 1 year ago

@MCUdude Christmas is a time for debugging, right? :)

Looks to me like there is some config missing before activating physical: reason 0x33 there are a few "must haves" for debugging (which unfortunately means programming too :/ )

For programming, the first two are needed - the rest can really be dummies

MCUdude commented 1 year ago

It looks like the flash page size and flash size are already present. and I can confirm that it works with Atmel ICE and the Power Debugger, so my initial thought was that GEN4 programmers need a slightly different initialization.

Pymcuprog/pyedbglib is a nice rabbit hole to go down, but I'm not able to get a proper verbose debug output, so I have no clue which initialization packets are sent. If there where I could compare them to the ones Avrdude sends to see if I could figure out what Avrdude is doing wrong.

https://github.com/avrdudes/avrdude/blob/159d12693e8787fab5bf68d87f331bedf85164a1/src/jtag3.c#L1243-L1299

xedbg commented 1 year ago

@MCUdude give us a minute then... Christmas lunch is only at 12... ;) Edit: 12:10 to be precise

janegilruud commented 1 year ago

PR submitted ;-)