cancel
Showing results for 
Search instead for 
Did you mean: 

Enabling X-Cube-AI in STM32CubeIDE project causes "undefined reference to `__wrap_malloc'" errors during compile.

RFeist
Associate

Steps to reproduce:

1.      Enable X-CUBE-AI core and add a network model.

2.      Go back into main.c and setup the calls to feed and run the model with data.

3.      Build the project.

Upon build, produces the following errors:

arm-none-eabi-gcc -o "NUCLEO-L476RG-Vibration_detect1.elf" @"objects.list" -larm_cortexM4lf_math -l:NetworkRuntime600_CM4_GCC.a -mcpu=cortex-m4 -T"C:\Users\feist\git\ROW_stationary_sensors\NUCLEO-L476RG-Vibration_detect1\STM32L476RGTX_FLASH.ld" --specs=nosys.specs -Wl,-Map="NUCLEO-L476RG-Vibration_detect1.map" -Wl,--gc-sections -static -Wl,--start-group -larm_cortexM4lf_math -l:NetworkRuntime600_CM4_GCC.a -Wl,--end-group -L../Middlewares/Third_Party/ARM_CMSIS/CMSIS/DSP/Lib/GCC -L../Middlewares/ST/AI/Lib -Wl,--wrap=malloc -Wl,--wrap=free -u _printf_float --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group

c:\st\stm32cubeide_1.6.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: c:/st/stm32cubeide_1.6.0/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard\libc_nano.a(lib_a-dtoa.o): in function `_dtoa_r':

dtoa.c:(.text._dtoa_r+0x24): undefined reference to `__wrap_malloc'

c:\st\stm32cubeide_1.6.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: c:/st/stm32cubeide_1.6.0/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard\libc_nano.a(lib_a-mprec.o): in function `_Balloc':

mprec.c:(.text._Balloc+0xc): undefined reference to `__wrap_malloc'

c:\st\stm32cubeide_1.6.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: c:/st/stm32cubeide_1.6.0/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard\libc_nano.a(lib_a-mprec.o): in function `_Bfree':

mprec.c:(.text._Bfree+0xc): undefined reference to `__wrap_malloc'

c:\st\stm32cubeide_1.6.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924\tools\arm-none-eabi\bin\ld.exe: c:/st/stm32cubeide_1.6.0/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard\libc_nano.a(lib_a-mprec.o): in function `__pow5mult':

mprec.c:(.text.__pow5mult+0x2a): undefined reference to `__wrap_malloc'

collect2.exe: error: ld returned 1 exit status

make: *** [makefile:66: NUCLEO-L476RG-Vibration_detect1.elf] Error 1

"make -j8 all" terminated with exit code 2. Build might be incomplete.

It seems enabling X-CUBE-AI automatically adds the following GCC Linker flags in the C/C++ Build Settings of project properties:

-Wl,--wrap=malloc -Wl,--wrap=free

I can remove these flags to get a successful build, but then during runtime I get a hard fault when trying to run my ai model.  Seemingly because X-CUBE-AI needs these linked libraries that the compiler cant find.

I’ve tried reverting back to X-CUBE-AI (v5.2) but getting the same errors.

STM32CubeIDE (v1.6)

X-Cube-AI (v6.0.0)

Target board: Nucleo-L476RG

Targeted Language: C

1 ACCEPTED SOLUTION

Accepted Solutions
fauvarque.daniel
ST Employee

Thanks for reporting this issue, in fact the "-Wl,--wrap=malloc -Wl,--wrap=free" is only necessary to generate the system performance application.

When generating for the other case this option should not be put so you can safely remove it from the build.

You may want to increase the heap and stack size to avoid the hard fault.

X-Cube-AI automatically sets a heap and stack size to be able to run the network but of course doesn't take into account the rest of the application

Regards

Daniel


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

9 REPLIES 9
fauvarque.daniel
ST Employee

Thanks for reporting this issue, in fact the "-Wl,--wrap=malloc -Wl,--wrap=free" is only necessary to generate the system performance application.

When generating for the other case this option should not be put so you can safely remove it from the build.

You may want to increase the heap and stack size to avoid the hard fault.

