V4.9.1 Waiting for Ever

MediumDebug20 minap_soc v1.5 · recorded bootReview the topic

A C test reads one byte from the UART and never finishes: the run ends at its cycle limit. The trace ends in a loop of three instructions. Find the transfer where the test went wrong first.

The firmware asks the bench for its test byte with one event, then waits in uart_getc() for RX_READY. It should print got and the byte. The run ended at its cycle limit instead, and the last rows of the trace repeat a load of UART0 STATUS.

The firmware of the recorded run (main.c).
#include "drivers/uart.h"
#include "tb.h"

#define EVT_SEND 0x31                              /* bench: send the test byte */

int main(void)
{
    reg_write32(SYSCTL_PINMUX, 2u << 2);           /* pad IO1 carries UART RX */
    reg_write32(UART0_DIV, 8);
    tb_event(EVT_SEND);
    unsigned char b = uart_getc();                 /* waits for RX_READY */
    tb_puts("got ");
    tb_put_hex(b);
    tb_putc('\n');
    return b != 0x5a;
}

The bench's side of the run: wait for an event, then send 0x5A on the receive pad.

WhoOperationAddressDataMaskExpectDelayRepeat
tbwait_event0000001300000000ffffffff0000000001
tbuart_send000000000000005affffffff0000000001

The full specification holds the listing of main. The Recorded Wave Window shows 64 cycles from cycle 200 of the run. It holds the core's data bus (address, write data, read data) and the receive pad IO1.

The trace below shows 21 of 852 retired loads and stores, cycles 183 to 6005. Name the first transfer that went wrong: its cycle, the wrong part, its address and its register or variable. Then choose the cause.

Full specification
main in the listing of this image (riscv64-unknown-elf-gcc (14.2.0+19) 14.2.0): address and instruction.
80000288 <main>:
80000288:  addi  sp,sp,-16
8000028c:  sw  ra,12(sp)
80000290:  sw  s0,8(sp)
80000294:  li  a5,8
80000298:  lui  a4,0x10004
8000029c:  sw  a5,16(a4)
800002a0:  lui  a4,0x10000
800002a4:  sw  a5,16(a4)
800002a8:  li  a0,49
800002ac:  jal  8000027c <tb_event>
800002b0:  lui  a4,0x10000
800002b4:  addi  a4,a4,4
800002b8:  lw  a5,0(a4)
800002bc:  andi  a5,a5,2
800002c0:  beqz  a5,800002b8 <main+0x30>
800002c4:  lui  a5,0x10000
800002c8:  lw  s0,12(a5)
800002cc:  lui  a0,0x80000
800002d0:  addi  a0,a0,792
800002d4:  jal  80000224 <tb_puts>
800002d8:  zext.b  a0,s0
800002dc:  jal  80000244 <tb_put_hex>
800002e0:  li  a0,10
800002e4:  jal  80000218 <tb_putc>
800002e8:  lw  ra,12(sp)
800002ec:  zext.b  a0,s0
800002f0:  lw  s0,8(sp)
800002f4:  addi  a0,a0,-90
800002f8:  snez  a0,a0
800002fc:  addi  sp,sp,16
80000300:  ret

The register list names every address the answer may use. Addresses are in hex without 0x in the trace; write them with or without 0x in the form.

Data in the trace is the word as the bus carried it. A load's data is what came back; a store's is what was written.

Diagnose the Failing Run

Recorded Console and Result

EVENT 208: 00000031
verdict=fail
reason=cycle_limit
status=00000002
cycles=6008
traps=0
interrupts=0
mismatches=0

Retired Memory Transfers

