Microchip® Advanced Software Framework

Dual Roles Support

In this use case, the USB host and USB device are enabled, it is the dual role.

Note
On the Atmel boards, the switch of USB role is managed automatically by the USB stack thank to a USB On-The-Go (OTG) connector and its USB ID pin. Refer to section "Dual roles" for further information in the application note:

Setup Steps

Prior to implement this use case, be sure to have already applied the UHI module "basic use case".

Usage Steps

Example Code

Content of conf_usb_host.h:

#define UHC_MODE_CHANGE(b_host_mode) my_callback_mode_change(b_host_mode)
extern void my_callback_mode_change(bool b_host_mode);

Add to application C-file:

void usb_init(void)
{
//udc_start();
}
bool my_host_mode;
void my_callback_mode_change(bool b_host_mode)
{
my_host_mode = b_host_mode;
}
void my_usb_task(void)
{
if (my_host_mode) {
// CALL USB Host task
} else {
// CALL USB Device task
}
}

Workflow

  1. In case of USB dual roles (Device and Host), the USB stack must be enabled by uhc_start() and the udc_start() must not be called.
    //udc_start();
  2. In dual role, to know the current USB mode, the callback to notify the mode changes can be used.
    • Ensure that conf_usb_host.h contains the following parameters:
      #define UHC_MODE_CHANGE(b_host_mode) my_callback_mode_change(b_host_mode)
      extern void my_callback_mode_change(bool b_host_mode);
    • Ensure that application contains the following code:
      bool my_host_mode;
      void my_callback_mode_change(bool b_host_mode)
      {
      my_host_mode = b_host_mode;
      }
      void my_usb_task(void)
      {
      if (my_host_mode) {
      // CALL USB Host task
      } else {
      // CALL USB Device task
      }
      }