My Raspberry Pi 4 + JTAG setup — Part 2 — The Hardware Setup

First, we’ll walk through the HW setup. More specifically, the portion of the diagram below that connects the two green boxes and the USB connection from the Host System to the FT232. This is a fairly simple setup. The HW consists of the Raspberry Pi 4, a FT232H breakout board, 6 jumper wires and a USB-C cable.

** WARNING **: There should be no power connected to the Raspberry Pi 4 and NO USB connected to the FT232 board while hooking up the Jumper wires. Hook these up first. This will be safer for you and the HW. There are no high voltages here, but doing this with the power off is always a good idea.

Probably the most complicated part of this is soldering the pin headers onto the FT232 board. However, I will not cover the soldering of the pin headers.

The headers can be oriented toward either side of the board. The picture below is my setup. I put the headers ‘under side’ of the board and mounted the board in a ‘dead roach’ configuration (on its back with the pins/legs up). Installing the FT232 board on a breadboard is another option you might consider. In this photo, the raspberry pi is mounted on an oak plank and the FT232 board is held in place with standoffs.

The HW setup is simply connecting the 6 jumper wires from the FT232 Breakout board to the Raspberry Pi 4. From the Table below we are hooking up the following

  • D0 to Pin 22 RPI4 J8
  • D1 to Pin 37 RPI4 J8
  • D2 to Pin 18 RPI4 J8
  • D3 to Pin 13 RPI4 J8
  • C0 to Pin 15 RPI4 J8
  • GND to Pin 39 RPI4 J8

Once again, you should do this before connecting power or a USB cable.

AdaFruit Board
PIN Name
FT232H
Pin Name
JTAG FunctionRPI 4 GPIORPI 4 J8 Pin
D0ADBUS0TCKGPIO 25Pin 22
D1ADBUS1TDIGPIO 26 Pin 37
D2ADBUS2TD0GPIO 24Pin 18
D3ADBUS3TMSGPIO 27Pin 13
D4ADBUS4GPIONot Connected
D5ADBUS5GPIONot Connected
D6ADBUS6GPIONot Connected
D7ADBUS7GPIONot Connected
C0ACBUS0/TRSTGPIO 22Pin 15
C1ACBUS1/SRSTNo Connected
C2ACBUS2GPIONot Connected
C3ACBUS3GPIONot Connected
C4ACBUS4GPIONot Connected
C5ACBUS5GPIONot Connected
C6ACBUS6GPIONot Connected
C7ACBUS7GPIONot Connected
C8ACBUS8func definedNot Connected
C9ACBUS9func definedNot Connected
GNDGNDGNDGNDPin 39
JTAG – Raspberry Pi Connection Details

Once these 6 wires are connected, you can connect USB-C cable between the FT232 and your PC. The AdaFruit FT232 board has two sockets on it, the image blow is of the USB-C connector.

Although the FT232 uses a USB-C connector, this is just a regular USB connection and you can use a USB-C to USB-C or USB-C to USB-A cable. Connecting the cable to your computer should be something you are already comfortable with.

Here is another image of my setup with the USB attached.

For information about connecting power to the Raspberry Pi 4, please consult the documentation that came with your Raspberry Pi 4.

My Raspberry Pi 4 + JTAG setup — Part 1 — introduction

In our Tools series, we will discuss software and hardware tools that facilitate embedded systems development. For each tool, we will discuss the primary purpose, typical installations, and demonstrate a common use.

JTAG (Joint Test Action Group) is a standard system for verifying and testing circuits after fabrication. Originally developed in 1985 as a validation tool, engineers quickly realized that its ability to control a CPU and communicate system state information could be used in conjunction with a debugger to create a powerful development and debug environment that could rival an ICE. In fact, many of these setups were and are still referred to as JTAG ICE setups. This series of articles will describe how to create a JTAG debug setup for bare metal and OS development and testing on a Raspberry Pi 4 board.

Specifically, we will cover:

    • Setting up “openocd”
    • Setting up gdb
    • Setting up VSCode to use gdb so you have a full IDE for debug of HW.

The hardware consists of a FT232H breakout board from Adafruit (under $20 at the time of writing this article), your Raspberry Pi 4, some jumper wires and a USB-C cable. This hardware is combined with several Open Source software tools to create complete development system.

The software stack for this article includes openOCD (Open On Chip Debugger), GDB (Gnu Debugger) and Visual Studio Code. In part 3 we will cover turning on the jtag in the Raspberry Pi 4 and a “Null” boot image for the Raspberry Pi. Then we will cover setting up the software in Parts 4, 5 and 6

LINK TO PART 2

101.1 Bare Metal Introduction – ‘Look Mom, No OS!’

Ask John or Jane Doe off the street for a definition of Bare Metal and you would likely hear about AC/DC crossed with the Full Monte. In embedded systems parlance, Bare Metal refers to systems that run on the hardware platform without the support of a commercial operating system. Bare Metal systems make up the vast majority of applications in the real world. Running programs native on the CPU or micro-controller creates some interesting challenges that developers don’t face when they have the support of an operating system.

    • How does the program start?
    • How can I tell if the program is working?
    • How do I trace bugs in my program?
    • What happens if there is a fundamental error in my program?
    • Who’s keeping track of time?

What happens before main()?

For some who are new to bare metal, this may sound like an existential philosophical question, but trust me, it’s not. In fact, this is a question that I often use as an interview question. Or maybe better said, what happens and what needs to happen before main(). While some details are platform-dependent, the process is similar for most systems. After power-up, the processor starts execution at some known address. In ARM’s case, it starts by securing the reset exception/reset vector and runs the code at that program address.

Many platforms have some kind of non-volatile memory where a small startup program called the boot loader is stored. This boot loader ‘catches’ the processor right after power-up and loads a second-level, more sophisticated boot loader or the main embedded firmware. Other systems simply look to a specific address for the first instructions.

As an embedded system programmer, this is where your job begins. Whether you are taking over at the second level boot loader or just at the start of your program, you are now in complete control and everything that happens next (or doesn’t) is up to you.

In future installments we will discuss some basic foundational components that embedded programs should provide and how to go about setting them up.