Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
858 Views

Nios and tcl script writing to RAM

Hi, 

 

I have an image loaded with a Nios , Jtag master and jtag UART. 

 

I have wrote C code to write to the on-chip RAM. I have also a tcl script that can read and write to the RAM. 

 

When I write and read to/ from a location with C code as follows : 

 

unsigned int* mem_ptr = (unsigned int*) 0x40000060; *mem_ptr = 0xff00; printf("Value is 0x%x\n", *mem_ptr);  

 

the correct value is read back fine with printf() but when I source a tcl script to read from the same location using "ram_read 0", I am getting different values :  

 

proc ram_read {offset} { global jtag if {!} { jtag_open } set addr return }  

 

When I tried this yesterday however, the correct values were being read back. I don't understand why now the printf() prints the correct value but the tcl script does not. Should the values be the same? Can anyone see where I am going wrong here or if I am going wrong at all? Thanks in advance.
0 Kudos
10 Replies
Altera_Forum
Honored Contributor I
26 Views

Does your NIOS have a data cache?

Altera_Forum
Honored Contributor I
26 Views

Hi, 

My Nios does have a data cache. It is the Nios II / f
Altera_Forum
Honored Contributor I
26 Views

For starters, try flushing the cache before reading from the TCL side.  

 

If that doesn't work, I would suggest removing the cache from the NIOS during your early debugging in order to remove it from the list of things that could possibly go wrong.
Altera_Forum
Honored Contributor I
26 Views

I have changed the Nios system to the Nios II / e , which doesn't have a cache and guess what? It works fine now. Thanks

Altera_Forum
Honored Contributor I
26 Views

Actually, I am still reading the wrong values, even with using the Nios II / e without a data cache. 

 

The thing I don't understand is that why sometimes I am reading the expected values back and other times not. I was convinced that it was the cache issue at first but it is still not behaving like I expect. 

 

If I write to memory with the ram_write tcl command and read it back with a ram_read command, it is reading the correct value back. Likewise with C, when writing to memory and read it back with printf(), I am reading the same value. Does this mean that my DDR3 controller is working? If so, why am I not reading the same values from tcl as in C (only sometimes). I am reading from the same memory locations. Maybe I am missing something else ?
Altera_Forum
Honored Contributor I
26 Views

How is your data wrong? Is it changing at all when written from the other side? 

If you extend the test to work against larger quantity of data (arrays instead of words) do you still have problems? 

 

You can always do something like forget about the NIOS software and halt the processor and just use the memory window in Eclipse to peek/poke until you get agreement with your TCL functions.
Altera_Forum
Honored Contributor I
26 Views

 

--- Quote Start ---  

 

I am reading from the same memory locations. Maybe I am missing something else ? 

 

--- Quote End ---  

 

Take a look at your processor linker script. You need to make sure that the memory you are writing and reading to is not being used by the processor, eg., for malloc or stack or program area. 

 

It the values are changing, then halt the processor and try again. If they do not change with the processor halted, then your problem is likely you are writing to an area that you have told the processor (via the linker script) belongs to it. 

 

Cheers, 

Dave
Altera_Forum
Honored Contributor I
26 Views

Hi Dave, 

 

The processor is using the on-chip memory and I am writing to off-chip DDR3.  

 

I have taken your bemicro_cv ddr example that you gave me before and adapted it for my board. I have checked it again and now it works as expected.  

 

The issue however is that I had cloned it into another separate project and removed the LED control from the Qsys and removed other ports from the top-level file such as for the MicroSD and I2C ports. I did this in order to make the design as simple as possible with just a DDR3 controller and Nios. Only when I do this, tcl and C are giving different values. If I reload the other image with everything included, I am reading the correct values again across C and tcl. 

 

This I find strange. If the tcl read command is showing the same value that I wrote using tcl, doesn't this mean that it is working fine anyways? I am wondering why by just removing the LED output and other unused ports from that project that I don't read the same values written with C from tcl and vice versa but write and read using only C or only tcl reads back the correct values. )) 

 

Thanks, 

Paul
Altera_Forum
Honored Contributor I
26 Views

 

--- Quote Start ---  

 

The issue however is that I had cloned it into another separate project and removed the LED control from the Qsys and removed other ports from the top-level file such as for the MicroSD and I2C ports. I did this in order to make the design as simple as possible with just a DDR3 controller and Nios. 

 

--- Quote End ---  

 

So long as you have made sure that unused pins are set to use weak pull-ups, that should be fine. 

 

 

--- Quote Start ---  

 

Only when I do this, tcl and C are giving different values. If I reload the other image with everything included, I am reading the correct values again across C and tcl. 

 

This I find strange. 

 

--- Quote End ---  

 

As do I :) 

 

My suggestion would be to add a SignalTap II instance and trigger off the Avalon-MM write to the DDR3 controller. You can then write from Tcl or NIOS and confirm that you trigger the analyzer. You can then perform reads and see if something weird happens, eg., do you get a bogus write? 

 

Cheers, 

Dave
Altera_Forum
Honored Contributor I
26 Views

 

--- Quote Start ---  

If I reload the other image with everything included, I am reading the correct values again across C and tcl. 

--- Quote End ---  

 

 

My suggestion would be to start with your functional image, and repeat the process of removing components until you break it. Remove one half of them, test it. Remove the other half, test it. And so on. 

 

Overall your problem sounds like operator-error in the process of having removed those components.
Reply