Go Down

Topic: Define new varibale type in pgmspace for PROGMEM : structure in FLASH (Read 2178 times) previous topic - next topic

MHDfo

Hi everyone,
In the PROGMEM documentation we can read :
PROGMEM keyword is a variable modifier, it should be used only with the datatypes defined in pgmspace.h.

So we can use: void, char, unsigned char, int8_t, uint8_t int16_t uint16_t, int32_t, uint32_t, int64_t, uint64_t.

My project start to be bigger and bigger, MenuBackend (without storing strings in FLASH) use quite a lot of SRAM.
I'm thinking of adapt it to use more FLASH memory or even program new menulib management.

The main question is can I define new variable type in pgmspace.h/.c, for exemple structure ?
My programming skill should be enough to do it, but without debugger and such, if its don't works, I won't be sure if its a weird bug or my fault ...
Did anyone (meaning someone who know is stuff ...) ever try to declared struct in pgmspace to store const struct item  in FLASH?

Nick Gammon

Everything starts off in flash memory. If you don't use the PROGMEM keyword it gets copied into SRAM.

So yes, anything can be put there.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

MHDfo


Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics


In the PROGMEM documentation we can read :
PROGMEM keyword is a variable modifier, it should be used only with the datatypes defined in pgmspace.h.


Well that is strange advice.  You can store anything in program memory:

Code: [Select]

#include <avr/pgmspace.h>

struct something_t
{
  int a;
  int b;
  long c;
};

const something_t PROGMEM something_in_flash = { 1,2,3 } ;

Nick Gammon


http://arduino.cc/playground/Code/EEPROMWriteAnything


Oops, I confused EEPROM with PROGMEM. But no matter. You can still put whatever you want into it, because that's where the compiler puts all your data initially anyway.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Delta_G



http://arduino.cc/playground/Code/EEPROMWriteAnything


Oops, I confused EEPROM with PROGMEM. But no matter. You can still put whatever you want into it, because that's where the compiler puts all your data initially anyway.


Couldn't you still use the same approach and use the pgm_read_word type macros?

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up