NANO100_BSP V3.04.002
The Board Support Package for Nano100BN Series
Macros | Typedefs | Functions | Variables
Collaboration diagram for USBD Exported Functions:

Macros

#define Maximum(a, b)   ((a)>(b) ? (a) : (b))
 Compare two input numbers and return maximum one. More...
 
#define Minimum(a, b)   ((a)<(b) ? (a) : (b))
 Compare two input numbers and return minimum one. More...
 
#define USBD_ENABLE_USB()   ((uint32_t)(USBD->CTL |= 0xF))
 Enable USBD engine. More...
 
#define USBD_DISABLE_USB()   ((uint32_t)(USBD->CTL &= ~USBD_USB_EN))
 Disable USBD engine. More...
 
#define USBD_ENABLE_PHY()   ((uint32_t)(USBD->CTL |= USBD_PHY_EN))
 Enable USBD PHY. More...
 
#define USBD_DISABLE_PHY()   ((uint32_t)(USBD->CTL &= ~USBD_PHY_EN))
 Disable USBD PHY. More...
 
#define USBD_SET_SE0()   ((uint32_t)(USBD->CTL |= USBD_DRVSE0))
 Force USB PHY Transceiver to Drive SE0. More...
 
#define USBD_CLR_SE0()   ((uint32_t)(USBD->CTL &= ~USBD_DRVSE0))
 Release SE0. More...
 
#define USBD_SET_ADDR(addr)   (USBD->FADDR = (addr))
 Set USBD address. More...
 
#define USBD_GET_ADDR()   ((uint32_t)(USBD->FADDR))
 Get USBD address. More...
 
#define USBD_ENABLE_INT(intr)   (USBD->INTEN |= (intr))
 Enable USBD interrupt. More...
 
#define USBD_GET_INT_FLAG()   ((uint32_t)(USBD->INTSTS))
 Get USBD interrupt flag. More...
 
#define USBD_CLR_INT_FLAG(flag)   (USBD->INTSTS = flag)
 Clear USBD interrupt. More...
 
#define USBD_GET_EP_FLAG()   ((uint32_t)(USBD->EPSTS))
 Get USBD Endpoint status. More...
 
#define USBD_GET_BUS_STATE()   ((uint32_t)(USBD->BUSSTS & 0xf))
 Get USBD bus state. More...
 
#define USBD_IS_ATTACHED()   ((uint32_t)(USBD->BUSSTS & USBD_BUSSTS_FLDET_Msk))
 check cable connect state More...
 
#define USBD_STOP_TRANSACTION(ep)   (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) |= USBD_CFG_CLRRDY_Msk)
 Stop USB endpoint transaction. More...
 
#define USBD_SET_DATA1(ep)   (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) |= USBD_CFG_DSQ_SYNC_Msk)
 Set USB data1 token. More...
 
#define USBD_SET_DATA0(ep)   (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) &= (~USBD_CFG_DSQ_SYNC_Msk))
 Set USB data0 token. More...
 
#define USBD_SET_PAYLOAD_LEN(ep, size)   (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4))) = (size))
 Set USB payload size (IN data) More...
 
#define USBD_GET_PAYLOAD_LEN(ep)   ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4))))
 Get USB payload size (OUT data) More...
 
#define USBD_CONFIG_EP(ep, config)   (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) = (config))
 config endpoint More...
 
#define USBD_SET_EP_BUF_ADDR(ep, offset)   (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4))) = (offset))
 Set buffer for USB endpoint. More...
 
#define USBD_GET_EP_BUF_ADDR(ep)   ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4))))
 Get buffer for USB endpoint. More...
 
#define USBD_SET_EP_STALL(ep)   (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) |= USBD_CFG_SSTALL_Msk)
 Set USB endpoint stall state. More...
 
#define USBD_CLR_EP_STALL(ep)   (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) &= ~USBD_CFG_SSTALL_Msk)
 Clear USB endpoint stall state. More...
 
#define USBD_GET_EP_STALL(ep)   (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) & USBD_CFG_SSTALL_Msk)
 Get USB endpoint stall state. More...
 

Typedefs

typedef void(* VENDOR_REQ) (void)
 
typedef void(* CLASS_REQ) (void)
 
typedef void(* SET_INTERFACE_REQ) (uint32_t u32AltInterface)
 
typedef void(* SET_CONFIG_CB) (void)
 

Functions

