Quality RTOS & Embedded Software

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


More memory on ATMega128

Posted by Nobody/Anonymous on December 11, 2004
Would you mind giving me a hand on FreeRTOS?

The FreeRTOS works fine to me in a project based on ATmega128 until recently that I would like to create one more task. It shows errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY when it is asked to create a new

I look at the output map file. There is still 1k not used. So look up the API, it is saying to change portTOTAL_HEAP_SIZE in portmacro.h. I could not find portTOTAL_HEAP_SIZE in it. Instead, I find

#define heapNUM_SMALL_BLOCKS ( 16 )
#define heapNUM_LARGE_BLOCKS ( 10 )

in portheap.c.

1. Are these the arrays that need changing?

2. How do the array sizes relate to the number of tasks created? In another word, how many heapNUM_SMALL_BLOCKS and heapNUM_LARGE_BLOCKS need being allocated for one task?

3. Does the kernel reserve some blocks?

Thanks in advance.

RE: More memory on ATMega128

Posted by Richard on December 11, 2004

It sounds like you are using an older version of FreeRTOS. The portheap.c you mention was replaced in version 2.5.0 with three sample (and simple) memory management schemes.

If you are using the portheap.c as directly downloaded on an ATMega128 then I suspect you have a lot of unused memory you can make use of.

First I will answer the questions relating to your current version, then make some suggestions as how you can upgrade:

> 1. Are these the arrays that need changing?

Basically yes. The old portheap.c you are using maintained two pools of fixed size memory blocks. When the kernel wanted to allocated some memory it would use a block from the array of small blocks if appropriate, or the array of large blocks if there were no small blocks left of the allocation required a large block anyway.

>2. How do the array sizes relate to the number of tasks created? In another word, how many heapNUM_SMALL_BLOCKS and heapNUM_LARGE_BLOCKS need being allocated for one task?

Normally one small block and one large block for each task. Blocks are also used for queues and semaphores so there is not a one to one relationship.

>3. Does the kernel reserve some blocks?

Every call to pvPortMalloc() obtains a block from either array. The kernel call pvPortMalloc() when a task, queue or semaphore is created.

V2.5.0 onwards of FreeRTOS has replaced the portheap.c files with heap_1.c, heap_2.c and heap_3.c. These are described here:


Have a look at this page and decide which scheme is best for you. They all use one single array of memory from which blocks of any size can be allocated. The total size of the array is set by the constant portTOTAL_HEAP_SIZE, making configuration a lot easier as you only have one constant to set.

I suggest you download the latest version of FreeRTOS and either:

1) Use the latest version in it’s entirety – this would be the preferred solution.


2) Just take the heap_x.c file from the latest version and use it in your project in place of portheap.c. You may need to replace the vTaskSuspendAll() and cTaskResumeAll() in heap_x.c with calls to portENTER_CRITICAL() and portEXIT_CRITICAL() respectively.

The other alternative of course is to keep the files you are using and increase the heapNUM_SMALL_BLOCKS and heapNUM_LARGE_BLOCKS constants.

I also suggest taking a look at the version history:



[ 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