cancel
Showing results for 
Search instead for 
Did you mean: 

__weak requirement on stm32f4xx_hal_pcd.h functions

MKanc.1
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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.

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

View solution in original post

4 REPLIES 4
TDK
Guru

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.

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

/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.

TDK
Guru

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.

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

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.