- Notifications
You must be signed in to change notification settings - Fork1k
chore(usb): cdc_queue now use uint32_t length#2550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…E_BUFFER_PACKET_NUMBER>512 or CDC_RECEIVE_QUEUE_BUFFER_PACKET_NUMBER>512.
which allows CDC_TRANSMIT_QUEUE_BUFFER_PACKET_NUMBER>512 orCDC_RECEIVE_QUEUE_BUFFER_PACKET_NUMBER>512.Signed-off-by: warmonkey <luoshumymail@gmail.com>
Hi@warmonkey
So I will not merge this PR, sorry. |
warmonkey commentedMay 20, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
On STM32F4 USB_WritePMA will not be called. The actual function to send data over USB is USBD_LL_Transmit() -> ... -> USB_EPStartXfer() There two paths can trigger the USBD_LL_Transmit(): USBSerial::write() -> CDC_continue_transmit(), USBD_CDC_TransmitCplt() -> CDC_continue_transmit() -> USBD_CDC_TransmitPacket() -> USBD_LL_Transmit() -> HAL_PCD_EP_Transmit() -> USB_EPStartXfer() In CDC_continue_transmit() file: usbd_cdc_if.c line 345, it's calling as stated in stm32f4xx_ll_usb.c function USB_EPStartXfer line 782:
from the code above we know that the size to send from CDC_TransmitQueue_ReadBlock() previously, is assigned to ep->xfer_len (at stm32f4xx_hal_pcd.c line 1940 for stm32f4), then write into OTG_FS_DIEPTSIZx or OTG_HS_DIEPTSIZx register as:
from RM0008 RM0090 RM0432 we know the PKTCNT has 10bits, max value 0x3ff (1023), XFRSIZ has 19bits, max value 0x7ffff (524287). 1023 * 512 = 523776 < 524287 but, it's not easy to know the USB is running in HS or FS mode. In conclusion, we should limit the maximum size returned by CDC_TransmitQueue_ReadBlock() to OTG_MAX_PKTCNTUSB_FS_MAX_PACKET_SIZE which is 102364 (for now). I will read The CDC queue is a software buffer, it's not relevant to the PMA area. The PMA is located in Before I submit this PR I checked multiple times, compiled and deployed on actual products. I ran the test for at least 24hrs. |
warmonkey commentedMay 20, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Im working on an improvement. Will use |
Uh oh!
There was an error while loading.Please reload this page.
raise cdc buffer size 32KB limit due to uint16_t length variables.
This PR fixes bug: cdc queue limited
Now CDC_TRANSMIT_QUEUE_BUFFER_PACKET_NUMBER and/or CDC_RECEIVE_QUEUE_BUFFER_PACKET_NUMBER both can be greater than 512. which every buffer size is 64B, 64*512=32768