1

i'm trying to initialize a defined section in my DRAM/IRAM with some pre-defined data.

For that purpose, I defined a section "my_section" in the memory map file, at some fixed address.

dram0_0 : C : 0x5ffd0400 - 0x5ffdb70f : .my_section.rodata ....

Then i defined a struct, with couple of fields, and the initialization list

struct ParamBuff
{
    int32_t first_val;
    int32_t second_val;

    constexpr ParamBuff() :
            first_val(0xcafecafe),second_val(0xdeadbeaf){};
};

and then i declared the variable, assigning it to the section i defined:

__attribute__((section(".my_section.rodata")))
constexpr ParamBuff param_buff;

later on in the code, i would like to use it as:


some_variable = param_buff.first_val

So that works fine, but not in compile time - when looking at the assembly file, i can see that the actual initialization of that struct (and inevitably, the memory section) happens at run-time:

5ffe1720 <_GLOBAL__I_a..MG_1638106100>:
5ffe1720:   004136          entry   a1, 32
5ffe1723:   fffe21          l32r    a2, 5ffe171c (deadbeaf <xthals_hw_configid0+0x1cad0c29>)
5ffe1726:   fffb31          l32r    a3, 5ffe1714 (5ffd0400 <_params_array_start>)
5ffe1729:   fffb81          l32r    a8, 5ffe1718 (cafecafe <xthals_hw_configid0+0x8fe1878>)
5ffe172c:   0389        s32i.n  a8, a3, 0
5ffe172e:   1329        s32i.n  a2, a3, 4
5ffe1730:   f01d        retw.n

wasting CPU cycles, instruction memory, and data memory (becoming crucial when this array becomes bigger and bigger)

My final goal is to get the binary output file, with that memory section already holding the data

I was managed to do it already with constant global variables, but i can't figure out how to do it with the struct.

Working with C++11

I would really appreciate any help!

Thanks Itay

  • 1
    I think a better solution would be to make the structure a "plain old data" type structure that you can initialize at definition (like `ParamBuf param_buf = { 0xcafecafe, 0xdeadbeaf };`, with suitable attribute for section) – Some programmer dude Nov 28 '21 at 14:06
  • I can try this, but i wanted to use the initialization list, to avoid mistakes when initializing this param buff. – user1651647 Nov 28 '21 at 14:10
  • 1
    eventually, i used your suggestion, with a minor change, and it worked: ParamsArray param_array = ParamsArray() thank for the help! – user1651647 Nov 29 '21 at 10:01

0 Answers0