【发布时间】:2018-11-10 15:20:44
【问题描述】:
我正在使用 Atmel AVR 并试图从存储在闪存(程序)存储器中的结构中访问数据。
结构是:
typedef struct {
uint8_t width;
uint8_t height; // row number 0 to 5
uint8_t images; // how many frames does this bitmap have
uint8_t data[]; // the actual pixel data
} bitmap_t;
数据是:
__flash static const bitmap_t bmp_stereo2 = {14,1,1,{126,129,60,66,24,36,60,60,36,24,66,60,129,126}};
我正在尝试使用(显示部分代码)访问数据...
void lcd_bitmap2(const bitmap_t *bit, uint8_t id, uint8_t posx, uint8_t posy) {
uint8_t x;
uint8_t y;
const uint8_t bw = pgm_read_byte(&bit->width); // this works -- I can print out to serial
const uint8_t bh = pgm_read_byte(&bit->height); //this also works -- I can print out to serial
// this doesn't work
const uint8_t *data = pgm_read_word(&bit->data); // I get: - initialization makes pointer from integer without a cast [enabled by default]
const uint8_t *data = (uint8_t *)pgm_read_word(&bit->data); // this also doen't work (no warning, but wrong data read out)
//rest of function...
所以我可以访问宽度、高度和图像变量,但不能访问结构的数据部分。 如果我不存储在闪存中,一切正常 - 这是我的检索,只是结构的数据数组部分存在问题(宽度、高度和图像读取正常)
【问题讨论】:
标签: c structure avr avr-gcc flash-memory