APB Map and Signals: What Changed from APB2 to APB5, the Signal Table, and the IDLE, SETUP, ACCESS States Checked with a Model

Sunhong··17 min read·0 views·Translated from Korean

Key points

  • APB is a simple bus for reading and writing the control registers of peripherals. It has no pipeline, every transfer goes through the IDLE, SETUP and ACCESS states, and takes at least two cycles. The versions run APB2, APB3 (PREADY, PSLVERR), APB4 (PPROT, PSTRB), APB5 (wake-up, user signals, parity protection, and RME in Issue E), and no signal of an earlier version is ever dropped.
  • We encoded the 18 signals of the specification's Table B-1 and counted them per version. The mandatory signals are the same 8 in all four versions. With 32-bit address and data the wire count is 101 for mandatory signals only, and with every optional signal it is 103 for APB3, 110 for APB4 and 112 for APB5 (user and parity signals not counted).
  • Reading the six timing figures of the specification (3-1, 3-2, 3-4 to 3-7) as states matched the transfer edges and wait counts in the text every time. 1,000 random traces (107,206 cycles, 40,000 transfers) gave 0 violations in the rule checker, and the mean length of back-to-back transfers followed 2 + p/(1-p) to within 0.02.

APB is the simplest bus in the AMBA family. That is exactly why it is easy to lose track of what each version added, which version a signal first appears in, and which signals are "optional" and which are "mandatory if the other side has them". This set covers only the protocol rules of APB, in three parts. Part 1 is the map, the signals and the operating states. Part 2 covers writes, reads, waiting, errors and byte selection. Part 3 covers protection attributes, RME, wake-up, user signals and parity protection. The basis is ARM IHI 0024 Issue E (2023-02-28), written as E below. It rewrites this blog's earlier APB note (AMBA APB protocol analysis) against the specification.

Terms follow E. The side that starts a transfer is the Requester (commonly the master, usually an APB bridge), and the peripheral that responds is the Completer (commonly the slave) (E 1.1). The names differ from the Manager and Subordinate of the AXI articles in this series, but the roles are the same. The AMBA 2 specification of 1999 (IHI 0011A) says master and slave.

For the practice part we encoded the specification's tables and state diagram in Python and ran them. Machine: Apple M1 Max, Python 3.12.13, all random seeds fixed. The code is signals.py in this article's folder and common/apb.py, shared by all three parts. Results are in results.json.

1. What APB does

E 1.1 introduces APB as follows. It is a low-cost interface tuned for minimal power consumption and reduced interface complexity. It is a simple synchronous protocol without pipelining, and every transfer takes at least two cycles. It is meant for accessing the programmable control registers of peripherals. Peripherals are usually connected to the main memory system through an APB bridge, for example an AXI-to-APB bridge that attaches several APB peripherals to an AXI memory system.

Two facts that bear directly on design follow.

  • There is one transfer at a time. The read data bus (PRDATA) and the write data bus (PWDATA) are separate, but neither has its own handshake, so data cannot move concurrently (E 2.1.2). A request has to finish before the next one goes out.
  • Because one transfer takes at least two cycles, throughput has a ceiling: with no waiting, half the data width per cycle. By direct calculation, that is 0.5, 1 and 2 bytes per cycle for 8-, 16- and 32-bit data. It is plenty for setting a few registers and not for copying memory.

2. The versions: from APB2 to APB5

The preface of the specification (APB Revisions) and Appendix C list the changes per version. The first point of confusion is that the version names (APB2 to APB5) and the Issue letters of the document differ.

Version Specification What is new New signals
APB2 IHI 0011A chapter 5 (Issue A) all signals timed only to the rising clock edge none
APB3 Issue B (2004-08) wait states, error reporting PREADY, PSLVERR
APB4 Issue C (2010-04) transfer protection, sparse writes PPROT, PSTRB
APB5 Issue D (2021-04) wake-up, user signals, parity protection PWAKEUP, four P?USER, *CHK
APB5 Issue E (2023-02) RME support (optional) PNSE

New signals per version: PREADY and PSLVERR in APB3, PPROT and PSTRB in APB4, and wake-up, user, parity and PNSE in APB5

Three points.

  • Issue E is not a new version. E only adds optional RME support to APB5 interfaces, and the specification says "this version remains APB5". So there is no "APB6".
  • Issue letters and version numbers do not line up. Under the same document number (IHI 0024), Issue A is APB2, B is APB3, C is APB4, and D and E are APB5. The preface also has a separate sentence saying that a "Rev E" released in 1998 is obsolete. That Rev E is an old specification unrelated to today's Issue E.
  • Signals of earlier versions do not disappear. An APB3 Completer lacks PPROT only because it first appears in APB4. Versions grow only in the direction of more signals.

3. Signals

Grouping Table 2-1 by purpose gives the following. The source is the side that drives the signal.

Signal Source Width Version
PCLK clock 1 all
PRESETn system reset 1 all
PADDR Requester ADDR_WIDTH (up to 32) all
PSELx Requester 1 (per Completer) all
PENABLE Requester 1 all
PWRITE Requester 1 all
PWDATA Requester 8, 16, 32 all
PRDATA Completer 8, 16, 32 all
PREADY Completer 1 APB3 and up
PSLVERR Completer 1 APB3 and up
PPROT, PSTRB Requester 3, DATA_WIDTH/8 APB4 and up
PNSE, PWAKEUP, P?USER, *CHK both set by properties APB5

What each signal means is below. The transfer sequence is in Part 2, protection and wake-up and so on in Part 3.

  • PCLK: every APB signal is timed to its rising edge. PRESETn is active-LOW and is normally connected directly to the system bus reset.
  • PADDR: a byte address. An address not aligned to the data width may be sent, but the result is UNPREDICTABLE. The Completer may use the unaligned address, use the aligned one, or give an error (E 2.1.1).
  • PSELx: the Requester creates one per Completer. It means that Completer is selected and a transfer is needed. Only one PSEL bit is routed to each Completer.
  • PENABLE: 1 in the second and later cycles of a transfer. (Remembering only "the second cycle" is wrong once there are wait states.)
  • PWRITE: 1 for a write, 0 for a read.
  • PWDATA and PRDATA: 8, 16 or 32 bits, and the two must have the same width (E 2.1.2).
  • PREADY: used by the Completer to extend a transfer. PSLVERR: an optional signal that reports a failed transfer.

3.1 Mandatory, optional, conditional: Table B-1

Table B-1 in Appendix B puts a one- or two-letter code per signal and version. The codes mean:

Code Meaning
Y mandatory
N must not be present
O optional on both inputs and outputs
OO optional on output ports, mandatory on inputs
C mandatory if the property is True
OC can be present only if the property is True, and then it is optional

It matters for design that PREADY and PSLVERR are OO from APB3 up. A Completer need not drive them, but a Requester must always have the input port. The table gives defaults for unused inputs: PREADY is 1 (no waiting) and PSLVERR is 0 (no error). A Completer without PREADY behaves exactly like an APB2-style peripheral that always finishes in two cycles. The specification says it too: a peripheral with a fixed two-cycle access can tie PREADY HIGH (E 3.1.2). The meaning of the PPROT default 0b000 is in Part 3.

We encoded this table (B1 in signals.py) and counted per version.

Version Mandatory Optional Conditional Absent
APB5 8 8 2 0
APB4 8 4 0 6
APB3 8 2 0 8
APB2 8 0 0 10

The 8 mandatory signals (PCLK, PRESETn, PADDR, PSELx, PENABLE, PWRITE, PWDATA, PRDATA) are the same in all four versions. The 8 optional signals of APB5 are PPROT, PSTRB, PREADY, PSLVERR and the four user signals, and the 2 conditional ones are PNSE (RME_Support) and PWAKEUP (Wakeup_Signal).

Converting to wires shows the size difference between versions. Take 32-bit address and data and one PSEL. User signals have widths the designer chooses, so they are not counted, and the parity check signals are left out too.

Version Mandatory only All optional All conditional too
APB2 101 101 101
APB3 101 103 103
APB4 101 110 110
APB5 101 110 112

PADDR 32 + PWDATA 32 + PRDATA 32 + 5 control signals = 101 is the floor for every version. On top of it APB3 adds two (PREADY, PSLVERR), APB4 adds PPROT 3 + PSTRB 4 = 7, and APB5 has two more, PNSE and PWAKEUP. So "APB is cheap because it has few signals" shows up in numbers, although the address and data widths decide almost all of the wire count.

