This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I'd like to put a static webpage into flash memory (to save RAM) on a M3 device. I'm using codegen 4.9.1.
The webpage is simply a char array:
unsigned char DEFAULT[676] = { 0x3C, 0x21, 0x44, 0x4F, ...}
I tried putting the array into a data section and place it in the linker file
main.c:
#pragma DATA_SECTION(DEFAULT, ".webpage")
link.cmd
.webpage : > FLASH
The array was placed in flash, but was all 0xff. I figure this is because it is initialized data, so will be set via cinit records during startup...that's a problem since it is in flash.
I tried putting the the array into .text (which is placed into flash also)
#pragma DATA_SECTION(DEFAULT, ".text")
This worked, but seemed a little dodgy.
Using CODE_SECTION also worked
#pragma CODE_SECTION(DEFAULT, ".webpage")
I'm leaning toward using CODE_SECTION (with a big comment!). Is there a better approach?
Thanks,
Todd
Oops, just show the compiler warning when I do "#pragma CODE_SECTION(DEFAULT, ".webpage")":
"demo.c", line 71: warning: pragma CODE_SECTION can only be applied to a function definition, not "DEFAULT" (declared at line 2 of "default.h")
Looks like I'm back to "#pragma DATA_SECTION(DEFAULT, ".text")" unless someone has a better idea.
Thanks,
Todd
Try declaring the array const to avoid cinit records:
const unsigned char DEFAULT[676] = { 0x3C, 0x21, 0x44, 0x4F, ...};
Sorry, I forgot to mention that I'm using a tool to generate the file that contains the array. It should put const, but doesn't. I'll see if I can get the tool changed. I'm a nervous about manually changing the generated file since I know I'll forget to do if I change the page. I probably code add the "const" as part of the build-system until the tool is fixed...
You can also mark an output section as NOINIT in the linker command file. A section marked NOINIT will be direct initialized in the output file.
.webpage: > FLASH type=NOINIT