1 Reply Latest reply on Dec 26, 2018 9:43 PM by SudheeshK_26

    Bug in driver

      Hi,

       

      I'm using S25FL256LAG as an external flash, and I found a bug in the driver that you supply:

      https://community.cypress.com/servlet/JiveServlet/download/171303-39906/slld_v16.2.1.zip

      In file slld.c, function slld_WriteOp(), you check whether the size is > PAGE_SIZE and if it is then you divide to multiple "page program" commands.

      The problem is that nobody promises you that I'm starting to write in the beginning of a page. Maybe I want to write 200 bytes (< PAGE_SIZE) but starting from address offset 100 from that page. So that means you have to check if there's enough space left starting from the address i'm writing to, not if size > PAGE_SIZE.

      So the following lines:

      if(len_in_bytes < PAGE_SIZE)

          length = len_in_bytes;

      else

          length = PAGE_SIZE;

       

      Should be replaced with:

       

      uint16_t space_left = PAGE_SIZE - (sys_addr % PAGE_SIZE);

      if(len_in_bytes > space_left)

          length = space_left;

      else

          length = len_in_bytes;

       

        • 1. Re: Bug in driver
          SudheeshK_26

          Hi,

           

          We checked internally and confirmed that this is a bug in our sLLD. Thank you for pointing this out.

          You can replace below lines,

          if(len_in_bytes < PAGE_SIZE)

                length = len_in_bytes;

          else

                length = PAGE_SIZE;

           

          With,

           

          if ((sys_addr % PAGE_SIZE) != 0)

          {

          length = sys_addr % PAGE_SIZE;

           

          if (length > len_in_bytes)

          length = len_in_bytes;

          }

          else

          {

          if(len_in_bytes < PAGE_SIZE)

          length = len_in_bytes;

           

          else

          length = PAGE_SIZE;

          }

           

          Thanks and Regards,

          Sudheesh