cancel
Showing results for 
Search instead for 
Did you mean: 

How to set unused gpio pins to analog input in code?

ATahi.1
Associate II

It is recomanded to set unused pins to analog input.

1 ACCEPTED SOLUTION

Accepted Solutions

In STM32L0xx, pins are set to Analog by default after reset, you don't need to do anything else. See GPIOx_MODER description in GPIO chapter of the RM.

JW

View solution in original post

3 REPLIES 3

Which STM32?

If those which don't have this by default after reset, maybe the easiest is to set all fields in GPIOx_MODER to Analog for all GPIOx, before any other GPIO setup. Of course, the GPIOx clocks have to be enabled in RCC before that. Make sure the SWD pins are not changed, if debugging ought to remain usable.

JW

ATahi.1
Associate II

@Community member​  Thanks for the answer. I am using STM32L072RZ.

If I want to set all the 16 pins for port A to analog input is this possible to do in this way:

GPIOA->MODER = GPIO_MODE_ANALOG;

In STM32L0xx, pins are set to Analog by default after reset, you don't need to do anything else. See GPIOx_MODER description in GPIO chapter of the RM.

JW