Forum Discussion
Newbie memory question
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.27 Replies
- Altera_Forum
Honored Contributor
I've used another method:
In Qsys I've instantiated a dual-port memory. One is connected to the data_master for reading purpose, the other is exported and connected to the logic in the symbolic top-level for writing. Tell me if that's bad. - Altera_Forum
Honored Contributor
Sorry to bother you once more but I don't know how to use the tcl script. I've saved it in the same folder as my .qsys file but I don't know how to import this component in Qsys.
Another thing: you didn't tell me why I can't use a dual-port memory in Qsys and simply export one of the ports to use it in Quartus II. - Altera_Forum
Honored Contributor
No problem, I'm sorry I didn't notice your previous post.
Exporting an Avalon Slave interface of a dual port memory is fine, that's a good idea I haven't thought about. As long as you get the subset of Avalon signals you want there's no problem about it. The TCL script, when put in your Qsys folder, should be listed on the left side panel (library). It should be the first one listed. Remember to rename from .tcl.txt to .tcl and, if you're not using Quartus 13.1, please comment out the first line (package require -exact qsys 13.1). If you put the file there with Qsys running you have to refresh (F5) so it will appear in the library, otherwise it will be read when Qsys loads. - Altera_Forum
Honored Contributor
OK,
I've created a system with a dual-port ram but (after recreating everything) it won't run the software: Eclipse is opening a window entitled "Create, manage and run configurations" with a pannel on the left side and five tabs on the right. Going back to a single-port ram and rebuilding everything is ok and the software works. Any idea of why? - Altera_Forum
Honored Contributor
After many tries and reprogramming, it finally works.
Thank you for the explanations and your patience. - Altera_Forum
Honored Contributor
Nice, Binome! I'm glad to know that.
Sorry for taking longer than expected to reply, it seems email notifications for forum replies are delayed, I've seen complains about it already... I hope it gets fixed soon - Altera_Forum
Honored Contributor
I think the different times are making the conversation difficult (I'm in France, you are in California, I think).
I have another question: my Qsys design is instantiating a dual-port memory. s2 is exported so the hardware part can control different signals to write on it. Now I want the cpu to read on the s1 port. How can the software access all the signals to read on a specific address? - Altera_Forum
Honored Contributor
I'm in Brazil, that's GMT-3 so I guess we're four hours apart...
You can access that memory in software using pointers. In your BSP you should have a system.h where the memory address is defined, like # define MEMORYNAME_BASE 0x08000000 Then in your code you can: unsigned char *pmem = (unsigned char *)MEMORYNAME_BASE; You can cast your memory address to whatever pointer type you need. Be aware that access to this memory will be cached, so there's a risk that you're reading old data because it's on processor data cache (if your Nios is configured with data cache). In order to avoid caching you can set the first address bit. Nios has 32bit address space but it can address only 2GB, because the first address bit is used to bypass data cache. To make uncached memory access you can: unsigned char *pmem = (unsigned char *)(0x80000000 | MEMORYNAME_BASE); - Altera_Forum
Honored Contributor
I don't exactly have that line. What seems to be the same is# define ONCHIP_MEM_BASE 0x8000
It's only a matter of name but there's a matter of address too. I use a 32000 bytes memory so I need 15 bits for the address. Does 0x8000 mean that the memory is uncached and the 15 LSBs represant the address? So I could read the nth word with printf("%d\n",ONCHIP_MEM_BASE+(n-1))? I tried that in the HelloWorld template but a window open claiming "Errors exist in a required project." I don't have more information. What can I do? - Altera_Forum
Honored Contributor
The 32nd NiosII Processor Data Master address bit is used to make uncached memory-mapped peripheral access. It means whichever slave you want to make uncached access, either a memory or another device, must have it's address bit 31 set to 1, that's why we do ADDR | 0x80000000 (pay attention to the number of zeroes used here!). So if you have
# define ONCHIP_MEM_BASE 0x8000 when you access the address 0x80008000 you will be making an uncached access to your memory. The line you suggested would print and address rather than memory content, and it would cache its contents. printf("%d\n",ONCHIP_MEM_BASE+(n-1)) You should make it a pointer of the correct type and then deference it, like this: printf("%d\n",*((int *)((0x80000000|ONCHIP_MEM_BASE)+(n-1)*4))); Note that I'm multiplying the index by four, that's because I'm casting the address to int, then each new int would be located for bytes apart from the other. You might as well prefer to use my explicit pointer aproach, where you would int *pmem = (int *)(0x80000000 | ONCHIP_MEM_BASE); and then printf("%d\n",pmem[n-1]); which would be much more convenient. The "Errors exist in a required project." should be further researched upon in order to be fixed. You should look for additional info in the "Problems" tab or in the "Console" tab. In the "Problems" tab you may see old compilation errors, so you may want to delete the errors before each compilation. In the "Console" tab you should click on the "screen" icon in the right side of the tabs bar, with the tooltip "Display Selected Console", and the select the console containing the compiler output. You may look for compilation errors there. I'm not very comfortable with Eclipse. If you prefer you can switch to the command line interface in order to debug. You can right click the project and select "Nios II" and then "Nios II Command Shell" in order to open a console where you can work from. You can then "make clean_all; make" and look for errors there. This is my preferred work flow (though I don't even open Eclipse).