Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By woodwax
#34693 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.
User avatar
By woodwax
#34751 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
User avatar
By eduperez
#34766 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.