Quality RTOS & Embedded Software

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




Loading

How the memory is menaged in ARM7?

Posted by Konoppo on March 23, 2009
Hi!!
After I yesterday rise a false alarm about "Bug in FreeRTOS" now I want to refresh my knowledge about FreeRTOS and memory organization.

Please, help me and tell me answer for following questions:
1)heap - what is it?? I though that is kind of stack :). It's divided between all task (each task has its own stac, but all the stacks are on heap), and it’s also used by queues and semaphores.

2)where is the heap?? I had though that heap is a part of normal stack so in linker script I should give enough space for stack. But I had no idea what kind of stack it should be (User Mode, Supervisor Mode, maybe IRQ Mode??) No I think that heap is kept in the “normal ram” (bss_section) like a regular variable. Is it OK?

3)Is freeRTOS using regular stack?? I think that it use “regular stack” but only in ISR and in kernel-function. It uses a supervisor mode’s stack ind IRQ mode’s stack (sometimes FIQ). Tasks have their own stacks on heap and their don’t use the stack defined in bss_sectrion in linker script. It means that stack size typically could be smaller than heap size. Is it OK??

4)What does author mean when writing paragraph Stack Overflow Detection on freertos.org site (User Documentation \ Configuration \ Stack Overflow Detection)? I think that is about overflowing task’s specific stack which really is on the heap, not in the regular stack. Is it true?

Thanks for explanations :)....
Konoppo

RE: How the memory is menaged in ARM7?

Posted by Richard on March 24, 2009
> Please, help me and tell me answer for following questions:
> 1)heap - what is it?? I though that is kind of stack :).
> It's divided between
> all task (each task has its own stac, but all the stacks are
> on heap), and it’s
> also used by queues and semaphores.

That is right. The heap is the memory that malloc() uses to allocate memory. In this case pvPortMalloc() is used so you can implement the heap however you like. See http://www.freertos.org/a00111.html



> of stack it should be (User Mode, Supervisor Mode, maybe IRQ
> Mode??) No I think
> that heap is kept in the “normal ram” (bss_section) like a
> regular variable.
> Is it OK?


If you use heap_1.c or heap_2.c then the heap is just an array. Declared as a normal array variable.

main() is called from Supervisor mode so you need a Supervisor stack (the kernel also uses that stack). Tasks use system mode but their stack comes from the heap so you don't have to allocate anything in the startup file for them. You will also need an IRQ stack for interrupts. No other stacks are required by the kernel, but your application may require other stacks (FIQ for example).


>
> 3)Is freeRTOS using regular stack?? I think that it use
> “regular stack”
> but only in ISR and in kernel-function. It uses a supervisor
> mode’s stack
> ind IRQ mode’s stack (sometimes FIQ). Tasks have their own
> stacks on heap
> and their don’t use the stack defined in bss_sectrion in
> linker script. It
> means that stack size typically could be smaller than heap
> size. Is it OK??

The Supervisor mode stack only needs to be big enough for main() to run, and taskYIELD() to be called. It can normally be very small.


>
> 4)What does author mean when writing paragraph Stack
> Overflow Detection on
> freertos.org site (User Documentation \ Configuration \ Stack
> Overflow Detection)?
> I think that is about overflowing task’s specific stack which
> really is on
> the heap, not in the regular stack. Is it true?

It is true that it is talking about the task stacks. The task starts are normal stacks, its just that they are allocated from the heap. They are the User/System mode stacks. The stack can be anywhere you point the stack pointer to.

Regards.

RE: How the memory is menaged in ARM7?

Posted by Konoppo on March 24, 2009
Thanks for great help :). Now I'm finally unterstand what's going on ;)... In 4) when I say "stack" I have in mind the stack declared in the startup file ;)... So the regular stac = stack declared in startup file, and stack which is located on heap - is not "regular" stack :).

This questions were so important for me because I use ethernet ram as a "universal purpose ram" in my project and I had to decide how to divide variables, heap and stack between two regions of RAM (regular 8K RAM and 16K ethernet ram). Now I'm using a 8kB RAM for regular stack and variables, and 16kB Ethernet RAM for heap.

Regards!!


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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