static __INLINE void USBD_MemCopy (uint8_t *dest, uint8_t *src, int32_t size)
 To support byte access between USB SRAM and system SRAM. More...
 
static __INLINE void USBD_SetStall (uint8_t epnum)
 Set USB endpoint stall state. More...
 
static __INLINE void USBD_ClearStall (uint8_t epnum)
 Clear USB endpoint stall state. More...
 
static __INLINE uint32_t USBD_GetStall (uint8_t epnum)
 Get USB endpoint stall state. More...
 
void USBD_Open (S_USBD_INFO_T *param, CLASS_REQ pfnClassReq, SET_INTERFACE_REQ pfnSetInterface)
 USBD Initial, Enable clock and reset USB. More...
 
void USBD_Start (void)
 USBD Start. More...
 
void USBD_GetSetupPacket (uint8_t *buf)
 Get Setup Packet. More...
 
void USBD_ProcessSetupPacket (void)
 Process Setup Packet. More...
 
void USBD_StandardRequest (void)
 Process USB standard request. More...
 
void USBD_PrepareCtrlIn (uint8_t *pu8Buf, uint32_t u32Size)
 Prepare Control IN transaction. More...
 
void USBD_CtrlIn (void)
 Start Control IN transfer. More...
 
void USBD_PrepareCtrlOut (uint8_t *pu8Buf, uint32_t u32Size)
 Prepare Control OUT transaction. More...
 
void USBD_CtrlOut (void)
 Start Control OUT transfer. More...
 
void USBD_SwReset (void)
 Clear all software flags. More...
 
void USBD_SetVendorRequest (VENDOR_REQ pfnVendorReq)
 USBD Set Vendor Request. More...
 
void USBD_SetConfigCallback (SET_CONFIG_CB pfnSetConfigCallback)
 The callback function which called when get SET CONFIGURATION request. More...
 
void USBD_LockEpStall (uint32_t u32EpBitmap)
 

Variables

uint8_t * s_usbd_info::gu8DevDesc
 
uint8_t * s_usbd_info::gu8ConfigDesc
 
uint8_t ** s_usbd_info::gu8StringDesc
 
uint8_t ** s_usbd_info::gu8HidReportDesc
 
uint32_t * s_usbd_info::gu32HidReportSize
 
uint32_t * s_usbd_info::gu32ConfigHidDescIdx
 
volatile uint8_t g_usbd_RemoteWakeupEn
 

Detailed Description

Macro Definition Documentation

◆ Maximum

#define Maximum (   a,
 
)    ((a)>(b) ? (a) : (b))

Compare two input numbers and return maximum one.

Parameters
[in]aFirst number to be compared.
[in]bSecond number to be compared.
Returns
Maximum value between a and b.

If a > b, then return a. Otherwise, return b.

Definition at line 172 of file usbd.h.

◆ Minimum

#define Minimum (   a,
 
)    ((a)<(b) ? (a) : (b))

Compare two input numbers and return minimum one.

Parameters
[in]aFirst number to be compared
[in]bSecond number to be compared
Returns
Minimum value between a and b

If a < b, then return a. Otherwise, return b.

Definition at line 185 of file usbd.h.

◆ USBD_CLR_EP_STALL

#define USBD_CLR_EP_STALL (   ep)    (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) &= ~USBD_CFG_SSTALL_Msk)

Clear USB endpoint stall state.

Parameters
[in]epThe USB endpoint ID.
Returns
None

Clear USB endpoint stall state for the specified endpoint ID. Endpoint will respond ACK/NAK token.

Definition at line 365 of file usbd.h.

◆ USBD_CLR_INT_FLAG

#define USBD_CLR_INT_FLAG (   flag)    (USBD->INTSTS = flag)

Clear USBD interrupt.

Parameters
[in]flaginterrupt flag
Return values
None

Definition at line 262 of file usbd.h.

◆ USBD_CLR_SE0

#define USBD_CLR_SE0 ( )    ((uint32_t)(USBD->CTL &= ~USBD_DRVSE0))

Release SE0.

Parameters
None
Return values
None

Definition at line 227 of file usbd.h.

◆ USBD_CONFIG_EP

#define USBD_CONFIG_EP (   ep,
  config 
)    (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) = (config))

config endpoint

Parameters
[in]ependpoint
[in]configconfig value
Return values
None

Definition at line 327 of file usbd.h.

◆ USBD_DISABLE_PHY

#define USBD_DISABLE_PHY ( )    ((uint32_t)(USBD->CTL &= ~USBD_PHY_EN))

