How can I switch between output and alternative function modes in an STM?

Hi everyone, Please how can I switch between output and alternative function modes in an STM microcontroller? For example, if I initially configure GPIOA_Pin0 as a digital output and later in the same program want to use it to send data via USART2, what steps are necessary to switch the pin configuration? @Middleware & OS
8 Replies
ZacckOsiemo
ZacckOsiemo6mo ago
Just set it up again, assuming you dont need it for the digital out anymore
electro_coco
electro_coco6mo ago
You have to write your own drivers then de init the pin and re init it for usart
ZacckOsiemo
ZacckOsiemo6mo ago
A plus would be a driver that can start from un known known state and set them up
ZacckOsiemo
ZacckOsiemo6mo ago
usually this just involves using the RSTR registers
ZacckOsiemo
ZacckOsiemo6mo ago
Do they really need to write their own drivers? the hal should let them reset and set up the pin as they wish. Admittedly I haven't use the HAL much so I may be wrong
electro_coco
electro_coco6mo ago
I think they are using the cube ide to setup pins otherwise they would have realized that they can wrap hal around their own functions
ZacckOsiemo
ZacckOsiemo6mo ago
Yeah code generation confuses me so much. Anyways @Sterling what you are trying is possible and rather straight forward. regardless of the approach you are using.
undefined.elf
undefined.elf5mo ago
you can follow few steps 1. Keep the GPIO Active and change the gpio configuration according to your needs 2. Reset The peripherals using RCC RSTR registers as @ZacckOsiemo said but make sure to do that in the super loop so that the mode can be changed when they neeed also if you see it is not working perfectly then can add a bit of delay since switching configurations can take a bit of time
Want results from more Discord servers?
Add your server