PWM Configuration on STM32F0 Topic is solved

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

PWM Configuration on STM32F0

Post by dflogeras »

Hi, I was trying to get PWM up and running on a STM32F030. Looking at the datasheet, it would be best for my application to use TIM3_CH1 because of pin routing. I tried using the testhal/STM32/STM32F0xx/PWM-ICU demo as a starting point and began getting a linker error

Code: Select all

Linking build/ch.elf
build/obj/pwm_lld.o (symbol from plugin): In function `pwm_lld_disable_channel_notification':
(.text+0x0): multiple definition of `Vector80'
build/obj/icu_lld.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
../os/common/ports/ARMCMx/compilers/GCC/rules.mk:238: recipe for target 'build/ch.elf' failed
make: *** [build/ch.elf] Error 1


You can easily reproduce this by just changing the STM32F0xx/PWM-ICU demo to use TIM3 instead of TIM1, and of course changing all occurrences of PWMD1 to PWMD3 in main.c

What might be going on here?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PWM Configuration on STM32F0

Post by Giovanni »

Hi,

Probably TIM3 is used by the ST driver for tickless mode. You may use another timer or disable the tickless mode in chconf.h.

Giovanni
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: PWM Configuration on STM32F0

Post by RoccoMarco »

If you have copied the demo under testhal note that ICU_USE_TIM3 is TRUE. If you are using TIM for ICU you cannot use it for PWM. If you need PWM only disable HAL_USE_ICU and remove every ICU reference in main.c
Ciao,
RM
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: PWM Configuration on STM32F0

Post by dflogeras »

Hi Giovanni,

Yes that is definitely the problem. However I can't seem to find my way out. This device (F030x4) has TIM1,3,14,16,17. In st_lld.h it seems only 2,3,4,5 can be used for ST driver, which means I have to leave it using TIM3.

Now when I go to the PWM, TIM1 is not convenient because of the pins it uses, and TIM3 is used for ST, leaving 14,16,17. However the PWM driver seems not to support anything higher than TIM9. Is there a way around this? The datasheet seems to indicate that they can be used for PWM.


PS My earlier instruction of how to reproduce from the PWM-ICU demo is oversimplified and not correct (in fact the ICU timer was conflicting in that case). However, you still guessed my root cause :)

PPS I see Rocco is smarted and faster than I am in both reasoning and replying :)
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: PWM Configuration on STM32F0

Post by dflogeras »

I see now from the forums that the possibility of TIM14, 16, 17 etc has been discussed at length and would require changes to the HAL to be supported due to interrupt sharing.

My best compromise I have found was to either use TIM3 in tickless mode like Giovanni suggests, or I can also use the TIM1_CH1N (N being a complementary output) with the PWM_COMPLEMENTARY_OUTPUT_ACTIVE_LOW/HIGH. This pin was accessible to me and allows me to continue using tickless mode. For anyone else trying this you must also enable STM32_PWM_USE_ADVANCED in mcuconf.h
electronic_eel
Posts: 95
Joined: Sat Mar 19, 2016 8:07 pm
Has thanked: 8 times
Been thanked: 23 times

Re: PWM Configuration on STM32F0

Post by electronic_eel »

dflogeras, are you using a F030F4, the TSSOP20 variant?

psst, don't tell anybody: it has a TIM2 present, even if it isn't in the datasheet. It seems like the die for the F031F4, F031F6 and F030F4 is the same. So it also has 32kb flash. Some programmers like ST-Link check the flash size register, so you can't write the full 32kb with them. But I have successfully done it with a Blackmagic Probe.

But using TIM2 requires nothing but using it like on the F031. I have just changed the define in the board.h and it worked out of the box.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PWM Configuration on STM32F0

Post by Giovanni »

The oldest trick in the book, selling the same silicon as a downgraded device. It is no guaranteed that it will stay that way however, the extra peripherals could disappear in purchased devices from different batches.

Giovanni
dflogeras
Posts: 232
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 8 times
Been thanked: 22 times

Re: PWM Configuration on STM32F0

Post by dflogeras »

Wow electronic_eel, good guess! I am indeed. Like Giovanni said, I wouldn't rely on this as gospel, but for this one-off hobby project, it is nice to have this info in my back pocket just in case :)
Post Reply