1 Reply Latest reply on Sep 10, 2015 9:15 AM by abuch

    Sflash write on wiced with sdk 2.4.1

      I am trying to write values to SFLASH but it is not writing. When I read SFLASH before and after writing, I get the same values.  Therefore, I think that the problem is in the writing part of code.

      My code is below:

       

       

          uint32_t pos;

          sflash_handle_t sflash_handle;

          data_transfer_area_t data_transfer;

          data_transfer.data[0] = 10;

          data_transfer.data[1] = 200;

          int i = 0;

          for(; i<4*1024;i++)

              data_transfer.data[i] = i+1;

          data_transfer.size = 8*1024;//sizeof(data_transfer.data[0] ) * 2;

          bootloader_app_header_t image_header;

       

       

          /* Initialise the serial flash driver */

          init_sflash( &sflash_handle, 0, SFLASH_WRITE_ALLOWED );

       

       

          sflash_read( &sflash_handle, 0, &image_header, sizeof( image_header ) );

          data_transfer.dest_address = image_header.size_of_app;

       

          /* Write into memory */

          pos = 0;

          while ( pos < data_transfer.size )

          {

              uint32_t write_size = ( data_transfer.size - pos > WRITE_CHUNK_SIZE )? WRITE_CHUNK_SIZE : data_transfer.size - pos;

              sflash_write( &sflash_handle, pos + data_transfer.dest_address, &data_transfer.data[pos], write_size );

              pos += write_size;

              watchdog_kick( );

          }

       

       

          /* Read data from SPI FLASH memory */

          pos = 0;

          while ( pos < data_transfer.size )

          {

              uint32_t read_size = 4*1024;//sizeof(data_transfer.data[0] );//( data_transfer_receive.size - pos > sizeof(Rx_Buffer) )? sizeof(Rx_Buffer) : data_transfer_receive.size - pos;

       

       

              sflash_read( &sflash_handle, pos + data_transfer.dest_address, Rx_Buffer, read_size );

       

       

              int i = 0;

              for(; i<12;i++)

                  printf("data %d = %d \r\n", i,Rx_Buffer[i]);

              printf("pos = %lu \r\n------", pos);

       

       

              pos += read_size;

              watchdog_kick( );

       

       

          }

       

       

      Best Regards