Built-in Statistics

This page details the way to interpret the various statistics that can be accessed within µC/USB-Device.

Configuration

In usbd_cfg.h, USBD_CFG_DBG_STATS_EN must be set to DEF_ENABLED.

By default, constant USBD_CFG_DBG_STATS_CNT_TYPE is set to CPU_INT08U, meaning that the counter will overflow after counting 256 events. This constant can be set to CPU_INT16U or CPU_INT32U to increase the overflow limit.

It is recommended that the statistics feature is turned OFF for 'release' code, since a good amount of RAM is used to keep the statistics counters.

Accessing statistics

The statistics can be accessed easily from any scope (application, class, core, driver, etc), simply by monitoring the variables USBD_DbgStatsDevTbl[] and USBD_DbgStatsEP_Tbl[]. This can usually be done by using a regular debugger.

Content

The statistics are split in two levels: device level and endpoint level. The following tables gives information about the fields of each of these structures. Please note that even though each endpoint has a complete statistics structure associated with it, since an endpoint only works in on direction, only the Rx or Tx fields will be used for a given endpoint. That is, if the endpoint is an IN endpoint, only the Tx fields will be modified. If the endpoint is an OUT endpoint, the Rx fields will be the only ones modified.

Device Level

The table USBD_DbgStatsDevTbl[] contains USBD_CFG_MAX_NBR_DEV number of USBD_DBG_STATS_DEV struct, one for each device. The device number is used as an index to access a specific device's statistics.

