USBD driver

nRF5 SDK v17.0.2

Universal Serial Bus Device (USBD) peripheral driver. More...

Data Structures

struct nrfx_usbd_evt_t
Event structure. More...
union nrfx_usbd_data_ptr_t
Universal data pointer. More...
struct nrfx_usbd_ep_transfer_t
Structure to be filled with information about the next transfer. More...
struct nrfx_usbd_transfer_t
Total transfer configuration. More...
union nrfx_usbd_handler_t
Universal transfer handler. More...
struct nrfx_usbd_handler_desc_t
USBD transfer descriptor. More...
struct nrfx_usbd_setup_t
Setup packet structure. More...

Macros

#define NRFX_USBD_EPSIZE 64
Number of bytes in the endpoint.
#define NRFX_USBD_ISOSIZE 1024
Number of bytes for isochronous endpoints. More...
#define NRFX_USBD_FEEDER_BUFFER_SIZE NRFX_USBD_EPSIZE
The size of internal feeder buffer. More...
#define NRFX_USBD_TRANSFER_IN (name, tx_buff, tx_size, tx_flags)
Auxiliary macro for declaring IN transfer description with optional flags. More...
#define NRFX_USBD_TRANSFER_OUT (name, rx_buff, rx_size)
Helper macro for declaring OUT transfer item ( nrfx_usbd_transfer_t ). More...

Typedefs

typedef void(* nrfx_usbd_event_handler_t )( nrfx_usbd_evt_t const *p_event)
USBD event callback function type. More...
typedef bool(* nrfx_usbd_feeder_t )( nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size)
USBD transfer feeder. More...
typedef bool(* nrfx_usbd_consumer_t )( nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size, size_t data_size)
USBD transfer consumer. More...

Enumerations

enum nrfx_usbd_ep_t {
NRFX_USBD_EPOUT0 = NRF_USBD_EPOUT(0),
NRFX_USBD_EPOUT1 = NRF_USBD_EPOUT(1),
NRFX_USBD_EPOUT2 = NRF_USBD_EPOUT(2),
NRFX_USBD_EPOUT3 = NRF_USBD_EPOUT(3),
NRFX_USBD_EPOUT4 = NRF_USBD_EPOUT(4),
NRFX_USBD_EPOUT5 = NRF_USBD_EPOUT(5),
NRFX_USBD_EPOUT6 = NRF_USBD_EPOUT(6),
NRFX_USBD_EPOUT7 = NRF_USBD_EPOUT(7),
NRFX_USBD_EPOUT8 = NRF_USBD_EPOUT(8),
NRFX_USBD_EPIN0 = NRF_USBD_EPIN(0),
NRFX_USBD_EPIN1 = NRF_USBD_EPIN(1),
NRFX_USBD_EPIN2 = NRF_USBD_EPIN(2),
NRFX_USBD_EPIN3 = NRF_USBD_EPIN(3),
NRFX_USBD_EPIN4 = NRF_USBD_EPIN(4),
NRFX_USBD_EPIN5 = NRF_USBD_EPIN(5),
NRFX_USBD_EPIN6 = NRF_USBD_EPIN(6),
NRFX_USBD_EPIN7 = NRF_USBD_EPIN(7),
NRFX_USBD_EPIN8 = NRF_USBD_EPIN(8)
}
Endpoint identifier. More...
enum nrfx_usbd_event_type_t {
NRFX_USBD_EVT_SOF ,
NRFX_USBD_EVT_RESET ,
NRFX_USBD_EVT_SUSPEND ,
NRFX_USBD_EVT_RESUME ,
NRFX_USBD_EVT_WUREQ ,
NRFX_USBD_EVT_SETUP ,
NRFX_USBD_EVT_EPTRANSFER ,
NRFX_USBD_EVT_CNT
}
Events generated by the driver. More...
enum nrfx_usbd_ep_status_t {
NRFX_USBD_EP_OK ,
NRFX_USBD_EP_WAITING ,
NRFX_USBD_EP_OVERLOAD ,
NRFX_USBD_EP_ABORTED ,
NRFX_USBD_EP_BUSY
}
Endpoint status codes. More...
enum nrfx_usbd_transfer_flags_t { NRFX_USBD_TRANSFER_ZLP_FLAG = 1U << 0 }
Flags for the current transfer. More...

Functions

nrfx_err_t nrfx_usbd_init ( nrfx_usbd_event_handler_t event_handler)
Driver initialization. More...
void nrfx_usbd_uninit (void)
Driver deinitialization.
void nrfx_usbd_enable (void)
Enable the USBD port. More...
void nrfx_usbd_disable (void)
Disable the USBD port. More...
void nrfx_usbd_start (bool enable_sof)
Start USB functionality. More...
void nrfx_usbd_stop (void)
Stop USB functionality. More...
bool nrfx_usbd_is_initialized (void)
Check if driver is initialized. More...
bool nrfx_usbd_is_enabled (void)
Check if driver is enabled. More...
bool nrfx_usbd_is_started (void)
Check if driver is started. More...
bool nrfx_usbd_suspend (void)
Suspend USBD operation. More...
bool nrfx_usbd_wakeup_req (void)
Start wake up procedure. More...
bool nrfx_usbd_suspend_check (void)
Check if USBD is in SUSPEND mode. More...
void nrfx_usbd_suspend_irq_config (void)
Enable only interrupts that should be processed in SUSPEND mode. More...
void nrfx_usbd_active_irq_config (void)
Default active interrupt configuration. More...
bool nrfx_usbd_bus_suspend_check (void)
Check the bus state. More...
void nrfx_usbd_force_bus_wakeup (void)
Force the bus state to active.
void nrfx_usbd_ep_max_packet_size_set ( nrfx_usbd_ep_t ep, uint16_t size)
Configure packet size that should be supported by the endpoint. More...
uint16_t nrfx_usbd_ep_max_packet_size_get ( nrfx_usbd_ep_t ep)
Get configured endpoint packet size. More...
bool nrfx_usbd_ep_enable_check ( nrfx_usbd_ep_t ep)
Check if the selected endpoint is enabled. More...
void nrfx_usbd_ep_enable ( nrfx_usbd_ep_t ep)
Enable selected endpoint. More...
void nrfx_usbd_ep_disable ( nrfx_usbd_ep_t ep)
Disable selected endpoint. More...
void nrfx_usbd_ep_default_config (void)
Disable all endpoints except for EP0. More...
nrfx_err_t nrfx_usbd_ep_transfer ( nrfx_usbd_ep_t ep, nrfx_usbd_transfer_t const *p_transfer)
Start sending data over endpoint. More...
nrfx_err_t nrfx_usbd_ep_handled_transfer ( nrfx_usbd_ep_t ep, nrfx_usbd_handler_desc_t const *p_handler)
Start sending data over the endpoint using the transfer handler function. More...
void * nrfx_usbd_feeder_buffer_get (void)
Get the temporary buffer to be used by the feeder. More...
nrfx_usbd_ep_status_t nrfx_usbd_ep_status_get ( nrfx_usbd_ep_t ep, size_t *p_size)
Get the information about last finished or current transfer. More...
size_t nrfx_usbd_epout_size_get ( nrfx_usbd_ep_t ep)
Get number of received bytes. More...
bool nrfx_usbd_ep_is_busy ( nrfx_usbd_ep_t ep)
Check if endpoint buffer is ready or is under USB IP control. More...
void nrfx_usbd_ep_stall ( nrfx_usbd_ep_t ep)
Stall endpoint. More...
void nrfx_usbd_ep_stall_clear ( nrfx_usbd_ep_t ep)
Clear stall flag on endpoint. More...
bool nrfx_usbd_ep_stall_check ( nrfx_usbd_ep_t ep)
Check if endpoint is stalled. More...
void nrfx_usbd_ep_dtoggle_clear ( nrfx_usbd_ep_t ep)
Clear current endpoint data toggle. More...
void nrfx_usbd_setup_get ( nrfx_usbd_setup_t *p_setup)
Get parsed setup data. More...
void nrfx_usbd_setup_data_clear (void)
Clear the control endpoint for packet reception during DATA stage. More...
void nrfx_usbd_setup_clear (void)
Clear setup endpoint. More...
void nrfx_usbd_setup_stall (void)
Stall setup endpoint. More...
void nrfx_usbd_ep_abort ( nrfx_usbd_ep_t ep)
Abort pending transfer on selected endpoint. More...
nrfx_usbd_ep_t nrfx_usbd_last_setup_dir_get (void)
Get the information about expected transfer SETUP data direction. More...
void nrfx_usbd_transfer_out_drop ( nrfx_usbd_ep_t ep)
Drop transfer on OUT endpoint. More...

Macros for creating endpoint identifiers.

Create identifier for IN endpoint.

Auxiliary macros for creating endpoint identifiers compatible with the USB specification.

Simple macro to create IN endpoint identifier for given endpoint number.

Parameters
[in] n Endpoint number.
Returns
Endpoint identifier that connects endpoint number and endpoint direction.
#define NRFX_USBD_EPIN (n)   (( nrfx_usbd_ep_t ) NRF_USBD_EPIN (n))
#define NRFX_USBD_EPOUT (n)   (( nrfx_usbd_ep_t ) NRF_USBD_EPOUT (n))
Create identifier for OUT endpoint. More...

Detailed Description

Universal Serial Bus Device (USBD) peripheral driver.

Macro Definition Documentation

#define NRFX_USBD_EPOUT ( n ) (( nrfx_usbd_ep_t ) NRF_USBD_EPOUT (n))

Create identifier for OUT endpoint.

Simple macro to create OUT endpoint identifier for given endpoint number.

Parameters
[in] n Endpoint number.
Returns
Endpoint identifier that connects endpoint number and endpoint direction.
#define NRFX_USBD_FEEDER_BUFFER_SIZE NRFX_USBD_EPSIZE

The size of internal feeder buffer.

See Also
nrfx_usbd_feeder_buffer_get
#define NRFX_USBD_ISOSIZE   1024

Number of bytes for isochronous endpoints.

Number of bytes for isochronous endpoints in total. This number would be shared between IN and OUT endpoint. It may be also assigned totaly to one endpoint.

See Also
nrf_usbd_isosplit_set
nrf_usbd_isosplit_get
#define NRFX_USBD_TRANSFER_IN ( name,
tx_buff,
tx_size,
tx_flags
)
Value:
const nrfx_usbd_transfer_t name = { \
. p_data = { . tx = (tx_buff) }, \
.size = (tx_size), \
.flags = (tx_flags) \
}

Auxiliary macro for declaring IN transfer description with optional flags.

The base macro for creating transfers with any configuration option.

Parameters
name Instance name.
tx_buff Buffer to transfer.
tx_size Transfer size.
tx_flags Flags for the transfer (see nrfx_usbd_transfer_flags_t ).
Returns
Configured variable with total transfer description.
#define NRFX_USBD_TRANSFER_OUT ( name,
rx_buff,
rx_size
)
Value:
const nrfx_usbd_transfer_t name = { \
. p_data = { . rx = (rx_buff) }, \
.size = (rx_size), \
.flags = 0 \
}

Helper macro for declaring OUT transfer item ( nrfx_usbd_transfer_t ).

Parameters
name Instance name.
rx_buff Buffer to transfer.
rx_size Transfer size.

Typedef Documentation

typedef bool(* nrfx_usbd_consumer_t)( nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size, size_t data_size)

USBD transfer consumer.

Pointer for a transfer consumer. Transfer consumer is a feedback function used to prepare a single RX (Host->Device) endpoint transfer.

The transfer must provide a buffer big enough to fit the whole data from the endpoint. Otherwise, the NRFX_USBD_EP_OVERLOAD event is generated.

Parameters
[out] p_next Structure with the data for the next transfer to be filled. Required only if the function returns true.
[in,out] p_context Context variable configured with the transfer.
[in] ep_size The endpoint size.
[in] data_size Number of received bytes in the endpoint buffer.
Return values
false Current transfer is the last one - you do not need to call the function again.
true There is more data to be prepared and when current transfer finishes, the feeder function is expected to be called again.
typedef void(* nrfx_usbd_event_handler_t)( nrfx_usbd_evt_t const *p_event)

USBD event callback function type.

Parameters
[in] p_event Event information structure.
typedef bool(* nrfx_usbd_feeder_t)( nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size)

USBD transfer feeder.

Pointer for a transfer feeder. Transfer feeder is a feedback function used to prepare a single TX (Device->Host) endpoint transfer.

The transfers provided by the feeder must be simple:

  • The size of the transfer provided by this function is limited to a single endpoint buffer. Bigger transfers are not handled automatically in this case.
  • Flash transfers are not automatically supported- you must copy them to the RAM buffer before.
Note
This function may use nrfx_usbd_feeder_buffer_get to gain a temporary buffer that can be used to prepare transfer.
Parameters
[out] p_next Structure with the data for the next transfer to be filled. Required only if the function returns true.
[in,out] p_context Context variable configured with the transfer.
[in] ep_size The endpoint size.
Return values
false The current transfer is the last one - you do not need to call the function again.
true There is more data to be prepared and when the current transfer finishes, the feeder function is expected to be called again.

Enumeration Type Documentation

Endpoint status codes.

Status codes that may be returned by nrfx_usbd_ep_status_get or, except for NRFX_USBD_EP_BUSY , reported together with NRFX_USBD_EVT_EPTRANSFER .

Enumerator
NRFX_USBD_EP_OK

No error occured.

NRFX_USBD_EP_WAITING

Data received, no buffer prepared already - waiting for configured transfer.

NRFX_USBD_EP_OVERLOAD

Received number of bytes cannot fit given buffer. This error would also be returned when next_transfer function has been defined but currently received data cannot fit completely in current buffer. No data split from single endpoint transmission is supported.

When this error is reported - data is left inside endpoint buffer. Clear endpoint or prepare new buffer and read it.

NRFX_USBD_EP_ABORTED

EP0 transfer can be aborted when new setup comes. Any other transfer can be aborted by USB reset or driver stopping.

NRFX_USBD_EP_BUSY

Transfer is in progress.

Endpoint identifier.

Endpoint identifier used in the driver. This endpoint number is consistent with USB 2.0 specification.

Enumerator
NRFX_USBD_EPOUT0

Endpoint OUT 0

NRFX_USBD_EPOUT1

Endpoint OUT 1

NRFX_USBD_EPOUT2

Endpoint OUT 2

NRFX_USBD_EPOUT3

Endpoint OUT 3

NRFX_USBD_EPOUT4

Endpoint OUT 4

NRFX_USBD_EPOUT5

Endpoint OUT 5

NRFX_USBD_EPOUT6

Endpoint OUT 6

NRFX_USBD_EPOUT7

Endpoint OUT 7

NRFX_USBD_EPOUT8

Endpoint OUT 8

NRFX_USBD_EPIN0

Endpoint IN 0

NRFX_USBD_EPIN1

Endpoint IN 1

NRFX_USBD_EPIN2

Endpoint IN 2

NRFX_USBD_EPIN3

Endpoint IN 3

NRFX_USBD_EPIN4

Endpoint IN 4

NRFX_USBD_EPIN5

Endpoint IN 5

NRFX_USBD_EPIN6

Endpoint IN 6

NRFX_USBD_EPIN7

Endpoint IN 7

NRFX_USBD_EPIN8

Endpoint IN 8

Events generated by the driver.

Enumeration of possible events that may be generated by the driver.

Enumerator
NRFX_USBD_EVT_SOF

Start Of Frame event on USB bus detected.

NRFX_USBD_EVT_RESET

Reset condition on USB bus detected.

NRFX_USBD_EVT_SUSPEND

This device should go to suspend mode now.

NRFX_USBD_EVT_RESUME

This device should resume from suspend now.

NRFX_USBD_EVT_WUREQ

Wakeup request - the USBD peripheral is ready to generate WAKEUP signal after exiting low power mode.

NRFX_USBD_EVT_SETUP

Setup frame received and decoded.

NRFX_USBD_EVT_EPTRANSFER

For Rx (OUT: Host->Device):

  1. The packet has been received but there is no buffer prepared for transfer already.
  2. Whole transfer has been finished.

For Tx (IN: Device->Host): The last packet from requested transfer has been transfered over USB bus and acknowledged.

NRFX_USBD_EVT_CNT

Number of defined events.

Flags for the current transfer.

Flags configured for the transfer that can be merged using the bitwise 'or' operator (|).

Enumerator
NRFX_USBD_TRANSFER_ZLP_FLAG

Add a zero-length packet.

Function Documentation

void nrfx_usbd_active_irq_config ( void )

Default active interrupt configuration.

Default interrupt configuration. Use in a pair with nrfx_usbd_active_irq_config .

See Also
nrfx_usbd_suspend_irq_config
bool nrfx_usbd_bus_suspend_check ( void )

Check the bus state.

This function checks if the bus state is suspended.

Note
The value returned by this function changes on SUSPEND and RESUME event processing.
Return values
true USBD bus is suspended.
false USBD bus is active.
void nrfx_usbd_disable ( void )

Disable the USBD port.

After calling this function USBD peripheral would be disabled. No events would be detected or processed by the driver. Clock for the peripheral would be disconnected.

void nrfx_usbd_enable ( void )

Enable the USBD port.

After calling this function USBD peripheral would be enabled. The USB LDO would be enabled. Enabled USBD peripheral would request HFCLK. This function does not enable external oscillator, so if it is not enabled by other part of the program after enabling USBD driver HFINT would be used for the USBD peripheral. It is perfectly fine until USBD is started. See nrfx_usbd_start .

In normal situation this function should be called in reaction to USBDETECTED event from POWER peripheral.

Interrupts and USB pins pull-up would stay disabled until nrfx_usbd_start function is called.

void nrfx_usbd_ep_abort ( nrfx_usbd_ep_t ep )

Abort pending transfer on selected endpoint.

Parameters
[in] ep Endpoint number.
void nrfx_usbd_ep_default_config ( void )

Disable all endpoints except for EP0.

Disable all endpoints that can be disabled in USB device while it is still active.

void nrfx_usbd_ep_disable ( nrfx_usbd_ep_t ep )

Disable selected endpoint.

This function disables endpoint itself and its interrupts.

Parameters
[in] ep Endpoint number to disable.
void nrfx_usbd_ep_dtoggle_clear ( nrfx_usbd_ep_t ep )

Clear current endpoint data toggle.

Parameters
[in] ep Endpoint number to clear.
void nrfx_usbd_ep_enable ( nrfx_usbd_ep_t ep )

Enable selected endpoint.

This function enables endpoint itself and its interrupts.

Parameters
[in] ep Endpoint number to enable.
Note
Max packet size is set to endpoint default maximum value.
See Also
nrfx_usbd_ep_max_packet_size_set
bool nrfx_usbd_ep_enable_check ( nrfx_usbd_ep_t ep )

Check if the selected endpoint is enabled.

Parameters
[in] ep Endpoint number to check.
Return values
true Endpoint is enabled.
false Endpoint is disabled.
nrfx_err_t nrfx_usbd_ep_handled_transfer ( nrfx_usbd_ep_t ep ,
nrfx_usbd_handler_desc_t const * p_handler
)

Start sending data over the endpoint using the transfer handler function.

This function initializes an endpoint transmission. Just before data is transmitted, the transfer handler is called and it prepares a data chunk.

Parameters
[in] ep Endpoint number. For an IN endpoint, sending is initiated. For an OUT endpoint, receiving is initiated.
[in] p_handler Transfer handler - feeder for IN direction and consumer for OUT direction.
Return values
NRFX_SUCCESS Transfer queued or started.
NRFX_ERROR_BUSY Selected endpoint is pending.
NRFX_ERROR_INVALID_ADDR Unexpected transfer on EPIN0 or EPOUT0.
bool nrfx_usbd_ep_is_busy ( nrfx_usbd_ep_t ep )

Check if endpoint buffer is ready or is under USB IP control.

Function to test if endpoint is busy. Endpoint that is busy cannot be accessed by MCU. It means that:

  • OUT (TX) endpoint: Last uploaded data is still in endpoint and is waiting to be received by the host.
  • IN (RX) endpoint: Endpoint is ready to receive data from the host and the endpoint does not have any data. When endpoint is not busy:
  • OUT (TX) endpoint: New data can be uploaded.
  • IN (RX) endpoint: New data can be downloaded using nrfx_usbd_ep_transfer function.
Parameters
[in] ep Endpoint number.
Return values
false Endpoint is not busy.
true Endpoint is busy.
uint16_t nrfx_usbd_ep_max_packet_size_get ( nrfx_usbd_ep_t ep )

Get configured endpoint packet size.

Function to get configured endpoint size on the buffer.

Parameters
[in] ep Endpoint number.
Returns
Maximum pocket size configured on selected endpoint.
void nrfx_usbd_ep_max_packet_size_set ( nrfx_usbd_ep_t ep ,
uint16_t size
)

Configure packet size that should be supported by the endpoint.

The real endpoint buffer size is always the same. This value sets max packet size that would be transmitted over the endpoint. This is required by the driver.

Parameters
[in] ep Endpoint number.
[in] size Required maximum packet size.
Note
Endpoint size is always set to NRFX_USBD_EPSIZE or NRFX_USBD_ISOSIZE / 2 when nrfx_usbd_ep_enable function is called.
void nrfx_usbd_ep_stall ( nrfx_usbd_ep_t ep )

Stall endpoint.

Stall endpoit to send error information during next transfer request from the host.

Note
To stall endpoint it is safer to use nrfx_usbd_setup_stall
Stalled endpoint would not be cleared when DMA transfer finishes.
Parameters
[in] ep Endpoint number to stall.
bool nrfx_usbd_ep_stall_check ( nrfx_usbd_ep_t ep )

Check if endpoint is stalled.

This function gets stall state of selected endpoint.

Parameters
[in] ep Endpoint number to check.
Return values
false Endpoint is not stalled.
true Endpoint is stalled.
void nrfx_usbd_ep_stall_clear ( nrfx_usbd_ep_t ep )

Clear stall flag on endpoint.

This function clears endpoint that is stalled.

Note
If it is OUT endpoint (receiving) it would be also prepared for reception. It means that busy flag would be set.
In endpoint (transmitting) would not be cleared - it gives possibility to write new data before transmitting.
Parameters
[in] ep Endpoint number.
nrfx_usbd_ep_status_t nrfx_usbd_ep_status_get ( nrfx_usbd_ep_t ep ,
size_t * p_size
)

Get the information about last finished or current transfer.

Function returns the status of the last buffer set for transfer on selected endpoint. The status considers last buffer set by nrfx_usbd_ep_transfer function or by transfer callback function.

Parameters
[in] ep Endpoint number.
[out] p_size Information about the current/last transfer size.
Returns
Endpoint status.
See Also
nrfx_usbd_ep_status_t
nrfx_err_t nrfx_usbd_ep_transfer ( nrfx_usbd_ep_t ep ,
nrfx_usbd_transfer_t const * p_transfer
)

Start sending data over endpoint.

Function initializes endpoint transmission. This is asynchronous function - it finishes immediately after configuration for transmission is prepared.

Note
Data buffer pointed by p_data have to be kept active till NRFX_USBD_EVT_EPTRANSFER event is generated.
Parameters
[in] ep Endpoint number. For IN endpoint sending would be initiated. For OUT endpoint receiving would be initiated.
[in] p_transfer Transfer parameters.
Return values
NRFX_SUCCESS Transfer queued or started.
NRFX_ERROR_BUSY Selected endpoint is pending.
NRFX_ERROR_INVALID_ADDR Unexpected transfer on EPIN0 or EPOUT0.
size_t nrfx_usbd_epout_size_get ( nrfx_usbd_ep_t ep )

Get number of received bytes.

Get the number of received bytes. The function behavior is undefined when called on IN endpoint.

Parameters
[in] ep Endpoint number.
Returns
Number of received bytes.
void* nrfx_usbd_feeder_buffer_get ( void )

Get the temporary buffer to be used by the feeder.

This buffer is used for TX transfers and it can be reused automatically when the transfer is finished. Use it for transfer preparation.

May be used inside the feeder configured in nrfx_usbd_ep_handled_transfer .

Returns
Pointer to the buffer that can be used temporarily.
See Also
NRFX_USBD_FEEDER_BUFFER_SIZE
nrfx_err_t nrfx_usbd_init ( nrfx_usbd_event_handler_t event_handler )

Driver initialization.

Parameters
[in] event_handler Event handler provided by the user. Cannot be null.
Return values
NRFX_SUCCESS Initialization successful.
NRFX_ERROR_INVALID_STATE Driver was already initialized.
bool nrfx_usbd_is_enabled ( void )

Check if driver is enabled.

Return values
false Driver is disabled.
true Driver is enabled.
bool nrfx_usbd_is_initialized ( void )

Check if driver is initialized.

Return values
false Driver is not initialized.
true Driver is initialized.
bool nrfx_usbd_is_started ( void )

Check if driver is started.

Return values
false Driver is not started.
true Driver is started (fully functional).
Note
The USBD peripheral interrupt state is checked.
nrfx_usbd_ep_t nrfx_usbd_last_setup_dir_get ( void )

Get the information about expected transfer SETUP data direction.

Function returns the information about last expected transfer direction.

Return values
NRFX_USBD_EPOUT0 Expecting OUT (Host->Device) direction or no data.
NRFX_USBD_EPIN0 Expecting IN (Device->Host) direction.
void nrfx_usbd_setup_clear ( void )

Clear setup endpoint.

This function acknowledges setup when SETUP command was received and processed. It has to be called if no data respond for the SETUP command is sent.

void nrfx_usbd_setup_data_clear ( void )

Clear the control endpoint for packet reception during DATA stage.

This function may be called if any more data in control write transfer is expected. Clears only OUT endpoint to be able to take another OUT data token. It does not allow STATUS stage.

See Also
nrfx_usbd_setup_clear
void nrfx_usbd_setup_get ( nrfx_usbd_setup_t * p_setup )

Get parsed setup data.

Function fills the parsed setup data structure.

Parameters
[out] p_setup Pointer to data structure that would be filled by parsed data.
void nrfx_usbd_setup_stall ( void )

Stall setup endpoint.

Mark an error on setup endpoint.

void nrfx_usbd_start ( bool enable_sof )

Start USB functionality.

After calling this function USBD peripheral should be fully functional and all new incoming events / interrupts would be processed by the driver.

Also only after calling this function host sees new connected device.

Call this function when USBD power LDO regulator is ready - on USBPWRRDY event from POWER peripheral.

Before USBD interrupts are enabled, external HFXO is requested.

Parameters
enable_sof The flag that is used to enable SOF processing. If it is false, SOF interrupt is left disabled and will not be generated. This improves power saving if SOF is not required.
Note
If the isochronous endpoints are going to be used, it is required to enable the SOF. In other case any isochronous endpoint would stay busy after first transmission.
void nrfx_usbd_stop ( void )

Stop USB functionality.

This function disables USBD pull-up and interrupts.

The HFXO request is released in this function.

Note
This function can also be used to logically disconnect USB from the HOST that would force it to enumerate device after calling nrfx_usbd_start .
bool nrfx_usbd_suspend ( void )

Suspend USBD operation.

The USBD peripheral is forced to go into the low power mode. The function has to be called in the reaction to NRFX_USBD_EVT_SUSPEND event when the firmware is ready.

After successful call of this function most of the USBD registers would be unavailable.

Note
Check returned value for the feedback if suspending was successful.
Return values
true USBD peripheral successfully suspended.
false USBD peripheral was not suspended due to resume detection.
bool nrfx_usbd_suspend_check ( void )

Check if USBD is in SUSPEND mode.

Note
This is the information about peripheral itself, not about the bus state.
Return values
true USBD peripheral is suspended.
false USBD peripheral is active.
void nrfx_usbd_suspend_irq_config ( void )

Enable only interrupts that should be processed in SUSPEND mode.

Auxiliary function to help with SUSPEND mode integration. It enables only the interrupts that can be properly processed without stable HFCLK.

Normally all the interrupts are enabled. Use this function to suspend interrupt processing that may require stable HFCLK until the clock is enabled.

See Also
nrfx_usbd_active_irq_config
void nrfx_usbd_transfer_out_drop ( nrfx_usbd_ep_t ep )

Drop transfer on OUT endpoint.

Parameters
[in] ep OUT endpoint ID.
bool nrfx_usbd_wakeup_req ( void )

Start wake up procedure.

The USBD peripheral is forced to quit the low power mode. After calling this function all the USBD registers would be available.

The hardware starts measuring time when wake up is possible. This may take 0-5 ms depending on how long the SUSPEND state was kept on the USB line.

When NRFX_USBD_EVT_WUREQ event is generated it means that Wake Up signaling has just been started on the USB lines.

Note
Do not expect only NRFX_USBD_EVT_WUREQ event. There always may appear NRFX_USBD_EVT_RESUME event.
NRFX_USBD_EVT_WUREQ event means that Remote WakeUp signal has just begun to be generated. This may take up to 20 ms for the bus to become active.
Return values
true WakeUp procedure started.
false No WakeUp procedure started - bus is already active.