AnsweredAssumed Answered

How to use QSPI-NAND flash for Non Volatile memory to store backup data while system configured for QSPI boot.

Question asked by Abdul Nihad on Dec 4, 2013
Latest reply on Jan 3, 2014 by Edward Karpicz

Hi,

 

I have developed an mqx 4.0.2 based audio application using vybrid tower system.I am using DS5 and Vybrid tower system for my development. my application boot from QSPI-NAND flash.

In my application I want to save the state of my application in QSPI-NAND flash. SO I need to do two things here,

1) Boot the system from QSPI-NAND Flash

2) Store/save state of my application in QSPI Flash while running.

 

I am using qspi sample code from MQX (C:\Freescale\Freescale_MQX_4_0\mqx\examples\qspi) to save data in QSPI flash.

 

Is this possible to use QSPI for both purpose(booting and storing) together at a time.

 

For storing data I want to use 4KB sector.

 

It shows busy when I try to write my data in QSPI Flash after booting and running my application from QSPI FLash.

Do I need to do erase before wring any data. In this case How to erase only one sector of size 4 KB (). I tried with below code but not erasing the sector.

 

#define CMD_PAR_SEC_ERASE       0x20

#define QuadSPI_CHIP_4K_SEC_ERASE  QuadSPI_SEQ(QuadSPI_INST_CMD, QuadSPI_SINGLE_PAD, CMD_PAR_SEC_ERASE)

#define NVM_ADDR                 0x20030000

#define NVM_SEC_ADDR            0x030000

qspi_mem_4kSec_erase(p->qspifd,NVM_ADDR, NVM_SEC_ADDR);

 

int_32 qspi_mem_4kSec_erase(MQX_FILE_PTR qspifd, uint_32 addr, uint_32 sector_addr)

{

    _mqx_int result;

    uint_8 buffer[4+QuadSPI_ADDR_BYTES] = {0};

    uint_8_ptr src_ptr = (uint_8_ptr)sector_addr;

 

    /* Enable flash memory write */

    qspi_mem_set_write_en(qspifd, addr, TRUE);

 

    /* Send erase command */

    buffer[0] = QuadSPI_CHIP_4K_SEC_ERASE & 0xFF;

    buffer[1] = (QuadSPI_CHIP_4K_SEC_ERASE >> 8) & 0xFF;

    buffer[2] = QuadSPI_LOOKUP_STOP & 0xFF;

    buffer[3] = (QuadSPI_LOOKUP_STOP >> 8) & 0xFF;

    sector_addr_to_data_buf((uint_32) src_ptr, &(buffer[4]));

 

    /* Write instruction */

    result = fwrite(buffer, 1, 4 + QuadSPI_ADDR_BYTES, qspifd);

 

    /* Wait till the flash is not busy at program */

    qspi_mem_wait_for_not_busy(qspifd);

 

    printf("Erase chip ... ");

    if (result < 0) {

        printf("ERROR\n");

        return -1;

    }

 

    printf("QuadSPI Successfully Erase Flash\n");

    return 0;

}

 

BR/-

Nihad

Outcomes