I am having trouble compiling the demonstration code for the STM32F4-Discovery using the arm-none-eabi
toolchain. The error is occuring in linking and this is the [first] error I'm receiving.
template/obj/stm32f4xx_it.o: In function `OTG_FS_IRQHandler':
template/src/stm32f4xx_it.c:192: undefined reference to `hpcd'
I've been trying to figure this out on and off for several months so I've created this github repository to track the project. The variable hpcd
is defined in template/src/usbd_conf.c
. My knowledge of C/C++ is unfortunately full of holes, so I'm hoping someone may help me both narrow down the problem and the suggest the proper way to fix it.
I have two questions.
hpcd
is included in the fileusbd_conf.c
. It is used in many files, but none of these files actually includeusbd_conf.c
, onlyusbd_conf.h
. The question is, by only including the header, can a file which declares a variable asextern PCD_HandleTypeDef hpcd;
use the variable without specifically including the.c
file?- Assuming the answer to question 1 is yes, why is it the function
OTG_FS_IRQHandler
isn't findinghpcd
? The chain of includes fromstm32f4xx_it
ismain.h -> usbd_core.h -> usbd_conf.h
.
I'm assuming the answer to question 1 is yes because this is the demonstration code I believe was running on the board when I purchased it. I can only assume the poblem is with the way I'm building it. Would anyone be willing to help me troubleshoot this problem? I would be happy to provide more details if relevant or to better structure this question, but I'm trying to avoid posting a full USB stack in my question. Thank you.
hpcd
thing is NOT instantiated intemplate/src/usbd_conf.c
;extern
means it declares a symbol to reference there. Something needs to instantiate an actualhpcd
object. I think the links provided by @melpomene will provide for good reading to basically understand how c builds work :). As for this particular issue, filestm32f4xx_hal_pcd.c
has a comment that states:Declare a PCD_HandleTypeDef handle structure, for example: PCD_HandleTypeDef hpcd;
and more stuff, which implies that you need to create anhpcd
in your source, I would think. – mkaltemplate/src/usbd_conf.c
following the include statements isPCD_HandleTypeDef hpcd;
. Is this what you mean byhpdc
needing to be 'instantiated', because it seems to me that it is. You're correct that the page posted by melpomene is good reading though :) Seems to be full of things that I don't know very well. – user2027202827