We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
This post is a follow up to:
https://community.arm.com/developer/tools-software/tools/f/keil-forum/47193/implementing-a-non-hanging-usb-listener
I've managed to connect to a PC through a VirtualCOM port (serial over USB); I have not implemented (overwritten) any functions defined in
rl_usb.h.
void USBCommTask(void const *argument) { int ret = -1; char strMessage[50]; // osDelay sometimes skipped depending depending on allocated stack size ret = USBD_Initialize(0U); osDelay(6000); sprintf(strMessage, "USBD_Initialize returned %d", ret); PrintDbgMessage(strMessage, 6000); memset(&strMessage[0], 0, sizeof(strMessage)); ret = USBD_Connect(0U); osDelay(6000); sprintf(strMessage, "USBD_Connect returned %d", ret); PrintDbgMessage(strMessage, 6000); while(!USBD_Configured (0U)); PrintDbgMessage("USBD configured successfully!", 6000); // Read from the USB port // http://www.keil.com/support/man/docs/rlarm/rlarm_usb_create_cdc_acm.htm // https://community.arm.com/developer/tools-software/tools/f/keil-forum/32812/usbd_cdc_acm_datasend-no-sending // http://wirelessblue.blogspot.com/2017/05/serial-port-over-usb-project.html while (1) { PrintDbgMessage("Writing to USB ... ", 6000); strcpy(strMessage, "ab"); ret = USBD_CDC_ACM_WriteData(0U, (const uint8_t *)strMessage, strlen(strMessage)); if (ret > 0) { sprintf(strMessage, "Wrote %d bytes of data to USB!", ret); PrintDbgMessage(strMessage, 6000); } else { sprintf(strMessage, "USBD_CDC_ACM_WriteData returned %d", ret); PrintDbgMessage(strMessage, 6000); } PrintDbgMessage("Wrote to USB!", 6000); } }
The code seems to be writing to the com port; LCD displays "Wrote 2 bytes of data to USB!".
The lpc device as seen from the PC:
I'm not able to connect to it and read the bytes it's sending programmatically or using putty. I have a C# snippet that works for other MCUs:
SerialPort serialPort = null; try { // Create a new SerialPort object with default settings. serialPort = new SerialPort(); // Allow the user to set the appropriate properties. serialPort.PortName = "COM6"; serialPort.BaudRate = 9600; // Use 115200 in all cases // serialPort.BaudRate = 115200; serialPort.Parity = Parity.None; serialPort.DataBits = 8; serialPort.StopBits = StopBits.One; serialPort.Handshake = Handshake.None; // Set the read/write timeouts serialPort.ReadTimeout = 500; serialPort.WriteTimeout = 500; serialPort.Open(); serialPort.DataReceived += WaitForHB01Ack; Console.WriteLine("Port opened successfully!"); } catch (SystemException se) { Console.WriteLine("Exception opening port: " + se.ToString()); }
that gives:
Exception opening port: System.IO.IOException: Ein an das System angeschlossenes Gerät funktioniert nicht. at System.IO.Ports.SerialStream.InitializeDCB(Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Boolean discardNull) at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace) at System.IO.Ports.SerialPort.Open()
With putty:
What is the default baudrate of the VirtualCOM port?