Disable USBD PHY.

Parameters
None
Return values
None

Definition at line 213 of file usbd.h.

◆ USBD_DISABLE_USB

#define USBD_DISABLE_USB ( )    ((uint32_t)(USBD->CTL &= ~USBD_USB_EN))

Disable USBD engine.

Parameters
None
Return values
None

Definition at line 199 of file usbd.h.

◆ USBD_ENABLE_INT

#define USBD_ENABLE_INT (   intr)    (USBD->INTEN |= (intr))

Enable USBD interrupt.

Parameters
[in]intrinterrupt mask
Return values
None

Definition at line 248 of file usbd.h.

◆ USBD_ENABLE_PHY

#define USBD_ENABLE_PHY ( )    ((uint32_t)(USBD->CTL |= USBD_PHY_EN))

Enable USBD PHY.

Parameters
None
Return values
None

Definition at line 206 of file usbd.h.

◆ USBD_ENABLE_USB

#define USBD_ENABLE_USB ( )    ((uint32_t)(USBD->CTL |= 0xF))

Enable USBD engine.

Parameters
None
Return values
None

Definition at line 192 of file usbd.h.

◆ USBD_GET_ADDR

#define USBD_GET_ADDR ( )    ((uint32_t)(USBD->FADDR))

Get USBD address.

Parameters
None
Return values
USBDaddress

Definition at line 241 of file usbd.h.

◆ USBD_GET_BUS_STATE

#define USBD_GET_BUS_STATE ( )    ((uint32_t)(USBD->BUSSTS & 0xf))

Get USBD bus state.

Parameters
None
Return values
busstatus

Definition at line 276 of file usbd.h.

◆ USBD_GET_EP_BUF_ADDR

#define USBD_GET_EP_BUF_ADDR (   ep)    ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4))))

Get buffer for USB endpoint.

Parameters
[in]ependpoint
Return values
bufferoffset

Definition at line 342 of file usbd.h.

◆ USBD_GET_EP_FLAG

#define USBD_GET_EP_FLAG ( )    ((uint32_t)(USBD->EPSTS))

Get USBD Endpoint status.

Parameters
None
Return values
endpointstatus

Definition at line 269 of file usbd.h.

◆ USBD_GET_EP_STALL

#define USBD_GET_EP_STALL (   ep)    (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) & USBD_CFG_SSTALL_Msk)

Get USB endpoint stall state.

Parameters
[in]epThe USB endpoint ID.
Return values
0USB endpoint is not stalled.
OthersUSB endpoint is stalled.

Get USB endpoint stall state of the specified endpoint ID.

Definition at line 378 of file usbd.h.

◆ USBD_GET_INT_FLAG

#define USBD_GET_INT_FLAG ( )    ((uint32_t)(USBD->INTSTS))

Get USBD interrupt flag.

Parameters
None
Return values
interruptstatus

Definition at line 255 of file usbd.h.

◆ USBD_GET_PAYLOAD_LEN

#define USBD_GET_PAYLOAD_LEN (   ep)    ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4))))

Get USB payload size (OUT data)

Parameters
[in]ependpoint
Return values
receiveddata length

Definition at line 319 of file usbd.h.

◆ USBD_IS_ATTACHED

#define USBD_IS_ATTACHED ( )    ((uint32_t)(USBD->BUSSTS & USBD_BUSSTS_FLDET_Msk))

check cable connect state

Parameters
None
Return values
connect/ disconnect

Definition at line 283 of file usbd.h.

◆ USBD_SET_ADDR

#define USBD_SET_ADDR (   addr)    (USBD->FADDR = (addr))

Set USBD address.

Parameters
[in]addrhost assign address number
Return values
None

Definition at line 234 of file usbd.h.

◆ USBD_SET_DATA0

#define USBD_SET_DATA0 (   ep)    (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) &= (~USBD_CFG_DSQ_SYNC_Msk))

Set USB data0 token.

Parameters
[in]ependpoint
Return values
None

Definition at line 304 of file usbd.h.

◆ USBD_SET_DATA1

#define USBD_SET_DATA1 (   ep)    (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) |= USBD_CFG_DSQ_SYNC_Msk)

Set USB data1 token.

Parameters
[in]ependpoint
Return values
None

Definition at line 297 of file usbd.h.

◆ USBD_SET_EP_BUF_ADDR

#define USBD_SET_EP_BUF_ADDR (   ep,
  offset 
)    (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4))) = (offset))

