[Solved] Can't remap Timer3 to PB4 on BluePill
Posted: Wed Dec 28, 2022 1:22 pm
I've tried everything I can think of. I'm not good at locating non-Arduino functions in the Maple library, so I do a bit of direct register manipulation (using defines and enums from the library). I have timer3 running as output compare, and its generating a square wave on PA6 (T3C1). I want to move this to PB4 which is 5V tolerant because I'm controlling a stepper driver which requires at least 4 Volts. I want to run PB4 as open drain.
Here is what I've tried:
RCC_BASE->APB2ENR |= 1; //enable the alternate function IO clock
AFIO_BASE->MAPR |= AFIO_MAPR_TIM3_REMAP_PARTIAL; //remap T3C1 and T3C2 to pins PB4 and PB5
GPIOB_BASE->CRL |= (GPIO_AF_OUTPUT_OD << 16); //Set PB4 as AF output open-drain, max speed 50 MHz.
what am I missing here?
I'm not calling the pinMode routine for PB4, as I'm not sure how to set it up for a remapped alternate function output with open drain.
The PINOUT diagram for BluePill indicates that PB4 is NOT a PWM pin, so I don't think "pinMode(PB4, PWM)" is the answer. Besides, I've tried it.
I've also checked to make sure the AF clock for other peripherals (SPI1) which share PB4 are not enabled.
I'm confused by how the STM32 RefManual refers to Alternate Function vs a Remapped Alternate Function.
HELP?....
Here is what I've tried:
RCC_BASE->APB2ENR |= 1; //enable the alternate function IO clock
AFIO_BASE->MAPR |= AFIO_MAPR_TIM3_REMAP_PARTIAL; //remap T3C1 and T3C2 to pins PB4 and PB5
GPIOB_BASE->CRL |= (GPIO_AF_OUTPUT_OD << 16); //Set PB4 as AF output open-drain, max speed 50 MHz.
what am I missing here?
I'm not calling the pinMode routine for PB4, as I'm not sure how to set it up for a remapped alternate function output with open drain.
The PINOUT diagram for BluePill indicates that PB4 is NOT a PWM pin, so I don't think "pinMode(PB4, PWM)" is the answer. Besides, I've tried it.
I've also checked to make sure the AF clock for other peripherals (SPI1) which share PB4 are not enabled.
I'm confused by how the STM32 RefManual refers to Alternate Function vs a Remapped Alternate Function.
HELP?....