Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
USBC Device Driver

USBC low-level driver for USB Device mode.

USBC Custom configuration

The following USBC driver configuration must be included in the conf_usb.h file of the application.

UDD_USB_INT_LEVEL
Option to change the interrupt priority (0 to 15) by default 5 (recommended).

UDD_USB_INT_FUN
Option to fit interrupt function to what defined in exception table.

UDD_NO_SLEEP_MGR
Feature to work without sleep manager module. Default not defined. Note that with this feature defined sleep manager must not be used in application.

management

The USB driver is fully managed by interrupt and does not request periodic task. Thereby, the USB events use callbacks to transfer the information. The callbacks are declared in static during compilation or in variable during code execution.

Static declarations defined in conf_usb.h:

Dynamic callbacks, called "endpoint job" , are registered in udd_ep_job_t structure via the following functions:

mode management

The Sleep modes authorized :

The USBC_SLEEP_MODE_USB_IDLE equals SLEEPMGR_IDLE.

The USBC_SLEEP_MODE_USB_SUSPEND depends on USB Power mode, USB clock startup timing and USB Speed mode: | Power Mode | Speed mode | Clock Startup | Sleep mode authorized | | X | LS, FS | >10ms | SLEEPMGR_BACKUP | | X | HS | >3ms | SLEEPMGR_BACKUP | | Self-Power | LS, FS | <=10ms | SLEEPMGR_RET | | Self-Power | HS | <=3ms | SLEEPMGR_RET | | Bus-Power | LS, FS | <=10ms | SLEEPMGR_RET | | Bus-Power | HS | <=3ms | SLEEPMGR_RET |

Power management routine.

static bool udd_b_idle
 State of USB line. More...
 
static void udd_sleep_mode (bool b_idle)
 Authorize or not the CPU powerdown mode. More...
 
#define USBC_SLEEP_MODE_USB_SUSPEND   SLEEPMGR_SLEEP_1
 Definition of sleep levels. More...
 
#define USBC_SLEEP_MODE_USB_IDLE   SLEEPMGR_ACTIVE
 

USB IO PADs handlers

static void uhd_vbus_handler (void)
 USB VBus pin change handler. More...
 
static volatile usb_desc_table_t udd_g_ep_table [2 *(USB_DEVICE_MAX_EP+1)]
 USB SRAM data about endpoint descriptor table The content of the USB SRAM can be : More...
 

Control endpoint low level management routine.

This function performs control endpoint management.

It handle the SETUP/DATA/HANDSHAKE phases of a control transaction.

enum  udd_ctrl_ep_state_t {
  UDD_EPCTRL_SETUP = 0,
  UDD_EPCTRL_DATA_OUT = 1,
  UDD_EPCTRL_DATA_IN = 2,
  UDD_EPCTRL_HANDSHAKE_WAIT_IN_ZLP = 3,
  UDD_EPCTRL_HANDSHAKE_WAIT_OUT_ZLP = 4,
  UDD_EPCTRL_STALL_REQ = 5
}
 Bit definitions about endpoint control state machine for udd_ep_control_state. More...
 
COMPILER_WORD_ALIGNED
udd_ctrl_request_t 
udd_g_ctrlreq
 Global variable to give and record information about setup request management. More...
 
static udd_ctrl_ep_state_t udd_ep_control_state
 State of the endpoint control management. More...
 
static uint16_t udd_ctrl_prev_payload_nb_trans
 Total number of data received/sent during data packet phase with previous payload buffers. More...
 
static uint16_t udd_ctrl_payload_nb_trans
 Number of data received/sent to/from udd_g_ctrlreq.payload buffer. More...
 

Management of bulk/interrupt/isochronous endpoints

Buffer to store the data received on control endpoint (SETUP/OUT endpoint 0)

Used to avoid a RAM buffer overflow in case of the payload buffer is smaller than control endpoint size

The UDD manages the data transfer on endpoints:

  • Start data transfer on endpoint with USB Device DMA
  • Send a ZLP packet if requested
  • Call callback registered to signal end of transfer The transfer abort and stall feature are supported.
 udd_ep_job_t
 
static udd_ep_job_t udd_ep_job [USB_DEVICE_MAX_EP]
 Array to register a job on bulk/interrupt/isochronous endpoint. More...
 
 UDC_BSS (4)
 Buffer to store the data received on bulk/interrupt endpoints. More...
 
bool udd_include_vbus_monitoring (void)
 Authorizes the VBUS event. More...
 
void udd_enable (void)
 Enables the USB Device mode. More...
 
void udd_disable (void)
 Disables the USB Device mode. More...
 
void udd_attach (void)
 Attach device to the bus when possible. More...
 
void udd_detach (void)
 Detaches the device from the bus. More...
 
bool udd_is_high_speed (void)
 Test whether the USB Device Controller is running at high speed or not. More...
 
void udd_set_address (uint8_t address)
 Changes the USB address of device. More...
 
uint8_t udd_getaddress (void)
 Returns the USB address of device. More...
 
uint16_t udd_get_frame_number (void)
 Returns the current start of frame number. More...
 
uint16_t udd_get_micro_frame_number (void)
 Returns the current micro start of frame number. More...
 
void udd_send_remotewakeup (void)
 The USB driver sends a resume signal called Upstream Resume. More...
 
void udd_set_setup_payload (uint8_t *payload, uint16_t payload_size)
 Load setup payload. More...
 
bool udd_ep_alloc (udd_ep_id_t ep, uint8_t bmAttributes, uint16_t MaxEndpointSize)
 Configures and enables an endpoint. More...
 
void udd_ep_free (udd_ep_id_t ep)
 Disables an endpoint. More...
 
bool udd_ep_is_halted (udd_ep_id_t ep)
 Check if the endpoint ep is halted. More...
 
bool udd_ep_set_halt (udd_ep_id_t ep)
 Set the halted state of the endpoint ep. More...
 
bool udd_ep_clear_halt (udd_ep_id_t ep)
 Clear the halted state of the endpoint ep. More...
 
bool udd_ep_run (udd_ep_id_t ep, bool b_shortpacket, uint8_t *buf, iram_size_t buf_size, udd_callback_trans_t callback)
 Allows to receive or send data on an endpoint. More...
 
void udd_ep_abort (udd_ep_id_t ep)
 Aborts transfer on going on endpoint. More...
 
bool udd_ep_wait_stall_clear (udd_ep_id_t ep, udd_callback_halt_cleared_t callback)
 Registers a callback to call when endpoint halt is cleared. More...
 
void udd_test_mode_j (void)
 
void udd_test_mode_k (void)
 
void udd_test_mode_se0_nak (void)
 
void udd_test_mode_packet (void)
 
static void udd_reset_ep_ctrl (void)
 
static void udd_ctrl_init (void)
 
static void udd_ctrl_setup_received (void)
 
static void udd_ctrl_in_sent (void)
 
static void udd_ctrl_out_received (void)
 
static void udd_ctrl_underflow (void)
 
static void udd_ctrl_overflow (void)
 
static void udd_ctrl_stall_data (void)
 
static void udd_ctrl_send_zlp_in (void)
 
static void udd_ctrl_send_zlp_out (void)
 
static void udd_ctrl_endofrequest (void)
 
static bool udd_ctrl_interrupt (void)
 
static void udd_ep_trans_done (udd_ep_id_t ep)
 
static bool udd_ep_interrupt (void)
 

USBC Device IP properties

These macros give access to IP properties

#define udd_get_endpoint_max_nbr()   otg_get_max_nbr_endpoints()
 Get maximal number of endpoints. More...
 
#define UDD_MAX_PEP_NB   (USBC_EPT_NBR-1)
 
#define UDD_PEP_NB   (USBC_EPT_NBR)
 

USBC Device speeds management

#define udd_low_speed_enable()   USBC_SET_BITS(UDCON,LS)
 Enable/disable device low-speed mode. More...
 
#define udd_low_speed_disable()   USBC_CLR_BITS(UDCON,LS)
 
#define Is_udd_low_speed_enable()   USBC_TST_BITS(UDCON,LS)
 Test if device low-speed mode is forced. More...
 
#define udd_high_speed_enable()   do { } while (0)
 
#define udd_high_speed_disable()   do { } while (0)
 
#define Is_udd_full_speed_mode()   true
 

USBC Device HS test mode management

#define udd_enable_hs_test_mode()   do { } while (0)
 
#define udd_enable_hs_test_mode_j()   do { } while (0)
 
