Forum Discussion

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

NIOS SOPC Flash Memory Interface (CFI)

I am trying to read the Query values from a CFI compliant flash device, a PC28F128P30b85.

I have implemented a NIOS SOPC solution with a tri-state bridge module and cfi-flash module. The cfi-flash module is configured for Intel256P30 so has 23 address bits and 16 data bits.

When I access the Query bytes using IORD_8DIRECT(CFI_FLASH_BASE, i) I only get the even bytes returned. I.e. only "Q" and "Y", The same happens using IORD_16DIRECT(CFI_FLASH_BASE, i).

What must I change to ensure that I am addressing the device correctly?

Any ideas or sample code very welcome!

5 Replies

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

    one common mistake is to setup the cfi for 16 bit mode but connect it as 8 bit device.

    when you have a 16 bit device, then you have no address bit 0 as the would always be 0 indicating even address access.

    so check wheter you have connected nios a1 to flash a0.

    some flash device have adressbit [-1] that is used in 8 bit mode and is a databit in 16bit mode
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks to MSchmitt I made a bit of progress with his suggestion.

    I can now do alt_flash_open_dev(CFI_FLASH_NAME).

    But I still can't access the QUERY bytes.

    Here's a simplified version of my code ...# define FLASH_CMD_BUFFERED_PROGRAM_SETUP 0xE8# define FLASH_CMD_BUFFERED_PROGRAM_CONFIRM 0xD0# define FLASH_CMD_BLOCK_ERASE_SETUP 0x20# define FLASH_CMD_BLOCK_ERASE_CONFIRM 0xD0# define FLASH_CMD_BLOCK_LOCK_SETUP 0x60# define FLASH_CMD_BLOCK_LOCK 0x01# define FLASH_CMD_BLOCK_UNLOCK 0xD0# define FLASH_CMD_CLEAR_STATUS 0x50# define FLASH_CMD_READ_DEVICE_ID 0x90# define FLASH_CMD_RESTORE_READ_MODE 0xFF# define FLASH_CMD_READ_STATUS 0x70# define FLASH_CMD_READ_QUERY 0x98

    int main()

    {

    int i;

    alt_putstr("Nios II welcomes you to Spyder Q module !\n");

    alt_putstr("\n");

    IOWR_16DIRECT(CFI_FLASH_BASE, 0x55, FLASH_CMD_READ_QUERY);

    for (i=0x00; i<=0x1f; i+=2)

    {

    alt_printf("QRY=x%x ", IORD_16DIRECT(CFI_FLASH_BASE, i));

    }

    alt_putstr("\n==\n");

    IOWR_16DIRECT(CFI_FLASH_BASE, 0x0, FLASH_CMD_READ_DEVICE_ID);

    for (i=0x0; i<=0x1F; i+=2)

    {

    alt_printf("DEV=x%x ", IORD_16DIRECT(CFI_FLASH_BASE, i));

    }

    }

    Where i expect the Query data to be printed, I get exactly the same data as for the FLASH_CMD_READ_DEVICE_ID. The FLASH_CMD_READ_DEVICE_ID data agrees with the spec for my device.

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

    Do you have a Nios with Datacache ?

    If yes, make shure that you use the cache work around.

    you could easily test the cace problem by compiling nios without data cache and see if anything changes.

    there is a HAL function for remaping or something like that

    you could also set adr. bit 31 as cache bypass.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The "QRY" bytes are at offset x10. When I used the offset x20 in my code all was well. I needed to interpret the offset as a word address.

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

    IOWR and IORD use word offsets (32 bit word offsets)

    The _8/16/32DIRECT macros use byte offsets.

    My preference are the _xxDIRECT macros since the master is providing byte addresses to the fabric. The DIRECT macros give you control over the byte enables too.