4. Operating states: IDLE, SETUP, ACCESS

The state diagram of E 4.1 says the interface moves among three states.

  • IDLE: the default state. PSELx is 0.
  • SETUP: entered when a transfer is needed. PSELx is 1 and PENABLE is 0. This state lasts exactly one cycle and always goes to ACCESS on the next rising edge.
  • ACCESS: PENABLE is 1. Leaving depends on PREADY. If it is 0 the interface stays in ACCESS; if it is 1 it leaves, going to IDLE when no transfer follows or straight to SETUP when one does.

APB operating states: IDLE goes to SETUP when there is a transfer, SETUP always goes to ACCESS, ACCESS stays while PREADY is 0 and goes to IDLE or SETUP when it is 1

In the ACCESS state the following signals must not change in the transition from SETUP to ACCESS or between ACCESS cycles: PADDR, PPROT, PWRITE, PWDATA (writes only), PSTRB, PAUSER, PWUSER. This list becomes the stability rule (STABLE) of the rule checker.

Enumerating the diagram as a table gives the number of allowed paths. Of the 9 possible moves among three states, 6 are allowed: IDLE to IDLE, IDLE to SETUP, SETUP to ACCESS, ACCESS to ACCESS, ACCESS to IDLE and ACCESS to SETUP. The 3 blocked ones are IDLE to ACCESS (skipping SETUP), SETUP to IDLE and SETUP to SETUP (SETUP lasting two or more cycles). A combination with PENABLE=1 and PSEL=0 cannot be a state at all. The state rule is fifteen lines of code.

def states(tr):
    out = []
    for c in range(len(tr["PSEL"])):
        s, e = tr["PSEL"][c], tr["PENABLE"][c]
        out.append(IDLE if not s and not e else "BAD" if not s
                   else ACCESS if e else SETUP)
    return out

def legal_next(state, pready):
    if state == IDLE:   return {IDLE, SETUP}
    if state == SETUP:  return {ACCESS}
    if state == ACCESS: return {IDLE, SETUP} if pready else {ACCESS}
    return set()

The state called ACCESS was called ENABLE in APB2 (IHI 0011A 5.2.1). In APB2 the ENABLE state lasted exactly one cycle, and with no PREADY it was always left at once. Since PREADY exists, the state can stretch over several cycles, and E calls it ACCESS. APB2 also said that select, address and write signals may glitch in the move from ENABLE to SETUP. The state description in E has no such sentence and only states the invariants within the ACCESS cycles.

5. Practice: reading the specification figures as states

We use the edge numbers T0, T1, … from the specification's timing figures as they are. Cycle c runs from edge c to just before edge c+1, values change right after an edge, and the value of that cycle is sampled at edge c+1. We copied the PSEL, PENABLE and PREADY values read from the figures into common/specfigs.py and built the state sequence with states() above.

Specification Figures 3-1 and 3-2 read as states: with no waiting it is one SETUP cycle and one ACCESS cycle, done at edge 3; with two wait states ACCESS lasts three cycles, done at edge 5

The grey stretches of PREADY are don't-care. The specification says PREADY can take any value while PENABLE is LOW (E 3.1.2). That is why PREADY drawn HIGH in the first two cycles of Figure 3-2 is legal.

We compared the six figures, as read by the model, with the text.

Spec figure Edge where transfer ends Waits Text or figure
3-1 write, no wait 3 0 text: "accepted at T3"
3-2 write, with waits 5 2 figure
3-4 read, no wait 3 0 figure
3-5 read, with waits 5 2 text: "two cycles are added"
3-6 write, error 4 1 figure
3-7 read, error 5 2 figure

For all six figures the model's reading matched the expected values and the rule checker reported 0 violations. 3-1 and 3-5 were compared with values the text states; the other four are values read directly off the figures, so the reference there is my own eye.

Now the rule checker. We built a Requester and a register-file Completer as a cycle model (simulate in common/apb.py) and generated 1,000 traces of 40 transfers each. The wait probability was drawn at random from 0, 0.2 and 0.5, and the probability of IDLE between transfers from 0 and 0.3. Half the traces have PSTRB and half do not.

Item Result
traces / cycles / transfers 1,000 / 107,206 / 40,000
rule violations 0
the 6 allowed paths all occurred
SETUP to ACCESS 40,000 (equal to the transfer count)
ACCESS to ACCESS (waiting) 17,069
ACCESS to SETUP (back to back) 32,845
ACCESS to IDLE 7,155

