- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello. I am doing a project regarding DMA. However I need to use flash memory on the DE2 Board. I have done the instantiation for the flash but I cannot use because it always return zero for the function alt_flash_open_dev().
Spec: Altera DE2 Board with 1Mb flash memory. Can I ask if it is possible to have someone to provide me a sample simple C-programming code on how to use flash? Like from beginning such as from library part till the end. Just a simple one will do. Because I tried so many but cant get it to work. I left lots of threads regarding this but none is helping. My code just to test alt_flash_open_dev() --- Quote Start --- # include <stdio.h> # include <stdlib.h># include <string.h># include "system.h" # include "altera_avalon_pio_regs.h" # include "alt_types.h" # include "altera_avalon_performance_counter.h"# include "sys/alt_flash.h" # include "sys/alt_flash_dev.h" int main(void) { alt_flash_fd* fd; alt_u8 flashname[30]; strcpy(flashname, "/dev/ext_flash"); fd = alt_flash_open_dev("/dev/ext_flash"); if (fd) { printf(" -Successfully opened %s\n", flashname); } else{ printf("The end\n");} return 0; } --- Quote End --- Thanks!Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If the very first function alt_flash_open_dev fails, the problem is not with application code,
unless you mistyped the device name However I'd use the define provided by system.h instead of "/dev/ext_flash"; I think in your case is it is EXT_FLASH_NAME Some points you can check: 1. Are you sure the flash memory is working? Can you test it with another sample application provided with the DE2 board? 2. Manually test the flash memory I suppose this is a parallel CFI flash. So you can write the autoselect sequence at EXT_FLASH_BASE and check if you can read vendor and product ID. 3. Debug into alt_flash_open_dev and find out where it fails. Compile all the project in debug mode, place a breakpoint on this function and step into it until you get to a 'return error'- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the reply.
This is part of the code from system.h --- Quote Start --- /* * ext_flash configuration * */ # define EXT_FLASH_NAME "/dev/ext_flash"# define EXT_FLASH_TYPE "altera_avalon_cfi_flash"# define EXT_FLASH_BASE 0x01100000# define EXT_FLASH_SPAN 1048576# define EXT_FLASH_SETUP_VALUE 45# define EXT_FLASH_WAIT_VALUE 160# define EXT_FLASH_HOLD_VALUE 35# define EXT_FLASH_TIMING_UNITS "ns"# define EXT_FLASH_UNIT_MULTIPLIER 1# define EXT_FLASH_SIZE 1048576# define ALT_MODULE_CLASS_ext_flash altera_avalon_cfi_flash --- Quote End --- 1. Yes, I tried before using the Control Panel from the CD. 2. How to manually test the flash? Sorry cause I am starting from zero, so I am very new in this. 3. I tried that before but I dont know how to place breakpoint then step into it, so I dont have any luck in this. Please assist. Thanks.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- 2. How to manually test the flash? Sorry cause I am starting from zero, so I am very new in this. --- Quote End --- Assuming your flash memory has a 16bit data interface /* enter autoselect mode */ IOWR(EXT_FLASH_BASE, 0x555, 0xaa); IOWR(EXT_FLASH_BASE, 0x2aa, 0x55); IOWR(EXT_FLASH_BASE, 0x555, 0x90); int Manufacturer_ID = IORD(EXT_FLASH_BASE, 0); int Device_ID = IORD(EXT_FLASH_BASE, 1); /* back to normal mode (memory data read) */ IOWR(EXT_FLASH_BASE, 0, 0xff); Search the web for the specific flash memory datasheet to have further information and the ID codes. About breakpoints and step into the code: what dev tools do you use? If Nios IDE, you simply place the breakpoint by double clicking on the left side of source code window. Then the Nios program will stop there when the instruction is executed (you must start the code with Debug as... -> Nios hardware). How are you debugging now?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, I can successfully use the flash now. The problem is not from coding or setting but the board itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- Thanks, I can successfully use the flash now. The problem is not from coding or setting but the board itself. --- Quote End --- Sir, I am also trying in the same way. But, flash open is always returning zero. I have interfaced S29GL032 (Actually 4MB but using only 1MB by connecting MSB address lines on board to ground) to EP3C25E with 50MHz external crystal (No PLL). Please help regarding this problem. Thanks in advance. Thanks and Regards, Srinivas M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sir,
I am also trying in the same way. But, flash open is always returning zero. I have interfaced S29GL032 (Actually 4MB but using only 1MB by connecting MSB address lines on board to ground) to EP3C25E with 50MHz external crystal (No PLL). Please help regarding this problem. Thanks in advance. Thanks and Regards, Srinivas M- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My problem is regarding the setting in the SOPC and the top level entity file in Quartus II. I am not sure in your case, you can use 1MB instead of 4MB in that way. You need to make sure you are using the right controller. what board are you using?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- My problem is regarding the setting in the SOPC and the top level entity file in Quartus II. I am not sure in your case, you can use 1MB instead of 4MB in that way. You need to make sure you are using the right controller. what board are you using? --- Quote End --- Sir, Thanks for the reply. It is an custom board. Can you clearly tell me the setting in SOPC and Top level entity in Quartus. Interfacing's are correct and tested by taking address, data and control lines as io lines instead of CFI Flash. Thanks in advance, Srinivas M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using Altera DE2 Board with 4MB Flash attached.
My setting in SOPC: Address Width: 22-bit Data Width: 8-bit Timing: Setup: 40 Wait: 160 Hold: 40 Unit: ns Remember to add in Avalon MM Tristate Bridge. For the top level entity: Open the .vhdl or .v file generated by the SOPC, find for your system, see the code generated and set according to it.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sir,
Thanks for the reply. My settings are also same like you. Even though it is not working. I am using Custom Board with 1MB Flash attached. My setting in SOPC: Address Width: 20-bit Data Width: 8-bit Timing: Setup: 45 Wait: 160 Hold: 45 Unit: ns Already added in Avalon MM Tristate Bridge. For 1MB i am using 20-bit and you are using 22-bit for 8MB. Is their any mistake here? Srinivas M- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i think 20-bit should be fine because different size. Try change the setup time and hold time to 40ns each.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sir,
Thanks for the reply. I have worked with all different timings, even though same result. My doubt about 22-bit is, it can assign only 4MB data using 8-bit data. How you are able to configure 8MB with 22-bit address? Another doubt is their any fixed Base Address for CFI Flash? Srinivas M- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, typo error, is 4MB.

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