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.
7 years, 5 months ago.
Maple Mini USB serial connect blocks and no data
I tried Zoltan Hudak's Maple Mini USB serial example:
Import programMapleMini_USBSerial
USB serial device with Maple Mini board.
The USBSerial's printf blocks until USB connected. LED is not blinking and no data on UART. On the first connection via USB serial, there is a partial data transmission, something like "I am a USB" or "I aseri" and nothing more, but the LED starts blinking, and the UART starts (happily printing "I am a serial port")
I checked the original lib here:
Import libraryF042K6_USBDevice
USB device stack for NUCLEO-F042K6, NUCLEO-L152RE and NUCLEO-F103RB.
There is an optional connect_blocking parameter in the constructor. This feature is missing from Zoltan's implementation. I do not know if it would help here.
I tried this lib also, it compiles fine, the virtual COM port shows up, no block, but never receive any data via virtual serial. The LED is blinking and the UART works fine.
1 Answer
7 years, 5 months ago.
Hello,
I have added a connection blocking parameter to the USBSerial
constructor (defaults to true). Use the code below to try out how it works.
#include "MapleMini.h" #include "mbed.h" #include "USBSerial.h" DigitalOut myled(LED1); DigitalOut usbEn(PB_9); //Used for connecting/disconnecting the 1k5 resistor to/from the USB DP pin int main() { confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock) Serial pc(PA_2, PA_3); USBSerial usbSerial(0x1f00, 0x2012, 0x0001, false); usbEn = 0; //Keep the on-board 1k5 resistor connected to the USB DP pin while(1) { myled = !myled; pc.printf("I am a serial port\r\n"); // 9600 bit/s usbSerial.printf("I am a USB serial port\r\n"); // 12 Mbit/s (USB full-speed) wait_ms(1000); } }
Thanks for your answer.
I've separated two problems:
A. Not every terminal application receives data via USB serial.
RealTerm and CoolTerm never receives data, but TeraTerm and Java JSSC based terminal does. The settings are same. It is really strange. I use CoolTerm with many projects and it always gets data from MCU.
B. Blocking when USB is plugged in but port is not opened.
- External power, no USB. UART works fine, no block.
- Plug in USB, but no terminal connection. Instant block, UART and blink stops. I checked with debugger, it loops forever in USBDevice.cpp line 861-863 do-while loop. configured() is true, but result is EP_PENDING.
- Connect terminal to USB serial. Immediately exits from loop and everything works fine.
- Disconnect terminal, still OK.
- Unplug USB, still OK.
- Re-plug USB, goto 2.
the newer USBSerial needs the DTR signal to be set. This should be done by the terminal or host programm. When I use putty, then DTR will be set on connect. With another Terminal program (Terminal from br@y), I must set the DTR signal manually. Maybe this is missing in your application?
posted by Johannes Stratmann 14 Dec 2016