cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 - How do I switch a pin from ADC to normal GPIO mode?

mwp
Senior

Greetings all,

I'm using the HAL libs to set a couple of pins for ADC use (one-shot).

Later on during fw execution, i need to flip some of these pins back to normal GPIO mode.

How do I do this?

I've been looking over the programming manual, and HAL/LL library source for a few hours now, and haven't been able to see anything that will let me do so.

Thanks in advance.

2 REPLIES 2
TDK
Guru

The HAL_GPIO_Init function is used to initialize/reinitialize pins.

If you feel a post has answered your question, please click "Accept as Solution".
Mohamed Aymen HZAMI
ST Employee

Hello,

You can change the mode state of the GPIO in GPIOx_MODER register in section "8.4.1 GPIO port mode register (GPIOx_MODER) (x = A..I/J/K)".

Also you can use the GPIO_InitTypeDef, this is a GPIO Initialization structure definition contain all the needed details of each GPIO Pin.

this is an example on how use this structure :

GPIO_InitTypeDef  GPIO_InitStruct;  
 
  GPIO_InitStruct.Mode  = GPIO_MODE_OUTPUT_PP; // Specifies the operating mode for the selected pin
  GPIO_InitStruct.Pull  = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
 
  GPIO_InitStruct.Pin = GPIO_PIN_1;//Specifies the GPIO pins to be configured
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);  //Initializes the GPIOA peripheral according to the specified parameters in the HAL_GPIO_Init

Best Regards,

Mohamed Aymen.