Quality RTOS & Embedded Software

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




Loading

Dynamic allocation of queue creates conflict

Posted by j-md on November 7, 2016

Hi all, I have an application running on Microchip dsPIC33 with FreeRTOS. I use the default options, that is, dynamic allocation everywhere for all FreeRTOS objects. The application has 5 tasks and 3 queues of 20 items of 34 bytes each. The heap_3.c version is used. I came across a bug, where the application would crash when accessing the queues. I eventually found that the 3 queues were created within one of the tasks, and when I looked at the addresses of the queues, they seem to overlap the stack of one of the tasks. I moved the creation of the 3 queues to the main() function, and the problem disappeared. So my question is : how is the dynamic memory allocation handled? Is it forbidden to allocate a queue from within a task?

On another project using a STM32, I currently also have instabilities, and I now realize that one task is creating a recursive mutex. Could this be the same problem again? In any case I will try and create the mutex from the main() function to see if it does any good.


Dynamic allocation of queue creates conflict

Posted by rtel on November 7, 2016

It is very common for tasks to create RTOS objects, and even other tasks. As you are using heap_3 you will be using the malloc() provided by your compiler. My best guess would be that the linker script is not set up correctly for your device.

When you create RTOS objects (Queues, etc.) are you checking the return value of the create function to check the object was actually created before you use it?

If you change the order in which the object are created (by creating the queues before you start the scheduler, as you said in your post) you are not changing the amount of memory allocation, so I expect all you have done is move the problem somewhere else.


Dynamic allocation of queue creates conflict

Posted by j-md on November 7, 2016

Yes, I have checked the return value and if it is null, the processor goes into an endless loop so that I can easily locate the problem in debug mode. In the configuration file, the heap size is set to 15120 which seems to be enough for all the tasks and all the queues. But still, since I moved the queue creation to the main() function, It has worked without any problem. When a task is created, does it allocate the size of the stack ? In my case, I doubted this is true.


Dynamic allocation of queue creates conflict

Posted by davedoors on November 7, 2016

In the configuration file, the heap size is set to 15120

Which configuration file? FreeeRTOSConfig? Heap 3 doesnt use configTOTALHEAPSIZE http://www.freertos.org/a00111.html


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists