TI中文支持网
TI专业的中文技术问题搜集分享网站

lm4f120(TM4C1233H6PMI) launchpad usb_dev_bulk例程求助!

开发板:lm4f120 launchpad

开发环境:CCS6.0.1

例程:StellarisWare 内官方例程 usb_dev_bulk

对例程基本未修改:

添加了一个全局变量x,用于x=(unsigned long)pcData; 查看pcData值

一个全局字符数组USB_READ[10] 用于USBBufferRead(&g_sRxBuffer,USB_READ,10); 读取十个字节数据

然后 我用的是自己用QT写的一个发送字符数据到设备的上位机,用的libusb—win32来完成usb端口的读写(上位机可以确认无问题)

然后我就在合适的地方设置断点,查看EchoNewDataToHost()这个函数的运行过程,然后发现没有完全按预期的运行,然后这里问几个问题:

1.ulSpace = USBBufferSpaceAvailable(&g_sTxBuffer);这句是获取发送缓存区空闲的空间,和接受缓存接收到的新数据数量有没有关系?

2.ulReadIndex = (unsigned long)(pcData – g_pucUSBRxBuffer);  ulReadIndex是用于获取新接收数据在接收缓存中的起始位置(相对位置),方便从这里开始读取新数据,pcData是新数据起始的地址,然后这个pcdata是否只要有对接受缓存的读取就会移动到尚未被读取的数据处,比如USBBufferRead(&g_sRxBuffer,USB_READ,10);是否会改变pcData的值?还是说pcData在设备接收到新数据时就固定(刷新),pcData 何时赋值的,会不会因为读取操作而改变。

3.ulNumBytes是收到的总的数据,这个变量只是针对对这个例程的吗?只要接收了没被发送出去,ulNumBytes(ulMsgValue)就一直增大吗?我如果发送超过256字节(接收缓存区大小)的数据,这个例程还能正常工作吗?

4.USB_EVENT_TX_COMPLETE 这个事件在发送缓存区数据发送完毕后触发,还是发出一个数据包就触发?

5.例程是只有一条管道,极限速率能达到多少?有没有多管道的例程(如何实现多管道)?

以下是修改过的函数。

volatile unsigned long x;
volatile unsigned char USB_READ[10];

static unsigned long
EchoNewDataToHost(tUSBDBulkDevice *psDevice, unsigned char *pcData,
unsigned long ulNumBytes)
{
unsigned long ulLoop, ulSpace, ulCount;
unsigned long ulReadIndex;
unsigned long ulWriteIndex;
tUSBRingBufObject sTxRing;

//
// Get the current buffer information to allow us to write directly to
// the transmit buffer (we already have enough information from the
// parameters to access the receive buffer directly).
//
USBBufferInfoGet(&g_sTxBuffer, &sTxRing);

//
// How much space is there in the transmit buffer?
//
ulSpace = USBBufferSpaceAvailable(&g_sTxBuffer);

//
// How many characters can we process this time round?
//
ulLoop = (ulSpace < ulNumBytes) ? ulSpace : ulNumBytes;
ulCount = ulLoop;

//
// Update our receive counter.
//
g_ulRxCount += ulNumBytes;

//
// Dump a debug message.
//
DEBUG_PRINT("Received %d bytes\n", ulNumBytes);

//
// Set up to process the characters by directly accessing the USB buffers.
//
x=(unsigned long)pcData;*********************************************此处添加一行
ulReadIndex = (unsigned long)(pcData – g_pucUSBRxBuffer);
ulWriteIndex = sTxRing.ulWriteIndex;

while(ulLoop)
{
x=(unsigned long)pcData;*********************************************此处添加一行
//
// Copy from the receive buffer to the transmit buffer converting
// character case on the way.
//

//
// Is this a lower case character?
//
if((g_pucUSBRxBuffer[ulReadIndex] >= 'a') &&
(g_pucUSBRxBuffer[ulReadIndex] <= 'z'))
{
//
// Convert to upper case and write to the transmit buffer.
//
g_pucUSBTxBuffer[ulWriteIndex] =
(g_pucUSBRxBuffer[ulReadIndex] – 'a') + 'A';
}
else
{
//
// Is this an upper case character?
//
if((g_pucUSBRxBuffer[ulReadIndex] >= 'A') &&
(g_pucUSBRxBuffer[ulReadIndex] <= 'Z'))
{
//
// Convert to lower case and write to the transmit buffer.
//
g_pucUSBTxBuffer[ulWriteIndex] =
(g_pucUSBRxBuffer[ulReadIndex] – 'Z') + 'z';
}
else
{
//
// Copy the received character to the transmit buffer.
//
g_pucUSBTxBuffer[ulWriteIndex] = g_pucUSBRxBuffer[ulReadIndex];
}
}

//
// Move to the next character taking care to adjust the pointer for
// the buffer wrap if necessary.
//
ulWriteIndex++;
ulWriteIndex = (ulWriteIndex == BULK_BUFFER_SIZE) ? 0 : ulWriteIndex;

ulReadIndex++;
ulReadIndex = (ulReadIndex == BULK_BUFFER_SIZE) ? 0 : ulReadIndex;

ulLoop–;
}

//
// We've processed the data in place so now send the processed data
// back to the host.
//
USBBufferRead(&g_sRxBuffer,USB_READ,10);*********************************************此处添加一行
USBBufferDataWritten(&g_sTxBuffer, ulCount);

DEBUG_PRINT("Wrote %d bytes\n", ulCount);

//
// We processed as much data as we can directly from the receive buffer so
// we need to return the number of bytes to allow the lower layer to
// update its read pointer appropriately.
//
return(ulCount);
}

xyz549040622:

楼主暂时先放下,不用学了,LM4F系列的芯片都停产了,楼主转学TM4吧

ming zhao:

回复 xyz549040622:

额,lm4f120h5qr 貌似现在的名字叫tm4c1233h6pmi。

xyz549040622:

回复 ming zhao:

对的,是兼容系列的,但是需要修改。。。所以最好先换芯片,再玩

赞(0)
未经允许不得转载:TI中文支持网 » lm4f120(TM4C1233H6PMI) launchpad usb_dev_bulk例程求助!
分享到: 更多 (0)