cancel
Showing results for 
Search instead for 
Did you mean: 

undefined reference to "MX_USB_DEVICE_Init" during Linker operation under System Workbench for STM32

LDel .1
Associate II

Hi all,

I'm developping an application under system workbench for STM32. The compilation works fine, but when it comes to the Linker I get the following output :

16:08:46 **** Incremental Build of configuration Release for project Firmware ****
make all 
Building target: Firmware.elf
Invoking: MCU GCC Linker
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -specs=nosys.specs -specs=nano.specs -T"../STM32F412ZETx_FLASH.ld" -Wl,-Map=output.map -Wl,--gc-sections -o "Firmware.elf" @"objects.list"   -lm
Src/main.o: In function `main':
D:\dev\AEL_FW\Firmware\Release/../Src/main.c:119: undefined reference to `MX_USB_DEVICE_Init'
Src/stm32f4xx_it.o: In function `OTG_FS_IRQHandler':
D:\dev\AEL_FW\Firmware\Release/../Src/stm32f4xx_it.c:282: undefined reference to `hpcd_USB_OTG_FS'
collect2.exe: error: ld returned 1 exit status
make: *** [Firmware.elf] Error 1
makefile:43: recipe for target 'Firmware.elf' failed
 
16:08:47 Build Finished (took 981ms)

I've tried to trace back the error :

main.c :

#include "usb_device.h"  
 
...
 
int main(void)
{
...
MX_USB_DEVICE_Init();
...
}

in usb_device.h :

void MX_USB_DEVICE_Init(void);

in usb_device.c

void MX_USB_DEVICE_Init(void)
{
  /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
 
  /* USER CODE END USB_DEVICE_Init_PreTreatment */
 
  /* Init Device Library, add supported class and start the library. */
  if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK)
  {
    Error_Handler();
  }
  if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK)
  {
    Error_Handler();
  }
  if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK)
  {
    Error_Handler();
  }
  if (USBD_Start(&hUsbDeviceFS) != USBD_OK)
  {
    Error_Handler();
  }
 
  /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */
 
  /* USER CODE END USB_DEVICE_Init_PostTreatment */
}

It also seems that FS_Desc cannot be resolved eventhough usbd_desc.h and usbd_desc.c are included and FS_Desc is declared and defined :

USBD_DescriptorsTypeDef FS_Desc =
{
  USBD_FS_DeviceDescriptor
, USBD_FS_LangIDStrDescriptor
, USBD_FS_ManufacturerStrDescriptor
, USBD_FS_ProductStrDescriptor
, USBD_FS_SerialStrDescriptor
, USBD_FS_ConfigStrDescriptor
, USBD_FS_InterfaceStrDescriptor
#if (USBD_LPM_ENABLED == 1)
, USBD_FS_USR_BOSDescriptor
#endif /* (USBD_LPM_ENABLED == 1) */
};

I've attached the whole project if you want to take a look at it.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

You'll need to mark the directory containing "usb_device.c" and other USB source files as one that need compiled.

https://stackoverflow.com/questions/9815131/eclipse-cdt-convert-a-normal-folder-to-a-source-folder-or-vice-versa

STM32CubeIDE is superior to the old system workbench for stm32. Consider switching if you can.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

You'll need to mark the directory containing "usb_device.c" and other USB source files as one that need compiled.

https://stackoverflow.com/questions/9815131/eclipse-cdt-convert-a-normal-folder-to-a-source-folder-or-vice-versa

STM32CubeIDE is superior to the old system workbench for stm32. Consider switching if you can.

If you feel a post has answered your question, please click "Accept as Solution".
LDel .1
Associate II

Thanks, it worked indeed. I had thought of including all the Inc path, and didn't think about doing it for the sources too, shame on me !

About switching to CubeIDE, I actually tried but using "File >Import... > Import ac6 System Workbench for STM32 Project" just doesn't do anything (the project explorer stays empty)

Using "Files > Open project from file system" does the same.

Which is weird because the project is actually detected : 0693W00000BZrRYQA1.png 

The only thing I managed to do was to go "File > Import > Existing project into workspace" which actually imported the project, but then the build configurations are lost...