Set buffer for USB endpoint.

Parameters
[in]ependpoint
[in]offsetbuffer offset
Return values
None

Definition at line 335 of file usbd.h.

◆ USBD_SET_EP_STALL

#define USBD_SET_EP_STALL (   ep)    (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) |= USBD_CFG_SSTALL_Msk)

Set USB endpoint stall state.

Parameters
[in]epThe USB endpoint ID.
Returns
None

Set USB endpoint stall state for the specified endpoint ID. Endpoint will respond STALL token automatically.

Definition at line 354 of file usbd.h.

◆ USBD_SET_PAYLOAD_LEN

#define USBD_SET_PAYLOAD_LEN (   ep,
  size 
)    (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4))) = (size))

Set USB payload size (IN data)

Parameters
[in]ependpoint
[in]sizeIN transfer length
Return values
None

Definition at line 312 of file usbd.h.

◆ USBD_SET_SE0

#define USBD_SET_SE0 ( )    ((uint32_t)(USBD->CTL |= USBD_DRVSE0))

Force USB PHY Transceiver to Drive SE0.

Parameters
None
Return values
None

Definition at line 220 of file usbd.h.

◆ USBD_STOP_TRANSACTION

#define USBD_STOP_TRANSACTION (   ep)    (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) |= USBD_CFG_CLRRDY_Msk)

Stop USB endpoint transaction.

Parameters
[in]ependpoint
Return values
None

Definition at line 290 of file usbd.h.

Typedef Documentation

◆ CLASS_REQ

typedef void(* CLASS_REQ) (void)

USB Class request callback function

Definition at line 486 of file usbd.h.

◆ SET_CONFIG_CB

typedef void(* SET_CONFIG_CB) (void)

Functional pointer type declaration for USB set configuration request callback handler

Definition at line 489 of file usbd.h.

◆ SET_INTERFACE_REQ

typedef void(* SET_INTERFACE_REQ) (uint32_t u32AltInterface)

USB Standard request "Set Interface" callback function

Definition at line 488 of file usbd.h.

◆ VENDOR_REQ

typedef void(* VENDOR_REQ) (void)

USB Vendor request callback function

Definition at line 484 of file usbd.h.

Function Documentation

◆ USBD_ClearStall()

static __INLINE void USBD_ClearStall ( uint8_t  epnum)
static

Clear USB endpoint stall state.

Parameters
[in]epnumUSB endpoint number
Returns
None

Clear USB endpoint stall state, endpoint will return ACK/NAK token.

Definition at line 435 of file usbd.h.

◆ USBD_CtrlIn()

void USBD_CtrlIn ( void  )

Start Control IN transfer.

Parameters
None
Returns
None

This function is used to start Control IN

Definition at line 484 of file usbd.c.

Here is the call graph for this function:

◆ USBD_CtrlOut()

void USBD_CtrlOut ( void  )

Start Control OUT transfer.

Parameters
None
Returns
None

This function is used to start Control OUT

Definition at line 553 of file usbd.c.

Here is the call graph for this function:

◆ USBD_GetSetupPacket()

void USBD_GetSetupPacket ( uint8_t *  buf)

Get Setup Packet.

Parameters
[in]bufBuffer pointer to store setup packet
Returns
None

This function is used to get Setup packet.

Definition at line 96 of file usbd.c.

Here is the call graph for this function:

◆ USBD_GetStall()

static __INLINE uint32_t USBD_GetStall ( uint8_t  epnum)
static

Get USB endpoint stall state.

Parameters
[in]epnumUSB endpoint number
Return values
0USB endpoint is not stalled.
non-0USB endpoint is stalled.

Get USB endpoint stall state.

Definition at line 463 of file usbd.h.

Here is the caller graph for this function:

◆ USBD_LockEpStall()

void USBD_LockEpStall ( uint32_t  u32EpBitmap)

Definition at line 631 of file usbd.c.

◆ USBD_MemCopy()

static __INLINE void USBD_MemCopy ( uint8_t *  dest,
uint8_t *  src,
int32_t  size 
)
static

To support byte access between USB SRAM and system SRAM.

Parameters
[in]destDestination pointer.
[in]srcSource pointer.
[in]sizeByte count.
Returns
None

This function will copy the number of data specified by size and src parameters to the address specified by dest parameter.

Definition at line 394 of file usbd.h.

Here is the caller graph for this function:

◆ USBD_Open()

