Closed MCUdude closed 1 year ago
Programming with SNAP over JTAG works with gdb and "Bloom" debug server https://github.com/bloombloombloom/Bloom.
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.
@bonidydy
Are you using the SNAP / PICKit 4 with class AVR in JTAG mode or with ATxmega parts? What is the issue you encounterd?
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>
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.
@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.
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.
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.
@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?
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.
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.
@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
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.
@MCUdude give us a minute then... Christmas lunch is only at 12... ;) Edit: 12:10 to be precise
PR submitted ;-)
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.
PICkit4
SNAP:
(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)