mioc_hust 发表于 2021-2-17 10:38:23

rl_usb发送数据截断现象

看看有这么一个现象哈。我PC下发USB数据命令A0 然后单板接收到以后,会回复数据,一个测试数据,16Bytes,其中前8个是一样的,顺序递增的。后8个0
然后在长时间数据交互时,会出现单板返回的数据被截断的现象(图片无法上传,我稍后试试看)手动描述就是
DeviceAddress            Length    PhaseData                      Description       Cmd.Phase.Ofs(rep)
------------------------------------------------------------------------------------------------
31.2                              8OUT    a0 00 00 0000 00 00 00........               117.1.0      
31.2                           16IN   72 72 72 7272 72 72 72rrrrrrrr               118.1.0      
                                                   00 00 00 0000 00 00 00........               118.1.8      
31.2                              8OUT    a0 00 00 0000 00 00 00........               119.1.0      
31.2                           16IN   73 73 73 7373 73 73 73ssssssss               120.1.0      
                                                   00 00 00 0000 00 00 00........               120.1.8      
31.2                              8OUT    a0 00 00 0000 00 00 00........               121.1.0      
31.2                           15IN   74 74 74 7474 74 74 74tttttttt               122.1.0      
                                                   00 00 00 0000 00 00   .......                122.1.8      
31.2                              8OUT    a0 00 00 0000 00 00 00........               123.1.0      
31.2                           17IN   00 75 75 7575 75 75 75.uuuuuuu               124.1.0      
                                                    75 00 00 0000 00 00 00u.......               124.1.8      
                                                   00                        .                      124.1.16      
31.2                              8OUT    a0 00 00 0000 00 00 00........               125.1.0      
31.2                           16IN   76 76 76 7676 76 76 76vvvvvvvv               126.1.0      
                                                   00 00 00 0000 00 00 00........               126.1.8   


在发送72和73的时候时候可以的,然后到74的时候,最后一个0被截断了没有发送。在下一次发送75的时候,发送了上次少发送的那个0.导致75的这次数据长度比正常的多一个
然后76又正常了



单板返回代码:
                case 0xA0:
                {
                  //printf("接收A0测试命令,返回序列数据\n");

                  //printf(" updata monitor data -> %d\r\n",index);
                  for(i = 0; i < 8; i++)
                  {
                        UsbSendBuf = index;
                  }

                  index ++;
                  iLen = USBD_CDC_ACM_DataSend(UsbSendBuf, 16);
                  if(iLen != 16)
                  {
                        printf(" Send monitor data Length(%d) ERROR !=16 \r\n",iLen);
                  }
                  break;
                }


想问的是, USBD_CDC_ACM_DataSend是把数据放到rl-usb协议的一个发送缓存区,这个数据发送被中断了,是和我rtx系统的任务切换有关系吗?
还是有其他地方可以保证我写入到这个发送缓存区的数据一定会被发送完成的?



eric2013 发表于 2021-2-17 11:21:26

我这里有个完整的回环,你可以参考

基于RL-USB实现ESP8266快速更新固件程序备份(2019-07-17)
http://www.armbbs.cn/forum.php?mod=viewthread&tid=94477&fromuid=58
(出处: 硬汉嵌入式论坛)

mioc_hust 发表于 2021-2-18 09:50:00

eric2013 发表于 2021-2-17 11:21
我这里有个完整的回环,你可以参考

基于RL-USB实现ESP8266快速更新固件程序备份(2019-07-17)


Bus Hound 6.01 capture on Windows Vista (x64). Complements of www.perisoft.net

Device - Device ID (followed by the endpoint for USB devices)
            (31) PLC_Capture_Control
Length - Total transfer length
Phase- Phase Type
            IN    Data in transfer         
            OUT   Data out transfer         
Data   - Hex dump of the data transferred
Descr- Description of the phase
Cmd... - Position in the captured data


DeviceLength    PhaseData                      Description       Cmd.Phase.Ofs(rep)
-----------------------------------------------------------------------------
31.2         8OUT    a0 00 00 0000 00 00 00........               1.1.0      
31.2         2IN   00 81                     ..                     2.1.0      
31.2         8OUT    a0 00 00 0000 00 00 00........               3.1.0      
31.2      16IN   00 00 00 0000 00 00 00........               4.1.0      
                         00 00 00 0000 00 00 00........               4.1.8      
31.2         8OUT    a0 00 00 0000 00 00 00........               5.1.0      
31.2      14IN   01 01 01 0101 01 01 01........               6.1.0      
                         00 00 00 0000 00      ......                   6.1.8      
31.2         8OUT    a0 00 00 0000 00 00 00........               7.1.0      
31.2         2IN   00 00                     ..                     8.1.0      
31.2         8OUT    a0 00 00 0000 00 00 00........               9.1.0      
31.2      16IN   02 02 02 0202 02 02 02........                10.1.0      
                         00 00 00 0000 00 00 00........                10.1.8      
31.2         8OUT    a0 00 00 0000 00 00 00........                11.1.0      
31.2      14IN   03 03 03 0303 03 03 03........                12.1.0      
                         00 00 00 0000 00      ......                  12.1.8      
31.2         8OUT    a0 00 00 0000 00 00 00........                13.1.0      
31.2      18IN   00 00 04 0404 04 04 04........                14.1.0      
                         04 04 00 0000 00 00 00........                14.1.8      
                         00 00                     ..                      14.1.16      
31.2         8OUT    a0 00 00 0000 00 00 00........                15.1.0      
31.2      14IN   05 05 05 0505 05 05 05........                16.1.0      
                         00 00 00 0000 00      ......                  16.1.8      
31.2         8OUT    a0 00 00 0000 00 00 00........                17.1.0      
31.2      18IN   00 00 06 0606 06 06 06........                18.1.0      
                         06 06 00 0000 00 00 00........                18.1.8      
                         00 00                     ..                      18.1.16      


看了下您工程里面用的发送函数是USBD_CDC_ACM_PutChar,采用单字符发送。但是在帮助文档里面,我觉得效果应该是一样的
USBD_CDC_ACM_PutChar
Summary #include <RTL.h>
#include <rl_usb.h>

int32_t USBD_CDC_ACM_PutChar (
    const uint8_t ch );            /* Character to be sent */

Description The function USBD_CDC_ACM_PutChar puts the requested character ch to the intermediate buffer and prepares it for being sent over the Virtual COM Port.

The function is part of the USB Device Function Driver layer of the RL-USB Device Software Stack.

Return Value -1 - Function failed
ch - Function succeeded

都是发送了到他内部的缓存中。

我试验了一下在usb_config.c里面把发送和接收的缓存从1024修改成64以后,数据被截断的现象明显增多。
这个数据截断发送应该是rl-usb协议栈自动周期发送的感觉。定时的? 数据量到了一定的长度就先发送。
bulk方式发送
页: [1]
查看完整版本: rl_usb发送数据截断现象