ArduinoCore-sam icon indicating copy to clipboard operation
ArduinoCore-sam copied to clipboard

USB_Host.h is missing extern "C" on function prototypes from uotghs_host.c

Open dewhisna opened this issue 10 years ago • 0 comments

The prototypes in USB_Host.h for the functions from uotghs_host.c should be tagged as extern "C" since the header can be included into C++ source and is referencing C code. Without this, it will fail to locate the export names in libsam_sam3x8e_gcc_rel.a, since they are not C++ decorated.

In other words, it needs the following:

#ifdef __cplusplus
extern "C" {
#endif

//extern uhd_speed_t uhd_get_speed(void);

extern void UHD_SetStack(void (*pf_isr)(void));
extern void UHD_Init(void);
extern void UHD_BusReset(void);
extern uhd_vbus_state_t UHD_GetVBUSState(void);
extern uint32_t UHD_Pipe0_Alloc(uint32_t ul_add, uint32_t ul_ep_size);
extern uint32_t UHD_Pipe_Alloc(uint32_t ul_dev_addr, uint32_t ul_dev_ep, uint32_t ul_type, uint32_t ul_dir, uint32_t ul_maxsize, uint32_t ul_interval, uint32_t ul_nb_bank);
extern void UHD_Pipe_Free(uint32_t ul_pipe);
extern uint32_t UHD_Pipe_Read(uint32_t ul_pipe, uint32_t ul_size, uint8_t* data);
extern void UHD_Pipe_Write(uint32_t ul_pipe, uint32_t ul_size, uint8_t* data);
extern void UHD_Pipe_Send(uint32_t ul_pipe, uint32_t ul_token_type);
extern uint32_t UHD_Pipe_Is_Transfer_Complete(uint32_t ul_pipe, uint32_t ul_token_type);

#ifdef __cplusplus
}
#endif

Without tagging them as extern "C", you get errors such as the following, which I encountered while experimenting with adding USB Keyboard support to an Arduino Due project using the USBHost library:

./libarduino_due_x_dbg_myproj.a(myproj.cpp.obj): In function `HIDBoot<(unsigned char)1>::Release()':
myproj.cpp:(.text._ZN7HIDBootILh1EE7ReleaseEv[_ZN7HIDBootILh1EE7ReleaseEv]+0x28): warning: undefined reference to `UHD_Pipe_Free(unsigned long)'
./libarduino_due_x_dbg_myproj.a(myproj.cpp.obj): In function `HIDBoot<(unsigned char)1>::EndpointXtract(unsigned long, unsigned long, unsigned long, unsigned long, USB_ENDPOINT_DESCRIPTOR const*)':
myproj.cpp:(.text._ZN7HIDBootILh1EE14EndpointXtractEmmmmPK23USB_ENDPOINT_DESCRIPTOR[_ZN7HIDBootILh1EE14EndpointXtractEmmmmPK23USB_ENDPOINT_DESCRIPTOR]+0x60): warning: undefined reference to `UHD_Pipe_Alloc(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)'

I would have submitted this as a pull-request, but I've just been using the auto-downloaded library and haven't bothered forking it yet.

I don't know how the Arudino IDE deals with this problem, as I'm building via a combination of the command-line and QtCreator on Linux using CMake as my build system.

dewhisna avatar Feb 08 '16 01:02 dewhisna