Misaligned Byte Transfers on Word-Addressable APB Slaves

The core issue revolves around the behavior of an AHB2APB bridge when handling narrow byte transfers, specifically when the AHB master initiates a single-byte read transaction targeting a word-addressable APB slave. The AHB master sends a starting address of 0x01 with HSIZE set to 0 (indicating a byte transfer), but the APB slave responds with a full 32-bit word of data. This raises questions about the legality of such transactions and the expected behavior of the AHB2APB bridge in handling misaligned addresses and protocol mismatches.

The AHB (Advanced High-performance Bus) and APB (Advanced Peripheral Bus) protocols have distinct characteristics. AHB supports a wide range of transfer sizes, including byte, half-word, and word transfers, while APB is typically designed for simpler, word-aligned transactions. The AHB2APB bridge acts as an intermediary, translating AHB transactions into APB-compatible transactions. However, the bridge must handle cases where the AHB master requests a transfer size or address alignment that does not directly map to the APB protocol’s expectations.

In this scenario, the APB slave is word-addressable, meaning it expects addresses aligned to 32-bit boundaries (i.e., addresses where the least significant two bits are 0). The AHB master, however, initiates a byte transfer with an unaligned address (0x01), which complicates the transaction. The APB slave responds with a full 32-bit word, as it is designed to handle word-aligned reads. This behavior highlights a potential mismatch between the AHB master’s intent and the APB slave’s capabilities.

The key questions to address are:

  1. Is it legal for the AHB master to initiate a byte transfer with an unaligned address on a word-addressable APB slave?
  2. How should the AHB2APB bridge handle such transactions to ensure correct and predictable behavior?
  3. What are the implications of performing a wider read (e.g., a 32-bit word read) than requested by the AHB master?

Protocol Mismatch and Unaligned Address Handling

The root cause of the issue lies in the inherent differences between the AHB and APB protocols, particularly in their handling of transfer sizes and address alignment. The AHB protocol is designed for high-performance systems and supports a variety of transfer sizes, including byte (8-bit), half-word (16-bit), and word (32-bit) transfers. It also allows for unaligned addresses, meaning the starting address of a transfer does not need to be aligned to the transfer size. For example, a byte transfer can start at any address, a half-word transfer can start at an even address, and a word transfer can start at an address divisible by 4.

In contrast, the APB protocol is simpler and typically designed for lower-performance peripherals. APB slaves are often word-addressable, meaning they expect addresses aligned to 32-bit boundaries. The APB protocol does not natively support narrow transfers (e.g., byte or half-word) in the same way as AHB. Instead, APB transactions are typically word-aligned, and the protocol assumes that the data bus width matches the address alignment.

When an AHB master initiates a byte transfer with an unaligned address (e.g., 0x01) targeting a word-addressable APB slave, the AHB2APB bridge must translate this transaction into an APB-compatible transaction. However, the APB slave is not designed to handle byte-level addressing, and it responds with a full 32-bit word of data. This creates a mismatch between the AHB master’s request and the APB slave’s response.

The APB protocol does allow for unaligned addresses, but the result is marked as UNPREDICTABLE. This means that while the transaction is technically legal, the behavior of the APB slave in response to an unaligned address is not guaranteed. In practice, many APB slaves will simply ignore the lower address bits and return a full word of data, as seen in this scenario.

Another factor to consider is the AHB2APB bridge’s design. The bridge must decide how to handle narrow transfers and unaligned addresses. One approach is to perform a wider read (e.g., a 32-bit word read) and return only the requested byte to the AHB master. This approach ensures that the APB slave receives a legal transaction while still fulfilling the AHB master’s request. However, this approach may not be suitable for all applications, particularly if the APB slave is read-sensitive (e.g., a FIFO or memory-mapped register).


Implementing Correct AHB2APB Bridge Behavior and Data Alignment

To address the issue of narrow byte transfers on a word-addressable APB slave, the AHB2APB bridge must implement specific handling mechanisms to ensure correct and predictable behavior. The following steps outline the recommended approach:

  1. Address Alignment and Transfer Size Handling: The AHB2APB bridge should first check the address alignment and transfer size of the incoming AHB transaction. If the address is unaligned or the transfer size is narrower than the APB slave’s data width, the bridge must decide how to handle the transaction. For byte transfers with unaligned addresses, the bridge should perform a word-aligned read from the APB slave and extract the requested byte from the returned data.

  2. Wider Read and Data Extraction: When the AHB master requests a byte or half-word transfer, the AHB2APB bridge should perform a full 32-bit word read from the APB slave. The bridge then extracts the relevant byte or half-word from the returned data based on the original address. For example, if the AHB master requests a byte from address 0x01, the bridge performs a word read from address 0x00 and extracts the byte at offset 0x01 from the returned data.

  3. Handling Write Transfers: For write transfers, the AHB2APB bridge must handle narrow writes differently. Starting from APB4, the protocol includes the PSTRB signal, which allows for narrow writes by specifying which bytes of the data bus should be written. The bridge should use the PSTRB signal to ensure that only the requested bytes are written to the APB slave. For earlier versions of the APB protocol, the bridge may need to perform a read-modify-write operation to update only the relevant bytes.

  4. Error Handling and Predictable Behavior: The AHB2APB bridge should provide predictable behavior for all transactions, even those that are technically legal but may result in UNPREDICTABLE outcomes on the APB side. For example, if the APB slave does not support unaligned addresses, the bridge should either align the address internally or return an error response to the AHB master. This ensures that the system behavior remains consistent and debuggable.

  5. Performance Considerations: Performing wider reads than requested can have performance implications, particularly if the APB slave is accessed frequently. The AHB2APB bridge should be designed to minimize the overhead of these operations. For example, the bridge could cache the results of wider reads to avoid repeated accesses to the APB slave for subsequent narrow transfers.

  6. Testing and Validation: The AHB2APB bridge should be thoroughly tested to ensure correct handling of all possible transfer sizes and address alignments. This includes testing edge cases such as unaligned addresses, narrow transfers, and read-sensitive APB slaves. Simulation and formal verification tools can be used to validate the bridge’s behavior under various conditions.

By implementing these steps, the AHB2APB bridge can effectively handle narrow byte transfers and unaligned addresses while maintaining compatibility with both the AHB and APB protocols. This ensures that the system operates correctly and predictably, even in complex scenarios involving protocol mismatches and address alignment issues.


In summary, the issue of narrow byte transfers on a word-addressable APB slave highlights the challenges of bridging different bus protocols with varying capabilities. The AHB2APB bridge plays a critical role in translating transactions between these protocols, and its design must account for differences in transfer sizes, address alignment, and protocol features. By carefully handling unaligned addresses, performing wider reads when necessary, and ensuring predictable behavior, the bridge can provide a robust and efficient solution for interfacing AHB and APB components.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *