Two Buses and the Bridge
APB is too slow for memory, and a fast bus is too costly for every small device. So a chip has both, and a bridge between them.
You Will Be Able To
- Explain how AHB overlaps two transfers, and what that buys.
- Find the address phase and the data phase of every transfer in a capture, with and without a wait.
- Say why a chip has two buses, and follow one store across the bridge.
- Lesson
- S0.5
- Time
- 25 min
- Runs on
- Your browser
- Check
- 5 questions
On APB the quickest transfer takes two cycles. A processor fetches an instruction from memory in almost every cycle. Put memory on APB, and the processor runs at half speed before it has done any work.
Before You Start
You need S0.3 and S0.4: manager and subordinate, the transfer edge, wait states, the setup phase and the access phase. You also need the decoder and the read multiplexer of S0.2.
| Question | |
|---|---|
| 1 | Why is APB too slow for memory, and what does AHB do about it? |
| 2 | What are the address phase and the data phase, and how do two transfers overlap? |
| 3 | What does HREADY at 0 do to the data phase, and to the address phase behind it? |
| 4 | Why does a chip keep its device registers on a second, simpler bus? |
| 5 | What does a bridge do, and what does a device access cost through it? |
The Idea: Ask the Next Question Early
Every bus so far finishes one transfer before it starts the next. The fast bus breaks that habit. It splits each transfer into two halves. In the first half, the address phase, the manager says what it wants. In the second half, the data phase, the value moves.
The trick is the overlap. While the data of one transfer moves, the manager already shows the address of the next. Each transfer still takes two cycles. But one transfer finishes in every cycle, because two are always in progress. A bus built this way is called pipelined.
The standard bus that works this way is AHB, the Advanced High-performance Bus. It belongs to the same AMBA family as APB.
So why not put every device on AHB? Because the speed has a price. An AHB subordinate needs more logic than an APB completer. Every block added to AHB also makes its decoder and its read multiplexer larger, and so slower. A chip has dozens of small device registers that software touches now and then. They gain nothing from speed.
So a chip keeps two buses. Memory sits on AHB. Device registers sit on APB. One block, the bridge, joins them: it takes a transfer from AHB and repeats it on APB.
New Words
| Word | Meaning |
|---|---|
| AHB | Advanced High-performance Bus: a standard bus for memory and fast blocks. |
| Address phase | The first half of an AHB transfer. The manager shows the address and the direction. |
| Data phase | The second half. The write value or the read value moves. A subordinate may stretch it with wait states. |
| Pipelined | Working on two transfers at once: the address phase of one overlaps the data phase of the one before. |
| Bridge | A block between two buses. It is a subordinate on the first bus and the manager, or requester, on the second. |
Every AHB signal name starts with H. Here is the toy bus of S0.3 beside AHB.
| Toy bus | AHB | Phase | What changed |
|---|---|---|---|
| the clock | HCLK | both | only the name |
| valid | HTRANS | address | two bits wide: IDLE (binary 00) means no transfer, NONSEQ (binary 10) means one transfer |
| addr | HADDR | address | the name, and the width: up to 32 bits (8 in this lab) |
| write | HWRITE | address | only the name: 1 = write, 0 = read |
| wdata | HWDATA | data | it now arrives one phase after the address |
| rdata | HRDATA | data | only the name |
| ready | HREADY | data | it ends the data phase, and lets the next address phase be taken |
HTRANS has two more values. They belong to transfers that run in a row, which the Protocols track covers.
One Picture: Two Buses and a Bridge
- Processor
- Bus
- Memory
- Peripheral
- The fast bus
The processor and memory talk over AHB. The processor uses memory in almost every cycle, so this bus is built for speed.
- The simple bus
Device registers sit on APB, as in S0.4. They are many, and each is used now and then. Simple matters more than fast here.
- The bridge joins them
To AHB, the bridge is one more subordinate. It answers for every device address. To APB, it is the requester.
- A store to memory
The address is 3, so the AHB decoder selects memory. The bridge and APB stay idle. The store costs one cycle of data phase.
- A store to the lamps
The address is 14, so the AHB decoder selects the bridge. The bridge runs a setup phase and an access phase on APB. AHB waits one cycle for it.
Read the diagram as text
- Processor: the manager: it starts every transfer
- AHB: the fast bus: a transfer can finish in every cycle
- Memory: addresses 0 to 13, an AHB subordinate
- Bridge: an AHB subordinate above, the APB requester below
- APB: the simple bus: two cycles or more for each transfer
- Lamp register: address 14, an APB completer
- Other device registers: more APB completers
- Processor → AHB: address, then data
- AHB → Memory: memory addresses
- AHB → Bridge: device addresses
- Bridge → APB: setup, then access
- APB → Lamp register: one select each
- APB → Other device registers: one select each
Each arrow stands for a group of wires. The processor sees one bus and one set of addresses. Only the decoder knows about the bridge.
Notice what the processor does not know. It puts an address on AHB and waits for HREADY. Whether the answer came from memory or crossed the bridge, it sees the same wires.
The Smallest Example, Worked by Hand: Transfers as Bars
Draw each transfer as a bar of two parts, one cycle wide each. Transfer A writes memory box 3. Transfer B reads it back. Memory needs no wait states.
| Transfer | Cycle 1 | Cycle 2 | Cycle 3 |
|---|---|---|---|
| A: write box 3 | address phase | data phase | |
| B: read box 3 | address phase | data phase |
Look down the column of cycle 2. The address wires carry B while the data wires carry A. Two transfers took three cycles. Ten would take eleven. On APB, ten transfers take twenty cycles or more.
Now add a wait. Transfer C writes the lamps, and its data phase needs one wait state. Transfer D, a read of box 3, comes right behind it.
| Transfer | Cycle 1 | Cycle 2 | Cycle 3 | Cycle 4 |
|---|---|---|---|---|
| C: write lamps | address phase | data phase (wait) | data phase | |
| D: read box 3 | address phase (held) | address phase | data phase | |
| HREADY | 1 | 0 | 1 | 1 |
In cycle 2, HREADY is 0. The data phase of C cannot end. The address phase of D cannot end either. The bus takes a new address only when the old data phase is over. One wire holds both bars in place.
The Rules
Rule 1: Every transfer has an address phase and then a data phase.
The address phase carries HTRANS, HADDR and HWRITE. The data phase carries HWDATA for a write, or HRDATA for a read.
Rule 2: The address phase of one transfer overlaps the data phase of the one before.
By the data phase, the address wires show another transfer. So the bus must remember the address it took.
Rule 3: A data phase ends at the rising edge that sees HREADY at 1.
That edge is the transfer edge. A write changes the register there. A read is taken there.
Rule 4: HREADY at 0 holds both phases.
The data phase gains a wait state. The manager holds the next address phase unchanged, and keeps HWDATA still.
Rule 5: A bridge turns one AHB data phase into one whole APB transfer.
It runs the setup phase and the access phase, and answers HREADY at 0 until the APB transfer has happened.
Sources for These Rules
Arm AMBA AHB Protocol Specification, document IHI 0033, issue C. The two phases, their overlap and HREADY: section 3.1. The values of HTRANS: section 3.2. Holding the address and the write data through wait states: sections 3.7.2 and 6.1.1. The decoder and the multiplexer: section 1.1.3.
The APB bridge as the APB requester: Arm AMBA APB Protocol Specification, document IHI 0024, issue E, section 1.1.
The reasons for two buses are engineering practice. The specifications describe each bus and leave the choice to the designer. The bridge in the lab is our own, and is the smallest one that obeys both sets of rules.
Now Run It
The lab at the end of this page holds the whole path in one file. It has a manager, AHB, memory, the bridge, APB and the lamp register. The manager is test code again, a bus-functional model. Each row ends with the transfer that is in its data phase.
e0 haddr=0 hwrite=0 htrans=IDLE | hwdata=0 hrdata=x hready=1 | psel=0 penable=0 lamps=0 | data phase: none
e1 haddr=3 hwrite=1 htrans=NONSEQ | hwdata=0 hrdata=x hready=1 | psel=0 penable=0 lamps=0 | data phase: none
e2 haddr=3 hwrite=0 htrans=NONSEQ | hwdata=7 hrdata=x hready=1 | psel=0 penable=0 lamps=0 | data phase: write 3 <- transfer
e3 haddr=14 hwrite=1 htrans=NONSEQ | hwdata=7 hrdata=7 hready=1 | psel=0 penable=0 lamps=0 | data phase: read 3 <- transfer
e4 haddr=3 hwrite=0 htrans=NONSEQ | hwdata=9 hrdata=x hready=0 | psel=1 penable=0 lamps=0 | data phase: write 14 (wait)
e5 haddr=3 hwrite=0 htrans=NONSEQ | hwdata=9 hrdata=x hready=1 | psel=1 penable=1 lamps=0 | data phase: write 14 <- transfer
e6 haddr=3 hwrite=0 htrans=IDLE | hwdata=9 hrdata=7 hready=1 | psel=0 penable=0 lamps=9 | data phase: read 3 <- transfer
e7 haddr=3 hwrite=0 htrans=IDLE | hwdata=9 hrdata=x hready=1 | psel=0 penable=0 lamps=9 | data phase: none- Cycle 1
Address phase of the first transfer: write, address 3. No transfer is in its data phase yet.
- Cycle 2
Two transfers at once. HWDATA carries 7 for the write to box 3. HADDR already shows the next transfer, a read of box 3.
- Cycle 3
HRDATA returns 7 for the read. HADDR shows 14: the address phase of the write to the lamps.
- Cycle 4
The bridge runs the APB setup phase: PSEL is 1 and PENABLE is 0. It answers HREADY at 0, so AHB waits. The read behind it stays on HADDR.
- Cycle 5
The APB access phase. HREADY is 1 again. The lamps take 9 at this edge, and the waiting read is accepted.
- Cycle 6
The lamps show 9. HRDATA returns 7 for the last read.
Recorded from the lab. Each column is what one rising clock edge sees. Names are in lower case in the lab code and in capitals in the text.
Rule 2 at work: in row e2, HADDR and HWRITE describe the read. HWDATA carries the 7 of the write before it. Rule 4 at work: at e4, HREADY is 0, and HADDR and HWRITE are the same at e5.
Rule 5 at work: e4 and e5 are one AHB data phase. On APB they are a setup phase and an access phase. The lamps change after e5, the edge with PSEL and PENABLE both at 1. This completer keeps PREADY at 1.
Count the cost. The two memory transfers each added one cycle. The lamp write added two. A device access through the bridge always costs at least one wait state on AHB.
This lab leaves things out. Its bridge is three lines, and its APB has one completer that answers at once. Real AHB also carries wires for the size of a transfer and for errors.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| Overlap the address and data phases | Finish each transfer before the next starts | One transfer can finish in every cycle. Every subordinate must remember its address. |
| One HREADY for the whole bus | A ready wire for each phase | One wire stops everything, so nothing can be lost. A slow block stops every transfer behind it. |
| Device registers on a second, simple bus | Every block on the fast bus | Small devices stay small, and the fast bus keeps a short decoder. Each device access costs extra cycles. |
| A bridge that looks like one subordinate | A processor that speaks two buses | The processor and its software see one bus and one memory map. |
The third row is the heart of it. Speed is spent where transfers are frequent, and saved where they are rare.
The Trap: Reading One Column as One Transfer
An engineer opens a capture and finds HADDR at 14 and HWDATA at 7 in the same column. The report says "7 was written to the lamps". Look at row e3 of the lab. HADDR is 14 and HWDATA is 7. The lamps never receive 7. They receive 9, two edges later.
On a pipelined bus, the address and the data in one column belong to different transfers. The 7 was the write to box 3. To pair them correctly, take the address at the edge that ends its address phase. Then take the data at the edge that ends the data phase after it.
At Scale
This section looks ahead. The chip of this track, ap_soc, has exactly this shape, with more blocks on each bus.
In ap_soc
Boot ROM and SRAM sit on AHB. UART0, GPIO and five more device blocks sit on APB, behind one bridge. Lesson S4.5 opens that bridge.
The full AHB
The Protocols track teaches AHB signal by signal, starting at AHB in one picture and wait states.
A third bus
AXI, named in S0.3, serves the largest chips. It lets several transfers wait for their data at once, and return out of order. A small chip like ap_soc does not need it.
Try It
Run the lab. For each row, name the transfer in its address phase and the transfer in its data phase.
Add a fifth transfer: a read of the lamps. Predict the edge where it happens and the value of hrdata there.
Send two lamp writes in a row. Predict how psel and penable move between them.
Break rule 2: make memory use haddr where it uses d_addr. Find the box that the first write changes.
e0 haddr=0 hwrite=0 htrans=IDLE | hwdata=0 hrdata=x hready=1 | psel=0 penable=0 lamps=0 | data phase: none e1 haddr=3 hwrite=1 htrans=NONSEQ | hwdata=0 hrdata=x hready=1 | psel=0 penable=0 lamps=0 | data phase: none e2 haddr=3 hwrite=0 htrans=NONSEQ | hwdata=7 hrdata=x hready=1 | psel=0 penable=0 lamps=0 | data phase: write 3 <- transfer e3 haddr=14 hwrite=1 htrans=NONSEQ | hwdata=7 hrdata=7 hready=1 | psel=0 penable=0 lamps=0 | data phase: read 3 <- transfer e4 haddr=3 hwrite=0 htrans=NONSEQ | hwdata=9 hrdata=x hready=0 | psel=1 penable=0 lamps=0 | data phase: write 14 (wait) e5 haddr=3 hwrite=0 htrans=NONSEQ | hwdata=9 hrdata=x hready=1 | psel=1 penable=1 lamps=0 | data phase: write 14 <- transfer e6 haddr=3 hwrite=0 htrans=IDLE | hwdata=9 hrdata=7 hready=1 | psel=0 penable=0 lamps=9 | data phase: read 3 <- transfer e7 haddr=3 hwrite=0 htrans=IDLE | hwdata=9 hrdata=x hready=1 | psel=0 penable=0 lamps=9 | data phase: noneCheck Yourself
Common Mistakes
Wrong Pair the HADDR and the HWDATA seen in one column.
They belong to two different transfers. The data is one phase behind its address.
Fix Match each address with the data phase that follows it.
Wrong Change HADDR while HREADY is 0.
The waiting address phase has not been taken yet. The bus would take the wrong address.
Fix Hold the address phase unchanged until an edge sees HREADY at 1.
Wrong Expect a device register to answer as fast as memory.
The bridge needs a setup phase and an access phase on APB for each transfer.
Fix Count at least one wait state on AHB for every access through the bridge.
Remember
- AHB splits a transfer into an address phase and a data phase, and overlaps them with the next transfer.
- One transfer can finish in every cycle, so memory and the processor talk over AHB.
- HREADY at 0 holds the data phase and the address phase behind it.
- Address and data seen in one cycle belong to different transfers.
- Device registers stay on APB; a bridge turns one AHB data phase into a setup phase and an access phase.