I recently received a new batch of my driver boards, only to find out that I made yet another mistake (probably :D) ahhhhh… Nevertheless, my new design uses STM32F103CB MCU instead of the old Atmega chip.
While porting the code to new MCU I got this statement from driver.init() function:
TIM1-CH1N TIM1-CH2N TIM1-CH3N score: -3
STM32-DRV: no workable combination found on these pins
It is quite obvious that SimpleFOC does not like my selection of pins for the 3-pwm output. I chose pins PB_13, PB_14 and PB_15. According to the datasheet of the MCU and SimpleFOC docs, these pins are connected to TIM1_CHxN.
They are a “negated” channels of TIM1. So I assume that there is no support for this in the library. Is that right (please no :D)?
It is very confusing, because while looking at Practical guides → Choosing PWM pins, I found this in STM32 section during design:
Therefore for all the use cases except 6PWM generation, the user does not have to worry about the timers associated with the pins, however it is still recommended to use the pins that belong to the same timers.
It states that choosing pins that belong to the same timer is basically the only thing you have to worry about. But seemingly this is not true. Or am I wrong? Did I ommit this somewhere in the documentation?
If not, can someone please add this to the d.ocs :D? I think it would help a lot of inattentive people like myself
Lastly, can I work around this somehow (some kind of branch where this is supported)?
Are the TIM1,2,3 pins used for anything else? If not, BLDCDriver6PWM should work to get the timer running. The effect of PWM duty will be inverted from usual (lower commanded voltage will give higher voltage relative to system ground) but I don’t think it will cause any trouble. Unless you’re using lowside current sense, in which case I think it will trigger when the high mosfet is active.
I haven’t studied the timer registers enough to say whether it’s possible to run 3 inverted channels alone.
Dang. Well, you’re not 100% sunk yet. The current sense is only a matter of software, so if you change how it’s set up in the hardware_specific code, it will work.
Checking RM0008 chapter 14, register TIMx_CCER sounds like the inverted channel enable bits CCxNE are ignored if the corresponding positive channel CCxE is not enabled (EDIT: Actually maybe not… each of their descriptions says they depend on the state of the other). However, it may still be possible to configure the GPIO pin registers to have a different function, so those timer signals are active internally but not connected to the pins. But I’d be surprised if you can get Arduino/HAL to let you do it without spewing errors about the pins being in use by multiple peripherals. And doing the entire timer and current sense register setup yourself is probably more trouble than redesigning the board.
But even if we did support them I am not really sure that you can use the negated channels if the regular channels are used for something else
Do you already use the TIM1 for something else?
Or are just the pins taken?
I use STlink to upload and serial for communication while running, but only because I don’t know how to upload via serial or debug via STlink.
“as long as they’re not PWM generation” is incorrect. Using them for PWM generation together with PA8,9,10 is how you do 6PWM.
If you can live without USART1, and having PWM output on the fault pin doesn’t bother the DRV, then you can probably use it as-is with BLDCDriver6PWM like I said in my first post. Only the current sense timing will be wrong, and that’s probably a one-line fix (although I don’t know which line it is).
Yes, as long as you only need 3-PWM the negated pins won’t be used and you can use them for other things.
STLink is best for uploading code and debugging (with debugger), although serial can be used also for the purpose of upload. The STLink is more automatic, you don’t always have to hold the boot button to enter bootloader mode.
For Serial output, you also need a serial port. The STLink includes a serial TTL to USB function (VCP function) so if you connect your UART RX/TX to the STLink as well as the SWD then you get everything in one easy to use USB connection to the STLink.
Just another mistake to add to my “knowledge” collection :D. Regardless, to answer the additional questions… TIM1 pins are just “taken” (2 of them used as USART1 and the last one as general input to report some DRV8302 faults).
I can use other USART interfaces and reroute the PWM inputs of the driver to TIM1 pins just fine. Should be matter of 30 minutes.
So if I get it right, if I use for example PA8, PA9, PA10 (TIM1 channels 1, 2, 3 respectively), it is still fine to use the TIM1N pins PB13, PB14 and PB15 for other purposes as long as they’re not PWM generation?
I am unfortunately quite low on time (and definitely not skilled enough) to try and fix that myself in software. Still, thank you @dekutree64 for posting the alternative solutions. I will probably just take a minute of silence for the money I spent on this version and then redesign/reorder .
One more thing that comes to my mind before the redesign. Do you guys use STlink or just serial for uploading the code to STM32? Do serial prints work just as easily with STlink as they do with serial line?