FreeRTOS Heap problem

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have modified the asf provided port of FreeRTOS by writing a few new tasks, I removed all of the demo tasks and added a few drivers from asf.

Now I geta failure to allocate memory everytime malloc in malloc3.c is called. This happens even if I dont create any tasks just have an empty main where I start the scheduler after seting up the clocks.

How can I troubleshoot this ? Is the source for malloc provided in the libraries?

I have attached the map output from failing freertos


 .bss.uxTopReadyPriority
                0x00000858        0x4 src/asf/thirdparty/freertos/source/tasks.o
 .bss.__malloc_max_total_mem
                0x0000085c        0x4 c:/program files/atmel/atmel studio 6.0/extensions/atmel/avrgcc/3.3.2.31/avrtoolchain/bin/../lib/gcc/avr32/4.4.3/../../../../avr32/lib/ucr3fp\libc.a(lib_a-mallocr.o)
                0x0000085c                __malloc_max_total_mem
 .bss.__malloc_max_sbrked_mem
                0x00000860        0x4 c:/program files/atmel/atmel studio 6.0/extensions/atmel/avrgcc/3.3.2.31/avrtoolchain/bin/../lib/gcc/avr32/4.4.3/../../../../avr32/lib/ucr3fp\libc.a(lib_a-mallocr.o)
                0x00000860                __malloc_max_sbrked_mem
 .bss.__malloc_top_pad
                0x00000864        0x4 c:/program files/atmel/atmel studio 6.0/extensions/atmel/avrgcc/3.3.2.31/avrtoolchain/bin/../lib/gcc/avr32/4.4.3/../../../../avr32/lib/ucr3fp\libc.a(lib_a-mallocr.o)
                0x00000864                __malloc_top_pad
 .bss.__malloc_current_mallinfo
                0x00000868       0x28 c:/program files/atmel/atmel studio 6.0/extensions/atmel/avrgcc/3.3.2.31/avrtoolchain/bin/../lib/gcc/avr32/4.4.3/../../../../avr32/lib/ucr3fp\libc.a(lib_a-mallocr.o)
                0x00000868                __malloc_current_mallinfo
 *(COMMON)
 COMMON         0x00000890        0x4 c:/program files/atmel/atmel studio 6.0/extensions/atmel/avrgcc/3.3.2.31/avrtoolchain/bin/../lib/gcc/avr32/4.4.3/../../../../avr32/lib/ucr3fp\libc.a(lib_a-reent.o)
                0x00000890                errno
                0x00000898                . = ALIGN (0x8)
 *fill*         0x00000894        0x4 00
                0x00000898                . = ALIGN (0x8)
                0x00000898                _end = .
                0x00000898                PROVIDE (end, .)
                0x00000898                __heap_start__ = ALIGN (0x8)

.heap           0x00000898     0xe768
 *(.heap)
                0x0000f000                . = (__heap_size__ == __max_heap_size__)?((0x10000 - __stack_size__) - ABSOLUTE (.)):__heap_size__
 *fill*         0x00000898     0xe768 00
                0x0000f000                __heap_end__ = .

I also have the output from unmodified example freertos map.


 .bss.uxTopReadyPriority
                0x00000840        0x4 src/asf/thirdparty/freertos/source/tasks.o
 .bss.ucCurrentOutputValue
                0x00000844        0x1 src/ParTest.o
 *fill*         0x00000845        0x3 00
 .bss.__malloc_max_total_mem
                0x00000848        0x4 c:/program files/atmel/atmel studio 6.0/extensions/atmel/avrgcc/3.3.2.31/avrtoolchain/bin/../lib/gcc/avr32/4.4.3/../../../../avr32/lib/ucr3fp\libc.a(lib_a-mallocr.o)
                0x00000848                __malloc_max_total_mem
 .bss.__malloc_max_sbrked_mem
                0x0000084c        0x4 c:/program files/atmel/atmel studio 6.0/extensions/atmel/avrgcc/3.3.2.31/avrtoolchain/bin/../lib/gcc/avr32/4.4.3/../../../../avr32/lib/ucr3fp\libc.a(lib_a-mallocr.o)
                0x0000084c                __malloc_max_sbrked_mem
 .bss.__malloc_top_pad
                0x00000850        0x4 c:/program files/atmel/atmel studio 6.0/extensions/atmel/avrgcc/3.3.2.31/avrtoolchain/bin/../lib/gcc/avr32/4.4.3/../../../../avr32/lib/ucr3fp\libc.a(lib_a-mallocr.o)
                0x00000850                __malloc_top_pad
 .bss.__malloc_current_mallinfo
                0x00000854       0x28 c:/program files/atmel/atmel studio 6.0/extensions/atmel/avrgcc/3.3.2.31/avrtoolchain/bin/../lib/gcc/avr32/4.4.3/../../../../avr32/lib/ucr3fp\libc.a(lib_a-mallocr.o)
                0x00000854                __malloc_current_mallinfo
 .bss.cur_heap_pos.1869
                0x0000087c        0x4 c:/program files/atmel/atmel studio 6.0/extensions/atmel/avrgcc/3.3.2.31/avrtoolchain/bin/../lib/gcc/avr32/4.4.3/../../../../avr32/lib/ucr3fp\libc.a(lib_a-syscalls.o)
 *(COMMON)
 COMMON         0x00000880        0x4 c:/program files/atmel/atmel studio 6.0/extensions/atmel/avrgcc/3.3.2.31/avrtoolchain/bin/../lib/gcc/avr32/4.4.3/../../../../avr32/lib/ucr3fp\libc.a(lib_a-reent.o)
                0x00000880                errno
                0x00000888                . = ALIGN (0x8)
 *fill*         0x00000884        0x4 00
                0x00000888                . = ALIGN (0x8)
                0x00000888                _end = .
                0x00000888                PROVIDE (end, .)
                0x00000888                __heap_start__ = ALIGN (0x8)

.heap           0x00000888     0xe778
 *(.heap)
                0x0000f000                . = (__heap_size__ == __max_heap_size__)?((0x10000 - __stack_size__) - ABSOLUTE (.)):__heap_size__
 *fill*         0x00000888     0xe778 00
                0x0000f000                __heap_end__ = .

To be honest I am not quite sure what I am looking at here. Please help me pointing me in the right direction on how to troubleshoot this problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi tridentsx

Do not use malloc with freeRTOS, you should use pvPortMalloc as this is the 'safe' version of malloc. (It suspends all tasks so that there is no conflict with memory).

You should also check what memory management is being used by FreeRTOS. In my code (for the UC3A) it is heap_3.c and this is where the above function is defined.

If you haven't purchased it already then I would suggest getting the FreeRTOS book, as it is well worth it.

Regards.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am indirectly using the pvPortMalloc since that is called by the xTaskCreate() and vTaskStartScheduler() functions.
The pvPortMalloc is calling the standard malloc in heap_3.c

This works fine when I use the template asf project, however after adding some asf drivers this code fails to allocate heap. It looks to me from the map files there should be heap available though.

Thanks though and I do have the books.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sounds like your ASF code might have standard malloc calls (it doesn't know you are running FreeRTOS)....search and replace any of them with pvPortMalloc.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The other option is to switch to the older AVR 32 Studio (which is what I use) as this does seem to correctly use the right functions for FreeRTOS and other Drivers. I remember reading (on here) that the integration for FreeRTOS is the newer IDE isn't as complete as it should be, which might be the issue you are running into.

Just some more thoughts.

Regards.