nxpUSBLib-0.95 compile errors with gnu gcc [incl. solutions]

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

nxpUSBLib-0.95 compile errors with gnu gcc [incl. solutions]

604 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by triffid_hunter on Mon Jul 02 08:00:29 MST 2012
Hi all,

Just pulled nxpUSBLib 0.95 and dropped into an existing project using arm-none-eabi-gcc (Sourcery G++ Lite 2011.03-42) 4.5.2

However, nxpUSBLib gives me the following errors:

<code>arm-none-eabi-gcc -Os -mcpu=cortex-m3 -mthumb -mthumb-interwork -mlong-calls -ffunction-sections -fdata-sections -Wall -g -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -I. -ICMSISv2p00_LPC17xx/inc -ILPC17xxLib/inc -InxpUSBLib/ -InxpUSBLib/Common -InxpUSBLib/Drivers -InxpUSBLib/Drivers/USB -InxpUSBLib/Drivers/USB/Core -InxpUSBLib/Drivers/USB/Core/LPC -InxpUSBLib/Drivers/USB/Core/LPC/HAL -InxpUSBLib/Drivers/USB/Core/LPC/HAL/LPC17XX -InxpUSBLib/Drivers/USB/Core/LPC/DCD -InxpUSBLib/Drivers/USB/Core/LPC/DCD/LPC17XX -InxpUSBLib/Drivers/USB/Core/LPC/HCD -InxpUSBLib/Drivers/USB/Core/LPC/HCD/EHCI -InxpUSBLib/Drivers/USB/Core/LPC/HCD/OHCI -InxpUSBLib/Drivers/USB/Class -InxpUSBLib/Drivers/USB/Class/Common -InxpUSBLib/Drivers/USB/Class/Host -InxpUSBLib/Drivers/USB/Class/Device -DMAX_URI_LENGTH=512 -D__LPC17XX__ -std=gnu99 -pipe -Wa,-adhlns=build/USBTask.lst -c -o build/USBTask.o nxpUSBLib/Drivers/USB/Core/USBTask.c
In file included from nxpUSBLib/Drivers/USB/Core/USBController.h:127:0,
                 from nxpUSBLib/Drivers/USB/Core/USBTask.h:50,
                 from nxpUSBLib/Drivers/USB/Core/USBTask.c:35:
nxpUSBLib/Drivers/USB/Core/LPC/USBController_LPC.h: In function 'USB_GetUSBModeFromUID':
nxpUSBLib/Drivers/USB/Core/LPC/USBController_LPC.h:360:9: error: 'USBSTA' undeclared (first use in this function)
nxpUSBLib/Drivers/USB/Core/LPC/USBController_LPC.h:360:9: note: each undeclared identifier is reported only once for each function it appears in
nxpUSBLib/Drivers/USB/Core/LPC/USBController_LPC.h:360:24: error: 'ID' undeclared (first use in this function)
nxpUSBLib/Drivers/USB/Core/USBTask.c: At top level:
nxpUSBLib/Drivers/USB/Core/USBTask.c:38:41: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__DATA'
make: *** [build/USBTask.o] Error 1</code>

__DATA is defined for CodeRed and keil compilers only, in nxpUSBLib/Drivers/USB/Core/LPC/HAL/HAL_LPC.h.

Simply adding <code>#ifndef __DATA
#define __DATA(x)
#endif</code> near the end of this file solves this for me.

'USBSTA' and 'ID' have me stumped though, there's only one use of them in the whole of nxpUSBLib and zero definitions, and it's not entirely clear from context what it's supposed to represent:
<code>            #if defined(USB_CAN_BE_BOTH)
            static inline uint8_t USB_GetUSBModeFromUID(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
            static inline uint8_t USB_GetUSBModeFromUID(void)
                if (USBSTA & (1 << ID))
                  return USB_MODE_Device;
                else
                  return USB_MODE_Host;
            }
            #endif</code>

I certainly can define these externally, but I'd really like to understand what they're supposed to represent rather than just blindly adding -DUSBSTA=1 -DID=0 to get device mode, or -DID=1 for host mode.

In fact, if I do add a numeric definition for ID, then compilation of LPC17xxLib/src/lpc17xx_can.c fails because it uses ID as a parameter in some function calls.

After digging around in the headers a bit, I discovered that defining USB_DEVICE_ONLY (or presumably USB_HOST_ONLY) prevents this error from occurring.

If this library can't handle switching modes, a more useful error message would be appreciated!
Labels (1)
0 Kudos
2 Replies

527 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by triffid_hunter on Wed Jul 04 20:29:02 MST 2012
I worked out the need for __LPC17XX__ pretty quickly :)

If the library doesn't support changing modes at runtime, perhaps the documentation could be updated to reflect this?

or perhaps spit a more intuitive error message than choking on vestigial undefined symbols, like this:

<code>--- nxpUSBlib v0.95/libraries/nxpUSBLib/Drivers/USB/Core/USBMode.h~2012-06-08 13:07:00.000000000 +1000
+++ nxpUSBlib v0.95/libraries/nxpUSBLib/Drivers/USB/Core/USBMode.h2012-07-05 13:21:38.202065455 +1000
@@ -238,7 +238,11 @@
#undef USB_CAN_BE_BOTH
#endif
#endif

+#if defined(USB_CAN_BE_BOTH)
+#error "nxpUSBLib does not support runtime mode switching at this time! Please define USB_DEVICE_ONLY or USB_HOST_ONLY."
+#endif
+
#if (defined(USB_HOST_ONLY) && defined(USB_DEVICE_ONLY))
#error USB_HOST_ONLY and USB_DEVICE_ONLY are mutually exclusive.
#endif</code>(note that forum strips leading whitespace, use attached patch)
0 Kudos

527 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tuong on Wed Jul 04 18:47:00 MST 2012
Dear triffid_hunter,

Compiling nxpUSBlib under Keil or LPCXpresso IDE requires these below pre-definitions:
   - Chips: __LPC11UXX__ or __LPC17XX__ or __LPC18XX__ or __LPC43XX__ for you to build for seperate chips
   - Modes: USB_DEVICE_ONLY or USB_HOST_ONLY for you to build for device or host mode

Currently, switching mode can only handled in compile time, not run time!

With best regards!
0 Kudos