The CubeMX2 USBX CDC Example is not working
- July 17, 2026
- 1 reply
- 15 views
I previously got CDC via USBX and FreeRTOS working on a custom C542 design, using the examples since CubeMX2 did not support the USBX middleware at that time.
I am now trying to port that code to the C562 since I need more memory. This does not work at the moment since I used CubeMX2 for the USBX configuration and setup.
So I thought, lets have a look into the examples and see what I am doing wrong.
Unfortunately that did not work, or rather the USBX-CDC-FreeRTOS example for the Nucleo-C562RE board using the CMake toolchain does not work.
I got "example_usbx_device_cdc_acm_uart_freertos" from "https://dev.st.com/stm32-example-library" for the CMake toolchain.
I extracted the ZIP and imported the project in the latest CubeIDE (version 2.2.0; Silicon MAC) and build the project in "release" and "debug" config without errors.
However, both version do not setup the USB stack correctly. The user-LED stays on, so everything should run without errors.
If I look at the USB communication with a Total Phase Beagle USB 480 analyzer, I see nothing (see attachment).
The USB connection is reseted after I press the reset button, then there is a "Full-speed" mark and then the connection is suspended.
The same happens, when I plug in the cable after the board reset.
I have only one C562 board, so I can not try another board, however the board is new, so it is unlikely that the board is damaged.
CubeMX2 Issues
I opened the ioc2 file with CubeMX2 (version 1.1.0) with the latest packs (2.1.0; Silicon MAC).
The was an error-indicator in the project config, which turned out to be an empty "HAL Timebase Timer Selection". I changed that to the only availabe/configured timer TIM6 and regenerated the project files.
Then CubeMX2 found a hole bunch of files changed on the disk, so maybe the "*.ioc2" or "exported-files.json" file is not up to date?
There where so many files changed, that the "Show Differences" (???) dialogue was overflowing, meaning that I almost could not click "ok" without resizing the window.
Anyway, the code is now regenerated. However, the code does no longer compile because of missing defines used in the background task function (e.g. NOTIFICATION_VALUE_UNKNOWN), previously defined in "./generated/middleware/usbx/mx_usbx_app.h".
After adding the enum, compilation has no more errors, but 136 warnings about "#define USBD_INCLUDE_USER_DESC_CONFIG_FILE" being redefined on the command line.
Now, the firmware ends up in a HardFault after calling "status = ux_dcd_stm32_initialize(0, (ULONG)p_usb_device);" (in "app_ux_device_thread_entry(void *argument)").
Probably because the newly generated version of the function does not call "mx_example_pcd_init();" beforehand.
After adding this, the code runs, as before.
The USB CDC device is still not available.
In Summary:
- example_usbx_device_cdc_acm_uart_freertos is broken
- the examples CubeMX2 configuration is not valid
- CubeMX2 does not generate the same code as distributed in the example, breaking the code
- CubeMX2 can become unusable during project code regeneration if many files where changed outside of CubeMX2 because the "Show Differences" dialogue overflows and has now scroll bars.
