3 Replies Latest reply on May 31, 2019 12:11 PM by ChMa_3922746

    How to Use SPI Flash for General Storage? (CYW943907AEVAL1F)

    ChMa_3922746

      I have been storing user data in APP DCT.  However, it appears that the avail. space is limited to ~ 4KB on the CYW943907AEVAL1F.

       

      Therefore, I am interested in using free sectors in the 8MB of SPI Flash for storing nonvolatile data.  I have dug around the forum and the SDK code and haven't come up with a good strategy for this.  I have come across spi_flash.c, but it isn't clear to me how to preserve sectors in Flash during the build for this, or how to access this space using the routines provided.

       

      Has anyone done this, and if so, do you have any recommended methods/function calls?  I think the minimum would be:

      1. Allocate sectors in SPI flash during build.

      2. SPI flash functions to:  erase sector, read sector and write sector.

       

      Thanks!

        • 1. Re: How to Use SPI Flash for General Storage? (CYW943907AEVAL1F)
          RaktimR_11

          We usually recommend to store the data in APP DCT for this type of use-case. As you need to store a large amount of data, you can investigate the staging area concept for sflash. sflash related details for WICED SDK can be found at SFLASH support addition in WICED

          1 of 1 people found this helpful
          • 2. Re: How to Use SPI Flash for General Storage? (CYW943907AEVAL1F)
            ChMa_3922746

            Thank you.  I did run across that thread.  Are there any further details or examples of the function calls that would be made to write/read free sectors of the sflash device? 

            • 3. Re: How to Use SPI Flash for General Storage? (CYW943907AEVAL1F)
              ChMa_3922746

              Here is an update:  I did examine further the very informative file \waf\sflash_write\sflash_write.c  I was able to use its examples to decipher the following:

               

              1.  First, initialize the sflash for writing (sflash_handle is declared in the header file "spi_flash.h")

              #include "../../libraries/drivers/spi_flash/spi_flash.h"

              init_sflash( &sflash_handle, 0, SFLASH_WRITE_ALLOWED)

              2. The functions to read, sector erase and write to sflash are as follows. 

              sflash_read(&sflash_handle, addr_start, buffer, num_bytes_read);

              sflash_sector_erase(&sflash_handle, sector_addr)

              sflash_write(&sflash_handle, addr_start, buffer, num_bytes_write)

               

              The other missing piece was the answer to "what sectors are avail"?  The file /platforms/CYW943907AEVAL1F/ota2_image_defines.mk provides a bit of background.

               

              I see that just before 0x600000, some sectors may be unused.  For the bit of memory I need, 0x580000 to 0x600000 works just fine.  However, it won't work very well if the linker ends-up plunking down some data in that space.

               

              Question:  Is there a way to block the linker from putting anything in a specific range (say 0x580000 to 0x600000)?  My forte is definitely not linkers.  If anyone knows, it would be greatly appreciated!