ESP8266 Developer Zone The Official ESP8266 Forum 2019-02-03T12:16:47+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=25810 2019-02-03T12:16:47+08:00 2019-02-03T12:16:47+08:00 https://bbs.espressif.com:443/viewtopic.php?t=25810&p=37223#p37223 <![CDATA[Re: SPI Push / Pop Variables]]>


Start -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Address now at: 70000
Buffer00 00 00 00 00 00 00 00
FF FF FF FF FF FF FF FF
Writing: FD FF FF FF


FF FF FF FF FF FF FF FF
FD FF FF FF FF FF FF FF

Start -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Address now at: 70001
Buffer00 00 00 00 00 00 00 00
FD FF FF FF FF FF FF FF
Writing: FE FF FF FF


FD FF FF FF FF FF FF FF
FD FE FF FF FF FF FF FF

Start -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Address now at: 70002
Buffer00 00 00 00 00 00 00 00
FD FE FF FF FF FF FF FF
Writing: FD FF FF FF


FD FE FF FF FF FF FF FF
FD FE FD FF FF FF FF FF

Start -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Address now at: 70003
Buffer00 00 00 00 00 00 00 00
FD FE FD FF FF FF FF FF
Writing: FE FF FF FF


FD FE FD FF FF FF FF FF
FD FE FD FE FF FF FF FF

mode : null



I had to format my types like this..

Code:

#define SPIStackAddress 0x70000
uint32 SPIStackPtr = SPIStackAddress;
typedef enum datatype
{
   COMPLETED = 0,          //00000000000000000000000000000000
   string = 0xFFFFFFFB,         //11111111111111111111111111111100
   integer = 0xFFFFFFFC,        //11111111111111111111111111111010
   booleanFalse = 0xFFFFFFFD,   //11111111111111111111111111111110
   booleanTrue = 0xFFFFFFFFE,    //11111111111111111111111111111101
   EOF =  0xFFFFFFFF,       //11111111111111111111111111111111
}thedatatype;

Statistics: Posted by AgentSmithers — Sun Feb 03, 2019 12:16 pm


]]>
2019-02-03T10:37:39+08:00 2019-02-03T10:37:39+08:00 https://bbs.espressif.com:443/viewtopic.php?t=25810&p=37221#p37221 <![CDATA[Re: SPI Push / Pop Variables]]>
spi_flash_erase_sector(0x60000/SPI_FLASH_SEC_SIZE); =====>>>>> spi_flash_erase_sector(0x60);

Thanks anyways! =]

After doing some read's and writes it seems that SPI flash writes the LSB to the MSB of a 32bit value seems to be written in that order.. Check these examples out


Start -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Address now at: 70000
Buffer inital state = FF FF FF FF FF FF FF FF
Writing: FF FF FF 7F
After: FF FF FF 7F FF FF FF FF

Start -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Address now at: 70001
Buffer currently: FF FF FF 7F FF FF FF FF
Writing: FF FF FF BF
FF FF FF 7F BF FF FF FF

Start -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Address now at: 70002
Buffer currently: FF FF FF 7F BF FF FF FF
Writing: FF FF FF 7F
After: FF FF FF 7F BF 7F FF FF


It seems that I may need to move my Type flags to the start of the 32bits and then bitshift the values accordingly to get the correct results back.

Statistics: Posted by AgentSmithers — Sun Feb 03, 2019 10:37 am


]]>
2019-02-03T09:18:33+08:00 2019-02-03T09:18:33+08:00 https://bbs.espressif.com:443/viewtopic.php?t=25810&p=37217#p37217 <![CDATA[SPI Push / Pop Variables]]> I believe I have a simple error and wanted to reach out to see what it may be. It appears after the write spi_flash_write it returns success but does not return the correct values.
The whole idea of this function is to allow me to push and pop variables like booleans and char arrays.

Additionally, if anyone has a better way to implement this via flash I am totally open for suggestions!

The operations of a Push and Pop flow is FILO (FIRST IN LAST OUT), However, I also want a function similar that is FIFO.

Thank you, everyone!!!

Code:

#define SPIStackAddress 0x70000
uint32 SPIStackPtr = SPIStackAddress;
typedef enum datatype
{
   EOF = 0,
   booleanTrue = 1,
   booleanFalse = 2,
   integer = 2,
   string = 3
}thedatatype;


uint32 pushSPIData(thedatatype ArgType, void * data) //returns 32bit address for L106
{   
   os_printf("Start");
   SPIStackPtr = SPIStackAddress;
   if (ArgType == booleanTrue || ArgType == booleanFalse)
   {
      spi_flash_erase_sector(SPIStackAddress);
      os_printf("Address now at: %x\r\n", SPIStackPtr);
      uint32 ArgTypeData;
      ArgTypeData = ArgType;

      os_printf("Writing: ");
      hex_printf(&ArgTypeData, sizeof(ArgTypeData));      
      os_printf("\r\n\r\n");

      SpiFlashOpResult writeResult = spi_flash_write(SPIStackPtr, (uint32 *)&ArgTypeData, sizeof(ArgTypeData));
      if (writeResult == SPI_FLASH_RESULT_OK)
      {
         os_printf("ThermSettings config written...\r\n");      
      }
      else if(writeResult == SPI_FLASH_RESULT_ERR)
      {
         os_printf("ThermSettings SPI_FLASH_RESULT_ERR...\r\n");
      }
      else if(writeResult == SPI_FLASH_RESULT_TIMEOUT)
      {
         os_printf("ThermSettings SPI_FLASH_RESULT_TIMEOUT...\r\n");
      }

      SPIStackPtr += sizeof(bool);
      os_printf("Address now at: %x\r\n", SPIStackPtr);

      char buffer[8] = {0};
      hex_printf(buffer, 8);
      if (spi_flash_read(SPIStackAddress, buffer, 8) != 0)
      {
         os_printf("Read failed at offset=0x%02x index=%d\r\n", SPIStackAddress, index);
         return 0;
      }
      
      hex_printf(buffer, 8);
      os_printf("\r\n");
      
      return writeResult;
   }
}



   pushSPIData(booleanFalse, NULL);
   pushSPIData(booleanTrue, NULL);
   pushSPIData(booleanFalse, NULL);
   pushSPIData(booleanTrue, NULL);



StartAddress now at: 70000
Writing: 02 00 00 00


ThermSettings config written...
Address now at: 70001
00 00 00 00 00 00 00 00
02 00 00 00 FF FF FF FF

StartAddress now at: 70000
Writing: 01 00 00 00


ThermSettings config written...
Address now at: 70001
00 00 00 00 00 00 00 00
00 00 00 00 FF FF FF FF

StartAddress now at: 70000
Writing: 02 00 00 00


ThermSettings config written...
Address now at: 70001
00 00 00 00 00 00 00 00
00 00 00 00 FF FF FF FF

StartAddress now at: 70000
Writing: 01 00 00 00


ThermSettings config written...
Address now at: 70001
00 00 00 00 00 00 00 00
00 00 00 00 FF FF FF FF

mode : null

Statistics: Posted by AgentSmithers — Sun Feb 03, 2019 9:18 am


]]>