jamesmintram
Posts: 15
Joined: Mon Jan 15, 2018 12:14 am

JTag for Pi 3

Mon Jan 15, 2018 12:22 am

Hey everyone,

I am new to bare metal programming.

I have been doing a fair bit of reading and came to the conclusion that if I want to debug bare metal code running on a pi from my PC/Mac, then I need a JTag programmer. (Correct me if I am wrong!)

I have seen lots of different types of programmers, all of which seem to support various chips and have software they are compatible with and the prices range from $20 up into the $1000s.

What I am looking for is something that will let me run a debugger on my pc/mac and step through "bare metal" code on a Raspberry pi3 and is as cheap as possible.

Can anyone point me in the direction of such a device?

LdB
Posts: 696
Joined: Wed Dec 07, 2016 2:29 pm

Re: JTag for Pi 3

Mon Jan 15, 2018 3:08 am

There is no requirement for a JTAG programmer for baremetal on the PI it can help in debugging that is all.

The only requirements to baremetal on the PI from a PC/MAC is
1.) a cross compiler
2.) a blank formatted SD card.
3.) a writer for the SD card from your MAC/PC

For the PC there are a number of free cross compilers the arm official site has one for both PC and MAC 64Bit
https://developer.arm.com/open-source/g ... /downloads

On your blank formatted SD card you need to add these 3 files
1.) bootcode.bin
2.) fixup.dat
3.) start.elf
from the Raspberry site
https://github.com/raspberrypi/firmware ... aster/boot

To that you add your produced kernel.img file which contains your code and away it goes and that is the bare minimum requirements

jamesmintram
Posts: 15
Joined: Mon Jan 15, 2018 12:14 am

Re: JTag for Pi 3

Mon Jan 15, 2018 11:57 am

Thanks for your reply LdB,
There is no requirement for a JTAG programmer for baremetal on the PI it can help in debugging that is all.
My question was specifically related to debugging.

I have already gotten a few bare metal programs compiling + running on the device. So my next step in establishing a "workflow" was getting some sort of debugging working.
Last edited by jamesmintram on Mon Jan 15, 2018 9:23 pm, edited 1 time in total.

dwelch67
Posts: 919
Joined: Sat May 26, 2012 5:32 pm

Re: JTag for Pi 3

Mon Jan 15, 2018 2:13 pm

I agree you dont need that, not required. but if you do get one an ftdi based part that supports mpsse is all you need, can be had for under $50, no reason to get the expensive ones. Use openocd. My jtag examples were based on the original pi, arm11 based, and a little into the armv7 based one. But the ftdi breakout boards from ftdi should work just fine. We werent meant to use these boards (or chips) in that manner so like anything baremetal research and hacking is required to get it up and running. You have to change the gpio pins (with code running on the arm or gpu) to alternate functions that connect them to jtag on the arm core, then you need to figure out how to hook up your debugger of choice, then configure the software you are using to speak through that dongle/board to the arm core for the board/chip you are using. this could take hours to months with lots of giving up. IMO part of baremetal is to work through the problem without needing those tools, I use jtag every day to load and run code, but in over two decades of this have single stepped through code less than a handful of times, have no use for it. If I can do it you can do it.

jamesmintram
Posts: 15
Joined: Mon Jan 15, 2018 12:14 am

Re: JTag for Pi 3

Mon Jan 15, 2018 5:12 pm

Hey dwelch67, thanks for your advice.
an ftdi based part that supports mpsse is all you need, can be had for under $50,
Have you got a link to one as an example?
IMO part of baremetal is to work through the problem without needing those tools
Just curious here, how do you handle occasions when you program crashes the hardware? Or you want to validate values in memory? I write reasonably low level C/C++ code at work, and the ability for me to inspect registers/memory via a debugger has always been invaluable when debugging complex issues. I wouldn't even know where to start tracking down an invalid memory access in a complex program without using a debugger.

LdB
Posts: 696
Joined: Wed Dec 07, 2016 2:29 pm

Re: JTag for Pi 3

Mon Jan 15, 2018 5:34 pm

I just spit the dumps to screen and use a GPIO input to single step if I need.
It's fairly trivial to setup a debug sequence into a terminal area on screen.

