Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
USBHS OTG Driver

USBHS low-level driver for OTG features.

Macros

#define USB_INT_LEVEL   5
 USB interrupt level By default USB interrupt have low priority. More...
 

Functions

void otg_dual_disable (void)
 Uninitialize the dual role This function is implemented in usbhs_host.c file. More...
 
bool otg_dual_enable (void)
 Initialize the dual role This function is implemented in usbhs_host.c file. More...
 

USBHS OTG ID pin management

The ID pin come from the USB OTG connector (A and B receptacle) and allows to select the USB mode host or device.

The ID pin can be managed through PIO pin. This feature is optional, and it is enabled if USB_ID_PIN is defined in board.h and CONF_BOARD_USB_ID_DETECT defined in conf_board.h.

#define OTG_ID_DETECT
 
#define OTG_ID_IO   (defined(USB_ID_PIN) && OTG_ID_DETECT)
 
#define otg_id_init(handler)
 
#define otg_id_interrupt_enable()   pio_enable_pin_interrupt(USB_ID_PIN)
 
#define otg_id_interrupt_disable()   pio_disable_pin_interrupt(USB_ID_PIN)
 
#define Is_otg_id_device()   ioport_get_pin_level(USB_ID_PIN)
 
#define Is_otg_id_host()   (!Is_otg_id_device())
 
#define otg_force_device_mode()   (Set_bits(USBHS->USBHS_CTRL, USBHS_CTRL_UIMOD))
 
#define Is_otg_device_mode_forced()   (Tst_bits(USBHS->USBHS_CTRL, USBHS_CTRL_UIMOD))
 Test if device mode is forced. More...
 
#define otg_force_host_mode()   (Clr_bits(USBHS->USBHS_CTRL, USBHS_CTRL_UIMOD))
 Disable external OTG_ID pin and force host mode. More...
 
#define Is_otg_host_mode_forced()   (!Tst_bits(USBHS->USBHS_CTRL, USBHS_CTRL_UIMOD))
 Test if host mode is forced. More...
 

USBHS OTG VBUS pin management

USBHS peripheral does not support VBUS management and it's monitored by a PIO pin.

This feature is optional, and it is enabled if USB_VBUS_PIN is defined in board.h and CONF_BOARD_USB_VBUS_DETECT defined in conf_board.h.

Note
ioport_init() must be invoked before using VBus pin functions since they use IOPORT API,
See Also
Common IOPORT API.
#define OTG_VBUS_DETECT
 
#define OTG_VBUS_IO   (defined(USB_VBUS_PIN) && OTG_VBUS_DETECT)
 
#define USB_VBUS_WKUP   0
 
#define otg_vbus_init(handler)
 
#define Is_otg_vbus_high()   ioport_get_pin_level(USB_VBUS_PIN)
 
#define Is_otg_vbus_low()   (!Is_otg_vbus_high())
 
#define otg_enable_vbus_interrupt()   pio_enable_pin_interrupt(USB_VBUS_PIN)
 
#define otg_disable_vbus_interrupt()   pio_disable_pin_interrupt(USB_VBUS_PIN)
 

USBHS OTG main management

These macros allows to enable/disable pad and USBHS hardware

#define otg_reset()
 Reset USB macro. More...
 
#define otg_enable()   (Set_bits(USBHS->USBHS_CTRL, USBHS_CTRL_USBE))
 Enable USB macro. More...
 
#define otg_disable()   (Clr_bits(USBHS->USBHS_CTRL, USBHS_CTRL_USBE))
 Disable USB macro. More...
 
#define Is_otg_enabled()   (Tst_bits(USBHS->USBHS_CTRL, USBHS_CTRL_USBE))
 
#define Is_otg_clock_usable()   (Tst_bits(USBHS->USBHS_SR, USBHS_SR_CLKUSABLE))
 Check Clock Usable. More...
 
#define otg_freeze_clock()   (Set_bits(USBHS->USBHS_CTRL, USBHS_CTRL_FRZCLK))
 Stop (freeze) internal USB clock. More...
 
#define otg_unfreeze_clock()   (Clr_bits(USBHS->USBHS_CTRL, USBHS_CTRL_FRZCLK))
 
#define Is_otg_clock_frozen()   (Tst_bits(USBHS->USBHS_CTRL, USBHS_CTRL_FRZCLK))
 
#define otg_enable_rderr_interrupt()   (Set_bits(USBHS->USBHS_CTRL, USBHS_CTRL_RDERRE))
 Enables RDERR interrupt. More...
 
#define otg_disable_rderr_interrupt()   (Clr_bits(USBHS->USBHS_CTRL, USBHS_CTRL_RDERRE))
 Disables RDERR interrupt. More...
 
#define Is_otg_rderr_interrupt_enabled()   (Tst_bits(USBHS->USBHS_CTRL, USBHS_CTRL_RDERRE))
 
#define otg_ack_rderr_interrupt()   (USBHS->USBHS_SCR = USBHS_SCR_RDERRIC)
 ACKs RDERR interrupt. More...
 
#define otg_raise_rderr_interrupt()   (USBHS->USBHS_SFR = USBHS_SFR_RDERRIS)
 Raises RDERR interrupt. More...
 
#define Is_otg_rderr_interrupt()   (Tst_bits(USBHS->USBHS_SR, USBHS_SR_RDERRI))
 Tests if a RDERR occurs. More...
 

#define Is_otg_clock_frozen ( )    (Tst_bits(USBHS->USBHS_CTRL, USBHS_CTRL_FRZCLK))
#define Is_otg_clock_usable ( )    (Tst_bits(USBHS->USBHS_SR, USBHS_SR_CLKUSABLE))

Check Clock Usable.

For parts with HS feature, this one corresponding at UTMI clock

Referenced by if(), udd_attach(), and udd_enable().

#define Is_otg_device_mode_forced ( )    (Tst_bits(USBHS->USBHS_CTRL, USBHS_CTRL_UIMOD))

Test if device mode is forced.

#define Is_otg_enabled ( )    (Tst_bits(USBHS->USBHS_CTRL, USBHS_CTRL_USBE))
#define Is_otg_host_mode_forced ( )    (!Tst_bits(USBHS->USBHS_CTRL, USBHS_CTRL_UIMOD))

Test if host mode is forced.

Referenced by udd_disable().

#define Is_otg_id_device ( )    ioport_get_pin_level(USB_ID_PIN)

Referenced by udd_enable().

#define Is_otg_id_host ( )    (!Is_otg_id_device())

Referenced by udd_disable().

#define Is_otg_rderr_interrupt ( )    (Tst_bits(USBHS->USBHS_SR, USBHS_SR_RDERRI))

Tests if a RDERR occurs.

#define Is_otg_rderr_interrupt_enabled ( )    (Tst_bits(USBHS->USBHS_CTRL, USBHS_CTRL_RDERRE))
#define Is_otg_vbus_high ( )    ioport_get_pin_level(USB_VBUS_PIN)

Referenced by udd_enable(), and udd_vbus_handler().

#define Is_otg_vbus_low ( )    (!Is_otg_vbus_high())
#define otg_ack_rderr_interrupt ( )    (USBHS->USBHS_SCR = USBHS_SCR_RDERRIC)

ACKs RDERR interrupt.

#define otg_disable ( )    (Clr_bits(USBHS->USBHS_CTRL, USBHS_CTRL_USBE))

Disable USB macro.

Referenced by udd_disable().

#define otg_disable_rderr_interrupt ( )    (Clr_bits(USBHS->USBHS_CTRL, USBHS_CTRL_RDERRE))

Disables RDERR interrupt.

#define otg_disable_vbus_interrupt ( )    pio_disable_pin_interrupt(USB_VBUS_PIN)
#define otg_enable ( )    (Set_bits(USBHS->USBHS_CTRL, USBHS_CTRL_USBE))

Enable USB macro.

Referenced by udd_enable().

#define otg_enable_rderr_interrupt ( )    (Set_bits(USBHS->USBHS_CTRL, USBHS_CTRL_RDERRE))

Enables RDERR interrupt.

