-->
Page 1 of 1

Noob question. ESP8266 via Arduino and spi_flash.h

PostPosted: Fri Feb 26, 2016 12:14 am
by Dieheart D.
Hi, all! This forum has a post about persisting struct variables into ESP8266 user memory address area. Here was an example on how to do it, using spi_flash_write: viewtopic.php?f=34&t=2662. But I do not know, what library I should be using for this actions. I was trying to include
My code looks like this:
Code: Select all#include <spi_flash.h>
#include "datastructures.h"

accessPointConfig currentAccessPointConfig;

void saveAccessPointConfig( accessPointConfig *pConfig ) {
  spi_flash_erase_sector(CONFIG_SECTOR);
  spi_flash_write(CONFIG_ADDRESS , (uint32 *)(pConfig), sizeof(accessPointConfig));
}

void loadAccessPointConfigFromSPI( accessPointConfig *pConfig ) {
  spi_flash_read(CONFIG_ADDRESS , (uint32 *)(pConfig), sizeof(accessPointConfig));
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(0, INPUT_PULLUP);
  pinMode(2, OUTPUT);
  Serial.println( "System start..." );

  loadAccessPointConfigFromSPI( &currentAccessPointConfig );
 
  Serial.println( "SPI flash test result..." );
  Serial.println(  currentAccessPointConfig.spotNameLen );
}

void loop() {
  // some stuff happening here
}


And my helper include file datastructures.h looks like this:
Code: Select all#define CONFIG_SECTOR 0x80-4
#define CONFIG_ADDRESS CONFIG_SECTOR * 4096

typedef struct {
  char wifiSpotName[256];
  char wifiSpotPassword[256];
  uint32_t spotNameLen;
  uint32_t spotPasswordLen;
} accessPointConfig;


When I'm trying to compile, I'm getting the following error messages:
Arduino: 1.6.7 (Windows 7), Board: "Generic ESP8266 Module, Serial, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS), ck"

sketch\sketch_accumulator.ino.cpp.o:(.text._Z28loadAccessPointConfigFromSPIP17accessPointConfig+0x4): undefined reference to `spi_flash_read(unsigned int, unsigned int*, unsigned int)'

sketch\sketch_accumulator.ino.cpp.o: In function `loadAccessPointConfigFromSPI(accessPointConfig*)':

C:\Users\Andrzej\Documents\Arduino\sketch_accumulator/sketch_accumulator.ino:47: undefined reference to `spi_flash_read(unsigned int, unsigned int*, unsigned int)'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling.


I think, I'm missing the actual implementation of spi_flash, or maybe it is a problem with my paths/directiories.
I would be glad, If I get any hint on how to resolve this, since I'm kinda to to MCUs, C and stuff.

Re: Noob question. ESP8266 via Arduino and spi_flash.h

PostPosted: Fri Feb 26, 2016 5:56 am
by schufti
try including it like
Code: Select allextern "C"{
#include "spi_flash.h"
}

Re: Noob question. ESP8266 via Arduino and spi_flash.h

PostPosted: Fri Feb 26, 2016 11:00 am
by Dieheart D.
It worked. Great thanks!