How to use PWM Timer 16, 17 on NUCLEO-F302R8?

Report here problems in any of ChibiOS components. This forum is NOT for support.
jslee
Posts: 15
Joined: Thu Jun 11, 2020 9:54 am
Has thanked: 3 times

How to use PWM Timer 16, 17 on NUCLEO-F302R8?

Postby jslee » Wed Jul 13, 2022 3:22 am

Hello.

I'm testing PWM Timer.
There are TIM1, 2, 6, 15, 16, 17 on NUCLEO-F302R8.
I want use TIM2, 16, 17 for led dimming

I made 'RT-STM32F302R8-NUCLEO64_MYBOARD' project.
I'm working on 'ChibiOS 20.3.1 stable' version(checked Components section in 'readme.txt')

First, I did led dimming using TIM2
And, I didn't know how to use TIM16, TIM17.

PWM Timer is defined for 1, 2, 3, 4, 8 like below.

Code: Select all

#define STM32_PWM_USE_ADVANCED              FALSE
#define STM32_PWM_USE_TIM1                  FALSE
#define STM32_PWM_USE_TIM2                  FALSE
#define STM32_PWM_USE_TIM3                  FALSE
#define STM32_PWM_USE_TIM4                  FALSE
#define STM32_PWM_USE_TIM8                  FALSE

#define STM32_PWM_TIM1_IRQ_PRIORITY         7
#define STM32_PWM_TIM2_IRQ_PRIORITY         7
#define STM32_PWM_TIM3_IRQ_PRIORITY         7
#define STM32_PWM_TIM4_IRQ_PRIORITY         7
#define STM32_PWM_TIM8_IRQ_PRIORITY         7

There are no define about TIM16, TIM17

In my case, how to use TIM16, TIM17 on NUCLEO-F302R8 using ChibiStudio?

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: How to use PWM Timer 16, 17 on NUCLEO-F302R8?

Postby Giovanni » Wed Jul 13, 2022 4:48 am

Hi,

Apparently mcuconf.h does not have all required settings for the 302, just add the missing definitions, you could take them from the mcuconf.h of an F303.

Giovanni

jslee
Posts: 15
Joined: Thu Jun 11, 2020 9:54 am
Has thanked: 3 times

Re: How to use PWM Timer 16, 17 on NUCLEO-F302R8?

Postby jslee » Tue Jul 19, 2022 8:10 am

Giovanni wrote:Hi,

Apparently mcuconf.h does not have all required settings for the 302, just add the missing definitions, you could take them from the mcuconf.h of an F303.

Giovanni


Thank you Giovanni for your reply.

I tried add missing definitions like below

Code: Select all

#define STM32_PWM_USE_ADVANCED              FALSE
#define STM32_PWM_USE_TIM1                  FALSE
#define STM32_PWM_USE_TIM2                  TRUE      // change. FALSE->TRUE
#define STM32_PWM_USE_TIM3                  FALSE
#define STM32_PWM_USE_TIM4                  FALSE
#define STM32_PWM_USE_TIM8                  FALSE
#define STM32_PWM_USE_TIM16                 TRUE      // add TIM16
#define STM32_PWM_USE_TIM17                 TRUE      // add TIM17

#define STM32_PWM_TIM1_IRQ_PRIORITY         7
#define STM32_PWM_TIM2_IRQ_PRIORITY         7
#define STM32_PWM_TIM3_IRQ_PRIORITY         7
#define STM32_PWM_TIM4_IRQ_PRIORITY         7
#define STM32_PWM_TIM8_IRQ_PRIORITY         7


Code build was success, but didn't work led dimming using TIM16, 17.
Is there any difference between TIM2 and TIM16(TIM17)?

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: How to use PWM Timer 16, 17 on NUCLEO-F302R8?

Postby Giovanni » Tue Jul 19, 2022 8:24 am

Hi,

TIM2 counter is 32 bits wide and has 4 comparators, see the STM32 RM for details. Other timers are 16 bits.

BTW, make sure that the timers are actually started by the driver, it could be a SW issue on that specific platform.

Giovanni

jslee
Posts: 15
Joined: Thu Jun 11, 2020 9:54 am
Has thanked: 3 times

Re: How to use PWM Timer 16, 17 on NUCLEO-F302R8?

Postby jslee » Wed Jul 20, 2022 10:09 am

Giovanni wrote:Hi,

TIM2 counter is 32 bits wide and has 4 comparators, see the STM32 RM for details. Other timers are 16 bits.

BTW, make sure that the timers are actually started by the driver, it could be a SW issue on that specific platform.

Giovanni


Finally, did it.

After changed 'STM32_PWM_USE_TIM1' define from FALSE to TRUE,
led dimming worked using TIM16, TIM17.

But, I still don't know why do that.

I'm wondering Why TIM1 does cause TIM16(TIM17) to work?
Could you please let me know, Giovanni?
Last edited by jslee on Wed Jul 20, 2022 11:43 am, edited 1 time in total.

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: How to use PWM Timer 16, 17 on NUCLEO-F302R8?

Postby Giovanni » Wed Jul 20, 2022 11:13 am

Hi,

TIM1 shares its IRQs with TIM16 and TIM17, the reason should be hidden there, I have not found it yet. Just keep TIM1 enabled as a workaround.

About IRQ priorities, the correct settings are:

Code: Select all

#define STM32_IRQ_TIM1_BRK_TIM15_PRIORITY   7
#define STM32_IRQ_TIM1_UP_TIM16_PRIORITY    7
#define STM32_IRQ_TIM1_TRGCO_TIM17_PRIORITY 7
#define STM32_IRQ_TIM1_CC_PRIORITY          7


Note the IRQ sharing.

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: How to use PWM Timer 16, 17 on NUCLEO-F302R8?

Postby Giovanni » Wed Jul 20, 2022 11:17 am

Moving this topic in "bug reports" as a reminder for me to look into this problem.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 20 guests