Repository navigation
Commit cd7b8c2
fix(cdc): stop arming OUT endpoint with a NULL buffer
USBD_CDC_Receive() falls back to USBD_CDC_ClearBuffer() when the
receive queue has no room left for another 64 byte block. That helper
re-arms the OUT endpoint with a NULL application buffer:
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, 0, 0);
The endpoint is valid again while ep->xfer_buff is NULL. The next OUT
packet the host sends reaches HAL_PCD_IRQHandler(), which copies the
packet without checking the destination:
if (count != 0U)
{
USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, count);
}
The packet lands at address 0 and the write faults. On a STM32F103C8
this is an imprecise bus fault escalated to a hard fault (CFSR
IMPRECISERR, HFSR FORCED), and the board stops answering until reset.
Do not arm the endpoint when there is no room. An unarmed bulk OUT
endpoint NAKs, the host retries, and USBSerial::read() and the
readBytes() family already call CDC_resume_receive() after dequeuing,
so the endpoint is armed with a real block as soon as the sketch
drains. That is the flow control this transfer needs.
Fixes #1399
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>1 parent 4a8b28a commit cd7b8c2
1 file changed
Lines changed: 9 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
247 | 252 | | |
248 | 253 | | |
249 | 254 | | |
| |||
0 commit comments