Flashing the ATxmega256A3BU - Page 1
Forum section: electronics / beginners

author: n00b1e
author_rank: Newbie
timestamp: May 03, 2022, 03:02:27 pm
content: Hello everyone.I own an OSVR HDK (v1.2/v1.3) but unfortunately it's not working anymore, so recently I started looking into it and my first guess was that it got bricked during firmware upgrade (I wasn't the one who did it, so it's just a wild guess).Anyway, after some research I found how to flash the bootloader (ATxmega256A3BU) using a programmer.What I got was the AVRISP mkII (used with Atmel Studio), but the board uses a JTAG interface so I have to connect the cable directly to the xmega PDI pins.I found a picture online which shows how the PDI interface is wired to the microcontroller.I tried to connect (and also not) the VCC (the JTAG VTref of 3.3V) pin (with and without the 10K Ohm resistor) to the RESET/PDI_CLK line.I also tried to connect the PDI data pin to the JTAG TDI pin, which is called PDI_DATA_R on the board file. Then, I tried to connect it to the PDI_DATA pin (which seems different from PDI_DATA_R) on the microcontroller (by directly touching the small pin, ouch).For every single thing I tried the programmer showed a blinking orange led, which the docs suggest it's either because the cable connection is reversed (which sounds weird) or because there's not a correct pull-up on the reset line (I think it's the resistor it's talking about, but I'm not sure).I apologise if I'm making a very simple mistake but since I know very little about electronics I had to research everything from what the bootloader flashing docs mentioned.Does anyone understand what I might be doing wrong?Thanks a lot in advance.Some other useful information:The actual interface the AVRISP mkII has is ISP but it does support PDI.You can find the JTAG interface labeled as J6 and the xmega as U12 in the top right of the board file (which can be opened with Cadence Allegro).I was wondering if the microcontroller itself was broken but when I was trying what cable combination worked LD11 (a led near J6) turned on. After some research I found that it turns on from port PF0 and it's used as debug during startup, so at least this part of code is running. What I don't understand however is that when fiddling with the cables it was turning off and then back on which I don't think it's supposed to happen since the code is not inside the main loop. I wasn't shorting the circuit since all the other leds were on, so maybe I was involuntarily sending a reset signal.:https://github.com/OSVR/OSVR-Docs/blob/master/Configuring/HDKBootloader.md:https://www.waveshare.com/w/upload/DVD_AVR8_EN/data/product/USB_AVR_ISP_XPII_PG-1-1.htm:https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-8362-8-and-16bit-AVR-microcontroller-ATxmega256A3BU_datasheet.pdf#G1.1211181:https://i.ibb.co/HFnBN13/image.png:https://i.ibb.co/f4FnTXY/image.png:https://github.com/OSVR/OSVR-HDK/tree/master/HDK%20Ver%201.3/electronics/board%20files/hmd-dvt-323am11-brd:https://de.catbox.moe/ghp4g7.pdf:https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42093-AVR-ISP-mkII_UserGuide.pdf#_OPENTOPIC_TOC_PROCESSING_d92e694:https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42093-AVR-ISP-mkII_UserGuide.pdf#_OPENTOPIC_TOC_PROCESSING_d92e770:https://github.com/OSVR/OSVR-HDK-MCU-Firmware/blob/main/Source%20code/Embedded/src/config/my_hardware.h#L29:https://github.com/OSVR/OSVR-HDK-MCU-Firmware/blob/main/Source%20code/Embedded/src/Boot.c#L41

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 03, 2022, 04:46:19 pm
content: I think you may've misunderstood what/how the JTAG vs. PDI pins are connected/used;  looks like a programming port, so, whatever's driving those signals is able to do so according to that pinout. But the inverse need not be true. So if you were trying to wire the MKII to the JTAG pins, that's not gonna work.The XMEGA have a completely independent programming port; it can only be locked, I think, by setting the fuse LOCKBITS (which aren't specific, they lock any write/readout of Flash, via SPM instructions, JTAG or PDI). The JTAG pins are separate from this, and is just another interface that can be enabled (by a fuse bit, and also en/disabled by soft register). Albeit a more tightly integrated interface, being it can do debugging! (Ah, well not exactly independent, it appears JTAG is an interface to the internal PDIBUS, see Fig. 32-1https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-8331-8-and-16-bit-AVR-Microcontroller-XMEGA-AU_Manual.pdf.)So you should have the right idea, connecting to the PDI pins directly. Holding wires in place can be very tricky; I suggest soldering wires in place (preferably wirewrap or fine enameled wire) and taping/gluing them down so they don't come loose. Inspect carefully, check there's no shorts, use a magnifier, whatever. Then find some spare pins somewhere, or glue down a connector or something, so you can get repeatable connection to it. And this can be a 2x3 header so the MKII just plugs in.JTAG should be usable, if the chip has it enabled (sounds like it) and you have a JTAG compatible adapter (which could be anything, of course they recommend their own Atmel-ICE).AVR Studio should be able to talk to whatever interface you have, and if you're having problems there, pay attention to the console output, if it's logging errors or anything. You can also use AVRDude separately; I think it's provided with Studio so just find where it's installed and open a command prompt there, otherwise, at worst, go download a copy and run it from wherever. Follow themanualto use it. It'll probably be something like:avrdude.exe -p x256a3bu -c AVRISPMKII -U flash:w:[file.elf]:eYou can omit the -U option to just "ping" the device; it should say the device signature.Likewise if you have a JTAG device, specify the respective programmer type and port (I don't know offhand how to enumerate JTAG devices, but they're usually routed through a virtual device driver scheme I think, so, look into that?). AVRDude supports most anything, so something workable should be in there.And, if you have the firmware image in some other format than ELF, then use the filename as appropriate, and change the :e option to another supported format.Tim

