Cypress FX3 SDK EXAMPLE serial interface GpioSpiFlash

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 Hi,

   

why is the function GetSpiFlashStatus reading the status of th SPI flash module twice?

   

The checks at the end of the do while loop just compare the first received byte concerning on BUSY and WIP flags. Also the datasheet of the M25P40 is telling no need to read the status twice at the instruction set description. 

   

But what I have identified is, that it results in wrong writes if I read the status at that place just once.

   

Can anybody explain me that behaviour, please?

   

thanks, 

   

Lumpi

0 Likes
7 Replies
Anonymous
Not applicable

Hi Lumpi,

   

Are you talking about CyFxFlashProgSpiWaitForStatus function in USBFlashProg example project?.

   

Please let me know.

   

Thanks,

   

sai krishna.

0 Likes
Anonymous
Not applicable

Hi Sai Krishna,

   

e. g. this function but it is all the time the same function in Project:

   

- cyfxflashprog.c

   

- cyfxusbspidmamode.c

   

- cyfxusbspigpiomode.c

   

- cyfxusbspiregmode.c

   

- cyfxuac.c

   

/* Wait for the status response from the SPI flash. */
CyU3PReturnStatus_t
CyFxSpiWaitForStatus (
        void)
{
    uint8_t buf[2], rd_buf[2];
    CyU3PReturnStatus_t status = CY_U3P_SUCCESS;

    /* Wait for status response from SPI flash device. */
    do
    {
        buf[0] = 0x06;  /* Write enable command. */

        CyFxSpiSetSsnLine (CyFalse);
        status = CyFxSpiTransmitWords (buf, 1);
        CyFxSpiSetSsnLine (CyTrue);
        if (status != CY_U3P_SUCCESS)
        {
            CyU3PDebugPrint (2, "SPI WR_ENABLE command failed\n\r");
            return status;
        }

        buf[0] = 0x05;  /* Read status command */

        CyFxSpiSetSsnLine (CyFalse);
        status = CyFxSpiTransmitWords (buf, 1);
        if (status != CY_U3P_SUCCESS)
        {
            CyU3PDebugPrint (2, "SPI READ_STATUS command failed\n\r");
            CyFxSpiSetSsnLine (CyTrue);
            return status;
        }

        status = CyFxSpiReceiveWords (rd_buf, 2);
        CyFxSpiSetSsnLine (CyTrue);
        if(status != CY_U3P_SUCCESS)
        {
            CyU3PDebugPrint (2, "SPI status read failed\n\r");
            return status;
        }

    } while ((rd_buf[0] & 1)|| (!(rd_buf[0] & 0x2)));

    return CY_U3P_SUCCESS;
}

   

regards,

   

lumpi

0 Likes
Anonymous
Not applicable

 Hi,

   

 

   

I modified the spiregmode example, and read only one status byte inside WaitforStatus (I modified the Read Status command as in the below pasted code snippet). I was able to succeffully read and write from the SPI flash. I believe you are aware of the fact that befor ewriting to SPI flash, you need to erase the SPI flash using 0xC2 command. I hope you are doing the erase before writing to the flash. If not please do so.

   

 

   

   

 buf[0] = 0x05;  /* Read status command */

   

CyU3PSpiSetSsnLine (CyFalse);

   

status = CyU3PSpiTransmitWords (buf, 1);

   

if (status != CY_U3P_SUCCESS)

   

{

   

            CyU3PDebugPrint (2, "SPI READ_STATUS command failed\n\r");

   

            CyU3PSpiSetSsnLine (CyTrue);

   

            return status;

   

}        
status = CyU3PSpiReceiveWords (rd_buf, 1);

   

CyU3PSpiSetSsnLine (CyTrue);

   

if(status != CY_U3P_SUCCESS)

   

{

   

            CyU3PDebugPrint (2, "SPI status read failed\n\r");

   

            return status;

   

}

   

} while ((rd_buf[0] & 1)|| (!(rd_buf[0] & 0x2)));

   

 

   

Regards,

   

Gayathri

0 Likes
Anonymous
Not applicable

Hi,

   

I am using exactly the same code and yes I am erasing flash. I just have that problem in case of writing a huge amount of data into flash. e. g. 2MB. Then most of the data is correct but some small blocks are corrupted.

   

regards,

   

lumpi

0 Likes
Anonymous
Not applicable

Hi Lumpi,

   

We tested write and read operations with 4KB of data only.

   

We will test these operations for large amount of data (like as you said 2MB) and let you know.

   

Thanks,

   

sai krishna.

0 Likes
Anonymous
Not applicable

Hi Sai Krishna,

   

I have now the issue found. I had a timeout counter in the loop and I have not checked the error condition. In case of erase flash it needs a very long time till busy flag will be deasserted. Now I have a longer posiible timeout and also I check and return if a timout error occurs.

   

The problem was, that in case of reading one byte the timeout was to short and in case of two times reading the status the timeout was enough. So now I changed it to reading one byte with a wise timout.

   

 

   

Thanks,

   

lumpi

0 Likes
Anonymous
Not applicable

Hi Lumpi,

   

Good to hear that 🙂

   

Thanks,

   

sai krishna.

0 Likes