Of course. This is an excellent and very common question when designing high-performance Zynq 7000 systems. The core of the problem is contention for shared resources, primarily the AXI Interconnect and the DDR Memory Controller.
When the Processing System (PS) initiates an SD card read/write, its DMA controller becomes an AXI master, competing for the same data paths that your high-performance Programmable Logic (PL) master is trying to use. This competition leads to stalls and unpredictable latency for your PL transfers.
Here is a comprehensive guide on how to prevent or mitigate this, ranked from most effective to supporting optimizations.
The Root Cause: Shared Resource Contention
- AXI Interconnect: All masters (CPU, PL's HP ports, SD Card DMA, etc.) must go through the central AXI interconnect. The interconnect has an arbiter that decides which master gets access at any given moment.
- DDR Memory Controller: This is the ultimate bottleneck. All requests eventually funnel into the memory controller, which has finite bandwidth. SD card I/O often involves many small, potentially unaligned transfers, which are very inefficient for DDR memory and can "choke" the controller, blocking the large, efficient burst transfers from your PL.
1. The Most Effective Solution: Quality of Service (QoS)
The Zynq's AXI interconnect has a built-in Quality of Service (QoS) mechanism. This is the primary tool for solving this problem. You can assign a priority level (0-15) to each AXI master. The interconnect arbiter will then prioritize requests from masters with a higher QoS value.
How to Implement QoS:
- In your Vivado Block Design, double-click the ZYNQ7 Processing System block.
- Navigate to the PS-PL Configuration page.
- In the left pane, go to AXI Port QoS.
- You will see a list of AXI masters. Your PL logic should be connected to one of the AXI HP (High Performance) Slave Ports on the PS (e.g.,
S AXI HP0). The SD card controller is a master on the PS side, typically grouped under DMA or IOP (I/O Peripherals).
- Set the Priorities:
- Increase the priority of your PL's HP Port: Find the
S AXI HPx Read QoS and S AXI HPx Write QoS fields corresponding to the port your PL uses. Set them to a high value, for example, 15 (1111 in binary).
- Lower the priority of other masters: You can optionally lower the priority of the
CPU AXI master ports (M AXI GP0/1), and most importantly, the DMA controllers that the SDIO peripheral uses. A good starting point is to leave them at their default (often low) values while ensuring your HP port is set to the maximum.
Why this works: When both your PL master and the SD card's DMA request access to the DDR controller simultaneously, the AXI interconnect's arbiter will see the high QoS value from the HP port and grant it access first, forcing the SD card transfer to wait.
2. Architectural Solution: Buffering in the PL
For truly deterministic real-time systems, you should make your PL logic tolerant to bus stalls. The best way to do this is by using on-chip memory (Block RAM / BRAM) as a buffer.
How to Implement PL Buffering:
- Use a FIFO: Place an AXI4-Stream FIFO or a custom BRAM-based buffer between your data-generating/consuming logic and your AXI Master IP (e.g., AXI DMA or a custom AXI Master).
- Decouple Logic:
- For PL-to-DDR: Your real-time logic writes data into the BRAM buffer. The AXI master reads from this buffer and bursts it to DDR memory. If the AXI bus is stalled, the AXI master simply waits, but your real-time logic can continue to fill the buffer (up to its depth).
- For DDR-to-PL: The AXI master pre-fetches data from DDR into the BRAM buffer. Your real-time logic reads data from the buffer, which is a fast, deterministic, on-chip operation, completely immune to DDR latency.
Why this works: This decouples your time-critical PL operations from the non-deterministic latency of the main memory system. The BRAM acts as a shock absorber for memory access stalls.
3. Software & System-Level Optimizations
These techniques reduce the overall load on the memory system, making contention less likely.
a. Use Non-Cacheable Memory for SD Card Buffers
When the CPU accesses the data buffer for the SD card, that data may be pulled into the L1/L2 caches. This creates traffic through the Snoop Control Unit (SCU) and adds to memory system congestion. By allocating the DMA buffers for the SD card in a non-cacheable memory region, you bypass the caches entirely.
How to Implement (Linux): When allocating DMA buffers (e.g., using dma_alloc_coherent), the kernel handles making this memory non-cacheable and mapping it correctly for the DMA engine.
How to Implement (Bare-Metal): You must configure the MMU (Memory Management Unit) translation tables for the memory region you use for SD card buffers. Set the memory attributes for that page to be Strongly-ordered or Device memory, which prevents caching.
b. Use On-Chip Memory (OCM) for CPU Tasks
The Zynq 7000 has 256 KB of On-Chip Memory (OCM). This memory is tightly coupled to the CPUs and has a separate access port, bypassing the main AXI interconnect and DDR controller for many operations.
If the SD card operations are managed by a small, self-contained CPU task, you can place its code, stack, and data buffers entirely in OCM.
How to Implement: Modify the linker script for your bare-metal application or RTOS to place specific sections (.text, .data, .bss) for that task into the OCM address range (0x00000000 - 0x0003FFFF).
4. Optimize Your PL's AXI Transactions
Make your high-performance master a "good citizen" that uses the bus as efficiently as possible. When it gets the bus (thanks to QoS), it should finish its work quickly.
- Use Long Bursts: Configure your AXI master to use the longest possible burst lengths (e.g.,
AXILEN = 15 for 16 transfers, or AXILEN = 255 for AXI4). A single long burst is far more efficient for DDR than many short bursts.
- Use Full Data Width: Ensure your AXI master uses the full width of the AXI HP port (typically 64 bits).
- Use
INCR Burst Type: For sequential memory access, use the INCR burst type.
- Align Addresses: Start your transfers on addresses aligned to your burst size.
Summary and Recommended Approach
For a robust, high-performance system, use a combination of these techniques:
-
Primary Fix (Must-Do):
- Connect your high-performance PL master to an AXI HP port.
- In the Zynq configuration, set the QoS for that HP port to the highest value (15).
-
Resilience Fix (Highly Recommended):
- Add a BRAM-based FIFO buffer in your PL between your core logic and the AXI master. Size it to absorb the worst-case latency you expect.
-
System Optimization (Good Practice):
- In your software, ensure the DMA buffers for peripherals like the SD card are allocated in non-cacheable memory to reduce cache coherency traffic.
By implementing these steps, you are explicitly telling the Zynq hardware which data stream is more important (QoS) and architecting your system to be resilient to the unavoidable, occasional stalls of a shared memory system (PL buffering).