#define udd_enable_hs_test_mode_k()   do { } while (0)
 
#define udd_enable_hs_test_mode_packet()   do { } while (0)
 

USBC device attach control

These macros manage the USBC Device attach.

#define udd_detach_device()   USBC_SET_BITS(UDCON,DETACH)
 detaches from USB bus More...
 
#define udd_attach_device()   USBC_CLR_BITS(UDCON,DETACH)
 attaches to USB bus More...
 
#define Is_udd_detached()   USBC_TST_BITS(UDCON,DETACH)
 test if the device is detached More...
 

USBC device bus events control

These macros manage the USBC Device bus events.

#define udd_initiate_remote_wake_up()   USBC_SET_BITS(UDCON,RMWKUP)
 Initiates a remote wake-up event. More...
 
#define Is_udd_pending_remote_wake_up()   USBC_TST_BITS(UDCON,RMWKUP)
 
#define udd_enable_remote_wake_up_interrupt()   USBC_REG_SET(UDINTE,UPRSME)
 Manage upstream resume event (=remote wakeup from device) The USB driver sends a resume signal called "Upstream Resume". More...
 
#define udd_disable_remote_wake_up_interrupt()   USBC_REG_CLR(UDINTE,UPRSME)
 
#define Is_udd_remote_wake_up_interrupt_enabled()   USBC_TST_BITS(UDINTE,UPRSME)
 
#define udd_ack_remote_wake_up_start()   USBC_REG_CLR(UDINT,UPRSM)
 
#define udd_raise_remote_wake_up_start()   USBC_REG_SET(UDINT,UPRSM)
 
#define Is_udd_remote_wake_up_start()   USBC_TST_BITS(UDINT,UPRSM)
 
#define udd_enable_resume_interrupt()   USBC_REG_SET(UDINTE,EORSME)
 Manage end of resume event (=remote wakeup from host) The USB controller detects a valid "End of Resume" signal initiated by the host. More...
 
#define udd_disable_resume_interrupt()   USBC_REG_CLR(UDINTE,EORSME)
 
#define Is_udd_resume_interrupt_enabled()   USBC_TST_BITS(UDINTE,EORSME)
 
#define udd_ack_resume()   USBC_REG_CLR(UDINT,EORSM)
 
#define udd_raise_resume()   USBC_REG_SET(UDINT,EORSM)
 
#define Is_udd_resume()   USBC_TST_BITS(UDINT,EORSM)
 
#define udd_enable_wake_up_interrupt()   USBC_REG_SET(UDINTE,WAKEUPE)
 Manage wake-up event (=usb line activity) The USB controller is reactivated by a filtered non-idle signal from the lines. More...
 
#define udd_disable_wake_up_interrupt()   USBC_REG_CLR(UDINTE,WAKEUPE)
 
#define Is_udd_wake_up_interrupt_enabled()   USBC_TST_BITS(UDINTE,WAKEUPE)
 
#define udd_ack_wake_up()   USBC_REG_CLR(UDINT,WAKEUP)
 
#define udd_raise_wake_up()   USBC_REG_SET(UDINT,WAKEUP)
 
#define Is_udd_wake_up()   USBC_TST_BITS(UDINT,WAKEUP)
 
#define udd_enable_reset_interrupt()   USBC_REG_SET(UDINTE,EORSTE)
 Manage reset event Set when a USB "End of Reset" has been detected. More...
 
#define udd_disable_reset_interrupt()   USBC_REG_CLR(UDINTE,EORSTE)
 
#define Is_udd_reset_interrupt_enabled()   USBC_TST_BITS(UDINTE,EORSTE)
 
#define udd_ack_reset()   USBC_REG_CLR(UDINT,EORST)
 
#define udd_raise_reset()   USBC_REG_SET(UDINT,EORST)
 
#define Is_udd_reset()   USBC_TST_BITS(UDINT,EORST)
 
#define udd_enable_sof_interrupt()   USBC_REG_SET(UDINTE,SOFE)
 Manage start of frame event. More...
 
#define udd_disable_sof_interrupt()   USBC_REG_CLR(UDINTE,SOFE)
 
#define Is_udd_sof_interrupt_enabled()   USBC_TST_BITS(UDINTE,SOFE)
 
