This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

const data is always initialized

Hi,

I have a product with some ROM containing some constant data and regular flash to keep code. I would like to declare a data structure in my program to access the data in ROM and I have tried several methods:

1) Declare a structure like this (following user manual indications): __attribute__((section(".rom_info"))) __attribute__((zero_init)) __attribute__((used)) uint8_t rom_info[2048];

Output in map file:
Execution Region REGION_ROM (Base: 0x10000000, Size: 0x00000800, Max: 0x00000800, ABSOLUTE, UNINIT)

Base Addr Size Type Attr Idx E Section Name Object
0x10000000 0x00000800 Zero RW 2299 .rom_info micro_hello_world_main.o

Total RO Size (Code + RO Data) 3360 ( 3.28kB)
Total RW Size (RW Data + ZI Data) 5680 ( 5.55kB)
Total ROM Size (Code + RO Data + RW Data) 3404 ( 3.32kB)

Drawback:
My RW data is increased by 2048, hinting that RAM needed is 2K more than what is actually used by my program.

2) Declare a structure like this: __attribute__((section(".rom_info"))) __attribute__((zero_init)) __attribute__((used)) const uint8_t rom_info[2048];

Output in map file:
Execution Region REGION_ROM (Base: 0x10000000, Size: 0x00000800, Max: 0x00000800, ABSOLUTE, UNINIT)

Base Addr Size Type Attr Idx E Section Name Object
0x10000000 0x00000800 Data RO 2299 .rom_info micro_hello_world_main.o

Total RO Size (Code + RO Data) 5424 ( 5.30kB)
Total RW Size (RW Data + ZI Data) 3632 ( 3.55kB)
Total ROM Size (Code + RO Data + RW Data) 5468 ( 5.34kB)

Drawback:
The 2K ROM are initialized during program loading and this of course fails.

Output of the section via objdump -h is as follow: 7 REGION_ROM 00000800 10000000 10000000 00000d90 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA

As you can see section REGION_ROM is of type LOAD meaning that the debugger will try to load this section.

In both methods, my scatter file is as follow: REGION_ROM _MEMORY_ROM_BEGIN_ UNINIT NOCOMPRESS _MEMORY_ROM_SIZE_ { *.o (.rom_info) }

Bootm line: is there a way to map a C const data in some ROM memory without initializing it ?

Michele