cancel
Showing results for 
Search instead for 
Did you mean: 

How to dynamically reassign the pin?

DK.7
Senior

Originally, I configured PB6 to work with OneWire using DMA! However, after some time, I need to use the same pin for operating an LED!
Below are the steps to reset the pin settings to default.
1. Stopping all processes associated with using DMA on pin PB6

void stopDMAProcesses() {
// Deinitialize the DMA channel associated with pin PB6
HAL_DMA_DeInit(&hdma_spi1_rx);
}

2. Releasing all resources of pin PB6 associated with the OneWire protocol
void releaseOneWireResources() {
// Turning off the timer used for OneWire protocol time slots
HAL_TIM_Base_Stop(&htim2);
// Releasing the corresponding pin control registers
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6);
// Releasing the memory allocated for DMA
HAL_DMA_DeInit(&hdma_tim2_ch1);
}
The following are the steps for configuring the pin to work with an LED.
Would this be sufficient to reassign the pin for operating an LED later on?

2 REPLIES 2

What about to just simply change pin mode from "alternate" to "output" (and back then) ?

TDK
Guru

Technically all you need is to re-initialize the pin as output with HAL_GPIO_Init. You can keep DMA going in the background, or in its current state, whatever it is.

If and when you switch back to OneWire, you just need another HAL_GPIO_Init to re-assign it back to what it was, which looks like alternate function SPI.

If you feel a post has answered your question, please click "Accept as Solution".