CyclePC (hex)OperationAddress (hex)Data (hex)
1838000007cstore1000402000000002
1888000028cstore8000fffc80000084
19180000290store8000fff800000000
1998000029cstore1000401000000008
202800002a4store1000001000000008
20980000280store1000402800000031
216800002b8load1000000400000001
223800002b8load1000000400000001
230800002b8load1000000400000001
237800002b8load1000000400000001
244800002b8load1000000400000001
251800002b8load1000000400000001
258800002b8load1000000400000001
265800002b8load1000000400000001
272800002b8load1000000400000001
5970800002b8load1000000400000001
5977800002b8load1000000400000001
5984800002b8load1000000400000001
5991800002b8load1000000400000001
5998800002b8load1000000400000001
6005800002b8load1000000400000001

Recorded Wave Window

Samples from cycle 200
CycleSystem clock edgeTime (ns)d_haddrd_hwdatad_hrdataIO1
200Rising238531801
200Falling239031801
201Rising239531801
201Falling2400ffffffd0001
202Rising2405ffffffd0001
202Falling241010000000001
203Rising241510000000001
203Falling242010000000001
204Rising242510000000001
204Falling243010004000001
205Rising243510004000001
205Falling244010004028001
206Rising244510004028001
206Falling2450800002b03101
207Rising2455800002b03101
207Falling2460800002b03101
208Rising2465800002b03101
208Falling24708000ffe0001
209Rising24758000ffe0001
209Falling24808000ffe0001
210Rising24858000ffe0001
210Falling249010000000001
211Rising249510000000001
211Falling250010000004001
212Rising250510000004001
212Falling251010000004001
213Rising251510000004001
213Falling25200001
214Rising25250001
214Falling25300011
215Rising25350011
215Falling25400001
216Rising25450001
216Falling2550fffffff8001
217Rising2555fffffff8001
217Falling256010000000001
218Rising256510000000001
218Falling257010000000001
219Rising257510000000001
219Falling258010000004001
220Rising258510000004001
220Falling25900001
221Rising25950001
221Falling26000011
222Rising26050011
222Falling26100001
223Rising26150001
223Falling2620fffffff8001
224Rising2625fffffff8001
224Falling263010000000001
225Rising263510000000001
225Falling264010000000001
226Rising264510000000001
226Falling265010000004001
227Rising265510000004001
227Falling26600001
228Rising26650001
228Falling26700011
229Rising26750011
229Falling26800001
230Rising26850001
230Falling2690fffffff8001
231Rising2695fffffff8001
231Falling270010000000001
232Rising270510000000001
232Falling271010000000001
233Rising271510000000001
233Falling272010000004001
234Rising272510000004001
234Falling27300001
235Rising27350001
235Falling27400011
236Rising27450011
236Falling27500001
237Rising27550001
237Falling2760fffffff8001
238Rising2765fffffff8001
238Falling277010000000001
239Rising277510000000001
239Falling278010000000001
240Rising278510000000001
240Falling279010000004001
241Rising279510000004001
241Falling28000001
242Rising28050001
242Falling28100011
243Rising28150011
243Falling28200001
244Rising28250001
244Falling2830fffffff8001
245Rising2835fffffff8001
245Falling284010000000001
246Rising284510000000001
246Falling285010000000001
247Rising285510000000001
247Falling286010000004001
248Rising286510000004001
248Falling28700001
249Rising28750001
249Falling28800011
250Rising28850011
250Falling28900001
251Rising28950001
251Falling2900fffffff8001
252Rising2905fffffff8001
252Falling291010000000001
253Rising291510000000001
253Falling292010000000001
254Rising292510000000001
254Falling293010000004001
255Rising293510000004001
255Falling29400001
256Rising29450001
256Falling29500011
257Rising29550011
257Falling29600001
258Rising29650001
258Falling2970fffffff8001
259Rising2975fffffff8001
259Falling298010000000001
260Rising298510000000001
260Falling299010000000001
261Rising299510000000001
261Falling300010000004001
262Rising300510000004001
262Falling30100001
263Rising30150001
263Falling30200011
Step 1 · The first bad cycle and signal
Step 2 · The cause

Given Files

Use the register map to identify the transfer in the recording.

