stm32duino / Arduino_Core_STM32

STM32 core support for Arduino
https://github.com/stm32duino/Arduino_Core_STM32/wiki
Other
2.85k stars 979 forks source link

Linking issue with FDCAN on STM32G0B1CBTx #2473

Closed 0x0fe closed 3 months ago

0x0fe commented 3 months ago

So, i need to use FDCAN on STM32G0B1CBTx target, since there is no wrapper i will directly access via the HAL APIs, however there seems to be some issue with scrwrapper, while i can see the HEL FDCAN sources are compiled, it cannot link with the functions from FDCAN, here is the error:

C:/Users/xxxxxxx/AppData/Local/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/13.2.1-1.1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\xxxxxxx\AppData\Local\Temp\arduino\sketches\7D345039B4813D6501D07371AD0DC887\sketch\BareMinimum.ino.cpp.o: in function `setup':
BareMinimum.ino.cpp:(.text.setup+0x4a): undefined reference to `HAL_FDCAN_Init'
collect2.exe: error: ld returned 1 exit status

Using library SrcWrapper at version 1.0.1 in folder: C:\Users\xxxxxxx\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.8.1\libraries\SrcWrapper 
exit status 1
Compilation error: exit status 1

and here is a sketch to reproduce the issue :

//target STM32G0B1CBT6

#include "stm32g0xx_hal.h"
#include "stm32g0xx_hal_fdcan.h"

FDCAN_HandleTypeDef hfdcan1;

void setup() {

  Serial.begin(115200);

  __HAL_RCC_FDCAN_CLK_ENABLE();
  hfdcan1.Instance = FDCAN1;
  hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
  hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK; // FDCAN_MODE_NORMAL
  hfdcan1.Init.ProtocolException = DISABLE;
  hfdcan1.Init.NominalPrescaler = 16;
  hfdcan1.Init.NominalSyncJumpWidth = 1;
  hfdcan1.Init.NominalTimeSeg1 = 1;
  hfdcan1.Init.NominalTimeSeg2 = 1;
  hfdcan1.Init.DataPrescaler = 16;
  hfdcan1.Init.DataSyncJumpWidth = 1;
  hfdcan1.Init.DataTimeSeg1 = 1;
  hfdcan1.Init.DataTimeSeg2 = 1;

  if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) {
    Serial.println("FDCAN1 init error");
  }
}

void loop() {

}

I tried to set the HAL includes as extern C but it did not help. How to fix this issue?

I suspect there is some issue with srcwrapper since i can see:

Using cached library dependencies for file: C:\Users\xxxxxxx\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.8.1\libraries\SrcWrapper\src\HAL\stm32yyxx_hal_can.c
Using cached library dependencies for file: 
C:\Users\xxxxxxx\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.8.1\libraries\SrcWrapper\src\HAL\stm32yyxx_hal_fdcan.c

And below, i can see an object file for hal_can but none for hal_fdcan

Using previously compiled file: C:\Users\xxxxxxx\AppData\Local\Temp\arduino\sketches\FA0B4FB95CC62D998AFD8E0B0B49444E\libraries\SrcWrapper\HAL\stm32yyxx_hal_can.c.o

I do not understand, provided that STM32G0B1 does not have any hal_can.c file, it only has hal_fdcan.c

https://github.com/stm32duino/Arduino_Core_STM32/tree/main/system/Drivers/STM32G0xx_HAL_Driver/Src

0x0fe commented 3 months ago

so, it seems the problem boils down to what i mentioned, however when trying to make a quick and dirty fix I ended up with another linking issue:

So what i did was to add

#define HAL_FDCAN_MODULE_ENABLED

in

stm32yyxx_hal_conf.h

and now i can see the object file for hal_fdcan.c

"C:\\Users\\xxxxxxx\\AppData\\Local\\Arduino15\\packages\\STMicroelectronics\\hardware\\stm32\\2.8.1\\libraries\\SrcWrapper\\src\\HAL\\stm32yyxx_hal_fdcan.c" -o "C:\\Users\\xxxxxxx\\AppData\\Local\\Temp\\arduino\\sketches\\7D345039B4813D6501D07371AD0DC887\\libraries\\SrcWrapper\\HAL\\stm32yyxx_hal_fdcan.c.o"

However i get a new linking issue related to the IRQ handler

C:/Users/xxxxxxx/AppData/Local/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/13.2.1-1.1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\xxxxxxx\AppData\Local\Temp\arduino\sketches\7D345039B4813D6501D07371AD0DC887\libraries\SrcWrapper\HardwareTimer.cpp.o: in function `TIM16_FDCAN_IT0_IRQHandler':
HardwareTimer.cpp:(.text.TIM16_FDCAN_IT0_IRQHandler+0x40): undefined reference to `phfdcan1'
C:/Users/xxxxxxx/AppData/Local/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/13.2.1-1.1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld.exe: HardwareTimer.cpp:(.text.TIM16_FDCAN_IT0_IRQHandler+0x48): undefined reference to `phfdcan2'
C:/Users/xxxxxxx/AppData/Local/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/13.2.1-1.1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\xxxxxxx\AppData\Local\Temp\arduino\sketches\7D345039B4813D6501D07371AD0DC887\libraries\SrcWrapper\HardwareTimer.cpp.o: in function `TIM17_FDCAN_IT1_IRQHandler':
HardwareTimer.cpp:(.text.TIM17_FDCAN_IT1_IRQHandler+0x40): undefined reference to `phfdcan1'
C:/Users/xxxxxxx/AppData/Local/Arduino15/packages/STMicroelectronics/tools/xpack-arm-none-eabi-gcc/13.2.1-1.1/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld.exe: HardwareTimer.cpp:(.text.TIM17_FDCAN_IT1_IRQHandler+0x48): undefined reference to `phfdcan2'
collect2.exe: error: ld returned 1 exit status
Using library SrcWrapper at version 1.0.1 in folder: C:\Users\xxxxxxx\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.8.1\libraries\SrcWrapper 
exit status 1
Compilation error: exit status 1