0
0
Cnc-programmingComparisonBeginner · 4 min read

AHB vs APB in ARM: Key Differences and Usage Explained

In ARM architecture, AHB (Advanced High-performance Bus) is a high-speed bus designed for fast data transfer and complex peripherals, while APB (Advanced Peripheral Bus) is a simpler, slower bus used for low-speed peripherals. AHB supports burst transfers and pipelining, making it suitable for performance-critical components, whereas APB focuses on low power and simple interface requirements.
⚖️

Quick Comparison

This table summarizes the main differences between AHB and APB buses in ARM systems.

FeatureAHB (Advanced High-performance Bus)APB (Advanced Peripheral Bus)
SpeedHigh-speed busLow-speed bus
ComplexityComplex with burst and pipeliningSimple, no burst or pipelining
Use CaseHigh-performance peripherals and memoryLow-speed peripherals like timers and UART
Power ConsumptionHigher due to complexityLower, optimized for simple peripherals
Data TransferSupports burst transfersSingle data transfer per cycle
Bus WidthTypically 32-bit or 64-bitTypically 32-bit
⚖️

Key Differences

The AHB is designed for high-performance and high-bandwidth communication within ARM systems. It supports features like burst transfers, pipelining, and multiple bus masters, which allow it to handle complex data transfers efficiently. This makes it ideal for connecting to memory controllers, DMA controllers, and high-speed peripherals.

In contrast, the APB is a simpler bus intended for low-speed peripherals that do not require high bandwidth or complex data handling. It does not support burst transfers or pipelining, which simplifies the design and reduces power consumption. APB is typically used for peripherals like timers, UARTs, and GPIO controllers where simplicity and low power are more important than speed.

Architecturally, AHB acts as a backbone bus connecting to multiple bus masters and slaves, while APB is usually connected as a subordinate bus off the AHB, providing a simple interface to peripherals that do not need the full performance of AHB.

💻

AHB Code Example

This example shows a simple conceptual code snippet illustrating how an AHB bus master might initiate a burst read transaction in an ARM system.

c
#include <stdio.h>
#include <stdint.h>

struct AHB_Master {
    uint32_t address;
    uint32_t data[4];
    void burst_read(uint32_t start_addr) {
        address = start_addr;
        for (int i = 0; i < 4; i++) {
            // Simulate burst read with pipelining
            data[i] = read_from_bus(address + i * 4);
        }
    }
};

uint32_t read_from_bus(uint32_t addr) {
    // Simulated bus read
    return addr + 0x1000; // dummy data
}

int main() {
    struct AHB_Master master;
    master.burst_read(0x20000000);
    for (int i = 0; i < 4; i++) {
        printf("Data[%d]: 0x%X\n", i, master.data[i]);
    }
    return 0;
}
Output
Data[0]: 0x20001000 Data[1]: 0x20001004 Data[2]: 0x20001008 Data[3]: 0x2000100C
↔️

APB Equivalent

This example shows how an APB bus master performs a simple single read transaction without burst or pipelining.

c
#include <stdio.h>
#include <stdint.h>

struct APB_Master {
    uint32_t address;
    uint32_t data;
    void single_read(uint32_t addr) {
        address = addr;
        data = read_from_apb(address);
    }
};

uint32_t read_from_apb(uint32_t addr) {
    // Simulated APB read
    return addr + 0x1000; // dummy data
}

int main() {
    struct APB_Master master;
    master.single_read(0x20000000);
    printf("Data: 0x%X\n", master.data);
    return 0;
}
Output
Data: 0x20001000
🎯

When to Use Which

Choose AHB when you need high-speed data transfer, support for burst transactions, and connection to performance-critical components like memory and DMA. It is best for complex systems requiring multiple bus masters and high throughput.

Choose APB for simple, low-speed peripherals where power efficiency and simplicity are more important than speed. It is ideal for connecting devices like timers, UARTs, and GPIOs that do not require complex bus features.

Key Takeaways

AHB is a high-speed, complex bus supporting burst and pipelining for performance-critical components.
APB is a simple, low-speed bus optimized for low power and simple peripheral interfaces.
AHB connects multiple masters and slaves, while APB typically connects as a subordinate bus.
Use AHB for memory and DMA; use APB for timers, UARTs, and simple peripherals.
Choosing the right bus improves system efficiency and power consumption.