I am building a USB driver on an ARM Cortex M series MCU, namely the STM32F107VCT. My code is based on the USB CDC library code generated by STM's own code generation software called CubeMX. In CubeMX the MCU is configured to support 64 byte USB messages.
Sending messages from a host computer and parsing them on the MCU works fine when the USB payload is 8 chars (i.e. 8 bytes) or smaller. I can see in Wireshark that such messages are padded out to be 64 bytes on the wire.
When 9 chars are being sent the MCU stops execution (without going to the hardware fault handler) and without hitting any of the breakpoint I inserted in the CDC_Receive_FS function as seen in the code segment below.
I can see the USB message (padded out to 64 bytes, just like when having 8 chars as payload) going out from the PC using Wireshark and the MCU hardware acknowledges the message, but the MCU halts without reaching any breakpoints.
My main questions:
Does anyone know why this would halt? Perhaps some simple setting I am missing? Is there any lower level code I can place breakpoints in to really try and figure out what is going on? To me it is not clear what function actually calls CDC_Receive_FS
My implementation of CDC_Receive_FS:
static int8_t CDC_Receive_FS (uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 6 */
// Test breakpoint 1 set here
//My custom parser
USBDRIVER_receive(&(project.usbDriver), Buf, Len);
// Test breakpoint 2 set here
//CubeMX Generated functions
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
// Test breakpoint 3 set here
return (USBD_OK);
/* USER CODE END 6 */
}
Please let me know if some additional information is needed in order to solve the issue.
The USB driver is initialized by the following CubeMX auto-generated code:
void MX_USB_DEVICE_Init(void)
{
/* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
/* USER CODE END USB_DEVICE_Init_PreTreatment */
/* Init Device Library, add supported class and start the library. */
USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC);
USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS);
USBD_Start(&hUsbDeviceFS);
/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */
/* USER CODE END USB_DEVICE_Init_PostTreatment */
}