Initialize USB when host may not be connected

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
user_1570836
Level 4
Level 4
50 replies posted 25 replies posted 25 sign-ins

Hello,

I am developing USB-capable self powered device. I need this device to work properly both with and without connection to USB host. What is correct way to initialize USB peripheral in this scenario? 

Here is my current init code:

 

 

if(VBus_Read() == 1)
    {
        UsbUart_Start(0, UsbUart_5V_OPERATION);
        while(!UsbUart_GetConfiguration());
        UsbUart_CDC_Init();
    }

 

 

 

Thanks in advance

Stanislav 

0 Likes
2 Replies
GuNo_288966
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

In case of a USB powered device, it is important that the device reacts to some commands over USB within a short time, something between 50ms and 500ms after power-up. If the reaction takes too long, no connection can be established.

In case of a self-powered device, the device must also react to a USB connect quickly. If the reaction comes too late, the connection wil not be established. Make sure to check VBUS frequently enough.

 

0 Likes
user_1570836
Level 4
Level 4
50 replies posted 25 replies posted 25 sign-ins

Hello GuNo,

Sorry for late reply. I have been thinking of this. I have a function that is to be periodically called, and will process incoming data(btw is there any way to do this with ISR instead of pooling?). Here I can also check VBUS.

Then, which init functions are to be called on boot, and which on VBUS rising edge? Also, do I need to call some deinit on VBUS falling edge?

 

For my concerns about USB specs, now I see that when I connect USB, I will init it. If I don't, it is unimportant what is on data pins.

 

Stanislav

0 Likes