Page 1 of 1

How to set OUTPUT_OPEN_DRAIN with HardwareTimer?

Posted: Fri Jul 07, 2023 11:40 am
by leonzhao101
Hi, I have searched for hours but could not find a solution to this issue.

I am using a STM32F103 board (blue pill) and I need to output a few channels of 5V PWM signals. I have learned to use the HardwareTimer library to output PWM signals, but they are only 3.3V. I have read on other posts that this can be achieved by setting the pinmode to OUTPUT_OPEN_DRAIN and using additional pull-up resistors. But since the pin configuration is handled by the HardwareTimer library, I could not find a way to set pinmode myself.

The only walkaround I can find so far is to use "software PWM" instead of hardware PWM, as shown in this example:
https://github.com/stm32duino/STM32Exam ... ration.ino

But it does not seem to be the best solution...

Any suggestions? Many thanks!!

Re: How to set OUTPUT_OPEN_DRAIN with HardwareTimer?

Posted: Fri Jul 21, 2023 9:47 am
by fpiSTM
Hi @leonzhao101
Right, we set by default to PP with PULLUP
https://github.com/stm32duino/Arduino_C ... Pins.c#L87

You can simply redefine this array at sketch level to change the default behavior:
https://github.com/stm32duino/Arduino_C ... nmap-array

Code: Select all

const PinMap PinMap_TIM[] = {
  {PA_0,       TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_OD, GPIO_NOPULL, AFIO_NONE, 1, 0)}, // TIM2_CH1
...
  {NC,         NP,   0}
};