2022-01-13 12:46 PM
I have default setup under linux with CubeIDE 1.7.0 and for overriding, i had to modify as
__weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd);
__weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd);
oh header definitions. Otherwise it complains about multiple definitions despite .c weak implementations. It might be related to gcc logic. These functions are said to be USB related.
Am i missing a point? Header files requires weak definitions. Update if necessary.
Solved! Go to Solution.
2022-01-13 03:40 PM
HAL puts it in usbd_conf.c, so that definition makes sense. This is the copy you should use and if you need to modify it, it should be done there. The original (weak) definition which this one overrides is in stm32f4xx_hal_pcd.c.
entry.cpp isn't a HAL file, why are you implementing it there as well? As far as I can tell this file isn't generated by any ST tool.
2022-01-13 02:35 PM
Post the actual complete error message you're seeing. You might just be compiling in two different places.
There are many weakly defined functions in various HAL files that get overridden and it doesn't make sense why it would work for all the others and not work for this one.
2022-01-13 02:56 PM
/opt/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.linux64_2.0.0.202105311346/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: ./USB_DEVICE/Target/usbd_conf.o: in function `HAL_PCD_ConnectCallback':
X/workspace_1.7.0/X/Debug/../USB_DEVICE/Target/usbd_conf.c:293: multiple definition of `HAL_PCD_ConnectCallback'; ./Core/Src/entry.o:/X/workspace_1.7.0/X/Debug/../Core/Src/entry.cpp:149: first defined here
/opt/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.linux64_2.0.0.202105311346/tools/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: ./USB_DEVICE/Target/usbd_conf.o: in function `HAL_PCD_DisconnectCallback':
X/workspace_1.7.0/X/Debug/../USB_DEVICE/Target/usbd_conf.c:307: multiple definition of `HAL_PCD_DisconnectCallback'; ./Core/Src/entry.o:/X/workspace_1.7.0/X/Debug/../Core/Src/entry.cpp:154: first defined here
collect2: error: ld returned 1 exit status
Might be triggered by double compilation but they're HAL libraries.
USB is defined as serial port which uses usbd_conf files
I suspect different prog. lang (c/c++) since i modified it.
2022-01-13 03:40 PM
HAL puts it in usbd_conf.c, so that definition makes sense. This is the copy you should use and if you need to modify it, it should be done there. The original (weak) definition which this one overrides is in stm32f4xx_hal_pcd.c.
entry.cpp isn't a HAL file, why are you implementing it there as well? As far as I can tell this file isn't generated by any ST tool.
2022-01-13 03:48 PM
True, entry.cpp is my own implementation files for codes. As you described, this override should be done in usbd_conf.c but i just wanted them with my regular callback functions.
CubeIDE interface does not work well with C++ language so i kept my main.c and generated a separate entry.cpp file for MCU configuration. I would forget about usbd_conf files but seems like this is the way STM32 lib handles.