freertos_blinky on NGX_xplorer 1830 - printf fails due to malloc

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

freertos_blinky on NGX_xplorer 1830 - printf fails due to malloc

258 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by robertpalmerjr on Mon May 19 14:58:08 MST 2014
I'm using the NGX_xplorer_1830 board and running the freertos_blinky example.

I have a serial connection to USART0.  If I use printf in the main (outside of a task), it will work.  If I use printf() inside a task, the malloc fails (I single stepped into the printf assembly) and the information never prints.  If I use the CR_PRINTF_CHAR symbol, it works fine (which makes sense since this flag causes printf to NOT use malloc).

I'm using the example, unchanged from the download.  So the question is, WHY is malloc failing?  The heap is configured as 16kB which should be PLENTY.  The stack is configured as 128.  I tried a stack of 256 and I tried a heap of 8k, 10k, and 32k - in all cases, malloc still fails.

I'm using lpcopen_2_09_lpcxpresso_ngx_xplorer_1830.zip

At least I have a work around for printf, but if malloc is failing, I need to know why - I'm going to need to call it directly from my code.
Labels (1)
0 Kudos
2 Replies

238 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by robertpalmerjr on Mon May 19 15:39:09 MST 2014
Ok, after more searching (regarding malloc instead of printf) I found the following:

http://www.lpcware.com/content/forum/malloc-allocation-failed-using-redlib

and

http://www.lpcware.com/content/faq/malloc-failure-using-freertos-heap3c-lpcxpresso-tool-chain

and

http://www.lpcware.com/content/faq/lpcxpresso/heap-checking-redlib

I did not try the last approach (two region memory model).  I did add the __check_heap_overflow() function described in the second link and it fixed the problem.

I would suggest that this be included in the freertos examples - in the case of the freertos_blinky example, it won't function correctly without it (IF you actually connect a serial cable).

0 Kudos

238 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sundarapandian on Mon May 19 15:28:56 MST 2014
Please see the the FAQ at http://www.lpcware.com/content/faq/malloc-failure-using-freertos-heap3c-lpcxpresso-tool-chain

Hope that helps.
0 Kudos