-
Notifications
You must be signed in to change notification settings - Fork 0
tutorial advanced debugging
You probably can't afford a logic analyzer. But if you can, or someone has lent you theirs, you can set a pin to go high during an operation, pulse or toggle on a certain event, or transmit some other information. Then, if you probe the GPIO output pin, you can get precise, unobtrusive debug information.
For example:
// This function does something stupid such as calculating
// 10 digits of pi using Monte Carlo Methods
void expensiveFunction() {
SetPin(PIN_F1, true);
doStuff();
SetPin(PIN_F1, false);
}
When probing pin F1, assuming no other functions modify that pin, the length of the positive pulse is then the amount of time taken to run this function.
One main advantage of this approach is that printing via Serial takes a really long time. For example, at a 80MHz clock speed on the processor and 115200 baud on the serial interface, transmitting just an 8-bit char will take over 5000 clock cycles! On the other hand, simply toggling a pin takes only 6:
; C code to toggle a pin will compile down to this
; Instructions typically execute in 2 clock cycles on the TM4C
LDR R0, [PIN_ADDR] ; PIN_ADDR should be a register already loaded with the pin address
EOR R0, R0, 0x04 ; Replace 0x04 with whatever needs to be toggled
STR R0, [PIN_ADDR]
Therefore, this type of debugging is called non-intrusive.
NOTE: This can also be done with an oscilloscope. You can check out oscilloscope probes at the ECE checkout desk for use in the ECE labs, or use the RAS Oscilloscope.
There's nothing special about RASLib's make uart
; it's simply a UART decoder.
As such, there's absolutely nothing stopping you from making a more sophisticated tool. For example, Python's pyserial is an excellent tool to use:
(Example taken from official PySerial documentation)
with serial.Serial('/dev/ttyS1', 19200, timeout=1) as ser:
x = ser.read() # read one byte
s = ser.read(10) # read up to ten bytes (timeout)
line = ser.readline() # read a '\n' terminated line
This can be extended into sophisticated systems that offload, log, or even visually display data for a more tactile analysis (such as this shameless plug for one of my own projects).