Retrieve data structure from flash memory

Dear all,

I've faced some trouble trying to retrieve some fields from a data structure that I tried to store on flash memory.
Here is the code:

#include <avr/pgmspace.h>

PROGMEM struct frankie {
  PROGMEM const char *key;
  PROGMEM const char *value;  
};

char buffer[30];

void setup() {
    Serial.begin(9600);
    
    PROGMEM frankie test[2];
    test[0].key = "KEY1";
    test[0].value = "VALUE1";
    test[1].key = "KEY2";
    test[1].value = "VALUE2";
    
    for (int i = 0; i < 2; i++) {
      strcpy_P(buffer, (char*)pgm_read_word(&(test[i].key)));
      Serial.println( buffer );
      strcpy_P(buffer, (char*)pgm_read_word(&(test[i].value)));
      Serial.println( buffer );
    }
}

void loop() { }

Would someone please offer me some guidance on this topic?
Thanks in advanced

test[0].key = "KEY1";

That's never going to work, I'm afraid - you can't write to PROGMEM at runtime, you can only initialise PROGMEM structures at compile-time.

Look into EEPROM WriteAnything library.

Thank you both.

@tuxduino: I'll take a better look at EEPROM lib option, it seems to solve my issue...

Even if you could write to PROGMEM at run time, writing bytes to PROGMEM, and then reading words hardly makes sense.

The variable you're trying to store in progmem needs to be global, it doesn't make sense to try to store a local variable in progmem.

The variable needs to be initialised as part of its definition; you can't define it and then assign values to it separately.

If you want persistent storage which can be modified at runtime, the EEPROM might be a better bet. If using EEPROM, make sure your code doesn't update the EEPROM stored values repeatedly because the storage only supports a limited number of write cycles.

Dear all,

I would like to thank you all, specially to AWOL who showed me the peculiarity of Harvard architecture.
So, I've solved my problem with this piece of code:

#include <avr/pgmspace.h>

prog_char string_0[] PROGMEM = "String 0";   // "String 0" etc are strings to store - change to suit.
prog_char string_1[] PROGMEM = "String 1";
prog_char string_2[] PROGMEM = "String 2";   // "String 0" etc are strings to store - change to suit.
prog_char string_3[] PROGMEM = "String 3";

struct map_t
{
  prog_char *a;
  prog_char *b;
};

const map_t some[2] PROGMEM = {
  {string_0, string_1},
  {string_2, string_3}
} ;

void setup () {
    Serial.begin(9600);
    Serial.println(availableMemory());
    for (int i = 0; i < 2; i++){
      int N = strlen_P((char*)pgm_read_word(&(some[i].b)));
      char buffer[N];
      strcpy_P(buffer, (char*)pgm_read_word(&(some[i].a))); // Necessary casts and dereferencing, just copy. 
      Serial.println( buffer );
      strcpy_P(buffer, (char*)pgm_read_word(&(some[i].b))); // Necessary casts and dereferencing, just copy. 
      Serial.println( buffer );
    }
    delay( 500 );
}
void loop () {}

My best regards