文章目录
- 前言
- 中断分析 USBHS_IRQHandler
- 传输完成:USBHS_UIF_TRANSFER
- TOKEN_IN:发送完成
- TOKEN_OUT:接收完成
- 描述符:USBHS_UIF_SETUP_ACT
- 总线复位:USBHS_UIF_BUS_RST
- 总线挂起:USBHS_UIF_SUSPEND
前言
所有数据都通过中断 USBHS_IRQHandler 处理
中断分析 USBHS_IRQHandler
intflag:获取中断标志寄存器内容
- USBHS_UIF_TRANSFER:传输完成
- USBHS_UIF_SETUP_ACT:SETUP 事务完成
- USBHS_UIF_BUS_RST:总线复位
- USBHS_UIF_SUSPEND:总线挂起或唤醒事件
传输完成:USBHS_UIF_TRANSFER
TOKEN_IN:发送完成
DEF_UEP3:端点3
UEP3_TX_CTRL :端点3
/* end-point 3 data in interrupt */
case USBHS_UIS_TOKEN_IN | DEF_UEP3:
USBHSD->UEP3_TX_CTRL = (USBHSD->UEP3_TX_CTRL & ~USBHS_UEP_T_RES_MASK) | USBHS_UEP_T_RES_NAK;
USBHSD->UEP3_TX_CTRL ^= USBHS_UEP_T_TOG_DATA1;
USBHS_Endp_Busy[ DEF_UEP3 ] &= ~DEF_UEP_BUSY;
break;
TOKEN_OUT:接收完成
/* end-point 4 data out interrupt */
case USBHS_UIS_TOKEN_OUT | DEF_UEP4:
USBHSD->UEP4_RX_CTRL ^= USBHS_UEP_R_TOG_DATA1;
/* Reverse the data and re-upload */
len = USBHSD->RX_LEN;
for( i = 0; i < len; i++ )
{
USBHS_EP4_Tx_Buf[ i ] = ~USBHS_EP4_Rx_Buf[ i ];
}
USBHSD->UEP4_TX_LEN = len;
USBHSD->UEP4_TX_CTRL &= ~USBHS_UEP_R_RES_MASK;
USBHSD->UEP4_TX_CTRL |= USBHS_UEP_R_RES_ACK;
break;
描述符:USBHS_UIF_SETUP_ACT
描述符在中断中作用的位置:标准请求
https://www.usbzh.com/article/detail-417.html
获取描述符:https://www.usbzh.com/article/detail-15.html
- USBHS_UIF_SETUP_ACT
- USBHS_SetupReqCode
- USB_GET_DESCRIPTOR
- USB_DESCR_TYP_DEVICE:MyDevDescr
- USB_DESCR_TYP_CONFIG:MyCfgDescr_HS
- USB_DESCR_TYP_HID:&MyCfgDescr_HS[ 84 ]
- USB_DESCR_TYP_REPORT:MyHIDReportDesc_HS
- USB_DESCR_TYP_STRING:MyLangDescr、MyManuInfo、MyProdInfo、MySerNumInfo
- USB_GET_DESCRIPTOR
- USBHS_SetupReqCode
总线复位:USBHS_UIF_BUS_RST
此处初始化端点
除了 USB 初始化外,唯二初始化端点的地方
总线挂起:USBHS_UIF_SUSPEND
有 10us 延时
同样的延时在 USB 初始化中也有