Field NameExplanationRelates to...
DevNbrNumber of the device, starting at 0.The device number depends of the order in which the device is added using USBD_DevAdd.
DevResetEventNbrNumber of reset event on the bus.Should be 2 after minimal enumeration.
DevSuspendEventNbrNumber of suspend event on the bus.Should be 2 after minimal enumeration.
DevResumeEventNbrNumber of resume event on the bus.Should be 1 after minimal enumeration.
DevConnEventNbrNumber of connection event of the device.Varies.
DevDisconnEventNbrNumber of disconnection event of the device.Varies.
DevSetupEventNbrNumber of SETUP packets the device received.Should be 10-11 after minimal enumeration, depending if Windows requests its OS descriptor or not.
StdReqDevNbrNumber of standard requests having 'device' as a recipient.Should be 10-11 after minimal enumeration, depending if Windows requests its OS descriptor or not and if it fails or not.
StdReqDevStallNbrNumber of standard requests having 'device' as a recipient that failed to be processed.Should normally be equal to 0. It can be 1, if Windows requests its OS descriptor and it fails (or USBD_CFG_MS_OS_DESC_EN is set to DEF_DISABLED).
StdReqIF_NbrNumber of standard requests having 'interface' as a recipient.Should be 0 after minimal enumeration.
StdReqIF_StallNbrNumber of standard requests having 'interface' as a recipient that failed to be processed.Should normally be equal to 0.
StdReqEP_NbrNumber of standard requests having 'endpoint' as a recipient.Should be 0 after minimal enumeration.
StdReqEP_StallNbrNumber of standard requests having 'endpoint' as a recipient that failed to be processed.Should normally be equal to 0.
StdReqClassNbrNumber of standard requests having a class as a recipient.Should be 0 after minimal enumeration.
StdReqClassStallNbrNumber of standard requests having a class as a recipient that failed to be processed.Should normally be equal to 0.
StdReqSetAddrNbrNumber of SET_ADDRESS standard request the device received.Should be equal to 1 after a successful enumeration.
StdReqSetCfgNbrNumber of SET_CONFIGURATION standard request the device received.Should be equal to 1 after a successful enumeration.
CtrlRxSyncExecNbrNumber of synchronous receive operation started on a control endpoint type.Varies with usage. Used throughout enumeration. Should be 0 after minimal enumeration.
CtrlRxSyncSuccessNbrNumber of synchronous receive operation on a control endpoint type that completed successfully.Should be equal to CtrlRxSyncExecNbr.
CtrlTxSyncExecNbrNumber of synchronous transmit operation started on a control endpoint type.Varies with usage. Used throughout enumeration. Should be 9 after minimal enumeration.
CtrlTxSyncSuccessNbrNumber of synchronous transmit operation on a control endpoint type that completed successfully.Should be equal to CtrlTxSyncExecNbr.
CtrlRxStatusExecNbr Number of status packets attempted to be received from the host.Varies with usage. Used throughout enumeration. Should be 9 after minimal enumeration.
CtrlRxStatusSuccessNbrNumber of status packets successfully received from the hostShould be equal to CtrlRxStatusExecNbr.
CtrlTxStatusExecNbrNumber of status packets attempted to be sent to the host.Varies with usage. Used throughout enumeration. Should be 1 after minimal enumeration.
CtrlTxStatusSuccessNbrNumber of status packets successfully sent to the hostShould be equal to CtrlTxStatusExecNbr.
BulkRxSyncExecNbrNumber of synchronous receive operation started on a bulk endpoint type.Varies with usage. Used by CDC, MSC, PHDC and vendor class synchronous demo.
BulkRxSyncSuccessNbrNumber of synchronous receive operation on a bulk endpoint type that completed successfully.Should be equal to BulkRxSyncExecNbr.
BulkTxSyncExecNbrNumber of synchronous transmit operation started on a bulk endpoint type.Varies with usage. Used by CDC, MSC, PHDC and vendor class synchronous demo.
BulkTxSyncSuccessNbrNumber of synchronous transmit operation on a bulk endpoint type that completed successfully.Should be equal to BulkTxSyncExecNbr.
IntrRxSyncExecNbrNumber of synchronous receive operation started on an interrupt endpoint type.Varies with usage. Used by HID class read/write demo and vendor class synchronous demo.
IntrRxSyncSuccessNbrNumber of synchronous receive operation on an interrupt endpoint type that completed successfully.Should be equal to IntrRxSyncExecNbr.
IntrTxSyncExecNbrNumber of synchronous transmit operation started on an interrupt endpoint type.Varies with usage. Used by PHDC and vendor class synchronous demo.
IntrTxSyncSuccessNbrNumber of synchronous transmit operation on an interrupt endpoint type that completed successfully.Should be equal to IntrTxSyncExecNbr.
BulkRxAsyncExecNbrNumber of asynchronous receive operation started on a bulk endpoint type.Varies with usage, used by vendor class asynchronous demo.
BulkRxAsyncSuccessNbrNumber of asynchronous receive operation on a bulk endpoint type that completed successfully.Should be equal to BulkRxAsyncExecNbr.
BulkTxAsyncExecNbrNumber of asynchronous transmit operation started on a bulk endpoint type.Varies with usage, used by vendor class asynchronous demo.
BulkTxAsyncSuccessNbrNumber of asynchronous transmit operation on a bulk endpoint type that completed successfully.Should be equal to BulkTxAsyncExecNbr.
IntrRxAsyncExecNbrNumber of asynchronous receive operation started on an interrupt endpoint type.Varies with usage, used by vendor class asynchronous demo.
IntrRxAsyncSuccessNbrNumber of asynchronous receive operation on an interrupt endpoint type that completed successfully.Should be equal to IntrRxAsyncExecNbr.
IntrTxAsyncExecNbrNumber of asynchronous transmit operation started on an interrupt endpoint type.Varies with usage, used by CDC, HID class mouse and read/write demo and in vendor class asynchronous demo.
IntrTxAsyncSuccessNbrNumber of asynchronous transmit operation on an interrupt endpoint type that completed successfully.Should be equal to IntrTxAsyncExecNbr.
IsocRxAsyncExecNbrNumber of asynchronous receive operation started on an isochronous endpoint type.Varies with usage, used by audio class when playback is enabled.
IsocRxAsyncSuccessNbrNumber of asynchronous receive operation on an isochronous endpoint type that completed successfully.Should be equal to IsocRxAsyncExecNbr.
IsocTxAsyncExecNbrNumber of asynchronous transmit operation started on an isochronous endpoint type.Varies with usage, used by audio class when record is enabled.
IsocTxAsyncSuccessNbrNumber of asynchronous transmit operation on an isochronous endpoint type that completed successfully.Should be equal to IsocTxAsyncExecNbr.

A minimal enumeration is considered to be a successful enumeration without any classes enabled.

Endpoint Level

The table USBD_DbgStatsEP_Tbl[] contains USBD_CFG_MAX_NBR_DEVUSBD_CFG_MAX_NBR_EP_OPEN number of USBD_DBG_STATS_EP struct, one for each potentially opened endpoint of each device. The device number and the endpoint's index are used as indexes to access a specific endpoint's statistics. It is also possible to simply browse the content of the USBD_DBG_STATS_EP struct to find the required endpoint address.

Field NameExplanationRelates to...
AddrAddress of the endpoint. The statistics of a given endpoint are kept if it is closed and then re-opened, if it uses the same endpoint structure. Otherwise, the statistics are reset when the endpoint is opened. 
EP_OpenNbrNumber of times the endpoint was opened successfully.Should be equal to 2 after minimal enumeration (the endpoint is closed and re-opened upon device reset).
EP_AbortExecNbrNumber of times an abort operation has been started.Should be equal to 0.
EP_AbortSuccessNbrNumber of times an abort operation has completed successfully.Should be equal to EP_AbortExecNbr.
EP_CloseExecNbrNumber of times a close operation has been started.Should be equal to 1 after minimal enumeration (the endpoint is closed upon device reset).
EP_CloseSuccessNbrNumber of times a close operation has completed successfully.Should be equal to EP_CloseExecNbr.
RxSyncExecNbrNumber of times a synchronous receive operation has been started.Should be equal to 0 after minimal enumeration.
RxSyncSuccessNbrNumber of times a synchronous receive operation has completed successfully.Should be equal to RxSyncExecNbr.
RxSyncTimeoutErrNbrNumber of times a synchronous receive operation has timed out.Varies with the type of application and transfer used, whether transfers are blocking or non-blocking, the protocol used by the application, etc.
RxAsyncExecNbrNumber of times an asynchronous receive operation has been started.Should be equal to 0 after minimal enumeration.
RxAsyncSuccessNbrNumber of times an asynchronous receive operation has completed successfully.Should be equal to RxAsyncExecNbr. At this point, the receive operation has been successfully signaled to the USB-Device core. It does not mean that the whole transfer has completed.
RxZLP_ExecNbrNumber of times a zero-length packet receive operation has been started.Should be equal to 9 after minimal enumeration.
RxZLP_SuccessNbrNumber of times a zero-length packet receive operation has completed successfully.Should be equal to RxZLP_ExecNbr.
TxSyncExecNbrNumber of times a synchronous transmit operation has been started.Should be equal to 9 after minimal enumeration.
TxSyncSuccessNbrNumber of times a synchronous transmit operation has completed successfully.Should be equal to TxSyncExecNbr.
TxSyncTimeoutErrNbrNumber of times a synchronous transmit operation has timed out.Varies with the type of application and transfer used, whether transfers are blocking or non-blocking, the protocol used by the application, etc.
TxAsyncExecNbrNumber of times an asynchronous transmit operation has been started.Should be equal to 0 after minimal enumeration.
TxAsyncSuccessNbrNumber of times an asynchronous transmit operation has completed successfully.Should be equal to TxAsyncExecNbr. At this point, the transmit operation has been successfully signaled to the USB-Device core. It does not mean that the whole transfer has completed.
TxZLP_ExecNbrNumber of times a zero-length packet transmit operation has been started.Should be equal to 1 after minimal enumeration.
TxZLP_SuccessNbrNumber of times a zero-length packet transmit operation has completed successfully.Should be equal to TxZLP_ExecNbr.
DrvRxStartNbrNumber of times the driver's EP_RxStart() function was called.Should be equal to 9 after minimal enumeration.
DrvRxStartSuccessNbrNumber of times the driver's EP_RxStart() function was called successfully.Should be equal to DrvRxStartNbr.
DrvRxNbrNumber of times the driver's EP_Rx() function was called.Should be equal to 0 after minimal enumeration.
DrvRxSuccessNbrNumber of times the driver's EP_Rx() function was called successfully.Should be equal to DrvRxNbr.
DrvRxZLP_NbrNumber of times the driver's EP_RxZLP() function was called.Should be equal to 9 after minimal enumeration.
DrvRxZLP_SuccessNbrNumber of times the driver's EP_RxZLP() function was called successfully.Should be equal to DrvRxZLP_Nbr.
RxCmplNbrNumber of times the driver has called USBD_EP_RxCmpl().Should be equal to 9 after minimal enumeration.
RxCmplErrNbrNumber of times the driver's call to USBD_EP_RxCmpl failed.Should be equal to 0.
DrvTxNbrNumber of times the driver's EP_Tx() function was called.Should be equal to 9 after minimal enumeration.
DrvTxSuccessNbrNumber of times the driver's EP_Tx() function was called successfully.Should be equal to DrvTxNbr.
DrvTxStartNbrNumber of times the driver's EP_TxStart() function was called.Should be equal to 9 after minimal enumeration.
DrvTxStartSuccessNbrNumber of times the driver's EP_TxStart() function was called successfully.Should be equal to DrvTxStartNbr.
DrvTxZLP_NbrNumber of times the driver's EP_TxZLP() function was called.Should be equal to 1 after minimal enumeration.
DrvTxZLP_SuccessNbrNumber of times the driver's EP_TxZLP() function was called successfully.Should be equal to DrvTxZLP_Nbr.
TxCmplNbrNumber of times the driver has called USBD_EP_TxCmpl().Should be equal to 10 after minimal enumeration.
TxCmplErrNbrNumber of times the driver's call to USBD_EP_TxCmpl() failed.Should be equal to 0.