Page 1 of 1
PWM Configuration on STM32F0
Posted: Wed May 11, 2016 12:30 pm
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?
Re: PWM Configuration on STM32F0
Posted: Wed May 11, 2016 12:35 pm
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
Re: PWM Configuration on STM32F0
Posted: Wed May 11, 2016 12:56 pm
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
Re: PWM Configuration on STM32F0
Posted: Wed May 11, 2016 12:59 pm
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

Re: PWM Configuration on STM32F0
Posted: Wed May 11, 2016 7:29 pm
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
Re: PWM Configuration on STM32F0
Posted: Wed May 11, 2016 8:56 pm
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.
Re: PWM Configuration on STM32F0
Posted: Wed May 11, 2016 9:59 pm
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
Re: PWM Configuration on STM32F0
Posted: Thu May 12, 2016 12:00 am
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
