AnsweredAssumed Answered

[SOLVED]storing struct into flash

Question asked by Erkan Ersoy on Aug 31, 2015
Latest reply on Sep 1, 2015 by Erkan Ersoy
Hello
I am trying to save my settings into flash. I use a struct that storing settings, then put a pointer begining of it and store all the bytes into flash along the size of that struct. But it seems struct is scattered in RAM. Is there an instruction that puts in Flash without scattered.
I tried
struct __attribute__((packed, aligned(4))) network_settings_t{
    unsigned char DHCP;
    ipAddress_t ip;
    ipAddress_t subnet_mask;
    ipAddress_t gateway;
    ipAddress_t dns;
    char MAC_ADDRESS[6];
};

but it didn't work

I am using old drivers with GCC on STM32F107RTC

   uint32_t address  = FLASH_USER_START_ADDR;
   uint32_t *ptr;
   ptr = data;
 
FLASHStatus = FLASH_ErasePage(FLASH_USER_START_ADDR);
   FLASH_WaitForLastOperation(100);
   FLASH_ProgramWord(FLASH_USER_START_ADDR,*ptr);
   FLASH_WaitForLastOperation(100);
 
   ptr = &network_settings;
   address += 4;
 
   while(ptr <= (&network_settings + sizeof(network_settings))){
       FLASH_ProgramWord(address,*ptr);
       FLASH_WaitForLastOperation(100);
       address += 4;
       ptr += 4;
   }


and to read it:
unsigned int *mem;
unsigned int *ptr;
printf("Load Settings From Flash\n");
 
printf("Loading Settings...\r\n");
 
ptr = &network_settings;
mem = (unsigned int*)FLASH_USER_START_ADDR;
 
 
while(ptr <= (&network_settings+sizeof(network_settings))){
    *ptr = *mem;
    ptr += 4;
    mem +=4;
}

Thank you...

Outcomes