-->
Page 1 of 2

save flash

PostPosted: Sun Nov 22, 2015 12:52 pm
by woodwax
Hello!

I have this structure:

Code: Select all#define MEMORY 400
#define NUMBER 2

struct __attribute__((aligned(4))) Watering_valve
{
  char      Name[9];
  short     set=LOW;           
  short     state=LOW;         
  short     autom=LOW;
  short     timeout=LOW;
  uint16_t  voltage[MEMORY];
  int16_t   temp[MEMORY];
  uint16_t  count=0;
  time_t    login_epoch=0;
  time_t    watering_epoch=0;
  Time      auto_watering_time;
  uint8_t   temperature_graph;
  uint8_t   voltage_graph;
};

struct Watering_valve watering_valve[NUMBER];


I need to save it into the flash memory. I doing it by this way:
spi_flash_erase_sector(0x7b);
spi_flash_write(mem_sector0,(uint32_t *)&watering_valve[0],sizeof(watering_valve[0]));
or read:
spi_flash_read(mem_sector0,(uint32_t *)&watering_valve[0],sizeof(watering_valve[0]));

But this saves only the the watering_valve[0] structure, its going fine.

I tried to save all of the structure like this:
spi_flash_erase_sector(0x7b);
spi_flash_write(mem_sector0,(uint32_t *)&watering_valve[0],sizeof(watering_valve));
or read:
spi_flash_read(mem_sector0,(uint32_t *)&watering_valve[0],sizeof(watering_valve));

But this will cause reset on reading.

Re: save flash

PostPosted: Mon Nov 23, 2015 2:38 am
by woodwax
Can anyone help, how can I store this structure in flash memory? Thanks!

Code: Select allstruct __attribute__((aligned(4))) Watering_valve
{
  char      Name[9];
  short     set=LOW;           
  short     state=LOW;         
  short     autom=LOW;
  short     timeout=LOW;
  uint16_t  voltage[MEMORY];
  int16_t   temp[MEMORY];
  uint16_t  count=0;
  time_t    login_epoch=0;
  time_t    watering_epoch=0;
  Time      auto_watering_time;
  uint8_t   temperature_graph;
  uint8_t   voltage_graph;
};

struct Watering_valve watering_valve[NUMBER];


where NUMBER=2

Re: save flash

PostPosted: Mon Nov 23, 2015 8:50 am
by eduperez
Just my two cents:

If "spi_flash_write(mem_sector0, (uint32_t *)&watering_valve[0], sizeof(watering_valve[0]));" works for the first element, then "spi_flash_write(mem_sector0, (uint32_t *)&watering_valve[0], NUMBER * sizeof(watering_valve[0]));" should work for the entire array (however, the size of a "sector" should probably be taken into consideration, but I am not sure about this). And "&watering_valve[0]" is the same as "watering_valve", if I am not mistaken.

Re: save flash

PostPosted: Tue Nov 24, 2015 6:43 am
by woodwax
Thanks! Its seems to be working now. :)