STMicroelectronics / STM32CubeF4

STM32Cube MCU Full Package for the STM32F4 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
Other
897 stars 424 forks source link

STM32CUBEIDE optimization level on USB CDC mode #181

Closed vahidajalluian closed 1 month ago

vahidajalluian commented 2 months ago

Dear Developers,

I am encountering an error and would like to determine if it is related to my code or an issue with the ST USB library.

Initially, I suspected that the problem might be caused by another part of my program, which is quite large and uses FreeRTOS. However, after simplifying the program as shown below, it appears that the issue lies within the ST USB code library.

I am using an STM32F429BIT6 chip with STM32CubeMX version 6.12 and F4 pack version 1.28.1. The core clock is set to 168MHz with a 25MHz external clock, and the USB clock is set to 48MHz. I added USB functionality, trying both HS and FS modes (individually and simultaneously), and included CDC support.

The problem arises when I use any optimization level (O1 to O3) in my program. Without optimization, the same code works correctly, whether FreeRTOS is enabled or not. With optimization, however, the mentioned code fails to work, regardless of whether FreeRTOS is used. In the working scenario, the PC successfully enumerates the USB device, and data transfer is fine. In the non-working scenario, Windows detects some activity on the ports, but it doesn’t show any device or even an error message indicating a failed descriptor request—only a refresh of the Device Manager screen.

I have searched the forums and found that some variables in the library might need to be declared with the volatile keyword but are not.

Does anyone have suggestions on how to resolve this issue? The link to the forum is https://community.st.com/t5/stm32-mcus-embedded-software/stm32cubeide-usb-optimization-level-on-usb-cdc-mode/td-p/714644

ALABSTM commented 1 month ago

Hi @vahidajalluian,

Could you please share a minimal project allowing to reproduce the issue you're describing please? A project that would work if no optimization is applied and fail otherwise. Ideally, if you're using STM32CubeMX to generate this project, the IOC file would be welcome.

Thank you in advance,

ALABSTM commented 1 month ago

Hi @vahidajalluian,

According to our development teams, the point you mentioned from the forum is rather related to the HAL driver than to the MW library. Moreover, the __IO or volatile related issue has already been fixed, as you can see, for instance, in this code snippet.

Hence, this looks more like an issue related to your application. As indicated in the CONTRIBUTING.md file, I suggest that you submit this to the ST Community. There, you will hopefully find the support you are looking for.

Please allow me to close this issue. Thank you for your comprehension and best of luck.

With regards,

vahidajalluian commented 1 month ago

@ALABSTM Sorry, I was away for some time, I have found that the reason arise from updating. If one create project purely by the newest case, that problem wont happen and all things work correctly, On the contrary, if the project is created by the past versions and then upgraded, it wont make the device descriptor code and hence, although the code is created by the latest version, it doesn't shown in device manager, here is a minimal project. https://github.com/vahidajalluian/USB_Test_Not_working https://github.com/vahidajalluian/USB_TEST_Working