'Noinit' Memory Sections

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

'Noinit' Memory Sections

9,885 Views
lpcware-support
Senior Contributor I

Normally global variables in an application will end up in either a ".data" (initialized) or ".bss" (zero-initialized) data section within your linked application. Then when your application starts executing, the startup code will automatically copy the initial values of ".data" sections from Flash to RAM, and zero-initialize ".bss" data sections directly in RAM.

The LPCXpresso IDE's managed linker script mechanism also supports the use of ".noinit" data within your application. Such data is similar to ".bss" except that it will not get zero-initialized during startup.

Note : Great care must be taken when using ".noinit" data such that your application code makes no assumptions about the initial value of such data. This normally means that your application code will need to explicitly set up such data before using it - otherwise the initial value of such a global variable will basically be random (i.e. it will depend upon the value that happens to be in RAM when your system powers up).

One common example of using such .noinit data items is in defining the frame buffer stored in SDRAM in applications which use an onchip LCD controller (for example NXP LPC178x and LPC408x parts).

Making global variables noinit

The linker script generated by the LPCXpresso IDE managed linker script mechanism will contain a section for each RAM memory block to contain ".noinit" items, as well as the ".data" and ".bss" items. Note that for a particular RAM memory block, all ".data" items will be placed first, followed by ".bss" items, and then ".noinit" items.

However, normally for a particular RAM memory block where you are going to be put ".noinit" items, you would actually be making all of the data placed into that RAM ".noinit".

The "cr_section_macros.h" header file then defines macros which can be used to place global variables into the appropriate ".noinit" section. First of all include this header file:

#include <cr_section_macros.h>

The __NOINIT macro can then be used thus:

// create a 128 byte noinit buffer in RAM2
__NOINIT(RAM2) char noinit_buffer[128];

And if you want ".noinit" items placed into the default RAM bank, then you can use the __NOINIT_DEF macro thus:

// create a noinit integer variable in the main block of RAM
__NOINIT_DEF int noinit_var ;

Linker script templates

If you are using the "linker script template" mechanism in your project and you wish to make use of ".noinit" sections, then you will need to ensure that your linker template in your project was based on the default one from a recent version of the Code Red tools (v5.0.14 or later). Otherwise, you will need to create a new template based on the one that can be found within <installdir>\lpcxpresso\Wizards\linker.

Tags (2)
0 Replies