实现STM32 USB双缓冲批量传输
时间:10-02
整理:3721RD
点击:
我现在想实现STM32 USB的双缓冲批量传输,枚举成功的,之前用端口2能正常实现单缓冲的收发数据,但是用端点2实现单方向的接收数据功能,却怎么也不能接收数据!
初始化代码
*USB_EP2R=(((*USB_EP2R)&EPREG_MASK)&(~EP_EA))|EP_ADDR_2;//端点2
UsbSetEPNewType(USB_EP2R,EP_BULK);
UsbSetEP_Kind(USB_EP2R); //批量双缓冲
UsbSetEPTxBufferTableAddr(EP2,EP2TxBufferTableAddr); //这个是当接收缓冲区0
UsbSetEPRxBufferTableAddr(EP2,EP2RxBufferTableAddr); //这个是当接收缓冲区1
//UsbSetEPRxCount(EP2,16);
_SetEPDblBuffCount(EP2,16); //设置接收0和1 数据长度 都是16
UsbSetEPDTOG_TX(USB_EP2R,EP_DTOG_TX_CLR);
UsbSetEPDTOG_RX(USB_EP2R,EP_DTOG_RX_CLR);
UsbSetEPDTOG_TX(USB_EP2R,EP_DTOG_TX_SET);
UsbSetEPTxStatus(USB_EP2R,EP_TX_DIS);
UsbSetEPRxStatus(USB_EP2R,EP_RX_VALID);
这样配置好,USB模块接收不了数据,高级USB中断进不去也,哪位大神帮忙下,万分感激。
说明下
_SetEPDblBuffCount(EP2,16);这个宏函数是从usb_reg.h文件里面拿过来直接用的
实现代码如下:
#define _BlocksOf32(dwReg,wCount,wNBlocks) {\
wNBlocks = wCount >> 5;\
if((wCount & 0x1f) == 0)\
wNBlocks--;\
*pdwReg = (u32)((wNBlocks << 10) | 0x8000);\
}/* _BlocksOf32 */
#define _BlocksOf2(dwReg,wCount,wNBlocks) {\
wNBlocks = wCount >> 1;\
if((wCount & 0x1) != 0)\
wNBlocks++;\
*pdwReg = (u32)(wNBlocks << 10);\
}/* _BlocksOf2 */
#define _pEPTxCount(bEpNum) ((u32 *)(((*BTABLE) +bEpNum*8+2)*2 + PMAAddr))
#define _pEPRxCount(bEpNum) ((u32 *)(((*BTABLE) +bEpNum*8+6)*2 + PMAAddr))
//---//
#define _SetEPCountRxReg(dwReg,wCount) {\
u16 wNBlocks;\
if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\
else {_BlocksOf2(dwReg,wCount,wNBlocks);}\
}/* _SetEPCountRxReg */
#define _SetEPRxDblBuf0Count(bEpNum,wCount) {\
u32 *pdwReg = _pEPTxCount(bEpNum); \
_SetEPCountRxReg(pdwReg, wCount);\
}
//---//
#define _SetEPCountRxReg(dwReg,wCount) {\
u16 wNBlocks;\
if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\
else {_BlocksOf2(dwReg,wCount,wNBlocks);}\
}/* _SetEPCountRxReg */
#define _SetEPRxCount(bEpNum,wCount) {\
u32 *pdwReg = _pEPRxCount(bEpNum); \
_SetEPCountRxReg(pdwReg, wCount);\
}
//------//
#define _SetEPDblBuf0Count(bEpNum, wCount) { \
{_SetEPRxDblBuf0Count(bEpNum,wCount);} \
}
#define _SetEPDblBuf1Count(bEpNum, wCount) { \
{_SetEPRxCount(bEpNum,wCount);}\
}
#define _SetEPDblBuffCount(bEpNum, wCount) {\
_SetEPDblBuf0Count(bEpNum, wCount); \
_SetEPDblBuf1Count(bEpNum, wCount); \
}
初始化代码
*USB_EP2R=(((*USB_EP2R)&EPREG_MASK)&(~EP_EA))|EP_ADDR_2;//端点2
UsbSetEPNewType(USB_EP2R,EP_BULK);
UsbSetEP_Kind(USB_EP2R); //批量双缓冲
UsbSetEPTxBufferTableAddr(EP2,EP2TxBufferTableAddr); //这个是当接收缓冲区0
UsbSetEPRxBufferTableAddr(EP2,EP2RxBufferTableAddr); //这个是当接收缓冲区1
//UsbSetEPRxCount(EP2,16);
_SetEPDblBuffCount(EP2,16); //设置接收0和1 数据长度 都是16
UsbSetEPDTOG_TX(USB_EP2R,EP_DTOG_TX_CLR);
UsbSetEPDTOG_RX(USB_EP2R,EP_DTOG_RX_CLR);
UsbSetEPDTOG_TX(USB_EP2R,EP_DTOG_TX_SET);
UsbSetEPTxStatus(USB_EP2R,EP_TX_DIS);
UsbSetEPRxStatus(USB_EP2R,EP_RX_VALID);
这样配置好,USB模块接收不了数据,高级USB中断进不去也,哪位大神帮忙下,万分感激。
说明下
_SetEPDblBuffCount(EP2,16);这个宏函数是从usb_reg.h文件里面拿过来直接用的
实现代码如下:
#define _BlocksOf32(dwReg,wCount,wNBlocks) {\
wNBlocks = wCount >> 5;\
if((wCount & 0x1f) == 0)\
wNBlocks--;\
*pdwReg = (u32)((wNBlocks << 10) | 0x8000);\
}/* _BlocksOf32 */
#define _BlocksOf2(dwReg,wCount,wNBlocks) {\
wNBlocks = wCount >> 1;\
if((wCount & 0x1) != 0)\
wNBlocks++;\
*pdwReg = (u32)(wNBlocks << 10);\
}/* _BlocksOf2 */
#define _pEPTxCount(bEpNum) ((u32 *)(((*BTABLE) +bEpNum*8+2)*2 + PMAAddr))
#define _pEPRxCount(bEpNum) ((u32 *)(((*BTABLE) +bEpNum*8+6)*2 + PMAAddr))
//---//
#define _SetEPCountRxReg(dwReg,wCount) {\
u16 wNBlocks;\
if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\
else {_BlocksOf2(dwReg,wCount,wNBlocks);}\
}/* _SetEPCountRxReg */
#define _SetEPRxDblBuf0Count(bEpNum,wCount) {\
u32 *pdwReg = _pEPTxCount(bEpNum); \
_SetEPCountRxReg(pdwReg, wCount);\
}
//---//
#define _SetEPCountRxReg(dwReg,wCount) {\
u16 wNBlocks;\
if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\
else {_BlocksOf2(dwReg,wCount,wNBlocks);}\
}/* _SetEPCountRxReg */
#define _SetEPRxCount(bEpNum,wCount) {\
u32 *pdwReg = _pEPRxCount(bEpNum); \
_SetEPCountRxReg(pdwReg, wCount);\
}
//------//
#define _SetEPDblBuf0Count(bEpNum, wCount) { \
{_SetEPRxDblBuf0Count(bEpNum,wCount);} \
}
#define _SetEPDblBuf1Count(bEpNum, wCount) { \
{_SetEPRxCount(bEpNum,wCount);}\
}
#define _SetEPDblBuffCount(bEpNum, wCount) {\
_SetEPDblBuf0Count(bEpNum, wCount); \
_SetEPDblBuf1Count(bEpNum, wCount); \
}
都没人回答的,算了...已解决,上面的配置对的,是其他问题。
小编的源码可以上传一份参考一下吗