How to change GPIO parameters from OUTPUT to PWM, and vice versa?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 1: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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 6:26 AM
You miss which AF mux value​ it should associate with the pin(s)
​
P​SC and ARR are N-1 comparators.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 2: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 3:15 AM
Hi, Jan.
It doesn't work.
But thank you for your answer.
Kind regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 3: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 5: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 6: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 6:26 AM
You miss which AF mux value​ it should associate with the pin(s)
​
P​SC and ARR are N-1 comparators.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 8: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 7: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 11:02 PM
Found this place, thank you.
