As you may recall, in my most recent column, we looked at programming the PicoBlaze quickly using the JTAG loader. This is great for a quick program update while testing and developing your code, but how do you debug the code when it's running?
The PicoBlaze is a tiny and simple but powerful eight-bit microprocessor/microcontroller soft core. Back in the good old days, processors didn't have built-in debugging tools. Now it's very common to find these features attached to the core, allowing single stepping, breakpoints, and the monitoring of registers and memory. However, the PicoBlaze has none of these. Let's look at how to get around these limitations.
As a starting point, let's cast our minds back to my Blinky LED blog, when I explained creating a basic I'm-alive function using a light-emitting diode (LED). Blinking the LED once per loop or on interrupts provides a very useful visual debugging tool.
In a follow-up blog, I showed how to add a universal asynchronous receiver/transmitter (UART) to the PicoBlaze. This is a real lifeline for debugging, because it lets you output messages when events happen. For example, you could output numerical values or just send single letters at key points in your code.
Over the past few weeks, I've been doing something very similar. If I'm going to be testing the Game of Life and observing what's going on deep inside, I need some debug code of my own. Using the UART, I have written a chunk of code that sends out the contents of the PicoBlaze's 16 registers. Here's an example of this output.
Some of the registers don't have values associated with them. That's because I'm using these registers to output the UART data. In fact, I could have worked my way around this, because the PicoBlaze has dual banks of registers. Nevertheless, dropping a few registers is not a big worry for the moment.
My next important chunk of code was the receive UART code. I can choose whether I want the output to be sent constantly, or whether I wish the code to halt. The receive UART code waits for a byte to arrive before returning. This allows me time to read the registers on the screen before hitting a key, thereby releasing the code to execute another loop. I can now simply send a message saying where I am in the code and output the values in the registers at that point.
To Page 2 >