6 Replies Latest reply on Mar 2, 2020 11:15 PM by MdNa_4387646

    Sector Erase concern in S70FL01GS.

    MdNa_4387646

      Hello Mam ApurvaS_36

       

      I am facing problem in Sector Erase command.

      My code given below to erase sector:

      //--------------------------------------------------------------------------------------

      u16 EraseFlashSector1(u32 Addr)

      {

      char tmpStr[50];

      int rVal=0;

      int RetryCount = 0;

      Print_0("\r\nErase_2Nd_ChipSector.......................\r\n");

      Flash2_Select();  FlashSPI_SendByte(0x06);   Flash2_DeSelect();//Write Enable

       

       

      Flash2_Select();

      FlashSPI_SendByte(0xDC);//Sector erase

      WriteAddr32(Addr);

      Flash2_DeSelect();

       

       

      Flash2_Select();

      FlashSPI_SendByte (0x05);//Read Status Register

       

       

      RetryCount=0;

      while(1)

      {

      rVal = FlashSPI_RecvByte();

      if((rVal & 0x01) == 0)

      {

      Flash2_DeSelect();

      Print_0("...............................Sector Erase Error....\r\n");

      return 0;

      }

       

       

      RetryCount++;

      if(RetryCount > FLASH_OP_RETRY_MAX*100)

      {

      sprintf(tmpStr,"RetryCount: %d\r\n",RetryCount); Print_0(tmpStr);

      Flash2_DeSelect();

      Print_0("...............................Sector Erase error....\r\n");

      return 0;

      }

      WAIT_TIME;

      }

      return (u16) SUCCESS;

      }

      //--------------------------------------------------------------------------------------------------------

       

      Please correct me where i am wrong.

        • 1. Re: Sector Erase concern in S70FL01GS.
          ApurvaS_36

          Hi Md Nasir,

           

          Thank you for contacting Cypress Semiconductor. I found the following issues with the code -

           

          • The following if condition -

          if((rVal & 0x01) == 0)

          {

          Flash2_DeSelect();

          Print_0("...............................Sector Erase Error....\r\n");

          return 0;

          }

          should return a SUCCESS and print Sector Erase Success.

           

          • The following if condition -

          if(RetryCount > FLASH_OP_RETRY_MAX*100)

          {

          sprintf(tmpStr,"RetryCount: %d\r\n",RetryCount);

          Print_0(tmpStr);

          Flash2_DeSelect();

          Print_0("...............................Sector Erase error....\r\n");

          return 0;

          }

          should return a FAILURE. If 0 means failure for your application then this snippet is correct. In that case, the previous if condition should be changed.

           

          • The program will never reach this statement return (u16) SUCCESS;
          • Could you please let me know the values of FLASH_OP_RETRY_MAX and WAIT_TIME macros?
          • Please elaborate a little more on the exact issue that your are facing with Sector Erase operation.
          • Is it possible to provide logic analyzer waveforms for the operation? If yes, please provide.

           

          Best Regards,

          Apurva

          1 of 1 people found this helpful
          • 2. Re: Sector Erase concern in S70FL01GS.
            MdNa_4387646

            Hello, Mam

            Thank you so much for your helpful response.

             

            #define FLASH_OP_RETRY_MAX 600

            #define WAIT_TIME vTaskDelay(5)

             

            The following if condition is only use for  timeout purpose when erase operation taking over time.

            if(RetryCount > FLASH_OP_RETRY_MAX*100)

            {

            sprintf(tmpStr,"RetryCount: %d\r\n",RetryCount);

            Print_0(tmpStr);

            Flash2_DeSelect();

            Print_0("...............................Sector Erase error....\r\n");

            return 1;

            }

            -----------------------------------------------------------------------------------------------------------

            Erase Whole Flash API is working Fine Given Below U can Check:-

            //-------------------------------------------------------------------------------------------------------

            u16 EraseWholeFlashCs1()

            {

                 int rVal=0;

                 int RetryCount = 0;

                 Print_0("EraseWholeFlashCs1.....\r\n");

                 Flash1_Select(); FlashSPI_SendByte(0x06); Flash1_DeSelect();

             

                 Flash1_Select();

                 FlashSPI_SendByte(0xC7);

                 Flash1_DeSelect();

             

             

                 Flash1_Select();

                 FlashSPI_SendByte (0x05);//Read Status Register

                 RetryCount=0;

                 while(1)

                 {

                      rVal = FlashSPI_RecvByte();

                      if((rVal & 0x01) == 0)

                      {

                           Flash1_DeSelect();

                           return 0;

                      }

                      RetryCount++;

                      if(RetryCount > FLASH_OP_RETRY_MAX*100)

                      {

                           Flash1_DeSelect();

                           Print_0("...............................Whole Flash Erase error....\r\n");

                           return 3;     //Sector erase error

                      }

                      WAIT_TIME;WAIT_TIME;

                    }

            }

            //----------------------------------------------------------------------------------------------------

            Please correct me where i am wrong.

            i am using (0xDC) command to Erasing Sector.

            1 of 1 people found this helpful
            • 3. Re: Sector Erase concern in S70FL01GS.
              ApurvaS_36

              Hi Md Nasir,

               

              • Could you please elaborate a little on the failure occurring during sector erase operation? As in, is the WEL and WIP bits of the Status Register remaining HIGH indefinitely or are any of the error bits of the Status Register getting set or Status Register values are fine but the sector is not getting erased or any other scenario is occurring?
              • I would like to point out that S70FL01GS part has two CS# lines. I notice in your code that the function name for chip erase EraseWholeFlashCs1() has Cs1 at the end and Flash1_Select() and Flash1_DeSelect() APIs are being called inside this function to control CS# lines (makes sense). But for sector erase function, function name is EraseFlashSector1(), however Flash2_Select() and Flash2_DeSelect() APIs are being called inside it to control the CS# line. Could you please confirm whether the correct CS# line is being toggled for the desired die upon which sector erase operation is supposed to be performed?
              • As you already know, Sector Erase command requires address and Bulk Erase (chip erase) command does not require address. Since the chip erase command is working, could you please recheck your WriteAddr32(Addr); function which is being called inside the u16 EraseFlashSector1(u32 Addr) function? If the WriteAddr32() function is not working as desired you can try sending the address (byte by byte) using the same API which is being used to send the commands (FlashSPI_SendByte()). You can take help from following snippet to shift the address bytes -

                          SPIDATA_4 = (BYTE)((Addr >> 24) & 0x000000FF);

                          SPIDATA_3 = (BYTE)((Addr >> 16) & 0x000000FF);

                          SPIDATA_2 = (BYTE)((Addr >> 8) & 0x000000FF);

                          SPIDATA_1 = (BYTE)(Addr        & 0x000000FF);

              • Can you provide us the SPI signals waveforms for u16 EraseFlashSector1(u32 Addr) function?
              • Is any kind of block protection enabled for either of dies?
              • You can download our Low Level Driver for Serial Flash devices from here and try to get an idea about the implementation.

               

              Best Regards,

              Apurva

              1 of 1 people found this helpful
              • 4. Re: Sector Erase concern in S70FL01GS.
                MdNa_4387646

                Hello mam,

                I Already use separate  pin for chip selection.

                #define Flash1_Select()  FlashSPI_CS1_Low();/** Select the Flash */

                #define Flash1_DeSelect() FlashSPI_CS1_High ();/** DeSelect the Flash */

                 

                 

                #define Flash2_Select()  FlashSPI_CS2_Low();/** Select the Flash */

                #define Flash2_DeSelect() FlashSPI_CS2_High ();/** DeSelect the Flash */

                 

                void FlashSPI_CS1_Low (void)

                {

                    /* SSEL is GPIO, set to high.  */

                    LPC_GPIO0->FIOPIN &= ~(1 << 16);

                }

                 

                 

                void FlashSPI_CS2_Low (void)

                {

                    /* SSEL is GPIO, set to high.  */

                    LPC_GPIO2->FIOPIN &= ~(1 << 4);

                }

                 

                void FlashSPI_CS1_High (void)

                {

                    /* SSEL is GPIO, set to high.  */

                    LPC_GPIO0->FIOPIN |= (1 << 16);

                }

                 

                 

                void FlashSPI_CS2_High (void)

                {

                    /* SSEL is GPIO, set to high.  */

                    LPC_GPIO2->FIOPIN |= (1 << 4);

                }

                 

                I am using that logic for giving address byte by byte:-

                 

                static inline void WriteAddr32(u32 Addr)

                {

                FlashSPI_SendByte(Addr>>24);

                FlashSPI_SendByte(Addr>>16);

                FlashSPI_SendByte(Addr>>8);

                FlashSPI_SendByte(Addr>>0);

                }

                 

                Please tell where i am wrong?

                Can u send me function for writing please in c language?

                 

                Thank you so much for your helpful immediate response.

                • 5. Re: Sector Erase concern in S70FL01GS.
                  ApurvaS_36

                  Hi Md Nasir,

                   

                  Thank you for your response. Can you please answer my below questions point wise?

                  • Can you please provide us the logic analyzer wave forms for the SPI signals for sector erase operation function?
                  • I would like to repeat my first question from the previous response. Could you please elaborate a little on the type of failure being encountered during sector erase operation? How are you concluding that the sector erase operation has failed? Is the WIP bit never going LOW? Are you reading the erased sector back to confirm that the data stored in it is not 0xFF?
                  • Is any kind of block protection enabled for either of dies? Is the sector erase operation failing for all sectors on both dies or only some sectors in a single die?
                  • Can you please confirm that the correct CS# line is being toggled? What is the significance of '1' at the end of the u16 EraseFlashSector1(u32 Addr) function name? I see that the CS#2 line is being toggled inside this function by calling the Flash2_Select(); and Flash2_DeSelect(); functions. Please confirm that this is correct according to your application.

                   

                  >>Can u send me function for writing please in c language?

                  Are you looking for a sample implementation for Page Program operation for this device? If yes, I would like to suggest you to download our Low Level Driver for SPI Flash devices from the following link - sLLD link. Please note that you will have to edit the HAL file to add your micro-controller specific APIs into it. It has a help document inside it that contains all the necessary information and instructions. You can also use this driver for performing sector erase operation.

                   

                  Please let me know your further updates and queries.

                   

                  Best Regards,

                  Apurva

                  1 of 1 people found this helpful
                  • 6. Re: Sector Erase concern in S70FL01GS.
                    MdNa_4387646

                    Erasing Problem Resolved.

                    Thanks you so much.