cancel
Showing results for 
Search instead for 
Did you mean: 

Enabling USB devices is slowing down the Timer clock in STM32L562VET6

Giridhara_Datta_G
Associate III

Hi STM Community,

I'm writing to report a critical issue affecting the SPI sampling rate when using the USB device middleware/software package as a Communication device class on an STM32 microcontroller.

Detailed Scenario:

I'm employing Timer TIM15 configured for a sampling frequency of 10 kHz (10,000 samples per second) to acquire data from a sensor connected via the SPI1 peripheral.
The SPI1 clock frequency is confirmed to be at the expected 20 MHz (main clock of 80 MHz divided by a prescaler of 4).
When the USB device middleware is disabled, the sampling functions as intended. A video attachment (Video 1) demonstrates the Index variable reaching values from 0 to 40,000 within 4 seconds, aligning with the 10 kHz target rate.
Crucial Observation:

Timer Clock Reduction: The core problem lies in the timer clock being halved when the USB middleware is enabled. This was verified by toggling a GPIO pin within the timer count elapse callback, which confirms a sampling rate of only 5 kHz instead of 10 kHz.
Unexpected Behavior:

With this reduced timer clock, the MCU theoretically requires 8 seconds to collect 40,000 samples (40,000 samples / 5,000 samples/second). However, in reality, the sampling process takes significantly longer, exceeding 2 minutes.
My Questions:

Has anyone encountered a similar scenario where USB middleware disrupts the timer clock, leading to a halved SPI sampling rate on STM32 devices?
Given the confirmed 20 MHz SPI clock and the halved timer clock, why does the sampling process take much longer than the anticipated 8 seconds? Are there potential hidden factors or middleware interactions affecting the overall timing?
Urgency:

Resolving this issue is critical for my application. I'd greatly appreciate any insights or suggestions to maintain the desired 10 kHz sampling rate while using both USB and SPI functionalities concurrently.

Additional Information:

Attached are the two videos mentioned earlier:
Video 1 (USB device middleware/software package Disabled)
Video 2 (USB device middleware/software package Enabled)

 

Any help will be greatly appreciated
Thank you for your prompt attention to this matter!

 

Best regards,

Giridhara Datta G

1 REPLY 1
gbm
Lead III

Set the USB interrupt main priority to one of lower levels, like 12..14. Set the timer priority to high level - 0 is the highest. Leave priority grouping at the default value (16 main levels, no subpriority).