Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


C18 linker restrictions loosened

Posted by Nobody/Anonymous on July 20, 2006

I studied the remarks by John Franklin about how to set up the linker script and modify heap_1.c to prevent variables leaking across page boundaries.

I think his solution is way too complex.

The goal is to get the heap in one memory section (which can cross multiple banks), and keep the rest of the variables from crossing a bank boundary.

This can simply be realised by combining no more banks than required for the heap.
Let's say the desired heap is 2200 bytes

This is done by
#define configTOTAL_HEAP_SIZE( ( size_t ) 2200 )
in FreeRTOSConfig.h

As a result the variable 'xHeap' defined in heap_1.c will be 2204 bytes long because of the additional long variable in the struct.
In hexadecimal 2204 is 0x89C, which is the minimum required size of the memory region. (There are no other variables defined in heap_1.c, so this is all the memory required for de .udata_heap_1.o memory section)

It is now sufficient to define a region in the linker script which is between 0x89C and 0x900 long.
The rest of the banks will be left alone and have a length of 0x100, starting at a boundary.

The linker will automatically fit the .udata_heap_1.o memory section (containing the xHeap variable) into the first region with enough space. The remaining space in the combined region can be used by other memory sections.
(It is in this example _not_ allowed to define the region _larger_ than 0x900 bytes since other variables stored in the region can then cross a boundary.)

- There is no need to modify the FreeRTOS library file heap_1.c with
#pragma udata heap_section
#pragma udata
- There is no need to define the combined region "PROTECTED"
- There is no need for a "SECTION NAME=heap_section RAM=heapregion" mapping in the linker script

All that is required is to combine no more banks than strictly required to accomodate configTOTAL_HEAP_SIZE+4 bytes
It is allowed to oversize the region to the next bank boundary, and let the linker fill up the rest of the region. You don't have to define your own (non-PROTECTED) region to fill up the bank if you don't want to waste the remaining space.


RE: C18 linker restrictions loosened

Posted by Nobody/Anonymous on July 20, 2006
Makes sense. Comments John?

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Version 10.1.0 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner