How to get the usb to work?

Hello. I am trying to connect a micro-usb cable to our hardware module to get data transfer (any at all) working. Currently I use a DAPlink connector for serial printing and such.
But I need to get the micro-usb connected to the PC. However, when I plug the hardware module in via the micro-usb port on it, it doesn’t show up anywhere in the device manager. I validated this by plugging it in- and out while having the device manager open. It should update, but it doesn’t.

I use the MAX32630FTHR and Mbed OS 6.13. The Micro USB connector is connected to “USB_P” and “USB-N”. I am unsure what those are but that’s how it is configured according to the design.

I have written the next piece of code to test if it connects at all, the USBSerial object never seems to get configured.

#include "mbed.h"
#include <cstdio>
#include "USBSerial.h"
#include "usb_phy_api.h"
#include "USBPhyHw.h"

#define LINE "\n-------------------------\n"

USBPhy* phy = get_usb_phy();
USBSerial usb(phy);

int main()
{
    printf("%sIn application%s", LINE, LINE);
    phy->configure();

    while (!usb.configured())
    {
        printf("USB not configured!\r\n");
        phy->configure();
        usb.enable_input(1);
        usb.enable_output(1);
    }
    printf("USB is now configured.\r\n");

    while (!usb.connected())
    {
        usb.disconnect();
        usb.connect();
    }
    
    printf("USB ready\r\n");
}

Should the USB just show up in your device manager, or am I doing the configuration wrong somehow?
I eagerly await any help at all.

Hello,

I tested your code with Nucleo-F429ZI and it was really not working.
Then I did some modifications and now it works, see below.

#include "mbed.h"
#include <cstdio>
#include "USBSerial.h"
#include "usb_phy_api.h"
#include "USBPhyHw.h"

#define LINE "\n-------------------------\n"

USBPhy* phy = get_usb_phy();
USBSerial usb(phy);

int main()
{
    printf("%sIn application%s", LINE, LINE);

    while (!usb.configured())
    {
        printf("USB not configured!\r\n");
        usb.connect();
        usb.enable_input(1);
        usb.enable_output(1);
    }
    printf("USB is now configured.\r\n");

    while (!usb.connected())
    {
        usb.init();

    }
    
    printf("USB ready\r\n");
}

Run the code in your board → wait until you will see “USB is now configured.” → then connect to a new COM port with your PC app → enable DTR signal → enjoy.

We are using code, see below, for a debug via USB on a machine.

#include "mbed.h"
#include "USBSerial.h"
 
USBSerial serial(false);
 
template<typename... Args> void debugPrint(const char *msg, Args... args){
    if(!serial.configured()){
        serial.connect();            
    }
    
    if(serial.configured()){
        if(!serial.connected()){
            serial.init();    
        }   
    }
    
    if(serial.connected()){
        serial.printf(msg, args...);
    } 
    
    //printf(msg, args...);
}

int main()
{
    printf("USB debug example\r\n");


    while (1)
    {
        debugPrint("Debug from USB!\r\n");
        ThisThread::sleep_for(1s);
    }
}

BR, Jan

1 Like

Hi Jan,
thanks for your response.
I tried running your code but sadly it never gets out of the loop to configure the USB.
Does the board show up in your device manager when you only connect it to USB? For me it doesn’t and I think that might be the issue, maybe it is not powered properly?

Yea, device is showed up in Windows device manager.

I do not know but look at this topic, I do not know if it can be related to this but you will see.

BR, Jan