Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7512

General • Re: How can i put a file .h in another section of memory? rp2040

$
0
0
Toolchain seems to be fine. Tested including large amounts of data in a few tables, worked for me, but I haven't tried uploading the thing to a board. Here is the build directory with about 1400KB of data in the binary:

built_with_lots_of_data.png

I had an OLED test program with a 576 byte font table and I used #include to compile everything as one file, so with OP's sound samples I would have done the same thing. To test OP's scenario I replicated the data and added a few more files in my main program like this:

Code:

#include "hd44780-font0.h"#include "hd44780-font1.h"#include "hd44780-font2.h"#include "hd44780-font3.h"#include "hd44780-font4.h"#include "SSD1306_driver.c"
And the data tables are like this, totals over 11MB and over 100K lines of code:

Code:

static uint8_t font_tab[] = {    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 32 */    0x00, 0x00, 0x4F, 0x00, 0x00, 0x00, /* 33 */    0x00, 0x07, 0x00, 0x07, 0x00, 0x00, /* 34 */    0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, /* 35 */...    0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00/* 127 */};
Each file has data changed slightly to avoid compiler optimization. Compiled binary size for Pico RP2040 is as expected, ~1400KB (576 bytes original table x 500 x 5 files) of table data. OP had more data files. I used "static uint8_t" and tables are only accessed like "font_tab[index]".

The toolchain seems to be working fine and I use default CMake build file settings etc. Perhaps OP should try a simple test program specifically to test the data table inclusion scenario.

[Edit] If I try to change the table data, for example:

Code:

        font_tab[f]++;        font_tab1[f]++;        font_tab2[f]++;        font_tab3[f]++;        font_tab4[f]++;
Then it overflows as expected:

Code:

E:/msys64/ucrt64/bin/../lib/gcc/arm-none-eabi/13.3.0/../../../../arm-none-eabi/bin/ld.exe: display_SSD1306.elf section `.data' will not fit in region `RAM'E:/msys64/ucrt64/bin/../lib/gcc/arm-none-eabi/13.3.0/../../../../arm-none-eabi/bin/ld.exe: region `RAM' overflowed by 1180472 bytes
[Edit2] Adding const to a data table:

Code:

const static uint8_t font_tab1[] = {    0x01, 0x01, 0x00, 0x00, 0x00, 0x00, /* 32 */
and the compiler does not compile the code:

Code:

E:/msys64/home/khman/pico_dev/display_SSD1306/SSD1306_driver.c:324:21: error: increment of read-only location 'font_tab1[f]'  324 |         font_tab1[f]++;      |                     ^~make[2]: *** [CMakeFiles/display_SSD1306.dir/build.make:79: CMakeFiles/display_SSD1306.dir/display_SSD1306.c.obj] Error 1
const works as expected. Would be useful to see the relevant code from OP. Or a test program for that data table scenario that fails with OP's toolchain.

Statistics: Posted by katak255 — Fri May 23, 2025 3:34 am



Viewing all articles
Browse latest Browse all 7512

Trending Articles