USB
USB 简介
USB(Universal Serial Bus)是一种通用的总线标准,用于连接主机和外设设备。USB 主机可以通过 USB 接口与 USB 设备连接,实现数据传输、电源供给等功能。
USB IF(USB Implementers Forum)是 USB 标准的制定者,它制定了 USB 标准,包括 USB 1.1、USB 2.0、USB 3.0 等,定义了 USB 接口的物理层、数据链路层、传输层、会话层、表示层等协议,以及 USB 设备类(Device Class)标准,常见的设备类包括 HID(Human Interface Device,人机接口设备)、MSC(Mass Storage Class,大容量存储设备)、CDC(Communication Device Class,通信设备)、Audio、Video 等。
博通BK7258芯片支持各种各样的 USB 应用,包括 USB 多媒体类应用,USB 通信类应用,USB 存储类应用,USB 人机交互类应用等。
USB 基本使用

USB open/close
USB 测试示例
注:BK7258 USB 默认运行在CPU2,使用默认avdk调试需要连接UART2协助输入命令测试,依赖CLI命令打开编译后调试。 测试目标:USB模块开关正常,枚举正常,解析正常,断开/连接等状态记录正常。
作为HOST 识别枚举Video+Audio融合设备为例,输入命令和LOG信息如下图所示:
1、在默认串口输入 bootcore 2 1 启动CPU2 ,log如下

CLI Boot CPU2
2、uart2 串口输入usb power 1c 1,log如下

CLI USB PowerON
3、uart2 串口输入usb open_host,枚举成功log如下

CLI USB Open Host
4、uart2 串口输入usb check_dev 0(是否支持video)/usb check_dev 1(是否支持mic)/usb check_dev 2(是否支持speaker),支持需要的类设备log如下

CLI USB Check video/mic/speaker
5、uart2 串口输入usb close,log如下

CLI USB Close
6、uart2 串口输入usb power 1c 0,log如下

