AXI4 Master Read SDRAM

39 views (last 30 days)
John
John on 6 Oct 2025 at 18:26
Commented: John on 16 Oct 2025 at 19:18
I'm using a Cyclone V SoC and in my reference design I have a FPGA to HPS SDRAM Interface enabled under the HPS. I'm expecting sensor data to be written to a specific address within this SDRAM. I need the Mathworks generated IP to have a AXI4 master interface in order to read directly from this memory so the sensor values can be used in the generated model. In the plugin_rd() function definition I tried adding something such as this:
% Define AXI4 Master interface
hRD.addAXI4MasterInterface( ...
'InterfaceConnection', 'hps_0.f2h_sdram0_data', ...
'InterfaceID', 'f2h_sdram0', ...
'AddrWidth', 32);
I don't see any blocks I can use in the simulink model in order to be able to read from the SDRAM. Thank you for any help.

Accepted Answer

Umar
Umar on 7 Oct 2025 at 5:02

Hi @John,

Saw your comments about the Cyclone V SoC setup and the missing “read from SDRAM” block—here’s a quick summary and clarification.You’re already on the right path with

hRD.addAXI4MasterInterface( ...
  'InterfaceConnection','hps_0.f2h_sdram0_data', ...
  'InterfaceID','f2h_sdram0', ...
  'AddrWidth',32);

but remember, that line only declares the AXI4 Master interface in the reference design. HDL Coder doesn’t automatically create read logic or a block for you; the actual handshake must live inside your DUT subsystem.

Here’s how to wire it up:

1. Inside `plugin_rd()` Add the master interface with read capability enabled:

     hRD.addAXI4MasterInterface( ...
       'InterfaceConnection','hps_0.f2h_sdram0_data', ...
       'InterfaceID','f2h_sdram0', ...
       'ReadSupport','true', ...
       'WriteSupport','false', ...
       'AddrWidth',32, ...
       'MaxDataWidth',32, ...
       'HasMemoryConnection',true, ...
       'DefaultReadBaseAddr',hex2dec('80000000'), ...
       'ProcessorAccessibleMemoryRegion',[hex2dec('80000000') 
        hex2dec('00200000')]);

2. In the DUT subsystem Expose ports for the simplified AXI4 Master handshake:

     rd_addr     – byte address
     rd_len      – number of words
     rd_avalid   – request valid
     rd_aready   – slave ready
     rd_data     – read data
     rd_dvalid   – data valid

Implement a small FSM that asserts `rd_avalid` when `rd_aready` is high, issues the address and length, then waits for `rd_dvalid` and samples `rd_data`.

3. For simulation Connect those ports to an AXI4 Random Access Memory block from the SoC Blockset. This acts as a stand-in for SDRAM and lets you verify timing and data flow before generating HDL.

Once the FSM is working, map your `rd_*` signals to the `f2h_sdram0` interface in the IP Core Editor (Target Interface tab). The generated IP will then access HPS SDRAM directly at runtime—no extra Simulink memory block needed.

References

Simplified AXI4 Master Interface


https://www.mathworks.com/help/soc/ug/model-design-for-axi4-master-interface-generation.html%E2%80%A8

This page shows exactly which rd_* / wr_* signals you model in your DUT, what their handshaking semantics are, and how HDL Coder translates them into real AXI4 master logic.

Model Design for AXI4 Master Interface Generation


https://www.mathworks.com/help/hdlcoder/ug/model-design-for-axi4-master-interface-generation.html%E2%80%A8

This covers how to design your DUT ports to map to AXI4 master, how the simplified protocol is used in IP Core Generation, and more.

Design a Model for AXI4 Interfaces


<https://www.mathworks.com/help/hdlcoder/modeling-for-deployment.html%E2%80%A8>

This gives a broader view: how to approach modeling algorithms in Simulink/HDL Coder for AXI4-Stream, AXI4 master, etc.

Generate HDL IP Core with Multiple AXI4-Stream and AXI4 Master Interfaces


https://www.mathworks.com/help/hdlcoder/ug/map-dut-ports-to-multiple-axi-interfaces.html%E2%80%A8

Useful when your design has more than one interface; explains how to map ports to multiple AXI interfaces.

Hope this helps.

  9 Comments
Umar
Umar about 3 hours ago

Hi @John,

Great troubleshooting! This confirms your AXI4 master interface is working correctly and can read from the bus. This definitively narrows the problem to the F2SDRAM bridge configuration, not your MATLAB-generated interface.

You mentioned, " I have been using the Mathworks provided Linux image and I'm not too familiar with altering the U-boot configuration but this seems to indicate that the bridge should be enabled, correct?"

The bridges showing "enabled" is a good sign—it means the kernel driver loaded successfully. However, this doesn't guarantee the low-level hardware registers are properly configured. The "enabled" state just means the bridge isn't actively disabled by Linux.

Good news: you don't need to modify U-Boot for this. The devmem commands I provided can be run directly from your Linux console after boot. They'll configure the hardware registers that control the actual SDRAM port, which may not be set by the Mathworks image.

Next Steps:

Before doing SignalTap debugging, try these commands from Linux:

devmem 0xFFC2505C 32 0xA       # Apply SDRAM bridge configuration
devmem 0xFFC25080 32 0xFFFF    # Release FPGA port reset

After running these commands, test your SDRAM read operation again from MATLAB and check if rd_aready and rd_dvalid now assert.Given that your AXI4 works with System ID but SDRAM signals never assert, this is very likely the missing piece. If these commands fix it, you can add them to a startup script so they run automatically after boot.

If this doesn't solve it:

Then proceed with the SignalTap capture to monitor rd_avalid, rd_aready, rd_dvalid, and rd_dready. Also verify you're reading from valid SDRAM address ranges (typically 0x00000000 - 0x3FFFFFFF on Cyclone V).

Keep me posted. You're doing great!

John
John about 1 hour ago
That worked! Thank you very much. Using devmem is fine now for testing but I assume for the final code I would want those HPS registers to be set by the u-boot script or something like that. I will eventually have to figure that out.

Sign in to comment.

More Answers (0)

Categories

Find more on System on Chip (SoC) in Help Center and File Exchange

Tags

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!