Go Down

Topic: Arduino Due JTAG Debugging and Testing w/ OpenOCD (Read 1 time) previous topic - next topic

SidPhillips

Hello everyone!

Circa a month ago I got a project topic from my uni professor - the project is my mid-term work and I do need to pass it. It's all basically writing a paper consisting a broad, yet specific review on how to execute JTAG technology on Arduino Due board. The aim is to - in maybe not-so-distant future - on that basis create some amount of experiment stands for forthcoming students to exercise. The constraints are:
1) The DUT is just regular Arduino Due
2) The JTAG adapter or any other communication device between Arduino and a computer is of my choice - however it needs to be at reasonable price (say, under 25$). Any articles like this one would be very valuable for me.
3) Professor strongly insisted on OpenOCD usage - due to being open source, universal and free.

Ok then, so what exactly do I need to write since I am not developing an actual system?
First, I need to pick some options for PC-Arduino communication that will be also JTAG-capable. I ran into one topic on this forum that presented use of Bus Pirate (Here), but maybe something more specific for the task (i.e. less universal) would do? Important note: cost here outranks the optimization, the whole system doesn't have to be the fastest possible. Then, I should describe pattern of writing configuration files with OpenOCD.

Additionally I need to describe the situations of what happens with the CPU timer while being in debugging mode and CPU work is held off (does it exceed its limit or is there some protection against that).
The other thing would be what if we set a breakpoint through GPIO in debug mode.
The last keyword that I got is bootloader - does JTAG somehow exchange it? To be honest, this one I don't quite understand...  :smiley-roll:

Any help that you guys can provide me with would be priceless, since my experience in the whole topic is poor. I did some research and found I think quality articles on JTAG basics (1) (2) (3), however finding and/or verifying some more specific threads is just too difficult for me.

Just to be clear - I am NOT a university worker that got a task from a superior - I just simply want to make decent project just to pass the class.

I also hope that I put the topic in the correct subforum. My project is very circuit-specific, so I hope that it is fine.


phr3ak

which IDE/tool can do source code level debugging?

westfw



