Hello, we'd like to compile some large image files into our project, have the data available to stream to a display peripheral via LTDC+DSI peripherals. I tried to get cute and created a desktop program that imports pictures and generates C functions to set memory locations, like:
void InitImageData_Untitled_400x400_To(uint32_t img_address) { *(uint32_t*) (img_address + 0x00000000) = 0xFF00A400; //... }
except for larger images this function gets impossibly large and crashes my compiler. :)
So I'm done being clever, and I'm asking the experts about the Right way to do this. What is the easiest way to compile bulk image data into a program for access during runtime?
Thanks very much!
In a nutshell: what you have there is a block of data, so what were you thinking turning all of that into code for no good reason? Let it stay data!
The compiler may not even have to see it. There are tools aplenty that can directly turn raw binary data into hex files, which can be merged with your program after linking. srecord is free.
Or, if you really need it inside the executable imabe directly, there's also a very old-fashioned actual picture file format, XPM (de.wikipedia.org/.../X_PixMap) that's actually compilable C code right there. Some conversion tools can still generate it to this day (e.g. those in the netpbm library).
Hm, point taken... my thought process was that the image data would have to start out in ROM/flash, and then be written to RAM on initialization. Encoding the image data as source code was basically a roundabout way to do this, I thought... just pretty inefficient w.r.t. ROM/flash space used (i.e., its both the data and the code to move the data) (but I think we have plenty of code space).
Or is my premise wrong? Can I leave my image data in ROM/flash and access it there with my code and peripherals? That would be great.
"which can be merged with your program after linking"
Could you please (please, please) expand on this. How exactly do I merge in another file to my build? I've been poking around my Keil compiler options, I see how I can define different regions (IROM1, IROM2, RAM1, RAM2)... what are the steps I take to merge in a hex file (after creating it with srecord or something else). I was hoping to see a way to refer to add'l files in my linker options, but I don't.
Thanks so much.
Can I leave my image data in ROM/flash and access it there with my code and peripherals?
Of course you can. Unless you reconfigured the tools rather strangely, all your "const" variables will already reside there.
How exactly do I merge in another file to my build?
Following my suggestion: you don't. You do it after building, i.e. as a post-processing step that happens after linking, modifying the final hex file. For debug sessions, you use a debugger script to the same effect.
In the context of uVision for ARM, you may be better of (ab)using their FCARM tool for this. It's intended to be used for packaging the image files used by an embedded web server (among other things), but it might manage to do what you need, too.