PlatformIO Community

[.pio/build/bluepill_f103c8/zephyr/firmware-pre.elf] Error 1

HI guys
I ran into this error while im trying to use HAL drivers in my main code i also included <stm32f1xx.h> in my main.c file .
i dont know what to do to solve this error can anyone help me?
/home/mohammad/.platformio/packages/toolchain-gccarmnoneeabi/bin/…/lib/gcc/arm-none-eabi/8.2.1/…/…/…/…/arm-none-eabi/bin/ld.bfd: .pio/build/bluepill_f103c8/src/main.o: in function main': /home/mohammad/Documents/PlatformIO/Projects/secondP/src/main.c:50: undefined reference to HAL_GPIO_WritePin’
collect2: error: ld returned 1 exit status
*** [.pio/build/bluepill_f103c8/zephyr/firmware-pre.elf] Error 1
please help thanks you.

Good question. I’m landing at the same error when trying to use the function.

The config values CONFIG_USE_STM32_HAL_GPIO — Zephyr Project Documentation and CONFIG_HAS_STM32CUBE — Zephyr Project Documentation select the STM32 HAL (and GPIO HAL), but these are not “user-assignable” in the prj.confg, rather Zephyr handles them internally. I’ll open an issue about this.

Tracked in Using STM32Cube HAL function results in linker error · Issue #37543 · zephyrproject-rtos/zephyr · GitHub.

Hi thanks you
Im trying to run that on ubuntu and im keep getting this error i dont know whats the matter with code.
if any solution you got , please aware me tnx.

I’m also running into the same problem. Here is what I’ve found out so far. I’m building for a bluepill so the project is the board is setup as bluepill_f103c8. It gives me this error:

collect2.exe: error: ld returned 1 exit status
*** [.pio\build\bluepill_f103c8\zephyr\firmware-pre.elf] Error 1

When I build a project for the MCU only, STM32F103C8, than it builds fine. For this, the board would be set to genericSTM32F103C8.

I will continue to investigate but I’m quite positive its something within the hardware build directory.

I was able to solve the issue as someone pointed to the right documentation in the linked issue.

I’m struggling to find how to set the Kconfig up, I’v reduced my entire code to this:

#include <zephyr.h>
#include <stm32f1xx.h>
#include <stm32f1xx_hal.h>

UART_HandleTypeDef huart3;

int main(void)
{
    HAL_Init();
    return 0;
}

And the output shows the error being caused during linking:

c:/users/brandon/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\bluepill_f103c8\modules\stm32\stm32cube\lib_pio__modules__hal__stm32__stm32cube.a(stm32f1xx_hal.c.o): in function `HAL_InitTick':
C:\Users\Brandon\.platformio\packages\framework-zephyr\_pio\modules\hal\stm32\stm32cube\stm32f1xx\drivers\src/stm32f1xx_hal.c:237: undefined reference to `HAL_SYSTICK_Config'
c:/users/brandon/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\Brandon\.platformio\packages\framework-zephyr\_pio\modules\hal\stm32\stm32cube\stm32f1xx\drivers\src/stm32f1xx_hal.c:245: undefined reference to `HAL_NVIC_SetPriority'
c:/users/brandon/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: .pio\build\bluepill_f103c8\modules\stm32\stm32cube\lib_pio__modules__hal__stm32__stm32cube.a(stm32f1xx_hal.c.o): in function `HAL_Init':
C:\Users\Brandon\.platformio\packages\framework-zephyr\_pio\modules\hal\stm32\stm32cube\stm32f1xx\drivers\src/stm32f1xx_hal.c:157: undefined reference to `HAL_NVIC_SetPriorityGrouping'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\bluepill_f103c8\zephyr\firmware-pre.elf] Error 1

From the issue you linked, it looks like I can’t use HAL drivers from CubeMX unless I create a Kconfig file. I’m not sure how to set that up. Do you have a project with this as an example you could point me too?

I don’t think you need to be calling HAL_Init() at all, Zephyr should already take care of base initialization. If you still wish to call it, you need to take care that all sub-dependenceis of the functions are found. The missing HAL_NVIC_SetPriority function is implemented in

Which gets activated by

As a project I used zephyr-blink and created the zephyr/Kconfig file as described in the issue. The values which activate certain HAL subsystems can be looked up in the CMakeLists.txt.

Note that calling STM32HAL functions directly instead of using the Zephyr APIs is very anti-pattern, as they themselves note.

HI, thanks for the help. You’re right, for me to use the HAL library would be avoiding the existing API calls that Zephyr already provides. The problem I’m running into is that I already have a large amount of HAL experience and switching to Zephyr at this point would require better resources and a steap learning curve. For now, I think I will switch back to FreeRTOS/HAL library but am looking forward to Zephyr growing and the community support improving. At first glance, there is a lot I like about it. I am following you on GitHub and will keep an eye on your contributions.