FreeRTOS memory footprint reduction at build time

Started by John Speth July 5, 2018
Hi Folks-

FreeRTOS has a build config file (FreeRTOSConfig.h) that users can apply 
at build time to customize the RTOS.  The FreeRTOS web site has a page 
to describe the options (https://www.freertos.org/a00110.html).  What it 
doesn't have is any hints about how much RAM it might save me.

Does anybody have any first hand advice about how much RAM each option 
might contribute to the RAM footprint?  Google isn't helping me.

I'm trying prepare an STM32L151 to accommodate my as yet unwritten 
application code with FreeRTOS.  The map file is showing me that 
FreeRTOS is using 15,000 bytes of RAM.  The HAL and startup/interrupt 
codes use 2,400 bytes of RAM.  That leaves me with about 14,800 bytes 
for application code.  I would like to be prepared to reduce the 
FreeRTOS RAM footprint if I need to in the future.

I know I can elevate optimization (presently set to none) but I don't 
want to do that this early in the code-writing stage because it makes 
the debugger present better steppable code.

Thanks - JJS
On Thu, 05 Jul 2018 17:29:18 -0700, John Speth wrote:

> Hi Folks- > > FreeRTOS has a build config file (FreeRTOSConfig.h) that users can apply > at build time to customize the RTOS. The FreeRTOS web site has a page > to describe the options (https://www.freertos.org/a00110.html). What it > doesn't have is any hints about how much RAM it might save me. > > Does anybody have any first hand advice about how much RAM each option > might contribute to the RAM footprint? Google isn't helping me. > > I'm trying prepare an STM32L151 to accommodate my as yet unwritten > application code with FreeRTOS. The map file is showing me that > FreeRTOS is using 15,000 bytes of RAM. The HAL and startup/interrupt > codes use 2,400 bytes of RAM. That leaves me with about 14,800 bytes > for application code. I would like to be prepared to reduce the > FreeRTOS RAM footprint if I need to in the future. > > I know I can elevate optimization (presently set to none) but I don't > want to do that this early in the code-writing stage because it makes > the debugger present better steppable code. > > Thanks - JJS
It has been a couple of years since I did a lot with FreeRTOS but if I remember correctly there are very few static built data structures. Most are linked list and such that grow based on your resource usage (number of task, queues, semaphores, etc). How are you allocating your heap. If you are using the default simple allocators then part of that 15K is the heap. You can try decreasing the size or plan on your app doing a lot of malloc allocation for data structures and allocate more ram to the heap. Optimization is not going to do a lot for your RAM usage. It will decrease your flash usage some. If you are starting to run out of flash that is a different story. You can try and remove some of API features you are not using and cut down some on flash usage. -- Chisolm Republic of Texas
On Friday, July 6, 2018 at 2:30:53 AM UTC+2, John Speth wrote:
> Hi Folks- > > FreeRTOS has a build config file (FreeRTOSConfig.h) that users can apply > at build time to customize the RTOS. The FreeRTOS web site has a page > to describe the options (https://www.freertos.org/a00110.html). What it > doesn't have is any hints about how much RAM it might save me. > > Does anybody have any first hand advice about how much RAM each option > might contribute to the RAM footprint? Google isn't helping me. > > I'm trying prepare an STM32L151 to accommodate my as yet unwritten > application code with FreeRTOS. The map file is showing me that > FreeRTOS is using 15,000 bytes of RAM. The HAL and startup/interrupt > codes use 2,400 bytes of RAM. That leaves me with about 14,800 bytes > for application code. I would like to be prepared to reduce the > FreeRTOS RAM footprint if I need to in the future. > > I know I can elevate optimization (presently set to none) but I don't > want to do that this early in the code-writing stage because it makes > the debugger present better steppable code. > > Thanks - JJS
It seems REALLY strange that freeRTOS uses 15KByte of RAM for itself. From this: https://www.freertos.org/FAQMem.html it seems that RAM usage is under 1KB. Or you meant flash instead of RAM, so 15KB might be correct, depending on the configuration. Bye Jack
On 7/5/2018 10:37 PM, Jack wrote:
> On Friday, July 6, 2018 at 2:30:53 AM UTC+2, John Speth wrote: >> Hi Folks- >> >> FreeRTOS has a build config file (FreeRTOSConfig.h) that users can apply >> at build time to customize the RTOS. The FreeRTOS web site has a page >> to describe the options (https://www.freertos.org/a00110.html). What it >> doesn't have is any hints about how much RAM it might save me. >> >> Does anybody have any first hand advice about how much RAM each option >> might contribute to the RAM footprint? Google isn't helping me. >> >> I'm trying prepare an STM32L151 to accommodate my as yet unwritten >> application code with FreeRTOS. The map file is showing me that >> FreeRTOS is using 15,000 bytes of RAM. The HAL and startup/interrupt >> codes use 2,400 bytes of RAM. That leaves me with about 14,800 bytes >> for application code. I would like to be prepared to reduce the >> FreeRTOS RAM footprint if I need to in the future. >> >> I know I can elevate optimization (presently set to none) but I don't >> want to do that this early in the code-writing stage because it makes >> the debugger present better steppable code. >> >> Thanks - JJS > > It seems REALLY strange that freeRTOS uses 15KByte of RAM for itself. > From this: > https://www.freertos.org/FAQMem.html > > it seems that RAM usage is under 1KB. > > Or you meant flash instead of RAM, so 15KB might be correct, depending on the
configuration.
> > Bye Jack >
A good nights sleep cleared my head for a closer examination of the map file. The config file specifies a single RTOS heap of 15K bytes. The map file confirmed it. So of course there is a tradeoff that I'll need to examine my application to minimize task heap usage. It's explained in greater detail at https://www.freertos.org/a00111.html. Thanks for getting me started - JJS
On 7/5/2018 10:12 PM, Joe Chisolm wrote:
> On Thu, 05 Jul 2018 17:29:18 -0700, John Speth wrote: > >> Hi Folks- >> >> FreeRTOS has a build config file (FreeRTOSConfig.h) that users can apply >> at build time to customize the RTOS. The FreeRTOS web site has a page >> to describe the options (https://www.freertos.org/a00110.html). What it >> doesn't have is any hints about how much RAM it might save me. >> >> Does anybody have any first hand advice about how much RAM each option >> might contribute to the RAM footprint? Google isn't helping me. >> >> I'm trying prepare an STM32L151 to accommodate my as yet unwritten >> application code with FreeRTOS. The map file is showing me that >> FreeRTOS is using 15,000 bytes of RAM. The HAL and startup/interrupt >> codes use 2,400 bytes of RAM. That leaves me with about 14,800 bytes >> for application code. I would like to be prepared to reduce the >> FreeRTOS RAM footprint if I need to in the future. >> >> I know I can elevate optimization (presently set to none) but I don't >> want to do that this early in the code-writing stage because it makes >> the debugger present better steppable code. >> >> Thanks - JJS > > It has been a couple of years since I did a lot with FreeRTOS but if > I remember correctly there are very few static built data structures. > Most are linked list and such that grow based on your resource usage > (number of task, queues, semaphores, etc). How are you allocating > your heap. If you are using the default simple allocators then part > of that 15K is the heap. You can try decreasing the size or plan on > your app doing a lot of malloc allocation for data structures and allocate > more ram to the heap. > > Optimization is not going to do a lot for your RAM usage. It will decrease > your flash usage some. If you are starting to run out of flash that is a > different story. You can try and remove some of API features you are not using
and
> cut down some on flash usage. >
That's a good point about the optimizer. It was long and late day fatigue that made me say it. The STM32 is swimming in flash compared to RAM. It's the RTOS heap that's pigging out on RAM (15K according to my config file). I can manage it easily from the config file. See https://www.freertos.org/a00111.html. Thanks - JJS
On 7/5/2018 10:37 PM, Jack wrote:
> On Friday, July 6, 2018 at 2:30:53 AM UTC+2, John Speth wrote: >> Hi Folks- >> >> FreeRTOS has a build config file (FreeRTOSConfig.h) that users can apply >> at build time to customize the RTOS. The FreeRTOS web site has a page >> to describe the options (https://www.freertos.org/a00110.html). What it >> doesn't have is any hints about how much RAM it might save me. >> >> Does anybody have any first hand advice about how much RAM each option >> might contribute to the RAM footprint? Google isn't helping me. >> >> I'm trying prepare an STM32L151 to accommodate my as yet unwritten >> application code with FreeRTOS. The map file is showing me that >> FreeRTOS is using 15,000 bytes of RAM. The HAL and startup/interrupt >> codes use 2,400 bytes of RAM. That leaves me with about 14,800 bytes >> for application code. I would like to be prepared to reduce the >> FreeRTOS RAM footprint if I need to in the future. >> >> I know I can elevate optimization (presently set to none) but I don't >> want to do that this early in the code-writing stage because it makes >> the debugger present better steppable code. >> >> Thanks - JJS > > It seems REALLY strange that freeRTOS uses 15KByte of RAM for itself. > From this: > https://www.freertos.org/FAQMem.html > > it seems that RAM usage is under 1KB. > > Or you meant flash instead of RAM, so 15KB might be correct, depending on the
configuration.
> > Bye Jack >
A good nights sleep cleared my head for a closer examination of the map file. The config file specifies a single RTOS heap of 15K bytes. The map file confirmed it. So of course there is a tradeoff that I'll need to examine my application to minimize task heap usage. It's explained in greater detail at https://www.freertos.org/a00111.html. Thanks for getting me started - JJS