--- Quote Start ---
What I want to really do is write C code that doesn't run out of the external SDRAM but as the program is running, it writes data to the SDRAM and then reads it back at some stage.
--- Quote End ---
In that case, your linker script can just avoid defining the SDRAM addresses as useable, and your C-code can just read/write to the SDRAM addresses, eg., assuming your SDRAM was in the Qsys address map at 0x1000_0000, you can write to the SDRAM from C code via
uint32_t *sdram_base = (uint32_t *)0x10000000;
// Fill a few locations in SDRAM
for (int i = 0; i < 0x100; i++) {
sdram_base = i;
}
In this code, because the pointer is defined as 32-bits, the sdram_base[i] will increment 32-bits per address.
--- Quote Start ---
If I could write VHDL code to do this it would be even better. This way I can understand properly how data is written and read from RAM. Example code showing how this is done would be a super help.
In order to do this, must I specify a RAM address on the address lines connected to the SDRAM, then place the data on the data lines? As these lines are parallel, i'm not sure how to do this in code. Should there be an address register and data register and the SDRAM controller takes care of converting from serial to parallel?
--- Quote End ---
In this case you need to create an Avalon-MM master. The master interface needs to implement the Avalon Memory Mapped Protocol.
Have you taken a look at the Avalon Interface Specification and the Avalon Verification IP Suite? If not, perhaps start by doing the JTAG-to-Avalon-MM tutorial I pointed you to earlier. You can view the Avalon-MM bus transactions in the BFM simulation, and then that'll help you "see" what HDL you need to implement to read or write SDRAM from VHDL.
What would actually be your "master", eg., are you trying to communicate with the FPGA via a microcontroller?
Cheers,
Dave