Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 1 month ago.
Serial vs USBSerial and blocking
Can someone clarify the difference between using Serial or RawSerial through a USB port versus using the USBserial?
I was reading another post about USBserial blocking when the USB was not connected. Does this same problem occur with Serial? If using RTOS, can I assume it only blocks the thread that is trying to use the USB port?
Thanks,
Chuck
2 Answers
10 years, 1 month ago.
Serial is a regular serial which goes via the interface chip most mbed devices have (not all of them, some NXP ones have an on-chip USB bootloader and don't have a seperate interface chip), which translates it into USB.
USBSerial uses directly the USB of the target chip. For the LPC1768 you have these are the D+ and D- pins, the USB connector is regular Serial.
USBSerial can these days also connect non-blocking. To be fair imo it is more a workaround, but it works. Blocking wise Serial blocks a bit when transmitting (depends on number of bytes, BufferedSerial is an alternative which does not block). USBSerial by default blocks until connected. When you use RTOS it depends on the priority of the thread. If that thread has higher priority it will block. With lower it won't, with equal I think it also won't block completely.
10 years, 1 month ago.
Do you have an example of using non blocking ??
One of my projects would really benifit From having the ability to randomly connect and disconnect USB.
...board powered from batteries.
Cheers
Ceri
The last argument of the USBSerial constructor defines if it blocks or not, so you then also got to copy VID and similar arguments into the constructor. I believe you can check the isConfigured() function to see if it is done connecting, but I don't know how it behaves with connects/disconnects.
I have only done it with a USBMSD class myself, and there all of it was interrupt driven, so I didn't have to worry if it was connected or not, interrupts were only generated if it was connected.
posted by 20 Jun 2014