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: Select all
#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