# STM32F103CB use of "inverted" timers

**URL:** https://community.simplefoc.com/t/stm32f103cb-use-of-inverted-timers/7436
**Category:** hardware support
**Tags:** timers, pinout, stm32
**Created:** [July 15, 2025, 1:01pm UTC](https://community.simplefoc.com/t/stm32f103cb-use-of-inverted-timers/7436 "2025-07-15T13:01:57Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Papouc](https://community.simplefoc.com/user_avatar/community.simplefoc.com/papouc/32/7467_2.png) [@Papouc](https://community.simplefoc.com/u/Papouc)
#### Post date: [July 15, 2025, 1:01pm UTC](https://community.simplefoc.com/t/stm32f103cb-use-of-inverted-timers/7436/1 "2025-07-15T13:01:57Z")

</div>

Hello everyone,

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:

```auto
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)?

Thanks,

Adam

---

<div class="post-metadata">

### Author: ![dekutree64](https://community.simplefoc.com/user_avatar/community.simplefoc.com/dekutree64/32/3398_2.png) [@dekutree64](https://community.simplefoc.com/u/dekutree64)
#### Post date: [July 15, 2025, 1:17pm UTC](https://community.simplefoc.com/t/stm32f103cb-use-of-inverted-timers/7436/2 "2025-07-15T13:17:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dekutree64](https://community.simplefoc.com/user_avatar/community.simplefoc.com/dekutree64/32/3398_2.png) [@dekutree64](https://community.simplefoc.com/u/dekutree64)
#### Post date: [July 15, 2025, 2:06pm UTC](https://community.simplefoc.com/t/stm32f103cb-use-of-inverted-timers/7436/4 "2025-07-15T14:06:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Antun\_Skuric](https://community.simplefoc.com/user_avatar/community.simplefoc.com/antun_skuric/32/21_2.png) [@Antun\_Skuric](https://community.simplefoc.com/u/Antun_Skuric)
#### Post date: [July 15, 2025, 2:14pm UTC](https://community.simplefoc.com/t/stm32f103cb-use-of-inverted-timers/7436/5 "2025-07-15T14:14:12Z")

</div>

Oh man!

Sorry about that, I’ll put that in the docs. We never really got to this. We have discussed it several times to add the inverted channels but not yet.  
We had a short discussion on this here: [[ENHANCEMENT] (STM32) BLDCDriver3PWM driver can't use negated PWM outputs · Issue #220 · simplefoc/Arduino-FOC · GitHub](https://github.com/simplefoc/Arduino-FOC/issues/220)

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?

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [July 15, 2025, 2:14pm UTC](https://community.simplefoc.com/t/stm32f103cb-use-of-inverted-timers/7436/6 "2025-07-15T14:14:16Z")

</div>

I’m sorry to say that we don’t support the negated channels in 3PWM at the moment.

Technically it would be possible, I believe.

I’m sorry the STM32 timers are so confusing. I take note of your suggestion to improve the docs.

---

<div class="post-metadata">

### Author: ![dekutree64](https://community.simplefoc.com/user_avatar/community.simplefoc.com/dekutree64/32/3398_2.png) [@dekutree64](https://community.simplefoc.com/u/dekutree64)
#### Post date: [July 15, 2025, 4:44pm UTC](https://community.simplefoc.com/t/stm32f103cb-use-of-inverted-timers/7436/8 "2025-07-15T16:44:36Z")

</div>

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.

> [@Papouc](#):
>
> 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?

“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).

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [July 16, 2025, 7:41am UTC](https://community.simplefoc.com/t/stm32f103cb-use-of-inverted-timers/7436/9 "2025-07-16T07:41:40Z")

</div>

> [@Papouc](#):
>
> 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?

Yes, as long as you only need 3-PWM the negated pins won’t be used and you can use them for other things.

> [@Papouc](#):
>
> 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?

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.

---

<div class="post-metadata">

### Author: ![Papouc](https://community.simplefoc.com/user_avatar/community.simplefoc.com/papouc/32/7467_2.png) [@Papouc](https://community.simplefoc.com/u/Papouc)
#### Post date: [July 15, 2025, 1:23pm UTC](https://community.simplefoc.com/t/stm32f103cb-use-of-inverted-timers/7436/3 "2025-07-15T13:23:04Z")

</div>

Unfortunately, all the TIM1 pins are used for something else + I really need to use the low side sensing. So this is not really an option for me.

---

<div class="post-metadata">

### Author: ![Papouc](https://community.simplefoc.com/user_avatar/community.simplefoc.com/papouc/32/7467_2.png) [@Papouc](https://community.simplefoc.com/u/Papouc)
#### Post date: [July 15, 2025, 3:13pm UTC](https://community.simplefoc.com/t/stm32f103cb-use-of-inverted-timers/7436/7 "2025-07-15T15:13:11Z")

</div>

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?

Thanks for all the help 😃!
