cancel
Showing results for 
Search instead for 
Did you mean: 

Defining NOLOAD section in ld script for GCC

Mohammad A
Senior

I want to define a new section in ld script so I can use that for variables which have to keep their values in case of soft resets (like IWDG).

I have done some researches and wrote something like this and added that below the .bss section in ld file.

/* Uninitialized data section into "RAM" Ram type memory */
  . = ALIGN(4);
  .bss :
  {
    /* This is used by the startup in order to initialize the .bss secion */
    _sbss = .;         /* define a global symbol at bss start */
    __bss_start__ = _sbss;
    *(.bss)
    *(.bss*)
    *(COMMON)
 
    . = ALIGN(4);
    _ebss = .;         /* define a global symbol at bss end */
    __bss_end__ = _ebss;
  } >RAM
  
  /**
	 * .noinit section - uninitialized data
	 */
	.noinit (NOLOAD):
	{
		. = ALIGN(4);
		_start_of_noinit = .;
		*(.noinit)
		*(.noinit.*)
		. = ALIGN(4);
		_end_of_noinit = .;
  } >RAM
 
  /* User_heap_stack section, used to check that there is enough "RAM" Ram  type memory left */
  ._user_heap_stack :
  {
    . = ALIGN(8);
    PROVIDE ( end = . );
    PROVIDE ( _end = . );
    . = . + _Min_Heap_Size;
    . = . + _Min_Stack_Size;
    . = ALIGN(8);
  } >RAM

I also define this kind of variables in this way:

uint32_t aVeryStableGeniusVariableArray[10] __attribute__ ((section (".noinit")));

As I'm not an expert in ld technics, I just wanted to know if the above code is OK and does not cause any unwanted malfunction.

Actual ld file is attached.

1 REPLY 1

The .MAP file would allow you to confirm the placement by the linker. The secondary dependency would come from startup.s

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..