2024-12-23 06:00 AM - edited 2024-12-23 06:01 AM
Hi all,
I'm developing a composite USB device on USB OTG port on a board based on STM32F429 chip.
The device has two interfaces: a custom device + a CDC device. I'm using USB_Device_Library code.
Windows host correctly shows 3 items: the composite device, the generic USB device with my custom label/name, a virtual serial port (COM8).
As test when I open the virtual port (by Putty) I see the three-linee welcome message and a prompt.
When I press a key on the terminal, the code is sent to the device by a BulkOut packet and the device, if the code is different from 0x0d, echoes the code by a BulkIn packet.
This is OK til I press the nine-th character on the keyboard: as echo of this character I see garbage on the terminal.
Dumping the memory of the internal buffers I see that the device received the correct code and replied 1 byte with the correct code!
If I sniff the usb channel with WireShark I see a 7-bytes packet on BulkIn reply (!!).
My debug log shows that the register containing the number of chars to sent to the host (IN_EP_TSIZ) is 1 and the char written in the FIFO (in USB_WritePacket fn) is 0x39 '9':
RXFLVL OUT DATA_UPD
RXFLVL DATA_UPD EP buff: x200100c1 - count: 1
OEPINT
OEPINT XFRC ep1
[USBD_LL_DataOutStage]
[USBD_LL_DataOutStage] DataOut ep1 - idx=1
[terminal] echo '9'
[transmit] x20010128, len: 1
[USB_EPStartXfer] IN_EP_TSIZ x00080001
IEPINT
IEPINT TXFE
[USB_WritePacket] ep2 - len: 1
[USB_WritePacket] IN_EP_TSIZ x00080001
[USB_WritePacket] x39
IEPINT
IEPINT XFRC ep2
[USBD_LL_DataInStage] ep2
[USBD_CDC_DataIn] ep2 - id=1
[USBD_CDC_DataIn] endTx TxBuf: x20010128 - 39 -
How it is possible that Wireshark and Windows terminal reveive a 7-bytes packet ??? (None of them are 0x39)
Thanks!
2025-01-09 05:53 AM
Hi @SteMMo
The issue is likely linked to endpoint configuration or the way the USB stack in CDC class driver handles the transmission. Could you share your code to reproduce on my board Nucleo F439?
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-01-29 07:56 AM
Hello!
Which ep configuration/parameter/register I can check?
In my case I'm using the IN 0x2 to send a single byte.
I'm in the OTG_FS_IRQHandler -> HAL_PCD_IRQHandler() when the USB_OTG_DIEPINT_TXFE interrupt is received for EP2.
Here I enter in the PCD_WriteEmptyTxFifo(), setup the ep variable mambers and len (=1) to call the USB_WritePacket() [stm32f4xx_ll_usb.c)] fn.
Here the variables are ok; pSrc points the buffer containing the byte, len=1 and count32b=1.
The registry values in the moment I write in the FIFO register (USB_WritePacket(..) in are:
DIEPCTRL2: 0x80888040
DIEPTSIZ2: 0x00080001
On the host side (Windows and Wireshark) I see a BULK IN dev-to-host 0x82 packet of 7 bytes as DataLength.
The routines are the 'standard' SDK involving stm32f4xx_hal_pcd.c and stm32f4xx_ll_usb.c files.
Thanks!
2025-01-30 12:58 AM - edited 2025-01-30 01:13 AM
Just for completeness:
2025-01-31 03:09 AM
Starting EP configuration:
CUSTOM device = 0x81, 0x02
CDC device = CMD 0x83, 0x82, 0x01
As said, CUSTOM device is detected and works well.
So, I tried to change the EP numbers:
CUSTOM device = 0x83, 0x01
CDC device = CMD 0x82, 0x81, 0x02
With this configuration the serial port is working, the custom device is detected as USB device, but it is not communicating and no IRQ are fired.
2025-02-03 10:36 AM - edited 2025-02-04 03:09 AM
Another test - just to switched the EP numbers:
The serial port is working well.
The custom device is detected but when I run my application no interrupts are fired on STM32 (????).
Other test - switched again the EP numbers:
The serial port is working well.
The custom device is detected but when I run my application no interrupts are fired but the Wireshark session shows that host sends BULK_IN followed by FUNCTION_ABORT_PIPE. The device replied with a BULK_IN cancelled + a ACK on ABORT_PIPE.