AVR Studio and Atmel-ICE

Some time ago I purchased an Atmel-ICE Basic for $50 (a very good price, I think). I'm a retired programmer and I'm very familiar with Visual Studio (C, C++ and C#), so I felt comfortable moving off the Arduino IDE to AVR Studio to gain the debugging capability. The Atmel-ICE has been sitting on the shelf for several months.

Recently I tried to use Atmel-ICE on an some cheap Arduino Nano Clones (using the debug-wire interface) with no success. Come to find out, the debug line on the Nano clones is all crapped up with a capacitor and a 1K pull-up on the reset line, which is an absolute no-no for the reset signal when using Atmel-ICE. I found a post where I could pull off the cap and 1K pull-up (should be a weaker 10K pull-up) and that would let the Nano clone work with Atmel-ICE. The only problem with that is that the parts to remove are very small surface mount parts that would be hard (for me) to remove cleanly. I just wanted something that would work out-of-the-box.

I rummaged around the parts bins I have and I found a couple of Leonardo boards. I checked the schematic on these, and I found that because the Leonardo 32U4 CPU automatically adds USB support internally, there was no cap on the reset line and that the pull-up is 10K, like it should be, and it had a beautiful ICSP connector that would fit the Atmel-ICE cable.

All went smoothly until I tried to do a debug. Got a message that Debug is not supported from the ICSP connector (or on the 32U4 chip). Only JTAG is supported for debugging. On one hand, I did not expect that the 32U4 would have the more sophisticated JTAG but I'm kind of excited that it does support it--seems better that the debug-wire kludge.

But then I found that the JTAG is supported using four of the analog pins of the 32U4. Also I need to use an obscure (but cheap) interface part from Adafruit to morph the SWD connector with 0.05 pitch pins onto a breakout board that will allow connection to the analog lines and the reset pin of the 32U4 chip. Now my question comes about because of the use of the analog pins by JTAG.

Does use of JTAG on the 32U4 (Leonardo) usurp the use of the A0-A3 pins for analog (or digital) use?

Also, when programming the 32U4 from Atmel-ICE, writes over the bootloader on the Leonardo. Is it possible to use the Atmel-ICE to write the bootloader to the Leonardo to restore its functionality on the Arduino IDE? It seems like the Atmel-ICE allows a programming from file capability, but it looks for a file with a different extension that the boot loader, which I think is a HEX file? I think the Atmel-ICE is always looking for an ELF file.

Yes, you do lose those pins when using JTAG.

Studio can load .hex files, the difference is that they contain no debugging info.

The Uno with the ATmega328 (same as the Nano) supports debugging with debugWire through the 6 pin isp connector. You may need to/should/must remove the typical 100nf cap connecting the processor reset line to the usb<->serial converter. You don’t lose any pins with that scheme but debug wire can be slower and more problematic than JTAG. Your mileage may vary.

Does use of JTAG on the 32U4 (Leonardo) usurp the use of the A0-A3 pins for analog (or digital) use?

Yes.

I need to use an obscure (but cheap) interface part from Adafruit to morph the SWD connector

Note that JTAG and SWD are not quite the same thing.
For an Arduino-compatible board with Atmel Studio debugging support, you might want to look at the Xplained 328p Mini - it has the arduino uno pinout and processor, and a properly connected debugWire debugger ON THE BOARD.
The external programmers are becoming a bit of a dinosaur - vendors are discovering that it's easier to put a $5 native-USB chip on the end-user board than it is to mess with connectors and cables. I think that these days I've got a STK200, an STK500, a JTAGICE2, an Atmel ICE, a PICkit 4, a Microchip SNAP, plus some additional PIC-only programmers, but when I actually want to debug something, I use one of the eval boards with a built-in debugger...

IIRC the 328 is pin compatible with the 88 and 48 ....

It's a kit you can customize, got a board and ZIF.

Why mess with the undocumented Chinese stuff when the Xplained 328p Mini is available for $9 from DigiKey and Mouser?

$1.75 for a development platform kit that includes a ZIF or $9 for an end-product board with SMT 328P; compare apples to turnovers.

What there needs documenting? The board is either okay or it isn't, the AVR's it was made for are in the same line as the 328P, pin and feature compatible just with less memory. Compare the parts to Nick Gammon's Breadboard Duino and if you'd rather use different then do it, it's a kit!

328P-PU was getting closer to $2 last time I bought, 6 ran $2.15 ea at Mouser. 1284P's were $5.50 ea, well worth it.

AVR's are so self-contained that you could wire bits and pins to a socket and do without a board. At least one project soldered directly to the pins of a 328P to build a duino with led, reset circuit and ICSP pins that can plug into a breadboard.

$1.75 for a development platform kit that includes a ZIF or $9 for an end-product board with SMT 328P; compare apples to turnovers.

In this case, the $9 board includes the mEDBG chip that provides debugger and usb/serial interfaces.
Just add headers and plug it in to a USB port on your computer and you have an Uno-compatible that can be debugged with Atmel Studio (even WITHOUT having an Atmel ICE.)
The $1.75 board needs the ICE, needs a USB/Serial converter to use "Serial", and isn't compatible with shields (but it DOES have the ZIF that permits easy use of different 28pin AVRs.)

$9 is a real good price then. I had counted that the OP has a debugger.