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?


1 Answer 1


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.

  • \$\begingroup\$ I think reading and writing a peripheral register is independent from the GPIO registers and clock. \$\endgroup\$ Jan 14, 2019 at 14:22
  • 2
    \$\begingroup\$ @Amin what you think how it works may be irrelevant. I am quite sure you must use the RCC to enable a peripheral clock to a peripheral you want to use before you can use it, and GPIO ports are peripherals with no exceptions. The clock tree system is described in chip datasheets and reference manuals. \$\endgroup\$
    – Justme
    Jan 14, 2019 at 15:21
  • 1
    \$\begingroup\$ for logic to work you need it out of reset and clocked. These clocks can be gated in the same way you keep someone out of your yard with a gate. If the clock is gated that reduces state changes in the block and reduces power, so in an mcu the peripheral clocks often power up in a gated state. If the logic block is gated then it cannot and will not answer the processor when a request is made so either you get a timeout on the bus and a bogus response or you hang the processor (or additional logic results in a data abort, etc). \$\endgroup\$
    – old_timer
    Jan 14, 2019 at 15:44
  • 2
    \$\begingroup\$ the gpio block is logic that manages those pins, it has registers, it may seem simple compared to a uart, but it still has clocked logic. in order to change a control register there need to be clocks driving the logic block that receives those reads or writes from the processor to manage those control registers. \$\endgroup\$
    – old_timer
    Jan 14, 2019 at 15:52
  • 3
    \$\begingroup\$ The more interesting question would be if you can disable the GPIO clock after configuring the pin function \$\endgroup\$ Jan 15, 2019 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.