Electronic – STM32 GPIO Clock

stm32

Why do we need to ENABLE a GPIO pheripheral's clock by RCC_AHB register while we are using of that GPIO's pins as an another Peripheral(e.g. ADC) Input/Output pin(Alternate Function)?

For instance for STM32F407 ADC1, it has its own clock that can be enabled through RCC_APB register and then it can samples the data present on the pin by its inside defined clock and prescaler.

So i think there is no need to enable the GPIO's Clock when we are using of that GPIO's pins as ADC peripheral input(Alternate Function Mode), but the problem is ADC doesn't do its job when i don't ENABLE the GPIO's Clock.

So the question is what is the job of GPIO clock generally?

Best Answer

The GPIO peripheral is a peripheral just like UART or Timer, it needs a clock to be able to respond to register reads and writes.

If you use a GPIO pin as an alternate functionality pin for a peripheral like UART, it still needs a clock to sample the physical IO pin for the UART to be synchronized with the system clock without metastability.

And if you use the pin as analog input for ADC, you should not need a GPIO clock for that - but you need it if you want to configure the GPIO pin for analog only input for best analog results.