With physical COM ports non-existent in laptops and fast disappearing on desktops, its a matter of immense convenience to embedded programmers if a chip has the USB interface.
The LPC1768 has a USB device interface and this library will allow you to use it as a virtual COM port. The library combines function from various sources which have been listed in the link.
Here's a simple example demonstrating the library. Check out the various functions offered in usbSerial.h
To build this example, first download and extract the latest project quick start code base. Then, download and extract to the same folder, the usbSerial library. The contents of main.cpp are as follows:
#include "LPC17xx.h"
extern "C" {
#include "usbSerial.h"
}
int main()
{
int i=0;
usbSerialInit();
while(1)
{
VCOM_printf("\nLooping %d times. Press a key...",i);
VCOM_getc_echo();
i++;
}
return 0;
}
Download the latest compiled project here. Change the flash start address in the linker file(LPC17xx.ld) and re-build if you are using a secondary bootloader. I've made the changes for NXP secondary USB bootloader.
Windows will ask for a driver the first time the device is used. The .inf file needed is in the library folder itself. For those who might want assistance installing the driver,
Windows 7 lacks a terminal software. So, you'll have to use a terminal emulator if you use windows 7. Some popular ones are TeraTerm, RealTerm, and putty. Another one which caught my eye for its simplicity is Bray's Terminal.
Whichever you may choose to use, you will need to know what number was assigned to the LPC1768 COM port. This information can be obtained from Device Manager.
As can be seen above, COM7 is what i'll need to use for communicating with LPC1768.
References:
1. Code Red RDB1768 example projects.
2. ARM Projects by Martin Thomas
The LPC1768 has a USB device interface and this library will allow you to use it as a virtual COM port. The library combines function from various sources which have been listed in the link.
Here's a simple example demonstrating the library. Check out the various functions offered in usbSerial.h
To build this example, first download and extract the latest project quick start code base. Then, download and extract to the same folder, the usbSerial library. The contents of main.cpp are as follows:
#include "LPC17xx.h"
extern "C" {
#include "usbSerial.h"
}
int main()
{
int i=0;
usbSerialInit();
while(1)
{
VCOM_printf("\nLooping %d times. Press a key...",i);
VCOM_getc_echo();
i++;
}
return 0;
}
Download the latest compiled project here. Change the flash start address in the linker file(LPC17xx.ld) and re-build if you are using a secondary bootloader. I've made the changes for NXP secondary USB bootloader.
Windows will ask for a driver the first time the device is used. The .inf file needed is in the library folder itself. For those who might want assistance installing the driver,
Windows 7 lacks a terminal software. So, you'll have to use a terminal emulator if you use windows 7. Some popular ones are TeraTerm, RealTerm, and putty. Another one which caught my eye for its simplicity is Bray's Terminal.
Whichever you may choose to use, you will need to know what number was assigned to the LPC1768 COM port. This information can be obtained from Device Manager.
As can be seen above, COM7 is what i'll need to use for communicating with LPC1768.
References:
1. Code Red RDB1768 example projects.
2. ARM Projects by Martin Thomas
thanks dude...its working great, even got it working with ubuntu,yippe. :)
ReplyDeleteNow i need to use CDC lib with LPC2148, how do i go about, i looked around a lot but could not find cdc library for 2148. can i use this lib with some modification, please tell me how???
I'm using BlueBoard-LPC214x from ngx technologies
THANK you once again.
Cheers!!!
You are most welcome.
ReplyDeleteLPC2148 has been around for a much longer time than LPC1768. Googling should give you a plethora of info and code.
LPCUSB was in fact developed for LPC2148 and then codered ported it to LPC1768.
found it!!!
ReplyDeletethanks for reply :)
Hello Sagar,
ReplyDeleteI'd like to use the usbSerial library shown here, but it seems nothing really works once I extract the VCOM_lib_1.1 folder into the src folder of my project directory.
I tried loading a blinky (I use the secondary bootloader) and it wouldn't work unless I remove the folder.
As far as I know, the makefile is configured correctly to compile the .c files in the library.
Would you suggest some reasons why this might be the case? Thanks!
Thats an older version.
ReplyDeleteTry this
http://cortex-m3-tutorials.googlecode.com/files/VCOM_lib1.3.rar
with this code base
http://embeddedhobby.googlecode.com/files/lpc_17xx_CPP_26Apr2011.rar
I've been trying to make this code work with LPC1766 but for some odd reason I can only tx to the host, all rx from host do not cause a bulk out event to be triggered. Any idea why this would happen?
ReplyDeleteHi,
ReplyDeleteI'm having problems using this on windows 7.
On linux it works fine, but when using usbser.sys as the driver, the read timeouts are huge (7-800ms).
What I basically do is write a command to the interface (works fast), to which I *should* receive an answer very fast, and read it out. Now windows blocks here for at least 7-800 ms.
Is there an alternative to usbser.sys? As I found out many people are having problems with it.
Regards,
Ákos Vandra
Does this work reliably on windows 7?
ReplyDeleteOn linux it works just fine, but on windows when reading from the device, the timeouts are huge (~7-800ms).
Basically I write a command to the serial port, and then read back the answer. On linux the answer is instant, on windows it takes the aforementioned time.
I've read that there are problems with usbser.sys, is there an alternative to it?
Regards,
Ákos Vandra
great job it works rapidly!!
ReplyDeleteit's no simple to load the usbser.sys driver on W7. How to do automatically?
what compiler programs do you use? Im looking to switch out of redsuite.
ReplyDeleteCodesourcery g++
ReplyDeleteOnce I've correct the System/system file renaming, I get:
ReplyDeletecwr@sixpence nxp $ make
arm-none-eabi-gcc -O2 -gdwarf-2 -mcpu=cortex-m3 -mthumb -mthumb-interwork -mlong-calls -ffunction-sections -fdata-sections -fpromote-loop-indices -Wall -Wextra -Wimplicit -Wcast-align -Wpointer-arith -Wredundant-decls -Wshadow -Wcast-qual -Wcast-align -Wnested-externs --std=gnu99 -c core_cm3.c -o core_cm3.o
/tmp/ccvWILBV.s: Assembler messages:
/tmp/ccvWILBV.s:508: Error: registers may not be the same -- `strexb r0,r0,[r1]'
/tmp/ccvWILBV.s:533: Error: registers may not be the same -- `strexh r0,r0,[r1]'
make: *** [core_cm3.o] Error 1
cwr@sixpence nxp $
What should these assembler instructions be?
Thanks - Will
Tks!! Worked like a charm ;)
ReplyDeleteThe compiler only complains about some types on "lpcusb_type.h" and warnings on funtions with no "forced" void arguments.
Respect and that i have a super give: How Much Do House Repairs Cost simple home renovations
ReplyDelete