lpcware

Usbcdc

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by Andre Schoeman on Tue Mar 29 20:56:03 MST 2011
[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]Hi[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]I have modified the USBCDC example eliminating the serial port and buffer data internally.[/SIZE][/FONT][/COLOR][COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]I have created simple Read and Write functionality for use by my application. This works fine.[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]The way that the USBCDC example is written is to wait for a USB connection before entering main. My device is not USB by default. I only want a USB connection when the device is plugged into a USB socket.[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]I have enabled the USB_POWER_EVENT in usbcfg.h. [/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]I have modified the USB_Power_Event function as follows,[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2][B]void[/B] [B]USB_Power_Event[/B] (uint32_t power)[/SIZE][/FONT][/COLOR]
[LEFT][COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]{[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]USB_Connect(TRUE); // USB Connect[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2][B]while[/B] (!USB_Configuration); // wait until USB is configured[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]}[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]At first I removed this code prior main.[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]USB_Connect(TRUE); // USB Connect[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2][B]while[/B] (!USB_Configuration); // wait until USB is configured[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]No USB connection is made when I insert the device.[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]I then added only[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]USB_Connect(TRUE); // USB Connect[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]prior to main.[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]This froze the device until first insertion at this while loop in,[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2][B]void[/B] [B]WrCmd[/B] (uint32_t cmd) {[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]LPC_USB->DevIntClr = CCEMTY_INT;[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]LPC_USB->CmdCode = cmd;[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2][B]while[/B] ((LPC_USB->DevIntSt & (CCEMTY_INT | DEV_STAT_INT)) == 0);[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]}[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]After that I can plug and unplug the device and it works as I would expect.[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]However if I don't run the code using the RED PORBE+ then it simply freezes.[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]Has anybody done this successfully? Am I using the USB_POWER_EVENT correctly?[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]How do I know if this power event is a insert or remove event?[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]Do I need to do something different, like an internal USB reset, for a remove event?[/SIZE][/FONT][/COLOR]


[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]Thanks[/SIZE][/FONT][/COLOR]
[COLOR=#000000][FONT=Arial, sans-serif][SIZE=2]Andre [/SIZE][/FONT][/COLOR][/LEFT]

Outcomes