X-Cube-AI automatically sets a heap and stack size to be able to run the network but of course doesn't take into account the rest of the application

Regards

Daniel


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
RFeist
Associate

Thanks Daniel. All very helpful information. I was able to resolve my hard fault by reassessing my memory allocations throughout my program. As for the linker flags being added even when I don't have the system performance application enabled, yea I think this may be a bug in the current version of cubeMX within cubeIDE.

fauvarque.daniel
ST Employee

It is actually a bug in the X-CUBE-AI plugin of STM32CubeMX that will be fixed in the next release


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
DPiór.1
Associate II

Hi @fauvarque.daniel​ ,

I have the same issue. How can I remove those flags? "-Wl,--wrap=malloc -Wl,--wrap=free"

I can see them in project properties (C/C++ Build/Settings/MCU G++ Linker), but I can't edit it there.

STM32CubeIDE (v1.6.1)

X-Cube-AI (v6.0.0)

Target board: Nucleo-WB55

fauvarque.daniel
ST Employee

To remove the flags in STM32CubeIDE right click on the project and select "Properties"

Then select "C/C++ build -> Settings -> MCU GCC Linker -> Miscellaneous

In the Other flag you should see something like

-Wl,--wrap=malloc -Wl,--wrap=free -u _printf_float

You can edit this field and remove the -Wl,--wrap=malloc -Wl,--wrap=free, you can also remove the -u_printf_float if you don't plan to use printf with float values.

Regards

Daniel


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Thanks Daniel!

I will check proposed solution if I will face this issue again.

I already created new project and don't have this issue anymore. I don't know why sometimes the problem appears and sometimes not.

I was only able to reproduce the issue by first generating with "validation" and then switch to "Application template"

Our strategy is to not touch the parameters of the project once it has been created once by STM32CubeMX, so in that case the parameters remain, so creating the issue.

This is a tricky one as if you actually need the wrap in your project you won't be happy if we remove it each time you generate again.

Regards

Daniel


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Unfortunately I have the problem again, and proposed solution is not possible.

  1. I use Cube IDE 1.6.1
  2. In Cube IDE, Cube MX I did the configuration: Timer, USART, added ML network in Cube.AI
  3. I generated to project.
  4. I developed some code.
  5. I was able to build the project without any issues.
  6. I closed Cube IDE and turned off the macbook.
  7. I turned on Macbook, opened Cube IDE.
  8. Without making any changes to the project (nor in code, nor in Cube MX), I tried to build it. But now I received errors. It's odd, because I really did not change anything.

/Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.macos64_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: /Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.macos64_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libc_nano.a(lib_a-dtoa.o): in function `_dtoa_r':

dtoa.c:(.text._dtoa_r+0x1e): undefined reference to `__wrap_malloc'

/Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.macos64_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: /Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.macos64_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libc_nano.a(lib_a-mprec.o): in function `_Balloc':

mprec.c:(.text._Balloc+0xc): undefined reference to `__wrap_malloc'

/Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.macos64_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: /Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.macos64_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libc_nano.a(lib_a-mprec.o): in function `_Bfree':

mprec.c:(.text._Bfree+0xc): undefined reference to `__wrap_malloc'

/Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.macos64_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: /Applications/STM32CubeIDE.app/Contents/Eclipse/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.macos64_1.5.0.202011040924/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+dp/hard/libc_nano.a(lib_a-mprec.o): in function `__pow5mult':

mprec.c:(.text.__pow5mult+0x2a): undefined reference to `__wrap_malloc'

collect2: error: ld returned 1 exit status

make: *** [makefile:81: m7-550.elf] Error 1

"make -j3 all" terminated with exit code 2. Build might be incomplete.

Now I receive the error every time, even in new project.

I'm not able to remove those flags as recommended by Daniel, because I don't see them in that place. Please see below screenshot:

0693W00000AN1lnQAD.png 

Any idea what is causing the issue and how to fix it? I can share the project if it will help.

I'm using:

macOS Catalina

Cube IDE 1.6.1

Nucleo-H723ZG

target language: C++

DPiór.1
Associate II

I found a way how to remove those flags. I just can remove them directly from .cproject file.

Unfortunately I still didn't find the rule for this issue. In most cases it happens after editing .ioc file in CubeMX, but not always.