Pages: [1]   Go Down
Author Topic: Define new varibale type in pgmspace for PROGMEM : structure in FLASH  (Read 1865 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice,
Then I will find a way to do it.

TY.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA
Offline Offline
God Member
*****
Karma: 11
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#include <avr/pgmspace.h>

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

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


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Offline Offline
God Member
*****
Karma: 17
Posts: 721
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes I don't see any major objection to that.
Logged

Pages: [1]   Go Up
Jump to: