I used last trunk 2.5.1 and STM32F103 board.
The problem is that for some time it is functioning properly, but after a number of transactions the device stops responding. After USB cable reinsertion the process starts again. I noticed that this happens when transferring big packets of data (512 bytes or more). The feeling that the MCU does not have time to respond and the computer loses it. I tried to increase enpoints max packet sizes in descriptors (not sure I did it right) to 256 bytes and it begins work better but I still have problems.
As a base, I used the USB_CDC example from testhal folder. All descriptors are the same.
The thread looks as:
Code: Select all
static WORKING_AREA(waThreadUSB, 2048);
static msg_t ThreadUSB(void *arg)
{
(void) arg;
for (;;)
{
chThdSleepMilliseconds(MS2ST(1000));
// Wait USB ready
while (SDU1.config->usbp->state != USB_ACTIVE)
{
chThdSleepMilliseconds(MS2ST(1000));
}
chprintf(dbg_port, "USB cable plugged.\n\r");
// Process commands
while (SDU1.config->usbp->state == USB_ACTIVE)
{
int size = USB_GET_PACKET(COMM_RX_BUFFER, sizeof(COMM_RX_BUFFER));
if (size > 0)
{
size = COMM_PROCESS_COMMAND(COMM_RX_BUFFER, COMM_RX_BUFFER, sizeof(COMM_RX_BUFFER));
if (size > 0)
{
// Send result
sdWrite(&SDU1, COMM_RX_BUFFER, size);
}
}
}
chprintf(dbg_port, "USB cable unplugged.\n\r");
}
}
I debugged the code and found that packets received from USB, processed OK and sdWrite running but on the PC side receive nothing. I look at the raw data from Port monitor and can''t understand what happens.
0.00029761 stm_loader.exe IRP_MJ_WRITE USBSER000 SUCCESS Length 5: 0C 02 00 00 48
0.00000021 stm_loader.exe IRP_MJ_WRITE USBSER000 SUCCESS Length 0:
0.00000208 stm_loader.exe IOCTL_SERIAL_GET_COMMSTATUS USBSER000 SUCCESS
0.00000210 stm_loader.exe IOCTL_SERIAL_PURGE USBSER000 SUCCESS Purge: TXABORT RXABORT TXCLEAR RXCLEAR
0.00000061 stm_loader.exe IOCTL_SERIAL_PURGE USBSER000 SUCCESS Purge: TXABORT TXCLEAR
0.00000519 stm_loader.exe IOCTL_SERIAL_SET_WAIT_MASK USBSER000 SUCCESS Mask:
0.00000075 stm_loader.exe IOCTL_SERIAL_PURGE USBSER000 SUCCESS Purge: RXABORT RXCLEAR
0.00000053 stm_loader.exe IRP_MJ_CLEANUP USBSER000 SUCCESS
0.00291877 stm_loader.exe IRP_MJ_CLOSE USBSER000 SUCCESS
When I using UART cable and the same soft on PC all works fine.