Quote
The JTAG adapter or any other communication device between Arduino and a computer is of my choice - however it needs to be at reasonable price (say, under 25$).
Alas, most JTAG probes are more expensive than that, up to several hundred dollars.  Particular vendors will sometimes have cheap probes (like ST's STlink2), but they tend to be somehow limited to working only with that particular vendor's chips, and/or only with their development environment (not OpenOCD.)
You already found the Bus Pirate.  There are also assorted FTDI FT232H Breakout boards. that are documented to work with openOCD.
Microchip now has their SNAP Debugger, but I don't think I've seen any info on using it with OpenOCD.
JTAG itself is best thought of as a communications protocol, vaguely similar to "serial."  It allows an external probe to access "registers" that are inside a chip.  What those registers actually do, or how to achieve a particular effect using those registers, is ... separate.
To do actual debugging or uploading, software will interact with registers inside the Due's SAM3X8A that are part of the SAM's debug capabilities.   Some of these are standardized across ARM Cortex CPU (The DWT "Debug, Watchpoint and Trace" module) and are documented by ARM, rather than Microchip.  Others are more specific to the SAM3X8A chip itself (the NVM controller that would be used to write progams to flash.)
My vague understanding (I've never actually used OpenOCD) is that OpenOCD provides a bunch of the conversion from chip-specific JTAG commands to some sort of common set of higher-level debugging commands (based on rather obscure configuration files that probably already exist for the Due chip.)   And then you'd use an even higher-level debugger (like gdb) that would talk to OpenOCD.
Quote
Ok then, so what exactly do I need to write since I am not developing an actual system?
Trying to second-guess a university professor?  Hmm.
I would say, at a minimum:
  • write  a tutorial describing how to achieve some level of debugging of the Due.  (Breakpoints, examining registers, loading code.)  Include all the bits and pieces you need to buy or download, how to connect them up, and how to use them.
  • Describe how they work together.
  • Cross-reference all the individual and scattered documentation that is relevant (SAM datasheet, ARM documents, JTAG references, FTDI datasheet, OpenOCD Docuementation, GDB (or whatever) documentation.  (As you've noticed, it can be painful to try to find everything in one place.)


For extra credit:
  • Document more than one probe (FT232H, J-Link EDU Mini, Bus Pirate)
  • Compare to a non-openOCD system (JLink Commander?)
  • figure out how to get OpenOCD to talk to something (like SNAP) that isn't already done.  (could range between "slight modifications to a CMSIS/DAP profile" to "not possible.)
  • Analyze/optimize performance.



Quote
I need to describe the situations of what happens with the CPU timer while being in debugging mode
Perhaps you're supposed to do that to prove that you got the debugging working?
Some chips have a per-peripheral configuration flag controlling whether the peripheral "operates" during debug mode.  I don't know if the SAM3X8e is one of them or not.
Quote
bootloader - does JTAG somehow exchange it?
I don't understand the question.  Using a JTAG probe/debugger can bypass the need to use a bootloader, but the SAM3x bootloader is in ROM, so you can't completely replace it...

SidPhillips

#4
Jan 21, 2020, 07:16 pm Last Edit: Jan 21, 2020, 07:16 pm by SidPhillips
https://forum.arduino.cc/index.php?topic=653892.0

Thanks! I took a look at it and it'll definitely be useful in terms of exploring hardware possibilities.

which IDE/tool can do source code level debugging?
I don't know either answer to this question or why did you ask it :)



Alas, most JTAG probes are more expensive than that, up to several hundred dollars.  Particular vendors will sometimes have cheap probes (like ST's STlink2), but they tend to be somehow limited to working only with that particular vendor's chips, and/or only with their development environment (not OpenOCD.)
You already found the Bus Pirate.  There are also assorted FTDI FT232H Breakout boards. that are documented to work with openOCD.
Microchip now has their SNAP Debugger, but I don't think I've seen any info on using it with OpenOCD.
First, thanks a lot for elaborate answer! It really got me get the topic a bit better.
I've found this adapter: http://www.distortec.com/jtag-lock-pick-tiny-2/
and I think it meets all my requirements. Still, I think I will include more than one adapter suggestion. Professor suggested that I find actually something less universal than Bus Pirate...


Trying to second-guess a university professor?  Hmm.
I would say, at a minimum:
  • write  a tutorial describing how to achieve some level of debugging of the Due.  (Breakpoints, examining registers, loading code.)  Include all the bits and pieces you need to buy or download, how to connect them up, and how to use them.
  • Describe how they work together.
  • Cross-reference all the individual and scattered documentation that is relevant (SAM datasheet, ARM documents, JTAG references, FTDI datasheet, OpenOCD Docuementation, GDB (or whatever) documentation.  (As you've noticed, it can be painful to try to find everything in one place.)


For extra credit:
  • Document more than one probe (FT232H, J-Link EDU Mini, Bus Pirate)
  • Compare to a non-openOCD system (JLink Commander?)
  • figure out how to get OpenOCD to talk to something (like SNAP) that isn't already done.  (could range between "slight modifications to a CMSIS/DAP profile" to "not possible.)
  • Analyze/optimize performance.

I have just dugged into OpenOCD documentation, and described some of FTDI commands, since that's precisely what my professor wanted. He also said that I should stick to OpenOCD only (hence purpose of my work). Thank you a lot for these suggestions though :)


Perhaps you're supposed to do that to prove that you got the debugging working?
Some chips have a per-peripheral configuration flag controlling whether the peripheral "operates" during debug mode.  I don't know if the SAM3X8e is one of them or not.
I will check this up.

I don't understand the question. 

Well, me neither, but during my second round with the professor he actually said that I can ommit this. Nvm :)

Thank you a lot for the answers guys!

Go Up