V13.2.1 Bring up the Flash Reader on the Model

EasyImplement20 minap_soc v1.5 · C virtual platform · serverReview the topic

Write the first driver test of a new chip and run it on the virtual platform. It reads the SPI flash's identity and a few frames. The same image must print the same on the hybrid, whose SPI and pads are RTL.

Hardware context: ap_vp: the instruction-level core with C models of ap_soc's devices. A flash driver brought up on the model.

A virtual platform runs firmware long before the chip's RTL is finished. The first thing a team brings up on it is a driver. Here that driver talks to the SPI flash on ap_soc's pads.

Write main.c. Set PINMUX to 0xAAA, which makes pads 0 to 5 serial: SPI on IO2 to IO5. Send command 0x9F and print id and the 24-bit answer as six lowercase hex digits. Send 0x66 to go back to byte 0 of the flash. Then read TB_ARG frames with command 0x03, one line of six hex digits each. End with xor and the XOR of all frames, then return 0.

Your image runs on the C virtual platform and on the hybrid. The hybrid has the RTL SPI controller, the RTL pin mux and the flash model on the pads. Both must print the same text and leave the same memory.

Full specification
CommandThe flash answers with
0x9FC0 FF EE: its identity
0x66nothing useful; the read pointer goes back to byte 0
0x03the next three bytes; the first one in bits 23:16
RegisterAddressUse
PINMUX0x1000_4010two bits a pad; 2 = serial. 0xAAA sets pads 0 to 5
SPI DATA0x1000_5000write a command; read the 24-bit answer
SPI STATUS0x1000_5004bit 0 BUSY, bit 1 DONE (write 1 to clear)

The kit's drivers/spi.h has spi_transfer(command). It waits for BUSY to clear, clears DONE, sends the command, waits for DONE and returns the answer. You may use it.

Given Files

Read-only files supplied by the bench.

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

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

SPI · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000DATA7:0commandwonot storedWrite: a command byte; the write starts a frame of 32 serial clocks. Read: the last 24 bits received. Command byte.
0x000DATA23:0receivedroblockLast 24 bits received.
0x004STATUS0busyroblockFrame state. A frame is running, and chip select is low.
0x004STATUS1donew1cblockA frame has ended (new in v1.5).
0x008IRQ_ENABLE0donerw0x0regsLets DONE raise interrupt source 4 (new in v1.5). 1 enables the request.
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.

Examples

Example 1

Four Frames
Input
Four frames
Output
the id line, four frames and the xor line, on both platforms

Twelve bytes of the image, three to a frame, first byte on top.

Example 2

Ten Frames
Input
Ten frames of another image
Output
ten frame lines

Another image and another TB_ARG.

Example 3

Pads Left at Their Reset Value
Input
a driver that never writes PINMUX
Output
the VP prints c0ffee; the hybrid prints 000000

The VP's SPI model ignores the pads. The hybrid's RTL pin mux does not, so the two platforms disagree.

Constraints and Contract

  • C firmware with the kit, SRAM layout.
  • Print exactly the lines asked for, with lowercase hex.
  • Return 1 if the identity is not C0FFEE, else 0.

Hints

Hint 1

tb_put_hex prints eight digits. Six digits need a small helper of your own.

Hint 2

Which bits of PINMUX does the SPI need, and what happens on a platform with real pads if they stay at 0?

Hint 3

The first byte of a frame is in bits 23:16 of the answer.

What the grader checks: Each case runs your image on the VP and the hybrid. It compares the console with the expected text, and the two platforms with each other. The flash identity is fixed on both platforms, so the check of a wrong identity is not exercised. The grader cannot see how many times your code polled.

6 checks on ap_soc v1.5 · C virtual platform · 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

Report a problem with this page

Your code CSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Four Frames

Input
Four frames
Expected output
the id line, four frames and the xor line, on both platforms

Twelve bytes of the image, three to a frame, first byte on top.

Run samples executes all 2 public checks. Check all tests runs 6 checks on the server.

ap_soc v1.5 · C virtual platform · server