Hi, I'm not sure if this belongs in the Embedded forum because this is something that is more likely to be used by people working with micro-controllers with low memory. But it is a C question so.
I'm working with an arm micro-controller. It has a parallel RGB LCD module inside it. I want to store images. Images are big. This uC has 256kb of Ram and 2MB of flash. Let me add that this uC is a Harvard Architecture. Separate program memory and RAM.
I was looking at example code and saw something very interesting. It appears to be a method to force data into the program memory (flash) as opposed to RAM. This is definetely useful because I have 2MB of flash, which is plenty for many small RGB888 images. Here is the example code.
there is a header file, and inside this header file the actual image in RGB565 format is stored. Its declared like this.
Then in the .C file in main() they have the following
The header file is included in the .C file. Also its kinda interesting that LCD_buff_addr is not a pointer, even though its storing an address.
I never saw anything like this in any C programming books. Is this even legal C? Maybe a subset of C like C99? I tested it and it works.
I looked at the .map file and lo and behold flash memory used 0x03fc2c bytes of data, not code. This is approximately 65280*4 which is the size of the data array. So its pretty clear that the array went entirely into flash memory.
This is a great feature, and I have been looking for something like this for a while now, but I never saw this explained anywhere on the internet or my C book. I would like a formal explanation of why this is legal and why it works.
Thank you.
-Gene
I'm working with an arm micro-controller. It has a parallel RGB LCD module inside it. I want to store images. Images are big. This uC has 256kb of Ram and 2MB of flash. Let me add that this uC is a Harvard Architecture. Separate program memory and RAM.
I was looking at example code and saw something very interesting. It appears to be a method to force data into the program memory (flash) as opposed to RAM. This is definetely useful because I have 2MB of flash, which is plenty for many small RGB888 images. Here is the example code.
there is a header file, and inside this header file the actual image in RGB565 format is stored. Its declared like this.
Rich (BB code):
const uint32_t RGB565_480x272[65280] =
{
0x7A537A53,
0x82538253, .............};
Rich (BB code):
uint32_t LCD_buff_addr;
LCD_buff_addr= (uint32_t)&RGB565_480x272;
I never saw anything like this in any C programming books. Is this even legal C? Maybe a subset of C like C99? I tested it and it works.
I looked at the .map file and lo and behold flash memory used 0x03fc2c bytes of data, not code. This is approximately 65280*4 which is the size of the data array. So its pretty clear that the array went entirely into flash memory.
This is a great feature, and I have been looking for something like this for a while now, but I never saw this explained anywhere on the internet or my C book. I would like a formal explanation of why this is legal and why it works.
Thank you.
-Gene