cancel
Showing results for 
Search instead for 
Did you mean: 

STM32C071USB composite device(HID+CDC)standalone,mouse data output error.

LLLLLL
Visitor

Hardware environment: STM32 Nucleo-64 development board with STM32C071RB MCU.
Software environment: Bare-metal operation without RTOS.
I am currently working on a USB composite device without an RTOS. Previously, I used STM32CubeMX to generate and modify separate HID mouse and CDC virtual serial port programs, both of which worked fine.
This time, I added a CDC component to the HID mouse program. After generating the code with CubeMX and supplementing the CDC interface functions, I encountered an issue with PMA endpoint memory allocation. I referred to the code example in the CubeMX repository (STM32Cube\Repository\STM32Cube_FW_C0_V1.4.0\Projects\NUCLEO-C071RB\Applications\USBX\Ux_Device_HID_CDC_ACM), which has the following memory configuration:
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x00, PCD_SNG_BUF, 0x14);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x80, PCD_SNG_BUF, 0x54);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x81, PCD_SNG_BUF, 0x94);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x01, PCD_SNG_BUF, 0xD4);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x82, PCD_SNG_BUF, 0x114);
The initial offset here is 0x14, which reserves 0x14 bytes for the endpoint buffer descriptor table, with each endpoint using 4 bytes, totaling five endpoints.
The USB control endpoint 0 has IN and OUT endpoints at addresses 0x00 and 0x80.
The three CDC endpoints correspond to addresses 0x01, 0x81, and 0x82.
Thus, it seems that the mouse endpoints are not configured, as there is no reserved space in the endpoint buffer descriptor table or configured data buffer area for them, which is where I'm confused.
Initially, during the porting process, I didn't follow the official PMA allocation scheme and used my own:
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x00, PCD_SNG_BUF, 0x18);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x80, PCD_SNG_BUF, 0x58);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x01, PCD_SNG_BUF, 0x98);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x81, PCD_SNG_BUF, 0xD8);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x82, PCD_SNG_BUF, 0x118);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x83, PCD_SNG_BUF, 0x158);
I reserved descriptor space and added a buffer for the mouse endpoint.
However, testing revealed that after sending mouse data, the PC received the same data repeatedly, suggesting a storage issue causing inconsistent data between the sent and buffered data. The hid_mouse data array appeared normal. I then suspected my PMA allocation was flawed. Switching back to the official scheme resolved the issue, but I still don't understand why. As I plan to add another CDC later, not grasping the PMA allocation mechanism could lead to more problems. I hope someone or the official team can explain this. Thank you!

For your reference, the exception data and specific project details are available in the attachment.

1 REPLY 1
FBL
ST Employee

Hi @LLLLLL 

First, the example provided doesn't use CMD CDC ACM endpoint (not HID endpoint). So, here we are using 2 CDC endpoints correspond to addresses 0x01, 0x81.

You are receiving the same data in GetPointerData() because you are incrementing the position of the counter when sending each time event. The comment here might be confusing since GetPointerData() actually updates as well cursor position.

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.