SETUP to ACCESS being exactly the transfer count confirms the rule that SETUP is one cycle per transfer. The three blocked paths never occurred.

Last, we measured how waiting affects the mean transfer length. Send transfers back to back, and let PREADY be 0 with probability p in every ACCESS cycle. The number of waits is then geometric, so the mean length of a transfer is 2 + p/(1-p) cycles (1 SETUP + 1 ACCESS + the mean waits). We measured with 20,000 transfers.

PREADY=0 probability p Measured mean length Formula 2 + p/(1-p)
0 2.000 2.000
0.25 2.331 2.333
0.5 2.985 3.000
0.75 4.982 5.000

At p=0 it is exactly 2 cycles, which reproduces the specification's "at least two cycles". Note that back-to-back sending does not shorten the SETUP cycle. The cycle right after ACCESS is the SETUP of the next transfer, so there is no empty cycle between transfers, but SETUP itself is one cycle needed per transfer.

6. Design checklist: map and states

Item Rule
Version choice PSTRB and PPROT from APB4, wake-up, user and parity only in APB5
Mandatory signals PCLK, PRESETn, PADDR, PSELx, PENABLE, PWRITE, PWDATA, PRDATA
PREADY the Requester input is mandatory. If the Completer lacks it, tie it HIGH
PSLVERR the Requester input is mandatory. If the Completer lacks it, tie it LOW
PSELx one bit per Completer. The APB2 specification says only one is active during a transfer
Widths PWDATA and PRDATA have the same width (8, 16, 32). PADDR is 32 bits or less
Alignment the result of an unaligned address is UNPREDICTABLE. The peripheral defines the behaviour
SETUP exactly one cycle per transfer. It can be neither skipped nor extended
ACCESS stays while PREADY=0. PADDR, PWRITE, PWDATA and so on must not change meanwhile
PENABLE cannot be 1 while PSEL=0
Minimum length every transfer takes 2 cycles or more. Throughput ceiling is half the data width per cycle

For verification the cheapest thing is a monitor that reads the state from just three signals, PSEL, PENABLE and PREADY. The legal_next above is its core, and Part 2 puts the stability rules on top of it.

Summary

  • APB is a simple synchronous bus for peripheral registers: one transfer at a time, no pipeline, at least 2 cycles per transfer. With no waiting, throughput is half the data width per cycle.
  • The versions are APB2, APB3 (PREADY, PSLVERR), APB4 (PPROT, PSTRB) and APB5 (wake-up, user signals, parity). Issue E only adds RME (PNSE) to APB5 as an optional feature and is not a new version.
  • Counting Table B-1, the 8 mandatory signals are the same in every version. With 32 bits the wire count goes from 101 mandatory to 103 for APB3, 110 for APB4 and 112 for APB5 with everything optional. PREADY and PSLVERR are optional on outputs but mandatory on the Requester's inputs.
  • The states are IDLE, SETUP, ACCESS, and 6 of the 3x3 moves are allowed. The six specification figures matched the model, 1,000 random traces had 0 violations, and the mean transfer length followed 2 + p/(1-p).

Next: Part 2 looks at the transfer itself. How writes and reads follow one another cycle by cycle, what must hold while PREADY inserts waiting, when PSLVERR is valid, and how sparse writes that pick bytes with PSTRB behave, all checked with the rule checker.

References

  • Arm, AMBA APB Protocol Specification, ARM IHI 0024 Issue E (2023-02-28). Preface APB Revisions, 1.1 About the APB protocol, 2.1 AMBA APB signals (2.1.1 Address bus, 2.1.2 Data buses), 3.1.2 Write transfer with wait states, 3.1 to 3.4 timing Figures 3-1, 3-2, 3-4 to 3-7, 4.1 Operating states, Appendix B Tables B-1 and B-3, Appendix C Revisions.
  • Arm, AMBA Specification Rev 2.0, ARM IHI 0011A (1999). 5.2 APB specification (IDLE, SETUP, ENABLE), Table 2-4 AMBA APB signals.
  • Code and results of this article: signals.py, ../common/apb.py, ../common/specfigs.py, results.json, figs_kit.py.

Similar posts