tb.h
#ifndef AP_TB_H
#define AP_TB_H
_Noreturn void tb_pass(void);
_Noreturn void tb_fail(unsigned code);
void tb_putc(char byte);
void tb_puts(const char *text);
void tb_put_hex(unsigned value);
void tb_event(unsigned id);
/* Slot zero is the single bench-to-firmware argument word. */
unsigned tb_arg(unsigned n);
void tb_wait_event(unsigned id);
#endif

drivers/uart.h
#ifndef AP_UART_H
#define AP_UART_H
#include "hal.h"

static inline void uart_flush(void)
{
    while (!FIELD_GET(UART0_STATUS_ROOM, reg_read32(UART0_STATUS))) { }
}

static inline void uart_putc(unsigned char byte)
{
    uart_flush();
    reg_write32(UART0_TXDATA, byte);
}

static inline unsigned char uart_getc(void)
{
    while (!FIELD_GET(UART0_STATUS_RX_READY, reg_read32(UART0_STATUS))) { }
    return reg_read32(UART0_RXDATA);
}

static inline void uart_enable_rx_irq(void)
{
    reg_write32(UART0_IRQ_ENABLE, UART0_IRQ_ENABLE_RX_READY_MASK);
}
#endif

UART0 · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000TXDATA7:0datawonot storedThe low byte is the next byte to send. Byte to send.
0x004STATUS0roomroblockTransmit room and receive queue state. The transmitter can take a byte.
0x004STATUS1rx_readyroblockAt least one received byte waits.
0x004STATUS2rx_fullroblockThe receive queue is full.
0x008IRQ_ENABLE0roomrw0x0regsWhich status bits raise interrupt source 1. ROOM raises the request.
0x008IRQ_ENABLE1rx_readyrw0x0regsRX_READY raises the request (new in v1.5).
0x00CRXDATA7:0dataroblockThe oldest received byte. The read removes it from the queue. Received byte.
0x010DIV15:0cyclesrw0x0010regsBit time in clk_sys cycles (new in v1.5). clk_sys cycles a bit.
ap_sysctl · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000CHIP_ID31:0valuero0x2A5310C5constThe chip's identity: the IDCODE of the TAP. Fixed number.
0x004RESET_CAUSE0power_onroblockSticky record of reset sources since power-on. Power-on reset.
0x004RESET_CAUSE1pinroblockReset pin.
0x004RESET_CAUSE2watchdogroblockWatchdog.
0x004RESET_CAUSE3softwareroblockSoftware request.
0x004RESET_CAUSE4debugroblockDebug request.
0x008SOFT_RESET0timerwonot storedReset requests from software. 1 arms one restart of the timer.
0x008SOFT_RESET1chipwonot stored1 requests the software reset (new in v1.5).
0x00CSTRAPS0bootroblockStraps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM.
0x010PINMUX31:0selectrw0x00000000regsTwo bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n.
0x014CLK_GATE0uart0rw0x1regs1 lets that block's clock run (new in v1.5). UART0.
0x014CLK_GATE1gpiorw0x1regsGPIO.
0x014CLK_GATE2timerrw0x1regsTimer and PWM.
0x014CLK_GATE3spirw0x1regsSPI.
0x014CLK_GATE4dmarw0x1regsDMA.
0x018LOCK0pinmuxw1s0x0regsWrite-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes.
0x018LOCK1clk_gatew1s0x0regs1: CLK_GATE ignores writes.
0x018LOCK2debugw1s0x0regs1: the debug lock is closed.
0x020TB_STATUS31:0valuerw0x00000000regs (power-on reset only)Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage.
0x024TB_PUTC31:0valuerw0x00000000regs (power-on reset only)Scratch word 1. The firmware kit writes one character here. Plain storage.
0x028TB_EVENT31:0valuerw0x00000000regs (power-on reset only)Scratch word 2. The firmware kit writes an event number here. Plain storage.
0x02CTB_ARG31:0valuerw0x00000000regs (power-on reset only)Scratch word 3. A bench leaves a word for the firmware here. Plain storage.