Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

URGENT: Flash memory

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!

13 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- 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?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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'