哪位兄弟做过stm32f10xx的双缓冲usb 同步传输帮忙看一下,我上位机读取的数据每两次中有一次的数据是错误的,不知道是不是程序的原因还是硬件的原因?
hw_config.c
void USB_Interrupts_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable and configure the priority of the USB_LP IRQ Channel*/
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable and configure the priority of the USB_HP IRQ Channel*/
NVIC_InitStructure.NVIC_IRQChannel = USB_HP_CAN1_TX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
stm32f10x_it.c
void USB_HP_CAN1_TX_IRQHandler(void)
{
CTR_HP();
}
void EP2_INT_IN_CallbackProc(void)
{
unsigned char readtest[256] = {0};
if(GetENDPOINT(ENDP2 & EP_DTOG_RX)
{
FreeUserBuffer(ENDP2, EP_DBUF_IN);
UserToPMABufferCopy(readtest, ENDP2_BUF0Addr, 256);
SetEPDblBuf0Count(ENDP2, EP_DBUF_IN, 256);
}
else
{
FreeUserBuffer(ENDP2, EP_DBUF_IN);
UserToPMABufferCopy(readtest, ENDP2_BUF1Addr, 256);
SetEPDblBuf1Count(ENDP2, EP_DBUF_IN, 256);
}
}
usb_conf.h
#define ENDP2_BUF0Addr (0xC0)
#define ENDP2_BUF1Addr (0x1D0)
usb_proc.c
void XXXX_Reset(void)
{//省略其他部分
SetEPType(ENDP2, EP_ISOCHRONOUS);
SetEPDblBuffAddr(ENDP2, ENDP2_BUF0Addr, ENDP2_BUF1Addr);
SetEPDblBuffCount(ENDP2, EP_DBUF_IN, 256);
ClearDTOG_RX(ENDP2);
ClearDTOG_TX(ENDP2);
ToggleDTOG_RX(ENDP2);
SetEPRxStatus(ENDP2, EP_RX_DIS);
SetEPTxStatus(ENDP2, EP_TX_VALID);
}
main.c
int main(void)
{//省略其他部分
while (1)
{
if (bDeviceState == CONFIGURED)
{
if(FALSE == bOnce)//为了进入IN中断回调函数,只调用一次
{
if(GetENDPOINT(ENDP2 & EP_DTOG_RX)
{
FreeUserBuffer((ENDP2, EP_DBUF_IN);
UserToPMABufferCopy(readtest, ENDP2_BUF0Addr, 256);
SetEPDblBuf0Count((ENDP2, EP_DBUF_IN, 256);
}
else
{
FreeUserBuffer((ENDP2, EP_DBUF_IN);
UserToPMABufferCopy(readtest, ENDP2_BUF1Addr, 256);
SetEPDblBuf1Count((ENDP2, EP_DBUF_IN, 256);
}
bOnce = TRUE;
}
}
}
}
usb_desc.c
/* endpoint */
sizeof(usb_ep_desc_t), /*bLength: Endpoint Descriptor size*/
USB_DT_ENDPOINT, /*bDescriptorType:*/
0x82,//*bEndpointAddress: Endpoint Address (IN)*/
USB_EP_TYPE_ISOCHRONOUS,
0x00, /*wMaxPacketSize:256 Byte max wwz0327*/
0x01,
0x01,
|