2022-02-07 01:53 AM
Hi, everyone, I have the next problem, I am using the same pins like a simple GPIO output, and like a PWM output.
To change the output from PWM to GPIO i using this code:
GPIO_InitTypeDef gpio;
gpio.Pin = GPIO_PIN_0|GPIO_PIN_1;
gpio.Mode = GPIO_MODE_OUTPUT_PP;
HAL_GPIO_Init(GPIOB, &gpio);
But, how to return PWM initialization?
Solved! Go to Solution.
2022-02-07 06:26 AM
You miss which AF mux value it should associate with the pin(s)
PSC and ARR are N-1 comparators.
2022-02-07 02:42 AM
I don't use Cube/HAL, but probably by using GPIO_MODE_AF_PP?
In reality you only need to change the bitfield which belongs to given pin in GPIO_MODERx register from 0b01 to 0b10.
JW
2022-02-07 03:15 AM
Hi, Jan.
It doesn't work.
But thank you for your answer.
Kind regards
2022-02-07 03:44 AM
What doesn't work? What did you do, and what are the results?
If PWM does not work, read out the TIM and relevant GPIO registers content and check/post.
Also, which STM32?
JW
2022-02-07 05:37 AM
Maybe i do something wrong, but i use the next code:
GPIO_InitTypeDef gpio;
gpio.Pin = GPIO_PIN_0|GPIO_PIN_1;
gpio.Mode = GPIO_MODE_AF_PP;
HAL_GPIO_Init(GPIOB, &gpio);
//MX_TIM8_Init();
TIM8->ARR=1023;
TIM8->PSC=500;
TIM8->CCR2=x;
Maybe i need to re-write some parameters?
Because, when i use this code in one of the int:
GPIO_InitTypeDef gpio;
gpio.Pin = GPIO_PIN_0|GPIO_PIN_1;
gpio.Mode = GPIO_MODE_OUTPUT_PP;
HAL_GPIO_Init(GPIOB, &gpio);
Need to reset the board, to enable pwm output.
2022-02-07 06:21 AM
> GPIO_InitTypeDef gpio;
> gpio.Pin = GPIO_PIN_0|GPIO_PIN_1;
> gpio.Mode = GPIO_MODE_AF_PP;
> HAL_GPIO_Init(GPIOB, &gpio);
Fill in *all* fields of the gpio struct, not just .Pin and .Mode.
If this won't help, read out and check/post content of *all* GPIOB and TIM8 registers.
JW
2022-02-07 06:26 AM
You miss which AF mux value it should associate with the pin(s)
PSC and ARR are N-1 comparators.
2022-02-07 08:07 AM
Thank you, for your answer, could you say how to check which AF I need to use?
Because previously never used before this function.
2022-02-07 07:09 PM
Configure the mode and af gpio field, under interrupt temporary disabled to avoid side effect. Then change dynamically. Remember to save the primask, change bit fields, restore. So the code also works under interrupts.
2022-02-07 11:02 PM
Found this place, thank you.