- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want a variable to be allocated in the on-chip RAM. I have all sections
(.text, .rodata, .rwdata, .heap, and .stack) in DDR2_SDRAM in the auto-generated linker script. I define a global variable "rawVideo" as I have seen in many examples: --- Quote Start --- int rawVideo __attribute__ ((section (".onchip_ram_100Kbytes.rwdata"))); --- Quote End --- where the on-chip is specified in the system.h:onchip_ram_100kbytes_name "/dev/onchip_ram_100kbytes" Then I copy some data from the flash device to it: --- Quote Start --- alt_read_flash( flash, offset, (void*) ( &rawVideo ), size); --- Quote End --- but the program execution suspends with error when applying the reading command! I made sure that the on-chip RAM size fits on the copy. So am I allocating the variable in a non-existed section or using a wrong syntax?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you reading from a CFI flash device? If so, then there's no need to use the HAL's flash layer to read from it. You can use memcpy (or the like) directly.
If you're reading from a serial flash, are you checking the return code of alt_read_flash? Are you "opening" your flash properly...and checking the return codes there, as well? Best Regards and Good Luck! - Brendan- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am reading from two EPCS64 flash memory serial configuration devices. And I have tried to do this READ operation before and it was correct when assertion the return code. The opening always goes well, but when I read from the flash device to the on-chip RAM something goes wrong.
I am not sure if the target memory section specification is correct or it needs a previous definition in the Nios II IDE. Thanks Brendan- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It could be something more like:int rawVideo __attribute__ ((section ("onchip_ram_100Kbytes")));
The special .* sections are only created for the main memory that you select for text heap and stack.
printf("Address of rawVideo is 0x%8.8x\n",&rawVideo);
It will display the variable address and you can check if it has been placed in the correct section. Why you want this variable there instead of the DDR?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want this variable to represent a raw frame which the algorithm will access frequently. So allocating this frame in the onchip RAM will increase the processing speed.
Here you the linker script: --- Quote Start --- MEMORY { reset : ORIGIN = 0x04120000, LENGTH = 32 epcs_controller : ORIGIN = 0x04141800, LENGTH = 2048 onchip_ram_100Kbytes : ORIGIN = 0x04120020, LENGTH = 99968 ssram : ORIGIN = 0x04000000, LENGTH = 1048576 ddr2_sdram : ORIGIN = 0x00000000, LENGTH = 67108864 } /* Define symbols for each memory base-address */ __alt_mem_epcs_controller = 0x04141800 ; __alt_mem_onchip_ram_100Kbytes = 0x04120000 ; __alt_mem_ssram = 0x04000000 ; __alt_mem_ddr2_sdram = 0x00000000 ; --- Quote End --- I displayed the the variable address and it is correct: --- Quote Start --- Address of rawVideo is 0x041201c8 --- Quote End --- but the read operation cannot be done. The question is must I define the corresponding section (i.e. .onchip_ram_100Kbytes.rwdata), and if so, how can that be done? It seems that I have to modify the linker memory regions using the BSP Build Tools? If there is another way to do so, I will be appreciated if you mention it because I have a deadline to finish my work and I am afraid that the BSP Build Tools software will take much time. Thanks a lot.http://www.qtl.co.il/img/copy.png http://www.qtl.co.il/img/copy.png- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
From what I can see, the rawVideo variable is indeed in the onchip_ram_100Kbytes, so your line worked. You don't need to create a section or modify the linker script.
The fact that the read operation fails must have another reason.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes you are right.
It's a little bit confusing that I could do the transfer operation from the flash to the SDRAM, but I couldn't do so to the on-chip RAM! Anyway thanks for giving your time.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could you compile the memory test example in the IDE (putting rodata/rwdata, text stack and heap in the SDRAM) and have it test the onchip ram? That way you'll at least know if the hardware is ok.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Now I know where the failure happens. I did the test for the full span of the onchip RAM but it failed!
The console just show the first msg: --- Quote Start --- Testing RAM from 0x4120000 to 0x4120100 --- Quote End --- then the program stops responding. So I retested it starting with offset equal to 16 KByte (which is the 8 KByte instruction cache and 8 KByte data cache), and the test was successful. I didn't know that the cache and the onchip RAM defined in SOPC builder are dependent (so the 16 KByte cache are included in the 100 KByte RAM !) However, I still can't read from the flash device into a well allocated variable on the onchip RAM. So I am thinking of separating the onchip RAM into two pieces and store my variable in one of them. And still the question why the attribution doesn't allocate the variable properly and overlapped the cache?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The cache and the on-chip memory are not overlapping and are independant so I don't think that this is the reason. What offset are you talking about?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry for miss-explanation. I was wrong about the cache issue.
The memtest fails between the following two addresses: --- Quote Start --- 0x04120000 - 0x0412013F (0x04120000 is the OnChip base address and its span is 100000) --- Quote End --- and passes for the rest of the ram range.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aren't you using the onchip_ram_100Kbytes for something else? Check that the Nios exception vectors are not set to that memory (double click on the Nios CPU in SOPC builder).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes I am using it for the reset vectors which starts at 0x04120000 and ends at 0x0412001f, and the exception vectors which starts at 0x04120020 and seems to end at 0x0412013f. So if the exception vectors ends at this address and the variable is located after it, there must not be a problem writing to it!
I still can't find a clear memory map for the design. http://www.qtl.co.il/img/copy.png- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could you try and put the reset and exceptions vectors to the SDRAM and see if it still hangs? This could help us determine if the problem comes from here or not.
Even if the variable is away from the vectors list, a software bug (such as a negative offset) could overwrite something important. I have another question. In your linealt_read_flash( flash, offset, (void*) ( &rawVideo ), size);
what is the value of "size"? If its greater than 4, you overwrite unnallocated memory space.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Well it seems that you were right, a negative offset is being added to the variable address!
The "size" value is less than a region block size ( which is 65535 Byte ) and I have tried the read operation before using the same size, to different memory device than the onchip RAM, and it passed successfully. Maybe I will change my strategy. Thanks for paying attention- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is something else. With yourint rawVideo __attribute__ ((section (".onchip_ram_100Kbytes.rwdata")));
line, you are only allocating an integer, which is 4 bytes. This means that each time you do a read of more than 4 bytes, you overwrite a part of memory that could be used for something else, causing random crashes. You need to allocate a buffer big enough for what you want to do. Something like:char rawVideo __attribute__ ((section (".onchip_ram_100Kbytes.rwdata")));
and then remove the & in front of rawVideo in the read call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for mentioning that too.:)

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page