ARMmbed / mbed-os

Arm Mbed OS is a platform operating system designed for the internet of things
https://mbed.com
Other
4.67k stars 2.98k forks source link

USB Serial constructor blocking #53

Closed larsgk closed 6 years ago

larsgk commented 11 years ago

Because of a blocking connect function in USBDevice ( https://github.com/mbedmicro/mbed/blob/master/libraries/USBDevice/USBDevice/USBDevice.cpp#L711 ) called from the USBCDC constructor ( https://github.com/mbedmicro/mbed/blob/master/libraries/USBDevice/USBSerial/USBCDC.cpp#L34 ), instatiating USB Serial with nothing connected on the actual port blocks execution.

I tried just commenting the while loop out and everything seems to run fine (connect/disconnect and CDC/serial communication with a host computer.

Maybe this should be solved in a different way - but especially when running on battery on KL25Z, this is a problem (the blocking).

larsgk commented 11 years ago

Hi again,

I did some more research on this issue (that more than me seem to have - according to some entries on mbed.org).

There are several issues (all tested on FRDM-KL25Z):

  1. if you try to construct USBSerial with nothing connected to the USB Comm port, the program hangs in a forever loop here (I commented it out to be able to do battery/wireless operation - and this seems to work quite nicely.. the device can be switched on while connected or not .. reconnects work just fine, etc.):

https://github.com/mbedmicro/mbed/blob/master/libraries/USBDevice/USBDevice/USBDevice.cpp#L711

  1. if you pull the plug while in a transfer, the program hangs in a forever "pending" loop here:

https://github.com/mbedmicro/mbed/blob/master/libraries/USBDevice/USBDevice/USBDevice.cpp#L835

I am going to try to see if there is any way (maybe only for the FRDM-KL25Z board specifically) to detect if there is something connected to do a graceful startup/shutdown of the USB chain.

Also - if the code in USBDevice.cpp#L835 knows that it's pending for a long time (e.g. 20 checks..) then there should be a way to throw an exception (I know... not exception but C-style callbacks, etc.) up through the chain AS WELL as doing a graceful shutdown/reset of anything in the transfer buffer. The current mechanism leaves room for improvement at least :) - I am happy to contribute with my findings but please help me out a bit..we have to deliver 30 educational packages to a high-school soon.. based on this.

br Lars

larsgk commented 10 years ago

I am wondering why the writable operation is not implemented to return something useful?

https://github.com/mbedmicro/mbed/blob/master/libraries/USBDevice/USBSerial/USBSerial.h#L99

ciarmcom commented 8 years ago

ARM Internal Ref: IOTMORF-331

ghost commented 6 years ago

GitHib issue review: Closed due to inactivity. Please re-file if critical issues found.