Write firmware that takes each pad function of ap_soc through the pin mux and proves it reaches its pad. It must pass on the good chip and fail on every faulty chip of a hidden set.
Hardware context: The pin mux of ap_soc v1.5: PINMUX, pins.csv and the board's UART and flash models. Every pad function from firmware.
The pin table below is the specification. Each row is one function on one pad, chosen by two bits of PINMUX. Write C firmware that selects each function in turn and shows it works at the pad.
Cover UART TX on IO0 and UART RX on IO1, and the SPI flash on IO2 to IO5. Cover PWM on IO0 and IO2, and the timer's event input on IO4. Cover the wake detector on IO15, which listens whatever PINMUX says. GPIO on every pad is the module's toggle test. Capture (select 3 on IO1 and IO3) is left out. The timer keeps only the slot number at which a capture fired. A check would need a timed pulse against a running counter. Its wiring, with the OR of the two pads, is a job for the proof of the pad rows.
The bench's side is fixed. After your TB_EVENT 0x831 it expects the byte 0x83 on IO0, then sends 0x38 on IO1. The SPI flash answers C0 FF EE to the command 9F. TB_EVENT 0x0200_0014 makes the board pulse IO4, and TB_EVENT 1 pulses IO15.
GPIO IN reads every pad whatever PINMUX says. That is your loopback for an output function the board does not check. Print pins ok and pass if every check holds; fail with your own code if one does not. Every wait needs a limit: a faulty chip that hangs your test to the cycle limit is not caught.
Full specification
| Pad | Select 1 | Select 2 | Select 3 |
|---|---|---|---|
| IO0 | GPIO | UART TX (out) | PWM (out) |
| IO1 | GPIO | UART RX (in) | capture (in) |
| IO2 | GPIO | SPI clock (out) | PWM (out) |
| IO3 | GPIO | SPI data in (in) | capture (in) |
| IO4 | GPIO | SPI data out (out) | timer event (in) |
| IO5 | GPIO | SPI select (out) | — |
| IO6 to IO15 | GPIO | — | — |
| IO15, always | the wake detector of ap_pwrctl |
| Register | Address | Use |
|---|---|---|
| PINMUX | 0x1000_4010 | Pad n at bits 2n+1:2n |
| GPIO IN | 0x1000_1004 | Bit n: the level of pad n, whatever PINMUX says |
| TIMER_EVENT | 0x1000_2020 | Bit 0 ENABLE; bit 3 PENDING: an edge of the event input was seen, write 1 to clear |
| PWRCTL REQUEST, STATUS, WAKE_ENABLE, WAKE_CAUSE | 0x1000_8000 to 0x1000_800C | Sleep: write 1 to REQUEST, wait for STATE 3. A wake completes at STATE 0 and sets its bit in WAKE_CAUSE (bit 0 PAD) |
timer_start(top, duty, compare) of drivers/timer.h runs the PWM. Duty 4 holds the output high for the whole period; duty 0 holds it low. spi_transfer(0x9f) of drivers/spi.h returns the 24 bits the flash sent back.
Given Files
Read-only files supplied by the bench.
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
drivers/spi.h
#ifndef AP_SPI_H
#define AP_SPI_H
#include "hal.h"
static inline unsigned spi_transfer(unsigned char command)
{
while (reg_read32(SPI_STATUS) & SPI_STATUS_BUSY_MASK) { }
reg_write32(SPI_STATUS, SPI_STATUS_DONE_MASK);
reg_write32(SPI_DATA, command);
while (!FIELD_GET(SPI_STATUS_DONE, reg_read32(SPI_STATUS))) { }
return FIELD_GET(SPI_DATA_RECEIVED, reg_read32(SPI_DATA));
}
#endif
drivers/timer.h
#ifndef AP_TIMER_H
#define AP_TIMER_H
#include "hal.h"
static inline void timer_stop(void)
{
reg_write32(TIMER_RUN, 0);
reg_write32(TIMER_IRQ_CLEAR, TIMER_IRQ_CLEAR_MATCH_MASK);
}
static inline void timer_start(unsigned top, unsigned duty, unsigned compare)
{
timer_stop();
reg_write32(TIMER_DIV_TOP, FIELD_PREP(TIMER_DIV_TOP_TOP, top));
reg_write32(TIMER_DUTY, FIELD_PREP(TIMER_DUTY_SLOTS, duty));
reg_write32(TIMER_COMPARE, FIELD_PREP(TIMER_COMPARE_SLOT, compare));
reg_write32(TIMER_IRQ_ENABLE, TIMER_IRQ_ENABLE_MATCH_MASK);
reg_write32(TIMER_RUN, TIMER_RUN_RUN_MASK);
}
#endif
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
hal.h
#ifndef AP_HAL_H
#define AP_HAL_H
#include "ap_soc_regs.h"
/* V13.4 supplies these two functions through DPI in a host-native build. */
#ifdef AP_HOST_DPI
unsigned reg_read32(unsigned address);
void reg_write32(unsigned address, unsigned value);
#else
static inline unsigned reg_read32(unsigned address)
{
return *(volatile unsigned *)address;
}
static inline void reg_write32(unsigned address, unsigned value)
{
*(volatile unsigned *)address = value;
}
#endif
#define FIELD_GET(field, word) (((word) & field##_MASK) >> field##_SHIFT)
#define FIELD_PREP(field, value) (((unsigned)(value) << field##_SHIFT) & field##_MASK)
#endif
ap_sysctl · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | CHIP_ID | 31:0 | value | ro | 0x2A5310C5 | const | The chip's identity: the IDCODE of the TAP. Fixed number. |
0x004 | RESET_CAUSE | 0 | power_on | ro | block | Sticky record of reset sources since power-on. Power-on reset. | |
0x004 | RESET_CAUSE | 1 | pin | ro | block | Reset pin. | |
0x004 | RESET_CAUSE | 2 | watchdog | ro | block | Watchdog. | |
0x004 | RESET_CAUSE | 3 | software | ro | block | Software request. | |
0x004 | RESET_CAUSE | 4 | debug | ro | block | Debug request. | |
0x008 | SOFT_RESET | 0 | timer | wo | not stored | Reset requests from software. 1 arms one restart of the timer. | |
0x008 | SOFT_RESET | 1 | chip | wo | not stored | 1 requests the software reset (new in v1.5). | |
0x00C | STRAPS | 0 | boot | ro | block | Straps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM. | |
0x010 | PINMUX | 31:0 | select | rw | 0x00000000 | regs | Two bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n. |
0x014 | CLK_GATE | 0 | uart0 | rw | 0x1 | regs | 1 lets that block's clock run (new in v1.5). UART0. |
0x014 | CLK_GATE | 1 | gpio | rw | 0x1 | regs | GPIO. |
0x014 | CLK_GATE | 2 | timer | rw | 0x1 | regs | Timer and PWM. |
0x014 | CLK_GATE | 3 | spi | rw | 0x1 | regs | SPI. |
0x014 | CLK_GATE | 4 | dma | rw | 0x1 | regs | DMA. |
0x018 | LOCK | 0 | pinmux | w1s | 0x0 | regs | Write-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes. |
0x018 | LOCK | 1 | clk_gate | w1s | 0x0 | regs | 1: CLK_GATE ignores writes. |
0x018 | LOCK | 2 | debug | w1s | 0x0 | regs | 1: the debug lock is closed. |
0x020 | TB_STATUS | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage. |
0x024 | TB_PUTC | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 1. The firmware kit writes one character here. Plain storage. |
0x028 | TB_EVENT | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 2. The firmware kit writes an event number here. Plain storage. |
0x02C | TB_ARG | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 3. A bench leaves a word for the firmware here. Plain storage. |
## ap_sysctl (base 0x1000_4000, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | CHIP_ID | 31:0 | value | ro | `0x2A5310C5` | const | The chip's identity: the IDCODE of the TAP. Fixed number. | | `0x004` | RESET_CAUSE | 0 | power_on | ro | | block | Sticky record of reset sources since power-on. Power-on reset. | | `0x004` | RESET_CAUSE | 1 | pin | ro | | block | Reset pin. | | `0x004` | RESET_CAUSE | 2 | watchdog | ro | | block | Watchdog. | | `0x004` | RESET_CAUSE | 3 | software | ro | | block | Software request. | | `0x004` | RESET_CAUSE | 4 | debug | ro | | block | Debug request. | | `0x008` | SOFT_RESET | 0 | timer | wo | | not stored | Reset requests from software. 1 arms one restart of the timer. | | `0x008` | SOFT_RESET | 1 | chip | wo | | not stored | 1 requests the software reset (new in v1.5). | | `0x00C` | STRAPS | 0 | boot | ro | | block | Straps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM. | | `0x010` | PINMUX | 31:0 | select | rw | `0x00000000` | regs | Two bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n. | | `0x014` | CLK_GATE | 0 | uart0 | rw | `0x1` | regs | 1 lets that block's clock run (new in v1.5). UART0. | | `0x014` | CLK_GATE | 1 | gpio | rw | `0x1` | regs | GPIO. | | `0x014` | CLK_GATE | 2 | timer | rw | `0x1` | regs | Timer and PWM. | | `0x014` | CLK_GATE | 3 | spi | rw | `0x1` | regs | SPI. | | `0x014` | CLK_GATE | 4 | dma | rw | `0x1` | regs | DMA. | | `0x018` | LOCK | 0 | pinmux | w1s | `0x0` | regs | Write-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes. | | `0x018` | LOCK | 1 | clk_gate | w1s | `0x0` | regs | 1: CLK_GATE ignores writes. | | `0x018` | LOCK | 2 | debug | w1s | `0x0` | regs | 1: the debug lock is closed. | | `0x020` | TB_STATUS | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage. | | `0x024` | TB_PUTC | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 1. The firmware kit writes one character here. Plain storage. | | `0x028` | TB_EVENT | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 2. The firmware kit writes an event number here. Plain storage. | | `0x02C` | TB_ARG | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 3. A bench leaves a word for the firmware here. Plain storage. |
ap_pwrctl · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | REQUEST | 0 | sleep | wo | not stored | Starts a power sequence of PD_PER. 1 starts the switch-off. | |
0x000 | REQUEST | 1 | wake | wo | not stored | 1 starts the switch-on. | |
0x004 | STATUS | 2:0 | state | ro | block | Where the sequencer is, and the levels it drives. 0 on, 1 isolate, 2 save, 3 off, 4 switch on, 5 restore. | |
0x004 | STATUS | 4 | isolate | ro | block | Isolation enable. | |
0x004 | STATUS | 5 | save | ro | block | Retention save level. | |
0x004 | STATUS | 6 | power_on | ro | block | Power switch closed. | |
0x008 | WAKE_ENABLE | 0 | pad | rw | 0x0 | regs | Which events may wake PD_PER. The wake detector. |
0x008 | WAKE_ENABLE | 1 | watchdog | rw | 0x0 | regs | The watchdog's early warning. |
0x00C | WAKE_CAUSE | 0 | pad | w1c | block | Why the last wake happened. A written 1 clears a bit. The wake detector. | |
0x00C | WAKE_CAUSE | 1 | watchdog | w1c | block | The watchdog's early warning. | |
0x00C | WAKE_CAUSE | 2 | software | w1c | block | REQUEST bit 1. | |
0x010 | IRQ_ENABLE | 2:0 | cause | rw | 0x0 | regs | Which wake causes raise interrupt source 9. Numbered as WAKE_CAUSE. |
## ap_pwrctl (base 0x1000_8000, interrupt source 9, clk_aon, PD_AON) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | REQUEST | 0 | sleep | wo | | not stored | Starts a power sequence of PD_PER. 1 starts the switch-off. | | `0x000` | REQUEST | 1 | wake | wo | | not stored | 1 starts the switch-on. | | `0x004` | STATUS | 2:0 | state | ro | | block | Where the sequencer is, and the levels it drives. 0 on, 1 isolate, 2 save, 3 off, 4 switch on, 5 restore. | | `0x004` | STATUS | 4 | isolate | ro | | block | Isolation enable. | | `0x004` | STATUS | 5 | save | ro | | block | Retention save level. | | `0x004` | STATUS | 6 | power_on | ro | | block | Power switch closed. | | `0x008` | WAKE_ENABLE | 0 | pad | rw | `0x0` | regs | Which events may wake PD_PER. The wake detector. | | `0x008` | WAKE_ENABLE | 1 | watchdog | rw | `0x0` | regs | The watchdog's early warning. | | `0x00C` | WAKE_CAUSE | 0 | pad | w1c | | block | Why the last wake happened. A written 1 clears a bit. The wake detector. | | `0x00C` | WAKE_CAUSE | 1 | watchdog | w1c | | block | The watchdog's early warning. | | `0x00C` | WAKE_CAUSE | 2 | software | w1c | | block | REQUEST bit 1. | | `0x010` | IRQ_ENABLE | 2:0 | cause | rw | `0x0` | regs | Which wake causes raise interrupt source 9. Numbered as WAKE_CAUSE. |
Timer and PWM · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | RUN | 0 | run | rw | 0x0 | regs | Starts and stops the counter. 1: the counter runs. |
0x004 | DUTY | 2:0 | slots | rw | 0x0 | regs | How many of the four slots drive the PWM pin high. 0 to 4. |
0x008 | CAPTURED | 1:0 | slot | ro | block | The slot number saved when the capture input fired. Slot number. | |
0x00C | DIV_TOP | 7:0 | top | rw | 0x00 | regs | Prescaler: the last count before the slot number steps. A write restarts the prescaler. Last prescaler count. |
0x010 | COMPARE | 1:0 | slot | rw | 0x0 | regs | The slot number that raises match. Slot number. |
0x014 | IRQ_CLEAR | 0 | match | wo | not stored | Writing 1 to bit 0 clears the stored match flag. 1 clears the flag. | |
0x018 | IRQ_ENABLE | 0 | match | rw | 0x0 | regs | Lets the stored match flag raise interrupt source 3. 1 enables the request. |
0x020 | EVENT | 0 | enable | rw | 0x0 | regs | Six teaching fields (S6.8). Plain read and write. |
0x020 | EVENT | 1 | online | ro | block | A level from the hardware. | |
0x020 | EVENT | 2 | kick | wo | not stored | A written 1 makes one pulse. | |
0x020 | EVENT | 3 | pending | w1c | block | Set by an event; a written 1 clears it. | |
0x020 | EVENT | 4 | seen | rc | block | Set by an event; a read clears it. | |
0x020 | EVENT | 5 | route | rw | 0x0 | block | Takes the first write only. |
0x024 | EVENT_COUNT_LOW | 31:0 | value | ro | block | Low 32 bits of the 64-bit event counter. Count, low word. | |
0x028 | EVENT_COUNT_HIGH | 31:0 | value | ro | block | High 32 bits of the event counter. Count, high word. |
## Timer and PWM (base 0x1000_2000, interrupt source 3, clk_sys, PD_PER) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | RUN | 0 | run | rw | `0x0` | regs | Starts and stops the counter. 1: the counter runs. | | `0x004` | DUTY | 2:0 | slots | rw | `0x0` | regs | How many of the four slots drive the PWM pin high. 0 to 4. | | `0x008` | CAPTURED | 1:0 | slot | ro | | block | The slot number saved when the capture input fired. Slot number. | | `0x00C` | DIV_TOP | 7:0 | top | rw | `0x00` | regs | Prescaler: the last count before the slot number steps. A write restarts the prescaler. Last prescaler count. | | `0x010` | COMPARE | 1:0 | slot | rw | `0x0` | regs | The slot number that raises match. Slot number. | | `0x014` | IRQ_CLEAR | 0 | match | wo | | not stored | Writing 1 to bit 0 clears the stored match flag. 1 clears the flag. | | `0x018` | IRQ_ENABLE | 0 | match | rw | `0x0` | regs | Lets the stored match flag raise interrupt source 3. 1 enables the request. | | `0x020` | EVENT | 0 | enable | rw | `0x0` | regs | Six teaching fields (S6.8). Plain read and write. | | `0x020` | EVENT | 1 | online | ro | | block | A level from the hardware. | | `0x020` | EVENT | 2 | kick | wo | | not stored | A written 1 makes one pulse. | | `0x020` | EVENT | 3 | pending | w1c | | block | Set by an event; a written 1 clears it. | | `0x020` | EVENT | 4 | seen | rc | | block | Set by an event; a read clears it. | | `0x020` | EVENT | 5 | route | rw | `0x0` | block | Takes the first write only. | | `0x024` | EVENT_COUNT_LOW | 31:0 | value | ro | | block | Low 32 bits of the 64-bit event counter. Count, low word. | | `0x028` | EVENT_COUNT_HIGH | 31:0 | value | ro | | block | High 32 bits of the event counter. Count, high word. |
Examples
Example 1
The Good Chip- Input
your firmware
- Output
console "pins ok"; pass
The bench sees 0x83 on IO0 and the flash answers C0 FF EE. Both PWM pads follow the duty, IO4's pulse sets PENDING, and the wake names the pad.
Example 2
A Hidden Faulty Chip- Input
your firmware on a faulty chip
- Output
your fail word
Each hidden chip breaks one function between its block and its pad. Your check of that function must notice and return its code.
Example 3
What Does Not Count- Input
firmware that only routes the UART
- Output
refused
A function you never selected can be miswired and your test still passes.
Constraints and Contract
- C firmware with the kit, SRAM layout.
- Pass on the good chip with the console line
pins ok; fail visibly on every hidden chip. - The good chip runs the case first; the hidden chips run the same case.
Hints
Hint 1
An output the board does not watch can still be read: what does GPIO IN show while PWM drives a pad?
Hint 2
Which single transfer of the SPI flash needs all four of its pads to work?
Hint 3
For the wake pad, check what woke the chip, not only that it woke.
What the grader checks: Your firmware runs on the pre-built ap_soc v1.5 bench, on the good chip and on several hidden faulty chips. The good chip must pass with pins ok and one byte on the UART pad. The grader cannot see which function caught a faulty chip. Nor can it see your checks of PWM, the event input or the received byte: no hidden chip needs them. Capture is not covered by this problem.
1 checks on ap_soc v1.5 · firmware · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your text only; the chip, the bench and the hidden checks stay on the server. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path