K82 : MCUExpresso disable heap usage

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

K82 : MCUExpresso disable heap usage

1,006 Views
EugeneHiihtaja
Senior Contributor I

Hello !

I use latest MCU Expresso and SDK for develop firmware for K82.

How-to completely disable heap usage and be sure if malloc/free is not called suddenly somewhere ?

I have set HeapSize =0 in Linker file and set trap for malloc/free in linker options.

But looks like heap is used somewhere in any case.

-Xlinker --wrap=malloc -Xlinker --wrap=free -Xlinker --wrap=calloc

But linker report :

c:/nxp/mcuxpressoide_10.3.0_2200/ide/plugins/com.nxp.mcuxpresso.tools.win32_10.3.0.201811011841/tools/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard\libcr_c.a(fpprintf.o): In function `printf':
fpprintf.c:(.text.printf+0x1e): undefined reference to `__wrap_malloc'
fpprintf.c:(.text.printf+0x3e): undefined reference to `__wrap_free'


c:/nxp/mcuxpressoide_10.3.0_2200/ide/plugins/com.nxp.mcuxpresso.tools.win32_10.3.0.201811011841/tools/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard\libcr_c.a(fclose.o): In function `fclose':
fclose.c:(.text.fclose+0x24): undefined reference to `__wrap_free'

How-to disable heap in MCUExpresso and K82 in correct way ?

Regards,

Eugene

0 Kudos
4 Replies

770 Views
BlackNight
NXP Employee
NXP Employee

You don't have much control what the GNU library does: internally it can use malloc() for things like printf() or file I/O. Another reason not to use the prinf() of the library. But what you can do is to disable at least some of it with selecting a 'none' or no-host' library variant:

pastedImage_1.png

The other way is that you overwrite the malloc() and free() functions with your own version to trap all usage of it.

I hope this helps,

Erich

0 Kudos

770 Views
EugeneHiihtaja
Senior Contributor I

Hi Erich !

I have MPU enabled environment  and any extra memory accesses to unknown area cause faults.

In linker file I set nohost version already 

/* Redlib Nohost */
GROUP(libcr_nohost.a libcr_c.a libcr_eabihelpers.a)

And in project settings it show nohost-nf like you recommend.

printf() is not used for sure but snprintf() is used for cook formatted strings.

Also FreeRTOS in some debug places use sprintf() functions.

Do you have idea why is latest MCUXpressoIDE_10.3.0_2200 is so slow in case of compilation ?

Previos version is fly on my computer, but current one need 5 min for compile project, even before it was 1 min.

Regards,

Eugene

0 Kudos

770 Views
bobpaddock
Senior Contributor III

Having directories in the path that do not exist can slow GCC to a crawl at times.

printf() and  snprintf() will likely call the same underlying print library.

Random tip that came to mind when reading your message, make sure all the stack are always aligned to an eight byte (long long) boundary when initialized.  Generally this happens by default by pointing at the end of RAM.

0 Kudos

770 Views
EugeneHiihtaja
Senior Contributor I

Hi Erich !

One more experiment. I have taken printf-stdarg.c implementation from Freertos examples and references to malloc/calloc are vanish.

But free is still in use somewhere c:/nxp/mcuxpressoide_10.3.0_2200/ide/plugins/com.nxp.mcuxpresso.tools.win32_10.3.0.201811011841/tools/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m/fpv4-sp/hard\libcr_c.a(fclose.o): In function `fclose':
fclose.c:(.text.fclose+0x24): undefined reference to `__wrap_free'
collect2.exe: error: ld returned 1 exit status

fclose() is actively used in mbedTLS  common code but for K82 it is excluded in configuration by using #ifdef flags.

May be linker is not willing so strip it or this call exists in other call function ?

At list active code dosn't have reference to it.

Any ideas ?

Regards,

Eugene

0 Kudos