
A multicycle CPU that runs a subset of the ARMv6-M Thumb instruction set. It is not an Arm product and is not claimed to be compatible with one. It grew out of a UCSD CSE 141 course project.
It runs one instruction at a time with a single ALU and a register file with one read port:
fetch (two fetches for a 32-bit instruction), decode, execute, then a memory transfer and a register write if the instruction needs them. PUSH, POP, LDM and STM move one register at a time.
On the chip: the control state machine, the decoder, the ALU, r0-r12, SP, LR, PC and the four condition flags, and the pin bus. Each register has its own clock gate.
Off the chip (an FPGA): all memory and the peripherals. Code is at 0x0000_0000 (the vector table first), SRAM at 0x2000_0000, LEDs at 0x4000_1000 and a cycle counter at 0x4000_2000. Any other address should answer with a bus error.
| Group | Instructions |
|---|---|
| Data processing | MOV, MVN, ADD, ADC, SUB, SBC, RSB, CMP, CMN, TST, AND, ORR, EOR, BIC, LSL, LSR, ASR, ROR |
| Extend and reverse | SXTB, SXTH, UXTB, UXTH, REV, REV16, REVSH |
| Loads and stores | LDR, LDRH, LDRB, LDRSH, LDRSB, STR, STRH, STRB, ADR |
| Multiple | PUSH, POP, LDM, STM |
| Branches | B, B<cond>, BL, BX, BLX |
| Other | NOP, ISB (does nothing), UDF #0 (halt) |
Not implemented: MUL, SVC, CPS, MRS, MSR, DMB, DSB, SEV, WFE, WFI, YIELD, exceptions, interrupts, SysTick, the process stack pointer and caches.
The halfword 0xDE00 (UDF #0) halts the CPU: HALT goes high and stays high until reset. With no exception hardware, every fault halts it the same way: an unimplemented or undefined instruction, BKPT, a bus error, an unaligned access, or a BX, BLX, POP or reset address with bit 0 clear.
Each transfer is sent as bytes on TX (uo_out), one per clock, while REQ is high:
| Byte | Contents |
|---|---|
| Command | bit 7 write, bit 6 instruction or vector-table fetch, bits 5:4 size (0 byte, 1 halfword, 2 word), bits 3:0 zero |
| Address | four bytes, low byte first |
| Write data | writes only: the bytes the size covers, low address first |
The CPU then waits for the host's answer on the inputs:
ui_in).The host may wait any number of cycles before and between its answers, but must not raise READY until it has received the last byte. REQ goes low for at least one cycle between transfers. The chip registers RX, READY and ERR before using them.
Instructions are fetched one halfword at a time, so most of the CPU's time goes into the bus. In simulation the four benchmark programs take 27,000 to 61,000 clocks.
| Pin | Direction | Use |
|---|---|---|
uo_out[7:0] |
out | TX: command, address, write data |
ui_in[7:0] |
in | RX: read data |
uio[0] |
out | REQ: a transfer is being sent or waiting for its answer |
uio[1] |
in | READY |
uio[2] |
in | ERR (with READY) |
uio[5:3] |
in | unused, reserved for IRQ2-0 |
uio[6] |
out | HALT |
uio[7] |
out | EXECUTING: high for one cycle as each instruction executes |
The host has to supply memory over the pin bus. test/host/link_host.sv is a synthesizable host that turns the
pin bus into AHB-Lite, and test/host/host_system.sv connects it to the memory, LEDs and cycle counter. They
are a starting point for the FPGA design.
rst_n low for at least five clocks, then release it. The CPU clears its registers, reads words 0 and
1 of the vector table, and runs from the reset address.udf #0, which raises HALT. Check its results in the FPGA's SRAM. If HALT rises
earlier than expected, the program hit a fault or an unimplemented instruction.Start with a slow clock, such as 1 MHz, and raise it once the bus works. The design targets 25 MHz.
In simulation (test/, cocotb and Icarus Verilog):
cd test
make # the chip with the host system, through the pins
make unit # ALU and decoder against reference models
An FPGA board, such as a Digilent Arty A7, holding the memory and peripherals and running the host side of the
pin bus. Connect it with short wires, at 3.3 V, with a common ground. It should also drive clk and rst_n.
Put the Tiny Tapeout demo board in ASIC_MANUAL_INPUTS mode, with every DIP switch off, so that its
microcontroller doesn't drive the same inputs.
| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | RX0 (read data from the host) | TX0 (command, address, write data) | REQ (out) |
| 1 | RX1 (read data from the host) | TX1 (command, address, write data) | READY (in) |
| 2 | RX2 (read data from the host) | TX2 (command, address, write data) | ERR (in) |
| 3 | RX3 (read data from the host) | TX3 (command, address, write data) | unused (reserved for IRQ0) |
| 4 | RX4 (read data from the host) | TX4 (command, address, write data) | unused (reserved for IRQ1) |
| 5 | RX5 (read data from the host) | TX5 (command, address, write data) | unused (reserved for IRQ2) |
| 6 | RX6 (read data from the host) | TX6 (command, address, write data) | HALT (out) |
| 7 | RX7 (read data from the host) | TX7 (command, address, write data) | EXECUTING (out) |