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

Malloc failed in with pic32MX port

Posted by chaabanemalki on February 22, 2016

Hello, Sometimes when I try to allocate 2048 bytes using pvPortMalloc() it fails and reported that remaining space heap size is greated then 11k in the vApplicationMallocFailedHook()

I use heap4.c and I can't really find an explanation for this ?

Regards Chaabane


Malloc failed in with pic32MX port

Posted by richard_damon on February 22, 2016

One danger with using heap memory is that the heap space can become fragmented and hard to find large blocks. For instance, if you allocate a number of 1k blocks, then release every other one, the space left normally can't be used to allocate a 2k block. This is one reason many coding standards restrict the use of heap memory to startup and 'non-critical' operations that are allowed to 'fail'.


Malloc failed in with pic32MX port

Posted by chaabanemalki on February 22, 2016

I have allocated 36k for the kernel total heap, after few allocations of 38,32,512... bytes (doesn't exceed 4k), the pvPortMalloc() systematically failes to allocate 2K space yet it reported that it has more than 11,5K free space.

I reduced the total heap to 30K and everything is working just fine now !!!

Any idea why i'm having this issue ?


Malloc failed in with pic32MX port

Posted by rtel on February 22, 2016

I don't know of any reason this should be a problem.

How much RAM does your PIC32 actually have? Is anything else walking over the heap space? Is your linker script correct for your device and are any linker warnings generated?


Malloc failed in with pic32MX port

Posted by chaabanemalki on February 22, 2016

My PIC has 128K RAM and I don't have any linker warning.

What do you mean by "Is anything else walking over the heap space?" I'm not sure how to check that !!


Malloc failed in with pic32MX port

Posted by rtel on February 22, 2016

What do you mean by "Is anything else walking over the heap space?" I'm not sure how to check that !!

The heap includes some meta data that describes its state (which blocks are free, which allocated, etc.). If there is a good old fashioned data corruption by another part of the application writing over this data then the heap implementation will misbehave because the meta data will be corrupt.

It might be that a certain part of your RAM is getting used by something else, either intentionally or unintentionally, and once you set the heap size large enough so it hits that RAM region, you get into problems of corruption.


Malloc failed in with pic32MX port

Posted by chaabanemalki on February 24, 2016

It could be the case, Is there a way to check this ?


[ 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