NXP USB lib with c++ code

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

NXP USB lib with c++ code

1,456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Noirim on Mon Nov 04 05:56:09 MST 2013
Hi,
I have tried to use NXP Usb lib but it seems that it couldn't work in a c++ project. Indeed when I try to include "usb.h" in my "main.cpp" file, the compilation process fails. Its work only if my project use a C99 code generation option (--gnu --c99). But in this case, I have to rewrite my code since I have functions that have been overloaded.

Is there any solution or I need to change  my code?

Thanks.
Labels (1)
0 Kudos
8 Replies

1,225 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Noirim on Wed Jan 22 00:44:55 MST 2014
Hi,
thanks for your post.
According to NXP, the USB lib already contains declaration that allows using it in c++ code (extern C that you have mentionned). I have verify and in all declaration #if de __cplusplus is used.
The issue for me is that for an obscur reason, some declaration in usb.h is not "correctly handled" when I compile the code. It seems to be compatibility declaration.
example from when I includes USB.H code :
first error occurs in "endianness.h"
static inline uint16_t SwapEndian_16(const uint16_t Word) ATTR_WARN_UNUSED_RESULT ATTR_CONST;
static inline uint16_t SwapEndian_16(const uint16_t Word)
{
...

this type of declaration is supposed, if i'm right, to manage ascending compatibility of the software.
I don't understand why you mentionned "clock" at the end. For now I didn't manage to build my software so for now I have no clock issue because no execution is possible.
Thanks.
0 Kudos

1,225 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by liaochengyi on Tue Jan 21 23:30:10 MST 2014
I am also work on NXP c to c++..

You can try the follow step:
1. GPIO LED workable.
2. import USB lib
3. extern "C"
4. make sure the main clock and usb clock is work

The warp in c++ to call c function is useful.

Good luck.
0 Kudos

1,225 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Noirim on Thu Jan 02 04:00:31 MST 2014
Hi,
anybody have some advice to help me??

Thanks and happy new year
0 Kudos

1,225 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Noirim on Tue Nov 05 03:25:39 MST 2013
Hi,
I have donloaded an dintegrated LPCopen lib USB in my code but unfortunatly I have the same erros as previously.
1 - I have compiled lib_lpcusblib_17xx_40xx project successfully
2 - I have added the lib file in my project
3 - I have included the usb.h file in my main.cpp
4 - I have defined the following symbols : __LPC175X_6X__ and USB_DEVICE_ONLY in my project.

I have noted that if I use --gnu --cpp command the error disappears but other errors appears (missing includes that i have tried to add but following this way looks very strange.....)

Thanks.
0 Kudos

1,225 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Noirim on Tue Nov 05 01:59:25 MST 2013
OK thanks you for your reply. I will try and keep you informed.
0 Kudos

1,225 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Mon Nov 04 07:58:00 MST 2013
As I said, NXPUSBlib is no longer supported. Suggest you switch to LPCOpen for your target.
0 Kudos

1,225 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Noirim on Mon Nov 04 07:26:36 MST 2013
Hi,
So to answer your questoins :
- I use nxpUSBlib v0.98b with Keil µVision
- about errors
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Endianness.h(397): error:  #130: expected a "{"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Endianness.h(426): error:  #130: expected a "{"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Endianness.h(461): error:  #130: expected a "{"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Endianness.h(464): warning:  #12-D: parsing restarts here after previous syntax error
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(243): error:  #130: expected a "{"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(259): error:  #77-D: this declaration has no storage class or type specifier
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(260): error:  #65: expected a ";"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(309): error:  #77-D: this declaration has no storage class or type specifier
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(309): error:  #247: variable "PRAGMA_ALWAYS_INLINE" has already been defined
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(310): error:  #65: expected a ";"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(337): error:  #77-D: this declaration has no storage class or type specifier
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(337): error:  #247: variable "PRAGMA_ALWAYS_INLINE" has already been defined
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(338): error:  #65: expected a ";"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(363): error:  #77-D: this declaration has no storage class or type specifier
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(363): error:  #247: variable "PRAGMA_ALWAYS_INLINE" has already been defined
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(364): error:  #65: expected a ";"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(386): error:  #77-D: this declaration has no storage class or type specifier
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(386): error:  #247: variable "PRAGMA_ALWAYS_INLINE" has already been defined
XXXXXX\LPC1768\Libraries\LPCUSBLib\Common\Common.h(387): error:  #65: expected a ";"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(249): error:  #260-D: explicit type is missing ("int" assumed)
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(249): error:  #65: expected a ";"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(255): warning:  #12-D: parsing restarts here after previous syntax error
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(266): error:  #84: invalid combination of type specifiers
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(272): error:  #65: expected a ";"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(283): error:  #84: invalid combination of type specifiers
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(285): error:  #20: identifier "USB_Descriptor_Header_t" is undefined
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(323): error:  #65: expected a ";"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(334): error:  #84: invalid combination of type specifiers
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(373): error:  #65: expected a ";"
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(382): error:  #84: invalid combination of type specifiers
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(384): error:  #20: identifier "USB_Descriptor_Header_t" is undefined
XXXXXX\LPC1768\Libraries\LPCUSBLib\Drivers\USB\Core\StdDescriptors.h(396): error:  #65: expected a ";"

after a few investigations, it appears that for versionning purpose, a macro ATTR_WARN_UNUSED_RESULT is use. But in my case it is no t define because of the preprocessor test :
#if (__GNUC__ >= 3) || defined(__DOXYGEN__)
so the versioning header contains error due to this macro which is not defined (in my case)
0 Kudos

1,225 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Mon Nov 04 07:13:09 MST 2013
As you have not told us which error you are getting, it is very difficult to know what you have done wrong.

However, one likely problem is that you have not used extern "C"{} around the header files.

Note: If you are using the OLD NXP USB Lib, this is no longer supported. You should be using LPCOpen instead, which does correctly define header files for use with C++.

If this is not your problem, please describe the problem exactly and include any error messages.
0 Kudos