We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a set of initialised data structures that are now located in external memory. The structures are each defined using __attribute__((section("menu_structures"))).
A linker scatter file is used to locate this section to external memory.
RW_RAM1 0x81000000 0x00100000 { menu.o(menu_structures) }
This compiles and links without errors, but the structure elements are all initialised to 0. I have tried setting the 'Options for target' for this memory area to NoInit, and also to not selected. Both ways seem to leave the structure contents at 0.
Originally the structures were all by default in internal ram, and they were correctly initialised with non-zero values.
Can anyone help me as to why the structures are no longer initialised properly when located in external memory?
You need to locate your data in a zero initialized section, then place that section is a UNINIT execution region in the scatter file. See your linker manual for details. Example:
#pragma arm section zidata = "non_init_2" __attribute__ ((zero_init)) static software_evt_std s_queue_software_event_std[MAX_SOFTWARE_EVENTS_STD] ; // ring buffer __attribute__ ((zero_init)) static int32u s_queue_software_event_std_rx ; // for consumer - software event task __attribute__ ((zero_init)) static int32u s_queue_software_event_std_tx ; // for producers - posting tasks/firmware __attribute__ ((zero_init)) static int32u s_queue_software_event_std_size ; // number of elements in the ring buffer __attribute__ ((zero_init)) static software_evt_str s_queue_software_event_str[MAX_SOFTWARE_EVENTS_STR] ; // ring buffer __attribute__ ((zero_init)) static int32u s_queue_software_event_str_rx ; // for consumer - software event task __attribute__ ((zero_init)) static int32u s_queue_software_event_str_tx ; // for producers - posting tasks/firmware __attribute__ ((zero_init)) static int32u s_queue_software_event_str_size ; // number of elements in the ring buffer __attribute__ ((zero_init)) static file_storage_medium s_file_storage_medium ; // where are software events stored // the software events buffer is located here to allow post-crash analysis. data remains in the buffer // as long as power supply is maintained. __attribute__ ((zero_init)) static int8s sp_event_buffer[SOFTWARE_EVENT_BUFFER_SIZE] ; #pragma arm section zidata
and then in the scatter file
SOFTWARE_EVENT_ZERO_INIT_DATA.o 0xA1FFEC00 UNINIT { SOFTWARE_EVENT.o (non_init_2) }
There may be other ways to achieve this, too.
I am not ure that I can place my structures into the initial zero initialised section, since my structures contains non-zero values. If I attempt to do this then the compiler gives an error "variable may not be initialised".