Using TIM15 PWM [STM32F072] Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
yiancar
Posts: 14
Joined: Fri Jan 04, 2019 11:26 am
Has thanked: 1 time

Using TIM15 PWM [STM32F072]

Postby yiancar » Sun May 17, 2020 11:12 pm

Hello all,
I was trying to use TIM15 PWM on a a 072.

Code: Select all

#define STM32_PWM_USE_TIM15                 TRUE
#define STM32_PWM_TIM15_IRQ_PRIORITY        3


I get the error:

Code: Select all

lib/chibios/os/hal/ports/STM32/LLD/TIMv1/hal_pwm_lld.c:324:2: error: #error "TIM15 ISR not defined by platform"
 #error "TIM15 ISR not defined by platform"
  ^~~~~


I looked here viewtopic.php?f=3&t=4956.
Do you know if its a driver limitation or a Chip limitation?

Cheers,
Yiangos

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Using TIM15 PWM [STM32F072]

Postby Giovanni » Mon May 18, 2020 4:53 am

Hi,

TIM15 (and other "high timers" are not yet supported in the F0 port. More info here: viewtopic.php?f=3&t=5331

Giovanni

yiancar
Posts: 14
Joined: Fri Jan 04, 2019 11:26 am
Has thanked: 1 time

Re: Using TIM15 PWM [STM32F072]

Postby yiancar » Mon May 18, 2020 12:29 pm

Cheers Giovanni,

I will wait for 20.x:)

electronic_eel
Posts: 77
Joined: Sat Mar 19, 2016 8:07 pm
Been thanked: 17 times

Re: Using TIM15 PWM [STM32F072]

Postby electronic_eel » Sun Mar 14, 2021 4:46 pm

I just faced the same problem, I wanted to output a PWM signal on TIM15 on a STM32F072. I didn't need any IRQs/callback.

To make it compile (current ChibiOS git master branch) I configured it like this in mcuconf.h:

Code: Select all

#define STM32_PWM_USE_TIM15                 TRUE
#define STM32_TIM15_SUPPRESS_ISR

Then it compiled, but the outputs stayed inactive.

After reading the reference manual and checking all the required bits, I saw that the MOE bit needs to be enabled for TIM15 to work as output on the STM32F072. So I added this after the pwmStart call:

Code: Select all

PWMD15.tim->BDTR  = STM32_TIM_BDTR_MOE;

Now it works as expected.

The code responsible for setting MOE in the TIMv1 LLD looks like this:

Code: Select all

#if STM32_PWM_USE_TIM1 || STM32_PWM_USE_TIM8 || STM32_PWM_USE_TIM20
#if STM32_PWM_USE_ADVANCED
  pwmp->tim->BDTR  = pwmp->config->bdtr | STM32_TIM_BDTR_MOE;
#else
  pwmp->tim->BDTR  = STM32_TIM_BDTR_MOE;
#endif
#endif

TIM15 is not an advanced timer, but it still needs the MOE bit set on the F0. I checked other timers on the F0 and MOE seems to be necessary for TIM16 and TIM17 too, but TIM2, TIM3 and TIM14 don't need it. So at least for the F0 the upper condition would have to be expanded to

Code: Select all

#if STM32_PWM_USE_TIM1 || STM32_PWM_USE_TIM8 || STM32_PWM_USE_TIM15 || STM32_PWM_USE_TIM16 || STM32_PWM_USE_TIM17 ||  STM32_PWM_USE_TIM20

but I haven't cross checked other STM32 series if this is valid for them too.

This probably qualifies as a bug report now :D

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Using TIM15 PWM [STM32F072]

Postby Giovanni » Sun Mar 14, 2021 5:04 pm

Then moving in "bug reports".

Giovanni

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Using TIM15 PWM [STM32F072]

Postby Giovanni » Sat Apr 24, 2021 7:08 am

Hi,

Back to this, perhaps TIM15, 16 and 17 are "advanced" timers, I need to check for more differences.

EDIT: I removed the concept of "advanced" entirely", now BDTR is initialized for those timers that have it only, this should also solve the issue with TIM15/16/17. Could you give it a try and confirm? I just did this in trunk code, could be back-ported later.

Giovanni

electronic_eel
Posts: 77
Joined: Sat Mar 19, 2016 8:07 pm
Been thanked: 17 times

Re: Using TIM15 PWM [STM32F072]

Postby electronic_eel » Sun Apr 25, 2021 12:21 pm

Thanks for working on this.

I tried the trunk code with my F072 and the PWM output for TIM15, 16 and 17 now works without needing any manual tweaks of the MOE bit.

But while playing with this code and trying different variations I found another issue:

You still have to either define STM32_TIM15_SUPPRESS_ISR or a STM32_PWM_TIM15_IRQ_PRIORITY in mcuconf.h to make it compile, you get "#error "Invalid IRQ priority assigned to TIM15"" otherwise.

On MCUs with ARMv7-M you don't have to do that, os/hal/ports/STM32/LLD/TIMv1/hal_pwm_lld.h defines the lowest prio (=7) if you don't manually define something else. But hal_pwm_lld.h explicitly defines the value 7 which is invalid for ARMv6-M.

Wouldn't it be better to use "(CORTEX_PRIORITY_LEVELS - 1)" as default value in hal_pwm_lld.h instead?

Sorry for coming up with just another issue. But it is a common pattern I recognize: once you look closely at one area of code due to one observed bug, you begin to see others crawling in vincinity :oops:

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Using TIM15 PWM [STM32F072]

Postby Giovanni » Sun Apr 25, 2021 2:43 pm

I think you need to assign the priority in mcuconf.h or it will take the default one (which is out of range for Cortex-M0).

Giovanni

electronic_eel
Posts: 77
Joined: Sat Mar 19, 2016 8:07 pm
Been thanked: 17 times

Re: Using TIM15 PWM [STM32F072]

Postby electronic_eel » Mon Apr 26, 2021 7:26 pm

I think the attached patch would improve the situation. It automatically sets the default, based on the IRQ prio levels the current architecture supports.

Now you can use the default both on ARMv6-M and ARMv7-M and not only on ARMv7-M. This makes it more consistent across the different MCU lines. Also it is more convenient not having to define a value if you don't need it in your code.
Attachments
pwm_irq_prio_all_arm.zip
zipped patch
(752 Bytes) Downloaded 183 times

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Using TIM15 PWM [STM32F072]

Postby Giovanni » Sun Dec 05, 2021 10:45 am

bumping as self-reminder


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 4 guests