Nano100AN Series BSP  V3.02.002
The Board Support Package for Nano100AN Series
Macros | Typedefs | Functions | Variables
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

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 168 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 181 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 361 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 258 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 223 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 323 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 209 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 195 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 244 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 202 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 188 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 237 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 272 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 338 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 265 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 374 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 251 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 315 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 279 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 230 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 300 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 293 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 331 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 350 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 308 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 216 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 286 of file usbd.h.

Typedef Documentation

◆ CLASS_REQ

typedef void(* CLASS_REQ) (void)

USB Class request callback function

Definition at line 482 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 484 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 483 of file usbd.h.

◆ VENDOR_REQ

typedef void(* VENDOR_REQ) (void)

USB Vendor request callback function

Definition at line 481 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 431 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 511 of file usbd.c.

◆ 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 580 of file usbd.c.

◆ 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.

◆ 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 459 of file usbd.h.

◆ USBD_LockEpStall()

void USBD_LockEpStall ( uint32_t  u32EpBitmap)

Definition at line 659 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 390 of file usbd.h.

◆ 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 480 of file usbd.c.

◆ 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 563 of file usbd.c.

◆ 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.

◆ 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 654 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 404 of file usbd.h.

◆ 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 641 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 284 of file usbd.c.

◆ 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.

◆ 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 611 of file usbd.c.

Variable Documentation

◆ g_usbd_RemoteWakeupEn

volatile uint8_t g_usbd_RemoteWakeupEn

Remote wake up function enable flag

Definition at line 19 of file usbd.c.