#define udd_ack_sof()   USBC_REG_CLR(UDINT,SOF)
 
#define udd_raise_sof()   USBC_REG_SET(UDINT,SOF)
 
#define Is_udd_sof()   USBC_TST_BITS(UDINT,SOF)
 
#define udd_frame_number()   USBC_RD_BITFIELD(UDFNUM,FNUM)
 
#define Is_udd_frame_number_crc_error()   USBC_TST_BITS(UDFNUM,FNCERR)
 
#define udd_enable_msof_interrupt()   do { } while(0)
 Manage Micro start of frame event (High Speed Only) More...
 
#define udd_disable_msof_interrupt()   do { } while(0)
 
#define Is_udd_msof_interrupt_enabled()   false
 
#define udd_ack_msof()   do { } while(0)
 
#define udd_raise_msof()   do { } while(0)
 
#define Is_udd_msof()   false
 
#define udd_micro_frame_number()   (Rd_bits(USBC->USBC_UDFNUM, USBC_UDFNUM_FNUM_Msk))
 
#define udd_enable_suspend_interrupt()   USBC_REG_SET(UDINTE,SUSPE)
 Manage suspend event. More...
 
#define udd_disable_suspend_interrupt()   USBC_REG_CLR(UDINTE,SUSPE)
 
#define Is_udd_suspend_interrupt_enabled()   USBC_TST_BITS(UDINTE,SUSPE)
 
#define udd_ack_suspend()   USBC_REG_CLR(UDINT,SUSP)
 
#define udd_raise_suspend()   USBC_REG_SET(UDINT,SUSP)
 
#define Is_udd_suspend()   USBC_TST_BITS(UDINT,SUSP)
 

#define Is_udd_detached ( )    USBC_TST_BITS(UDCON,DETACH)

test if the device is detached

#define Is_udd_frame_number_crc_error ( )    USBC_TST_BITS(UDFNUM,FNCERR)
#define Is_udd_full_speed_mode ( )    true

Referenced by udd_is_high_speed().

#define Is_udd_low_speed_enable ( )    USBC_TST_BITS(UDCON,LS)

Test if device low-speed mode is forced.

#define Is_udd_msof ( )    false
#define Is_udd_msof_interrupt_enabled ( )    false
#define Is_udd_pending_remote_wake_up ( )    USBC_TST_BITS(UDCON,RMWKUP)
#define Is_udd_remote_wake_up_interrupt_enabled ( )    USBC_TST_BITS(UDINTE,UPRSME)
#define Is_udd_remote_wake_up_start ( )    USBC_TST_BITS(UDINT,UPRSM)
#define Is_udd_reset ( )    USBC_TST_BITS(UDINT,EORST)
#define Is_udd_reset_interrupt_enabled ( )    USBC_TST_BITS(UDINTE,EORSTE)
#define Is_udd_resume ( )    USBC_TST_BITS(UDINT,EORSM)
#define Is_udd_resume_interrupt_enabled ( )    USBC_TST_BITS(UDINTE,EORSME)
#define Is_udd_sof ( )    USBC_TST_BITS(UDINT,SOF)
#define Is_udd_sof_interrupt_enabled ( )    USBC_TST_BITS(UDINTE,SOFE)
#define Is_udd_suspend ( )    USBC_TST_BITS(UDINT,SUSP)
#define Is_udd_suspend_interrupt_enabled ( )    USBC_TST_BITS(UDINTE,SUSPE)
#define Is_udd_wake_up ( )    USBC_TST_BITS(UDINT,WAKEUP)
#define Is_udd_wake_up_interrupt_enabled ( )    USBC_TST_BITS(UDINTE,WAKEUPE)
#define udd_ack_msof ( )    do { } while(0)
#define udd_ack_remote_wake_up_start ( )    USBC_REG_CLR(UDINT,UPRSM)
#define udd_ack_reset ( )    USBC_REG_CLR(UDINT,EORST)

Referenced by udd_attach().

#define udd_ack_resume ( )    USBC_REG_CLR(UDINT,EORSM)
#define udd_ack_sof ( )    USBC_REG_CLR(UDINT,SOF)

Referenced by udd_attach().

#define udd_ack_suspend ( )    USBC_REG_CLR(UDINT,SUSP)
#define udd_ack_wake_up ( )    USBC_REG_CLR(UDINT,WAKEUP)

Referenced by udd_attach().

#define udd_attach_device ( )    USBC_CLR_BITS(UDCON,DETACH)

attaches to USB bus

Referenced by udd_attach().

#define udd_detach_device ( )    USBC_SET_BITS(UDCON,DETACH)

detaches from USB bus

Referenced by udd_detach().

#define udd_disable_msof_interrupt ( )    do { } while(0)
#define udd_disable_remote_wake_up_interrupt ( )    USBC_REG_CLR(UDINTE,UPRSME)
#define udd_disable_reset_interrupt ( )    USBC_REG_CLR(UDINTE,EORSTE)
#define udd_disable_resume_interrupt ( )    USBC_REG_CLR(UDINTE,EORSME)
#define udd_disable_sof_interrupt ( )    USBC_REG_CLR(UDINTE,SOFE)
#define udd_disable_suspend_interrupt ( )    USBC_REG_CLR(UDINTE,SUSPE)
#define udd_disable_wake_up_interrupt ( )    USBC_REG_CLR(UDINTE,WAKEUPE)
#define udd_enable_hs_test_mode ( )    do { } while (0)
#define udd_enable_hs_test_mode_j ( )    do { } while (0)

Referenced by udd_test_mode_j().

#define udd_enable_hs_test_mode_k ( )    do { } while (0)

Referenced by udd_test_mode_k().

#define udd_enable_hs_test_mode_packet ( )    do { } while (0)

Referenced by udd_test_mode_packet().

#define udd_enable_msof_interrupt ( )    do { } while(0)

Manage Micro start of frame event (High Speed Only)

#define udd_enable_remote_wake_up_interrupt ( )    USBC_REG_SET(UDINTE,UPRSME)

Manage upstream resume event (=remote wakeup from device) The USB driver sends a resume signal called "Upstream Resume".

#define udd_enable_reset_interrupt ( )    USBC_REG_SET(UDINTE,EORSTE)

Manage reset event Set when a USB "End of Reset" has been detected.

Referenced by udd_attach().

#define udd_enable_resume_interrupt ( )    USBC_REG_SET(UDINTE,EORSME)

Manage end of resume event (=remote wakeup from host) The USB controller detects a valid "End of Resume" signal initiated by the host.

#define udd_enable_sof_interrupt ( )    USBC_REG_SET(UDINTE,SOFE)

Manage start of frame event.

Referenced by udd_attach().

#define udd_enable_suspend_interrupt ( )    USBC_REG_SET(UDINTE,SUSPE)

Manage suspend event.

Referenced by udd_attach().

#define udd_enable_wake_up_interrupt ( )    USBC_REG_SET(UDINTE,WAKEUPE)

Manage wake-up event (=usb line activity) The USB controller is reactivated by a filtered non-idle signal from the lines.

Referenced by udd_attach().

#define udd_frame_number ( )    USBC_RD_BITFIELD(UDFNUM,FNUM)

Referenced by udd_get_frame_number().

#define udd_get_endpoint_max_nbr ( )    otg_get_max_nbr_endpoints()

Get maximal number of endpoints.

#define udd_high_speed_disable ( )    do { } while (0)

Referenced by udd_enable().

#define udd_high_speed_enable ( )    do { } while (0)

Referenced by udd_enable().

#define udd_initiate_remote_wake_up ( )    USBC_SET_BITS(UDCON,RMWKUP)

Initiates a remote wake-up event.

Referenced by udd_send_remotewakeup().

#define udd_low_speed_disable ( )    USBC_CLR_BITS(UDCON,LS)

Referenced by udd_enable().

#define udd_low_speed_enable ( )    USBC_SET_BITS(UDCON,LS)

Enable/disable device low-speed mode.

Referenced by udd_enable().

#define UDD_MAX_PEP_NB   (USBC_EPT_NBR-1)
#define udd_micro_frame_number ( )    (Rd_bits(USBC->USBC_UDFNUM, USBC_UDFNUM_FNUM_Msk))
#define UDD_PEP_NB   (USBC_EPT_NBR)
#define udd_raise_msof ( )    do { } while(0)
#define udd_raise_remote_wake_up_start ( )    USBC_REG_SET(UDINT,UPRSM)
#define udd_raise_reset ( )    USBC_REG_SET(UDINT,EORST)
#define udd_raise_resume ( )    USBC_REG_SET(UDINT,EORSM)
#define udd_raise_sof ( )    USBC_REG_SET(UDINT,SOF)
#define udd_raise_suspend ( )    USBC_REG_SET(UDINT,SUSP)

Referenced by udd_attach().

#define udd_raise_wake_up ( )    USBC_REG_SET(UDINT,WAKEUP)
#define USBC_SLEEP_MODE_USB_IDLE   SLEEPMGR_ACTIVE

Referenced by udd_sleep_mode().

#define USBC_SLEEP_MODE_USB_SUSPEND   SLEEPMGR_SLEEP_1

Definition of sleep levels.

Referenced by udd_disable(), and udd_enable().

Bit definitions about endpoint control state machine for udd_ep_control_state.

Enumerator
UDD_EPCTRL_SETUP 

Wait a SETUP packet.

UDD_EPCTRL_DATA_OUT 

Wait a OUT data packet.

UDD_EPCTRL_DATA_IN 

Wait a IN data packet.

UDD_EPCTRL_HANDSHAKE_WAIT_IN_ZLP 

Wait a IN ZLP packet.

UDD_EPCTRL_HANDSHAKE_WAIT_OUT_ZLP 

Wait a OUT ZLP packet.

UDD_EPCTRL_STALL_REQ 

STALL enabled on IN & OUT packet.

UDC_BSS ( )

Buffer to store the data received on bulk/interrupt endpoints.

Used to avoid a RAM buffer overflow in case of the user buffer is smaller than endpoint size

Warning
The protected interrupt endpoint size is 512 bytes max.
The isochronous and endpoint is not protected by this system and the user must always use a buffer corresponding at endpoint size. Function called by USBC interrupt to manage USB device interrupts

USB Device interrupt events are split in three parts:

  • USB line events (SOF, reset, suspend, resume, wakeup)
  • control endpoint events (setup reception, end of data transfer, underflow, overflow, stall)
  • bulk/interrupt/isochronous endpoints events (end of data transfer)

Note: Here, the global interrupt mask is not clear when an USB interrupt is enabled because this one can not be occurred during the USB ISR (=during INTX is masked). See Technical reference $3.8.3 Masking interrupt requests in peripheral modules.

void udd_attach ( void  )

Attach device to the bus when possible.

Warning
If a VBus control is included in driver, then it will attach device when an acceptable Vbus level from the host is detected.

References cpu_irq_restore(), cpu_irq_save(), Is_otg_clock_usable, otg_freeze_clock, otg_unfreeze_clock, udd_ack_reset, udd_ack_sof, udd_ack_wake_up, udd_attach_device, udd_enable_reset_interrupt, udd_enable_sof_interrupt, udd_enable_suspend_interrupt, udd_enable_wake_up_interrupt, udd_raise_suspend, and udd_sleep_mode().

Referenced by udc_attach(), udd_enable(), and uhd_vbus_handler().

static void udd_ctrl_endofrequest ( void  )
static
static void udd_ctrl_overflow ( void  )
static
static void udd_ctrl_send_zlp_out ( void  )
static
static void udd_ctrl_stall_data ( void  )
static
void udd_detach ( void  )

Detaches the device from the bus.

The driver must remove pull-up on USB line D- or D+.

References otg_freeze_clock, otg_unfreeze_clock, udd_detach_device, and udd_sleep_mode().

Referenced by udc_detach(), udd_disable(), and uhd_vbus_handler().

void udd_ep_abort ( udd_ep_id_t  ep)

Aborts transfer on going on endpoint.

If a transfer is on going, then it is stopped and the callback registered is called to signal the end of transfer. Note: The control endpoint is not authorized.

Parameters
epEndpoint to abort

References cpu_irq_restore(), cpu_irq_save(), dbg_print, Is_udd_endpoint_in, udd_disable_endpoint_interrupt, udd_enable_busy_bank0, udd_ep_job_t, UDD_EP_TRANSFER_ABORT, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.

Referenced by udc_req_std_ep_set_feature(), udd_ep_free(), and udd_ep_set_halt().

bool udd_ep_alloc ( udd_ep_id_t  ep,
uint8_t  bmAttributes,
uint16_t  MaxEndpointSize 
)

Configures and enables an endpoint.

Parameters
epEndpoint number including direction (USB_EP_DIR_IN/USB_EP_DIR_OUT).
bmAttributesAttributes of endpoint declared in the descriptor.
MaxEndpointSizeEndpoint maximum size
Returns
1 if the endpoint is enabled, otherwise 0.

References Assert, Is_udd_endpoint_enabled, udd_configure_endpoint, udd_disable_nyet, udd_enable_busy_bank0, udd_enable_endpoint, USB_EP_ADDR_MASK, USB_EP_DIR_IN, USB_EP_TYPE_BULK, USB_EP_TYPE_INTERRUPT, USB_EP_TYPE_ISOCHRONOUS, and USB_EP_TYPE_MASK.

Referenced by udc_iface_enable().

bool udd_ep_clear_halt ( udd_ep_id_t  ep)

Clear the halted state of the endpoint ep.

After calling this function, any transaction on ep will be handled normally, i.e. a STALL handshake will not be sent, and the data toggle sequence will start at DATA0.

Parameters
epThe ID of the endpoint to be un-halted
Returns
1 if function was successfully done, otherwise 0.

References Is_udd_endpoint_stall_requested, Is_udd_stall, udd_ack_stall, udd_disable_stall_handshake, udd_ep_job_t, udd_reset_data_toggle, and USB_EP_ADDR_MASK.

Referenced by udc_req_std_ep_clear_feature().

void udd_ep_free ( udd_ep_id_t  ep)

Disables an endpoint.

Parameters
epEndpoint number including direction (USB_EP_DIR_IN/USB_EP_DIR_OUT).

References Is_udd_ram_access_error, udd_disable_endpoint, and udd_ep_abort().

Referenced by udc_iface_disable().

bool udd_ep_is_halted ( udd_ep_id_t  ep)

Check if the endpoint ep is halted.

Parameters
epThe ID of the endpoint to check.
Returns
1 if ep is halted, otherwise 0.

References Is_udd_endpoint_stall_requested, and USB_EP_ADDR_MASK.

Referenced by udc_req_std_ep_get_status().

bool udd_ep_run ( udd_ep_id_t  ep,
bool  b_shortpacket,
uint8_t *  buf,
iram_size_t  buf_size,
udd_callback_trans_t  callback 
)

Allows to receive or send data on an endpoint.

The driver uses a specific DMA USB to transfer data from internal RAM to endpoint, if this one is available. When the transfer is finished or aborted (stall, reset, ...), the callback is called. The callback returns the transfer status and eventually the number of byte transfered. Note: The control endpoint is not authorized.

Parameters
epThe ID of the endpoint to use
b_shortpacketEnabled automatic short packet
bufBuffer on Internal RAM to send or fill. It must be align, then use COMPILER_WORD_ALIGNED.
buf_sizeBuffer size to send or fill
callbackNULL or function to call at the end of transfer
Warning
About b_shortpacket, for IN endpoint it means that a short packet (or a Zero Length Packet) will be sent to the USB line to properly close the usb transfer at the end of the data transfer. For Bulk and Interrupt OUT endpoint, it will automatically stop the transfer at the end of the data transfer (received short packet).
Returns
1 if function was successfully done, otherwise 0.

References cpu_irq_restore(), cpu_irq_save(), dbg_print, Is_udd_endpoint_enabled, Is_udd_endpoint_stall_requested, udd_ep_job_t, udd_ep_trans_done(), udd_get_endpoint_size, udd_get_endpoint_type, udd_udesc_rst_buf0_ctn, udd_udesc_rst_buf0_size, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.

Referenced by udi_cdc_ctrl_state_notify(), udi_cdc_data_received(), udi_cdc_rx_start(), and udi_cdc_tx_send().

bool udd_ep_set_halt ( udd_ep_id_t  ep)

Set the halted state of the endpoint ep.

After calling this function, any transaction on ep will result in a STALL handshake being sent. Any pending transactions will be performed first, however.

Parameters
epThe ID of the endpoint to be halted
Returns
1 if ep is halted, otherwise 0.

References udd_enable_stall_handshake, udd_ep_abort(), and USB_EP_ADDR_MASK.

Referenced by udc_req_std_ep_set_feature().

bool udd_ep_wait_stall_clear ( udd_ep_id_t  ep,
udd_callback_halt_cleared_t  callback 
)

Registers a callback to call when endpoint halt is cleared.

Parameters
epThe ID of the endpoint to use
callbackNULL or function to call when endpoint halt is cleared
Warning
if the endpoint is not halted then the callback is called immediately.
Returns
1 if the register is accepted, otherwise 0.

References Is_udd_endpoint_enabled, Is_udd_endpoint_stall_requested, udd_ep_job_t, and USB_EP_ADDR_MASK.

uint16_t udd_get_frame_number ( void  )

Returns the current start of frame number.

Returns
current start of frame number.

References udd_frame_number.

Referenced by udi_cdc_tx_send().

uint16_t udd_get_micro_frame_number ( void  )

Returns the current micro start of frame number.

Returns
current micro start of frame number required in high speed mode.

References udd_micro_frame_number.

Referenced by udi_cdc_tx_send().

uint8_t udd_getaddress ( void  )

Returns the USB address of device.

Returns
USB address

References udd_get_configured_address.

Referenced by udc_req_std_dev_set_configuration().

bool udd_include_vbus_monitoring ( void  )

Authorizes the VBUS event.

Returns
true, if the VBUS monitoring is possible.

Referenced by udc_include_vbus_monitoring().

bool udd_is_high_speed ( void  )

Test whether the USB Device Controller is running at high speed or not.

Returns
true if the Device is running at high speed mode, otherwise false.

References Is_udd_full_speed_mode.

Referenced by udc_req_std_dev_get_descriptor(), udc_req_std_dev_set_configuration(), udc_req_std_dev_set_feature(), and udi_cdc_tx_send().

void udd_send_remotewakeup ( void  )

The USB driver sends a resume signal called Upstream Resume.

References otg_unfreeze_clock, udd_b_idle, udd_initiate_remote_wake_up, and udd_sleep_mode().

Referenced by udc_remotewakeup().

void udd_set_address ( uint8_t  address)

Changes the USB address of device.

Parameters
addressNew USB address

References udd_configure_address, udd_disable_address, and udd_enable_address.

Referenced by udc_valid_address().

void udd_set_setup_payload ( uint8_t *  payload,
uint16_t  payload_size 
)
static void udd_sleep_mode ( bool  b_idle)
static

Authorize or not the CPU powerdown mode.

Parameters
b_enabletrue to authorize powerdown mode

References sleepmgr_lock_mode(), sleepmgr_unlock_mode(), udd_b_idle, and USBC_SLEEP_MODE_USB_IDLE.

Referenced by udd_attach(), udd_detach(), and udd_send_remotewakeup().

void udd_test_mode_j ( void  )
void udd_test_mode_k ( void  )
void udd_test_mode_se0_nak ( void  )
static void uhd_vbus_handler ( void  )
static

USB VBus pin change handler.

References dbg_print, Is_pad_vbus_high, pad_ack_vbus_interrupt, UDC_VBUS_EVENT, udd_attach(), and udd_detach().

Referenced by udd_enable().

bool udd_b_idle
static

State of USB line.

Referenced by udd_enable(), udd_send_remotewakeup(), and udd_sleep_mode().

uint16_t udd_ctrl_payload_nb_trans
static

Number of data received/sent to/from udd_g_ctrlreq.payload buffer.

Referenced by udd_ctrl_in_sent(), udd_ctrl_out_received(), and udd_ctrl_setup_received().

uint16_t udd_ctrl_prev_payload_nb_trans
static

Total number of data received/sent during data packet phase with previous payload buffers.

Referenced by udd_ctrl_in_sent(), udd_ctrl_out_received(), and udd_ctrl_setup_received().

udd_ep_job_t udd_ep_job[USB_DEVICE_MAX_EP]
static

Array to register a job on bulk/interrupt/isochronous endpoint.

volatile usb_desc_table_t udd_g_ep_table[2 *(USB_DEVICE_MAX_EP+1)]
static

USB SRAM data about endpoint descriptor table The content of the USB SRAM can be :

  • modified by USB hardware by interface to signal endpoint status. Thereby, it is read by software.
  • modified by USB software to control endpoint. Thereby, it is read by hardware. This data section is volatile.

Referenced by udd_enable().