Invalid memory problems is not something you should be getting a lot of, write better code .. time to review pointer safety programming :-)

jamesmintram
Posts: 15
Joined: Mon Jan 15, 2018 12:14 am

Re: JTag for Pi 3

Mon Jan 15, 2018 6:13 pm

Invalid memory problems is not something you should be getting a lot of, write better code .. time to review pointer safety programming :-)
I wish I could just "write better code .." but I think I am in the vast majority ( along with this guy: http://robert.ocallahan.org/2017/07/con ... ammer.html )
use a GPIO input to single step if I need.
Is that via some mechanism built into the program you are debugging? (Like a wait_for_key() call between statements?)
It's fairly trivial to setup a debug sequence into a terminal area on screen
Again, I am assuming this is done by the program itself? Something like: render_debug_memory_to_console(&address); called periodically.

Or are you using some debug functionality provided by the chip itself? (Like some sort of debug interrupt handler routine)

LdB
Posts: 696
Joined: Wed Dec 07, 2016 2:29 pm

Re: JTag for Pi 3

Tue Jan 16, 2018 1:51 am

jamesmintram wrote:
Mon Jan 15, 2018 6:13 pm
I wish I could just "write better code .." but I think I am in the vast majority ( along with this guy: http://robert.ocallahan.org/2017/07/con ... ammer.html )
I was being semi serious overrunning or invalid memory allocations means you should be doing something different there
you probably need to show a simple example where you got it and discuss what can be done to stop it in future. Most of
the time it's just code organization or providing proper memory utility functions.
jamesmintram wrote:
Mon Jan 15, 2018 6:13 pm
use a GPIO input to single step if I need.
Is that via some mechanism built into the program you are debugging? (Like a wait_for_key() call between statements?)
That or the GPIO can be set as interrupt and you nest your debug code in the interrupt.
I just do the usual #define DEBUG so I can include/exclude the code from a single define at the code top
jamesmintram wrote:
Mon Jan 15, 2018 6:13 pm
It's fairly trivial to setup a debug sequence into a terminal area on screen
Again, I am assuming this is done by the program itself? Something like: render_debug_memory_to_console(&address); called periodically.

Or are you using some debug functionality provided by the chip itself? (Like some sort of debug interrupt handler routine)
[/quote]
Again Either/OR usually I am debugging something specific.

Typically I just have a debug.c file with the debug functions and header and I just include them if DEBUG is defined along with the functions which are wrapped in an include.

I probably should add however that I use Windows and Visual Studio (the community free version) as my IDE to write code for the PI and link it to the make files for ARM GCC. So if I really needed to debug general C code I just switch the project to windows and debug the code on VS2017, it's only hardware access I would need to debug on the PI.

jamesmintram
Posts: 15
Joined: Mon Jan 15, 2018 12:14 am

Re: JTag for Pi 3

Wed Jan 17, 2018 12:26 pm

Cool, thanks!

I have been reading the ARMv8 documentation and the BCM2835 ARM Peripherals (as well as writing code) and I can see that the ARM chip offers a lot of "hosted debugging" features. Which sound cool (I don't know what they do yet, I haven't read those chapters :D )

Anyway, I am still only at the "spew stuff out via UART" stage at the moment. I think my next step (to aid with workflow) is being able to load binary files over UART and save my poor SD connection pads. (I think dwelch has written a similar thing)

dwelch67
Posts: 919
Joined: Sat May 26, 2012 5:32 pm

Re: JTag for Pi 3

Wed Jan 17, 2018 9:33 pm

serial bootloader, yes I have. well worth doing IMO. place/solder down a reset button, get some usb uart or other development machine to pi solution and just press the reset buttton and try again...

David

SonicWave
Posts: 22
Joined: Mon Mar 19, 2018 1:10 pm

Re: JTag for Pi 3

Mon Mar 19, 2018 8:21 pm

Did you read this? https://wiki.aalto.fi/download/attachme ... 322&api=v2
I think for the faster and more convenient uploading via JTAG it is worth the effort already.

Return to “Bare metal”

Who is online

Users browsing this forum: No registered users and 4 guests