author: n00b1e
author_rank: Newbie
timestamp: May 03, 2022, 07:02:45 pm
content: What I was doing with the JTAG interface was exploiting the fact that some pins were shared between the JTAG and PDI interface. This way I don't have to connect all of the cables to the microcontroller directly.I see why the programmer wouldn't work when connecting all pins there, but some pins would work right? For example, I should be able to connect VCC (VTref of 3.3V) and GND from the JTAG interface to the programmer's PDI. As for PDI_CLK, Allegro Cadence allows you to highlight the connections between components, and the nSRST JTAG pin is connected to pin 57 which is also used by PDI (but what about pull-up? Even trying to put the 10K resistor didn't make it work, so I don't know if it's necessary or not).The last pin I need to connect is PDI_DATA which  reports as TDI. Trying TDI didn't work, so I tried to connect it to TDO since it's called PDI_DATA_R on the board file which, unfortunately, is connected to a different pin (from what I understand) compared to PDI_DATA (but the two are connected together I think). Either way, since the two pins are different I tried to manually holding the wire on pin 56, but it still didn't work.As for the avrdude command, the problem is that it doesn't detect the target at all, with or without the 10K resistor. I'll attach the logs.Also, while trying this LD11 turned on most of the times.:https://i.ibb.co/Q9zzbKv/nrst.png:https://i.ibb.co/stkxW9b/image.png

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 03, 2022, 09:39:00 pm
content: Ohh, they have them (DAT and CLK, or just CLK?) tied on the board? Probably can't use both then. Cut the traces/jumpers to the JTAG maybe?Tim

author: n00b1e
author_rank: Newbie
timestamp: May 04, 2022, 05:30:49 am
content: Wha to do you mean with tied? I'm assuming you're talking about PDI_DATA and PDI_DATA_R (TDO) being connected together between the two resistors. But PDI_CLK is not connected with either of the two.Maybe I was a little vague on the previous post; I meant that pin 57 is used by the PDI interface as the CLK signal and also by the JTAG interface as nSRST signal. This is a good thing (I think) because I can connect to the header instead of the the microcontroller directly.As for cutting the traces, do I really have to separate PDI_DATA and PDI_DATA_R? Wouldn't connecting to pin 56 on the microcontroller work instead?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 04, 2022, 09:51:37 am
content: It sounds like you're describing them [some JTAG and PDI port lines] joined together somehow. Which means one probably takes precedence over the other, or interferes with the other. I don't know, it's very unclear without a schematic to actually see the connections on, and the random aside references that are difficult to follow in post form...Tim

author: n00b1e
author_rank: Newbie
timestamp: May 04, 2022, 05:19:05 pm
content: PDI_CLK and nSRST are the same. But if you meant the other two then yes, PDI_DATA and PDI_DATA_R look like they're joined together (the latter of which is the same as JTAG TDO).Maybe you're right about the communication getting interfered with by PDI_DATA_R, however should I actually just scratch the board to cut the trace between the two small resistors?I'm not entirely sure this is the problem and breaking the connection might make a mess if I end up having to buy a JTAG because nothing works.P.S.: I understand that those "random" references are a mess when used in posts, but I have no way to know if I interpreted those documents correctly, so if someone is unsure about what I wrote at least they can see where I got that information from. Oh and, the entire OSVR project is open source, so I don't understand what you mean with "without a schematic".

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 04, 2022, 05:51:46 pm
content: I don't know anything about joining the two together. Seems like it wouldn't be very effective. But yeah, trying JTAG would seem the other thing. If that doesn't work, who knows how they did it or why, but break the trace(s) and go on with life.You can always repair a trace by scraping back the soldermask and soldering a jumper over it. Not a big deal, just a bit of tricky work.If you have some other MCU projects laying around, there might be JTAG adapter firmware you can load on one. Like, a lot of dev boards have been used that way. Idunno. If nothing else, it's not a huge cost in the grand scheme of things (depending on which adapter you buy)."Open source", is meaningless by itself. It appears they've taken the approach of "technically yes, but we're an asshole about it": I see fab files, but absolutely no PDF or other interchange format, at least in the subfolders I clicked through. Not everyone has proprietary software like Allegro. Big fail.The one exception I would allow [to not be an "open source but you're an asshole" type project] is KiCAD, which itself is open (GPL) so is relatively accessible at no cost. But you're still a bit of an asshole if you don't provide PDFs or legible screenshots alongside the project files, it's just basic courtesy y'know?Tim

author: n00b1e
author_rank: Newbie
timestamp: May 04, 2022, 06:51:02 pm
content: Alright, I'll see if I can get JTAG working then (hopefully I can use my raspberry for that). If it doesn't I guess I'll try to cut the trace.Yeah the Allegro thing pissed me off as well. I was kinda expecting the file format to be open source as well so it could be read by multiple programs as well but I got slapped in the face.Anyway, thanks for the help man.