Mbed OS5 - Nucleo USB host Serial

Dear community,
I’m struggling with the USB OTG module on a Nucleo STM32F767ZI,
I’m using this library : USBHOST | Mbed
the given examples work with success. (keyboard, mouse, msd)
In my application I need to use the Host Serial functionality. there is no example with it., so I’m writing my own. it doesn’t work…
I’m using this kind of approach with the given methods
USBHostSerial - Handbook | Mbed

the usb device simply sends data over usb-serial.
what should I check to make it work properly?!

I can:

  • detect a serial device when connected/disconnected

I can’t communicate properly:
as I fill the send buffer i get:

[USB_WARNING: /src/USBHOST/USBHost/USBHost.cpp:1080][ep: 200033d4 - dev: 20003854 - Serial] NOT IDLE: USB_TYPE_ERROR

any help would be appreciated,

this is the thread :slight_smile:Preformatted text

void serial_device(void const *){

float sensVal[6]; 
                       
while(1){
    printf("wait for ATI sensor\n");                     //store TF values

    while(!dev.connect()) {                 // try to connect a MSD device
        Thread::wait(500);
    }        
    
    printf("ATI sensor found\n");
    dev.baud(19200);                       //set serial baud
    dev.format();                          //default 8n1
   // dev.attach(ATIread, USBHostSerialPort::RxIrq);      //callbacks
   // dev.attach(ATIwrite, USBHostSerialPort::TxIrq);

    char cmd[1] ={ 0x70};                   //start reading     

    while(dev.connected()){                  //main loop : read request until connected
        Thread::wait(500);
        dev.writeBuf(cmd,strlen(cmd)); 
        printf("ci sono\n");
    }
    
    printf("ATI disconnected\n");                        
  //  dev.disconnect();

}   //fine while(1)

} //fine serial_device
indent preformatted text by 4 spaces

Hi,

Your question subject refers to Mbed OS 5 but you have used Mbed OS 2 example. I would recommended you to start with this document for Mbed OS 5:
https://os.mbed.com/docs/mbed-os/v5.15/apis/usbserial.html#usbserial-example

Regards,
Pekka

Hi,
thank you for your reply,
I’m using the mbed os2 logics applied to the mbed os5 ST libraries.
I noticed that there is nothing regarding the USBhostSerial support anymore on mbed os 5. only for other devices (mouse keyboard msd).
the thing is that everything concerning the connection and enumeration works, rather than the opening of the data stream, in any direction.

today I’m doing tests on MBED os2 on LPC1768. I can get a stream only by downgrading to rev87.
this situation is so frustrating…

Here is the final working solution:
after digging in hell I found out that you need to define :
#define USBHOST_OTHER

before including the needed USBHostSerial.h libraries.

such a simple thing to know that could spare me a lot of time, I hope this could help other users:
the setup is:

Nucleo F767ZI + USB HOST SERIAL + usb serial sensor
Mbed OS 5 rev6.0.0 alpha2 USB + ST USBhost Libraries
https://os.mbed.com/teams/ST/code/USBHOST/docs/tip/classUSBHostSerialPort.html#ab7fffa71178d557de1c880498c711563

2 Likes

thanks for sharing your solution. I found that USBHOST_OTHER was formerly set in the target definition in targets/targets.json for the F767

        "macros_add": ["USBHOST_OTHER"], 

This could be added now also in mbed_app.json.