8 months, 3 weeks ago.

What timer is wait_us(); using on Stm32L053?

Our target is a STM32L053. We started Timer21 for capture mode, on Pin PA_3:CH2. External 5KHz is on the pin. The CCMR2 is read and values are not stable. (We use timer2 and timer22 for PWM out).

No Timer timer; are used in the code, only FastPWM lib. We do use wait_us(50); in two places. Can this bother timer21?

Code below:


Comment on this question

1 Answer

8 months, 3 weeks ago.

It is defined here in the source code:

So sadly, the timer (which includes wait_us) runs on timer21. You can use the mbed-dev lib and modify it yourself to run on another timer. Or if it is not too critical, just create your own loop with a certain delay. Either just figure out in a few attempts how long your dummy loop needs to be for a certain delay. Or before you start the timer in capture mode, run your loop for a certain amount of cycles, use a Timer to measure how long your loop takes, and using that information calculate in your program how long you need to set your loop for a delay of 50us.

Thanks! Good to know. Any other timers used? How would I know(any hints) to how to know what hardware is used by the mbed-dev lib for a given CPU? (Or is it only "one timer"...?) Fantastic with mbed in general.

How do one get/build the mbed-dev lib fast and easy?

posted by Jorgen Andersson 28 Jun 2017

There is no unified way to know, it really depends per target. Many require one timer for wait/Timer/Ticker, some require 2 or even 3. And then you got PWM timer often on top of that, although for example the LPC1768 has a dedicated PWM timer.

Besides experience and checking mbed source code I don't really got an answer for you sadly.

posted by Erik Olieman 29 Jun 2017

To post an answer, please log in.