#define otg_enable_vbus_interrupt ( )    pio_enable_pin_interrupt(USB_VBUS_PIN)
#define otg_force_device_mode ( )    (Set_bits(USBHS->USBHS_CTRL, USBHS_CTRL_UIMOD))
#define otg_force_host_mode ( )    (Clr_bits(USBHS->USBHS_CTRL, USBHS_CTRL_UIMOD))

Disable external OTG_ID pin and force host mode.

#define otg_freeze_clock ( )    (Set_bits(USBHS->USBHS_CTRL, USBHS_CTRL_FRZCLK))

Stop (freeze) internal USB clock.

Referenced by if(), udd_attach(), udd_detach(), udd_disable(), and udd_enable().

#define OTG_ID_DETECT
Value:
(defined(CONF_BOARD_USB_PORT) && \
defined(CONF_BOARD_USB_ID_DETECT))
#define CONF_BOARD_USB_PORT
USB pins are used.
Definition: conf_board.h:44
#define otg_id_init (   handler)
Value:
USB_ID_PIN_IRQn, USB_INT_LEVEL, handler, false)
static __always_inline void otg_io_pin_init(uint32_t pin, uint32_t flags, IRQn_Type port_irqn, uint8_t irq_level, void(*handler)(uint32_t, uint32_t), uint32_t wkup)
Definition: usbhs_otg.h:53
#define USB_ID_PIN_IRQn
Definition: same70_xplained.h:528
#define USB_ID_FLAGS
Definition: same70_xplained.h:526
#define USB_INT_LEVEL
USB interrupt level By default USB interrupt have low priority.
Definition: usbhs_otg.h:79
#define USB_ID_PIN
Definition: same70_xplained.h:527
#define otg_id_interrupt_disable ( )    pio_disable_pin_interrupt(USB_ID_PIN)
#define otg_id_interrupt_enable ( )    pio_enable_pin_interrupt(USB_ID_PIN)
#define OTG_ID_IO   (defined(USB_ID_PIN) && OTG_ID_DETECT)
#define otg_raise_rderr_interrupt ( )    (USBHS->USBHS_SFR = USBHS_SFR_RDERRIS)

Raises RDERR interrupt.

#define otg_reset ( )
Value:
do { \
USBHS->USBHS_CTRL = 0; \
while( USBHS->USBHS_SR & 0x3FFF) {\
USBHS->USBHS_SCR = 0xFFFFFFFF;\
} \
} while (0)

Reset USB macro.

#define otg_unfreeze_clock ( )    (Clr_bits(USBHS->USBHS_CTRL, USBHS_CTRL_FRZCLK))
#define OTG_VBUS_DETECT
Value:
(defined(CONF_BOARD_USB_PORT) && \
defined(CONF_BOARD_USB_VBUS_DETECT))
#define CONF_BOARD_USB_PORT
USB pins are used.
Definition: conf_board.h:44
#define otg_vbus_init (   handler)
Value:
static __always_inline void otg_io_pin_init(uint32_t pin, uint32_t flags, IRQn_Type port_irqn, uint8_t irq_level, void(*handler)(uint32_t, uint32_t), uint32_t wkup)
Definition: usbhs_otg.h:53
#define USB_VBUS_PIN_IRQn
Definition: same70_xplained.h:518
#define USB_VBUS_WKUP
Definition: usbhs_otg.h:143
#define USB_INT_LEVEL
USB interrupt level By default USB interrupt have low priority.
Definition: usbhs_otg.h:79
#define USB_VBUS_PIN
Definition: same70_xplained.h:517
#define USB_VBUS_FLAGS
Definition: same70_xplained.h:516

Referenced by udd_enable().

#define OTG_VBUS_IO   (defined(USB_VBUS_PIN) && OTG_VBUS_DETECT)
#define USB_INT_LEVEL   5

USB interrupt level By default USB interrupt have low priority.

#define USB_VBUS_WKUP   0

void otg_dual_disable ( void  )

Uninitialize the dual role This function is implemented in usbhs_host.c file.

bool otg_dual_enable ( void  )

Initialize the dual role This function is implemented in usbhs_host.c file.

Returns
true if the ID pin management has been started, otherwise false.

Referenced by udd_enable().