Avr: PROGMEM, PSTR i struktura

Aug 07, 2011 6 Replies

Witam.



Chce zrobić coś takiego:



struct Data { const char *foo; unsigned char a; };



Data PROGMEM data = { PSTR("Coś"), 4 };



Oczywiscie nie mogę, bo PSTR to jest "__extension__" i można tego używać chyba tylko jako argumentu funkcji: " statement-expressions are not allowed outside functions nor in template-argument lists"



W kazdym razie padłem na tym że nie mam jak zainicjować statycznej const struktury. Chciałbym ja inicjować dokladnie tak jak to widać, tzn w miejscu.



Tak też się nie da:



const char PROGMEM *z = "Inne";



Data PROGMEM data2 = { z, 8 };



Wylatuje z: "error: data2 causes a section type conflict"



Zamiana z const char* na PGM_P tez nic nie pomaga. Co jeszcze powinienem sprawdzić?



WinAVR-20100110.


W dniu 2011-08-08 00:38, Sebastian Biały pisze:

I jest to nawet opisane w FAQ:

formatting link

U siebie stosuję coś takiego:

static const prog_char cmd_sin_rgb_fast[] = "$sin_rgb_fast#"; [...]

struct{ const prog_char * cmd; uint8_t len; uint8_t mode; }static const PROGMEM cmd_tab[] = { {cmd_sin_rgb_fast, sizeof(cmd_sin_rgb_fast) - 1, mode_sin_rgb_fast}, [...] };

i działa.

Take the red pill, Sebastian Biały...

Spróbuj tak :

#v+ #include <avr/pgmspace.h> typedef struct{ const char * foo; unsigned char a; } Data;

const char const string1[] PROGMEM = "foo.shmoo";

const Data const data PROGMEM = { string1 , 7 };

int main() { // ... return 0; } #v-

00000026 <string1>: 26: 66 6f 6f 2e 73 68 6d 6f 6f 00 foo.shmoo. 00000031 <data>: 31: 26 00 07 &..

Sławek

A miało być tak pięknie:

formatting link
Co się stało z tym pomysłem? gcc miało coś implementować.

Niby ma przestrzenie adresowe i są jakieś próby z avr:

formatting link
formatting link

Trochę strzelam, bo nie mam teraz jak sprawdzić, ale czy nie zadziała po prostu: Data PROGMEM data = {"Coś" , 4}; ??

Nie, "coś" ląduje w RAM zamiast Flash. We Flash znajdzie się tylko sama struktura z pointerem.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required