void USBD_Open ( S_USBD_INFO_T param,
CLASS_REQ  pfnClassReq,
SET_INTERFACE_REQ  pfnSetInterface 
)

USBD Initial, Enable clock and reset USB.

Parameters
[in]paramDescriptor
[in]pfnClassReqClass Request Callback Function
[in]pfnSetInterfaceSetInterface Request Callback Function
Return values
None.

Definition at line 54 of file usbd.c.

◆ USBD_PrepareCtrlIn()

void USBD_PrepareCtrlIn ( uint8_t *  pu8Buf,
uint32_t  u32Size 
)

Prepare Control IN transaction.

Parameters
[in]pu8BufControl IN data pointer
[in]u32SizeIN transfer size
Returns
None

This function is used to prepare Control IN transfer

Definition at line 453 of file usbd.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBD_PrepareCtrlOut()

void USBD_PrepareCtrlOut ( uint8_t *  pu8Buf,
uint32_t  u32Size 
)

Prepare Control OUT transaction.

Parameters
[in]pu8BufControl OUT data pointer
[in]u32SizeOUT transfer size
Returns
None

This function is used to prepare Control OUT transfer

Definition at line 536 of file usbd.c.

Here is the caller graph for this function:

◆ USBD_ProcessSetupPacket()

void USBD_ProcessSetupPacket ( void  )

Process Setup Packet.

Parameters
None
Returns
None

This function is used to process Setup packet.

Definition at line 110 of file usbd.c.

Here is the call graph for this function:

◆ USBD_SetConfigCallback()

void USBD_SetConfigCallback ( SET_CONFIG_CB  pfnSetConfigCallback)

The callback function which called when get SET CONFIGURATION request.

Parameters
[in]pfnSetConfigCallbackCallback function pointer for SET CONFIGURATION request
Returns
None

This function is used to set the callback function which will be called at SET CONFIGURATION request.

Definition at line 626 of file usbd.c.

◆ USBD_SetStall()

static __INLINE void USBD_SetStall ( uint8_t  epnum)
static

Set USB endpoint stall state.

Parameters
[in]epnumUSB endpoint number
Returns
None

Set USB endpoint stall state, endpoint will return STALL token.

Definition at line 408 of file usbd.h.

Here is the caller graph for this function:

◆ USBD_SetVendorRequest()

void USBD_SetVendorRequest ( VENDOR_REQ  pfnVendorReq)

USBD Set Vendor Request.

Parameters
[in]pfnVendorReqVendor Request Callback Function
Returns
None

This function is used to set USBD vendor request callback function

Definition at line 613 of file usbd.c.

◆ USBD_StandardRequest()

void USBD_StandardRequest ( void  )

Process USB standard request.

Parameters
None
Returns
None

This function is used to process USB Standard Request.

Definition at line 267 of file usbd.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ USBD_Start()

void USBD_Start ( void  )

USBD Start.

Parameters
None
Returns
None

This function is used to start transfer

Definition at line 79 of file usbd.c.

Here is the call graph for this function:

◆ USBD_SwReset()

void USBD_SwReset ( void  )

Clear all software flags.

Parameters
None
Returns
None

This function is used to clear all software control flag

Definition at line 583 of file usbd.c.

Variable Documentation

◆ g_usbd_RemoteWakeupEn

volatile uint8_t g_usbd_RemoteWakeupEn
extern

Remote wake up function enable flag

Definition at line 19 of file usbd.c.

◆ gu32ConfigHidDescIdx

uint32_t* s_usbd_info::gu32ConfigHidDescIdx

Pointer for HID Descriptor start index

Definition at line 33 of file usbd.h.

◆ gu32HidReportSize

uint32_t* s_usbd_info::gu32HidReportSize

Pointer for HID Report descriptor Size

Definition at line 32 of file usbd.h.

◆ gu8ConfigDesc

uint8_t* s_usbd_info::gu8ConfigDesc

Config descriptor

Definition at line 29 of file usbd.h.

◆ gu8DevDesc

uint8_t* s_usbd_info::gu8DevDesc

Device descriptor

Definition at line 28 of file usbd.h.

◆ gu8HidReportDesc

uint8_t** s_usbd_info::gu8HidReportDesc

Pointer for HID Report descriptor

Definition at line 31 of file usbd.h.

◆ gu8StringDesc

uint8_t** s_usbd_info::gu8StringDesc

Pointer for USB String Descriptor pointers

Definition at line 30 of file usbd.h.