2021-03-28 09: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.
2021-03-29 03: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
2021-03-29 03: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
2021-03-29 07: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.
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
2021-04-22 01: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
2021-04-26 01: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
2021-04-28 01: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.
2021-04-28 03: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
2021-04-30 07:40 AM
Unfortunately I have the problem again, and proposed solution is not possible.
/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++
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.