CLI USB PowerDown
USB API Status
API |
BK7258_cp2 |
---|---|
Y |
|
Y |
|
Y |
|
Y |
|
Y |
|
Y |
|
Y |
|
Y |
|
Y |
|
Y |
|
Y |
USB Port Number
Capability |
BK7258_cp1 |
BK7258_cp2 |
---|---|---|
Port Number |
1 |
1 |
USB Pin and GPIO Map
USB Pin |
BK7258_cp1 |
BK7258_cp2 |
---|---|---|
USB DP |
12 |
12 |
USB DN |
13 |
13 |
USB power |
28 |
28 |
USB API Reference
Header File
Functions
-
bk_err_t bk_usb_driver_init(void)
USB Driver initialization.
Register the adaptation layer and pass the function pointers used by the closed source library. Register the current USB Class type to be supported, and it can be uninstalled and reinitialized during execution. But be sure to do so before calling other interfaces.
Configure Interrupt handling function registration
Configure Class Driver Registration
This API should be called before any other USB APIs.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_usb_driver_deinit(void)
USB Driver uninstallation.
Turn off the USB main interrupt switch Unregister Total Interrupt Handling Function Unregistered Class Driver
This API should be called after any other USB APIs.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_usb_power_ops(uint32_t gpio_id, bool ops)
Pin controlled USB Vbus.
This API controls VBUS for USB:
Determine whether to output voltage through the high and low levels of a GPIO output parameter: gpio_id Select the corresponding pin number ops Choose to power on or off
Configure whether USB is power on
When the fusion device is working, if there is a device voting for use, it cannot be directly turned off.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_usb_open(uint32_t usb_mode)
open the USB
This API configure the resoure common to USB:
Select the identity as host or slave parameter: usb_mode USB_HOST_MODE = 0 USB_DEVICE_MODE = 1
Configure USB common clock
Configure USB common registers
This API should be called before any other USB APIs.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_usb_close(void)
close the USB
This API release USB resources:
Restore register
Turn off the power and clock
This API should be called after any other USB APIs.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_usb_control_transfer_init(void)
Initializes the control transfer request resource.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_usb_control_transfer_deinit(void)
Unmount control transfer to release resource.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_usb_control_transfer(s_usb_device_request *pSetup, s_usb_transfer_buffer_info *buffer_info)
Control command and data interface fucntion to be passed.
This API is used to send commands and transfer data:
Two parameters pSetup/buffer_info.
s_usb_device_request: The command format is specified by the USB protocol
s_usb_transfer_buffer_info: Buffer informataion for sending and receiving data.
example: Reference UVC_OTA demo
- 返回
BK_OK: succeed
others: other errors.
-
void bk_usb_device_set_using_status(bool use_or_no, E_USB_DEVICE_T dev)
A voting function is currently in use.
This API requires two parameters to be filled in for voting to prevent it from being closed parameter: use_or_no TRUE USBING FALSE NOT used dev USB_UVC_DEVICE USB_UAC_MIC_DEVICE USB_UAC_SPEAKER_DEVICE USB_MSD_DEVICE USB_OTA_DEVICE USB_USER_CHECK_DEVICE
- 返回
BK_OK: succeed
others: other errors.
-
bool bk_usb_get_device_connect_status(void)
Obtain whether there is currently a device connection.
- 返回
TRUE: connect
FALSE: disconnect
-
bk_err_t bk_usb_check_device_supported(E_USB_DEVICE_T usb_dev)
Check if the corresponding device class is supported.
- 返回
BK_OK: succeed
others: other errors.
-
bk_err_t bk_usb_get_device_descriptor(struct usb_device_descriptor_t *dev_descriptor)
Obtain device descriptor.
dev_descriptor: uint8_t bLength; Descriptor size in bytes = 18 uint8_t bDescriptorType; DEVICE descriptor type = 1 uint16_t bcdUSB; USB spec in BCD, e.g. 0x0200 uint8_t bDeviceClass; Class code, if 0 see interface uint8_t bDeviceSubClass; Sub-Class code, 0 if class = 0 uint8_t bDeviceProtocol; Protocol, if 0 see interface uint8_t bMaxPacketSize0; Endpoint 0 max. size uint16_t idVendor; Vendor ID per USB-IF uint16_t idProduct; Product ID per manufacture uint16_t bcdDevice; Device release # in BCD uint8_t iManufacturer; Index to manufacturer string uint8_t iProduct; Index to product string uint8_t iSerialNumber; Index to serial number string uint8_t bNumConfigurations; Number of possible configurations
-
void bk_usb_mailbox_sw_master_init(void)
Initialize the USB master mailbox software.
-
void bk_usb_mailbox_sw_slave_init(void)
Initialize the USB slave mailbox software.
-
void bk_usb_mailbox_sw_master_deinit(void)
Uninstall the USB master mailbox software.
-
void bk_usb_mailbox_sw_slave_deinit(void)
Uninstall the USB slave mailbox software.
USB API Typedefs
Header File
Structures
-
struct usb_device_descriptor_t
-
struct usb_configuration_descriptor_t
-
struct usb_interface_association_descriptor_t
-
struct usb_interface_descriptor_t
-
struct usb_audio_endpoint_general_descriptor_t
-
struct s_bk_usb_endpoint_descriptor
-
struct bk_uvc_format_index
-
struct bk_uvc_frame
-
struct bk_uvc_all_frame
-
struct bk_uvc_device_brief_info_t
-
struct bk_uvc_config_t
-
struct audio_packet_t
-
struct audio_packet_control_t
-
struct bk_uac_ring_buffer_t
-
struct bk_uac_device_brief_info_t
-
struct bk_uac_mic_config_t
-
struct bk_uac_spk_config_t
-
struct bk_uac_config_t
-
struct bk_uvc_uac_app_callback
-
struct s_usb_device_request
-
struct s_usb_transfer_buffer_info
Macros
-
BK_ERR_USB_NOT_POWER
USB vbus poweron, etc
-
BK_ERR_USB_NOT_OPEN
USB dose not turn on clock and power, etc
-
BK_ERR_USB_NOT_CLOSE
USB dose not turn off clock and power, etc
-
BK_ERR_USB_NOT_CONNECT
USB device not connected
-
BK_ERR_USB_OPERATION_NULL_POINTER
USB Operated with null pointer
-
BK_ERR_USB_UVC_NOT_START
UVC Transfer not started
-
BK_ERR_USB_UVC_NOT_STOP
UVC Transfer not stopped
-
BK_ERR_USB_UVC_NOT_PAUSE
UVC Transfer not paused
-
BK_ERR_USB_UVC_GET_PARAMETER_FAILED
UVC The command to obtain parameters did not respond
-
BK_ERR_USB_UVC_SET_PARAMETER_FAILED
UVC Configuration parameter command did not respond
-
BK_ERR_USB_UVC_SET_INTERFACE_FAILED
UVC The set port command did not respond
-
BK_ERR_USB_UVC_NOSUPPORT_ATTRIBUTE
UVC The attribute configuration is not supported
-
BK_ERR_USB_UAC_NOT_START
UAC Transfer not started
-
BK_ERR_USB_UAC_NOT_STOP
UAC Transfer not stopped
-
BK_ERR_USB_UAC_NOT_PAUSE
UAC Transfer not paused
-
BK_ERR_USB_UAC_GET_PARAMETER_FAILED
UAC The command to obtain parameters did not respond
-
BK_ERR_USB_UAC_SET_PARAMETER_FAILED
UAC Configuration parameter command did not respond
-
BK_ERR_USB_UAC_SET_INTERFACE_FAILED
UAC The set port command did not respond
-
BK_ERR_USB_UAC_NOSUPPORT_ATTRIBUTE
UAC The attribute configuration is not supported
-
BK_USB_ENDPOINT_XFERTYPE_MASK
Type Definitions
-
typedef void (*control_irpcomplete)(void*, void*)
Enumerations
-
enum E_USB_CONNECTION_STATUS
Values:
-
enumerator USB_DEVICE_DISCONNECT
-
enumerator USB_DEVICE_CONNECT
-
enumerator USB_DEVICE_DISCONNECT
-
enum E_FRAME_RATE_ID
Values:
-
enumerator FPS_60
-
enumerator FPS_30
-
enumerator FPS_25
-
enumerator FPS_20
-
enumerator FPS_15
-
enumerator FPS_10
-
enumerator FPS_5
-
enumerator FPS_60
-
enum E_USB_DEVICE_T
Values:
-
enumerator USB_UVC_DEVICE
-
enumerator USB_UAC_MIC_DEVICE
-
enumerator USB_UAC_SPEAKER_DEVICE
-
enumerator USB_MSD_DEVICE
-
enumerator USB_OTA_DEVICE
-
enumerator USB_USER_CHECK_DEVICE
-
enumerator USB_CDC_DEVICE
-
enumerator USB_DEVICE_MAX
-
enumerator USB_UVC_DEVICE
-
enum E_USB_ENDPOINT_TRANSFER_MODE_T
Values:
-
enumerator USB_ENDPOINT_CONTROL_TRANSFER
-
enumerator USB_ENDPOINT_ISOCH_TRANSFER
-
enumerator USB_ENDPOINT_BULK_TRANSFER
-
enumerator USB_ENDPOINT_INT_TRANSFER
-
enumerator USB_ENDPOINT_INVALID_TRANSFER
-
enumerator USB_ENDPOINT_CONTROL_TRANSFER
-
enum bk_usb_drv_op_t
Values:
-
enumerator USB_DRV_IDLE
-
enumerator USB_DRV_EXIT
-
enumerator USB_POWER_OPS
-
enumerator USB_DRV_USB_INIT
-
enumerator USB_DRV_USB_DEINIT
-
enumerator USB_DRV_SET_DEV_USE
-
enumerator USB_DRV_USB_OPEN
-
enumerator USB_DRV_USB_CLOSE
-
enumerator USB_DRV_CONNECT_HANDLE
-
enumerator USB_DRV_DISCONNECT_HANDLE
-
enumerator USB_DRV_GET_DEV_CONNECT_STATUS
-
enumerator USB_DRV_CHECK_DEV_SUPPORT
-
enumerator USB_DRV_PRASE_DESCRIPTOR
-
enumerator USB_DRV_INIT_CONTROL_TRANS
-
enumerator USB_DRV_DEINIT_CONTROL_TRANS
-
enumerator USB_DRV_CONTROL_TRANSFER
-
enumerator USB_DRV_UVC_REGISTER_CONNECT_CB
-
enumerator USB_DRV_UVC_REGISTER_DISCONNECT_CB
-
enumerator USB_DRV_UVC_GET_PARAM
-
enumerator USB_DRV_UVC_SET_PARAM
-
enumerator USB_DRV_UVC_REGISTER_TRANSFER_OPS
-
enumerator USB_DRV_UVC_TRANSFER_BUFFER_MALLOC
-
enumerator USB_DRV_UVC_TRANSFER_BUFFER_PUSH
-
enumerator USB_DRV_UVC_TRANSFER_BUFFER_POP
-
enumerator USB_DRV_UVC_TRANSFER_BUFFER_FREE
-
enumerator USB_DRV_VIDEO_OPEN_PIPE
-
enumerator USB_DRV_VIDEO_CLOSE_PIPE
-
enumerator USB_DRV_VIDEO_START
-
enumerator USB_DRV_VIDEO_STOP
-
enumerator USB_DRV_VIDEO_RX
-
enumerator USB_DRV_VIDEO_RXED
-
enumerator USB_DRV_UAC_REGISTER_CONNECT_CB
-
enumerator USB_DRV_UAC_REGISTER_DISCONNECT_CB
-
enumerator USB_DRV_UAC_GET_PARAM
-
enumerator USB_DRV_UAC_SET_PARAM
-
enumerator USB_DRV_UAC_REGISTER_TRANSFER_OPS
-
enumerator USB_DRV_UAC_TRANSFER_BUFFER_MALLOC
-
enumerator USB_DRV_UAC_TRANSFER_BUFFER_PUSH
-
enumerator USB_DRV_UAC_TRANSFER_BUFFER_POP
-
enumerator USB_DRV_UAC_TRANSFER_BUFFER_FREE
-
enumerator USB_DRV_AUDIO_OPEN_PIPE
-
enumerator USB_DRV_AUDIO_CLOSE_PIPE
-
enumerator USB_DRV_AUDIO_MIC_START
-
enumerator USB_DRV_AUDIO_MIC_STOP
-
enumerator USB_DRV_AUDIO_SPK_START
-
enumerator USB_DRV_AUDIO_SPK_STOP
-
enumerator USB_DRV_AUDIO_RX
-
enumerator USB_DRV_AUDIO_RXED
-
enumerator USB_DRV_AUDIO_TX
-
enumerator USB_DRV_AUDIO_TXED
-
enumerator USB_DRV_UVC_TRANSFER_DUAL_BUFFER_MALLOC
-
enumerator USB_DRV_UVC_TRANSFER_DUAL_BUFFER_PUSH
-
enumerator USB_DRV_UVC_TRANSFER_DUAL_BUFFER_POP
-
enumerator USB_DRV_UVC_TRANSFER_DUAL_BUFFER_FREE
-
enumerator USB_DRV_VIDEO_DUAL_START
-
enumerator USB_DRV_VIDEO_DUAL_STOP
-
enumerator USB_DRV_VIDEO_DUAL_RX
-
enumerator USB_DRV_VIDEO_DUAL_RXED
-
enumerator USB_DRV_IDLE
-
enum E_USB_ATTRIBUTE_OP
Values:
-
enumerator USB_ATTRIBUTE_RC_UNDEFINED
-
enumerator USB_ATTRIBUTE_SET_CUR
-
enumerator USB_ATTRIBUTE_GET_CUR
-
enumerator USB_ATTRIBUTE_GET_MIN
-
enumerator USB_ATTRIBUTE_GET_MAX
-
enumerator USB_ATTRIBUTE_GET_RES
-
enumerator USB_ATTRIBUTE_GET_LEN
-
enumerator USB_ATTRIBUTE_GET_INFO
-
enumerator USB_ATTRIBUTE_GET_DEF
-
enumerator USB_ATTRIBUTE_RC_UNDEFINED
-
enum E_UVC_ATTRIBUTE_T
Values:
-
enumerator UVC_ATTRIBUTE_CONTROL_UNDEFINED
-
enumerator UVC_ATTRIBUTE_BACKLIGHT_COMPENSATION
-
enumerator UVC_ATTRIBUTE_BRIGHTNESS
-
enumerator UVC_ATTRIBUTE_CONTRAST
-
enumerator UVC_ATTRIBUTE_GAIN
-
enumerator UVC_ATTRIBUTE_POWER_LINE_FREQUENCY
-
enumerator UVC_ATTRIBUTE_HUE
-
enumerator UVC_ATTRIBUTE_SATURATION
-
enumerator UVC_ATTRIBUTE_SHARPNESS
-
enumerator UVC_ATTRIBUTE_GAMMA
-
enumerator UVC_ATTRIBUTE_WHITE_BALANCE_TEMPERATURE
-
enumerator UVC_ATTRIBUTE_WHITE_BALANCE_TEMPERATURE_AUTO
-
enumerator UVC_ATTRIBUTE_WHITE_BALANCE_COMPONENT
-
enumerator UVC_ATTRIBUTE_WHITE_BALANCE_COMPONENT_AUTO
-
enumerator UVC_ATTRIBUTE_DIGITAL_MULTIPLIER
-
enumerator UVC_ATTRIBUTE_DIGITAL_MULTIPLIER_LIMIT
-
enumerator UVC_ATTRIBUTE_HUE_AUTO
-
enumerator UVC_ATTRIBUTE_ANALOG_VIDEO_STANDARD
-
enumerator UVC_ATTRIBUTE_ANALOG_LOCK_STATUS
-
enumerator UVC_ATTRIBUTE_NUM
-
enumerator UVC_ATTRIBUTE_CONTROL_UNDEFINED
-
enum E_UAC_ATTRIBUTE_T
Values:
-
enumerator UAC_ATTRIBUTE_UNDEF
-
enumerator UAC_ATTRIBUTE_MUTE
-
enumerator UAC_ATTRIBUTE_VOLUME
-
enumerator UAC_ATTRIBUTE_BASS
-
enumerator UAC_ATTRIBUTE_MID
-
enumerator UAC_ATTRIBUTE_TREBLE
-
enumerator UAC_ATTRIBUTE_GRAPHIC_EQUALIZER
-
enumerator UAC_ATTRIBUTE_AUTOMATIC_GAIN
-
enumerator UAC_ATTRIBUTE_DEALY
-
enumerator UAC_ATTRIBUTE_BASS_BOOST
-
enumerator UAC_ATTRIBUTE_LOUDNESS
-
enumerator UAC_ATTRIBUTE_INP_GAIN
-
enumerator UAC_ATTRIBUTE_INP_GAIN_PAD
-
enumerator UAC_ATTRIBUTE_PHASE_INVERT
-
enumerator UAC_ATTRIBUTE_UNDERFLOW
-
enumerator UAC_ATTRIBUTE_OVERFLOW
-
enumerator UAC_ATTRIBUTE_LATENCY
-
enumerator UAC_ATTRIBUTE_NUM
-
enumerator UAC_ATTRIBUTE_UNDEF