Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Newbie memory question

Altera_Forum
Honored Contributor II
1,666 Views

Hi, 

I got a Terasic DE0-nano board with a Cyclone IV FPGA. My design is writing data in the memory. I use a NIOS II softcore too and I'd like it to read the FPGA memory and the data I wrote in a hardware-way. Can I do that? 

Thanks.
0 Kudos
27 Replies
Altera_Forum
Honored Contributor II
124 Views

So for now: 

I use Eclipse because the tutorials I found tell me to do that and I don't know how to do it otherwise but I don't think it's relevant. 

 

I don't really understand what is wrong: 

I have a hardware part that is writing the memory. I know it's correct as I'm writing "01010101" and the LEDs of my DE0-NANO board are ok when reading the memory. But when using this code: 

#include <stdio.h> # define ONCHIP_MEM_BASE 0x10000 int main() { int *pmem=(int*)(0x80000000|ONCHIP_MEM_BASE); printf("Hello from Nios II!\n"); usleep(1000000); printf("%04x\n",*pmem); return 0; }  

the console is printing: 

 

--- Quote Start ---  

Hello from Nios II! 

820014 

 

--- Quote End ---  

 

 

Please tell me what is wrong in my code. 

 

Another question: 

the system.h file is not read, I have to write the# define line so it's correct. How could I include that automatically?
0 Kudos
Altera_Forum
Honored Contributor II
124 Views

Don't worry, you should be fine with Eclipse. 

 

You'd better replace your 

# define ONCHIP_MEM_BASE 0x10000 

with 

# include "system.h" 

 

Everything else seems to be ok, so if the hardware is correct and you have the right value in memory you should be reading the correct value. 

 

You could check it by turning this memory into a single port memory (disconnecting from Nios and ignoring the software) and then enabling the ISMCE - In System Memory Content Editor. This way you could check if your hardware is writing to the memory as expected. The ISMCE can be enabled in the memory properties in Qsys and you can monitor it using the tool from the "Tools" menu in Quartus. 

 

Also if in doubt you could try reading from memory using IORD_8DIRECT(ONCHIP_MEM_BASE,0) which would return the first byte from your memory or IORD_32DIRECT(ONCHIP_MEM_BASE,0) if you need to read four bytes into an int.
0 Kudos
Altera_Forum
Honored Contributor II
124 Views

Or learn how to use signaltap, and use it to monitor the memory block.

0 Kudos
Altera_Forum
Honored Contributor II
124 Views

OK but when using a single-port memory and exporting the port, I don't have any internal memory and I have two errors: 

Error: System.cpu: Reset slave onchip_mem.s1 not connected to instruction_master. 

Error: System.cpu: Exception slave onchip_mem.s1 not connected to instruction_master. 

What should I do?
0 Kudos
Altera_Forum
Honored Contributor II
124 Views

hmmm... It seems you're using the same memory for your hardware to write data and for your program to run from, is it right? 

 

You shouldn't write data directly to arbitrary addresses withing your program/data memory, it may even cause your program to hang. 

 

That may explain as well why you are reading the wrong value: maybe it's been overwritten when you run the software.
0 Kudos
Altera_Forum
Honored Contributor II
124 Views

So I added another memory in Qsys connected to instruction_master of my cpu but now the compilation of the program tells it won't feet, so I make the memory a lot bigger: it compiles. But now the Hello world template won't print anything. It's another problem I have.

0 Kudos
Altera_Forum
Honored Contributor II
124 Views

ok, some points you may want to check: 

* make sure your CPU reset vector (and exception vector) points to the right memory 

* your software will run, by default, in the biggest memory connected to your CPU. You can change that in the BSP Editor. 

* stdout must be correctly set to your jtag uart device in the BSP Editor 

* check for timing issues, it may cause your system to malfunction (or "no function" at all). Big on-chip memories will make it harder to route and may cause timing closure issues. 

* you may want to debug your software using Eclipse debug capabilities and run it step by step so you will know where and what it's going wrong (debug as -> niosII hw)
0 Kudos
Reply