Enabling X-Cube-AI in STM32CubeIDE project causes "undefined reference to `__wrap_malloc'" errors during compile.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-03-28 9:24 AM
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
Solved! Go to Solution.
- Labels:
-
STM32CubeIDE
-
X-CUBE-AI
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-03-29 3:13 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-03-29 3:13 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-03-29 7:00 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-03-30 12:43 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-04-22 1:04 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-04-26 1:44 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-04-28 1:04 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-04-28 3:10 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-04-30 7:40 AM
Unfortunately I have the problem again, and proposed solution is not possible.
- I use Cube IDE 1.6.1
- In Cube IDE, Cube MX I did the configuration: Timer, USART, added ML network in Cube.AI
- I generated to project.
- I developed some code.
- I was able to build the project without any issues.
- I closed Cube IDE and turned off the macbook.
- I turned on Macbook, opened Cube IDE.
- 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:
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++
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-05-05 11:18 PM
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.
