Pin configuration not working as expected

Hello Dears,

I have configured my pin A as an output ( push pull) but when I entered to debug mode and it is defined as an input (floating input) in peripherals.

Where can be the problem?
Thanks!

Just to be more specified : I have configured my GPIOA.5 as an output ( push pull) …

The reset value GPIO_CRL and GPIOC_CRH value are unchanged (See, the debug window, the value is 0x44444444). It seems like you have not enabled the clock for the GPIO port you have trying to configure.

1 Like

But I haven’t used any clock for the GPIO port I am trying to configure.

2 Likes

You have to first enable the clock for peripherals on ARM devices. Unlike in other microcontrollers, you have to enable the clock for peripherals which is disabled by default to reduce power consumption.

1 Like

Okay, I’ll go for it

3 Likes

Well, I didn’t find how to eneble the clock. I reviewed the way I configured my I/O and now my code is working well.

1 Like

@Administrator is right. You have to enable the GPIO clock in order to make it work. You have to use the RCC_AHB1ENR register to enable the clock.

RCC -> APB2ENR |= (1<<0); // Enable the GPIOA clock in a STM32F103C8 MCU

I don’t know how the GPIO in your STM works without enabling its clock. Are you using real hardware or any kind of simulator?

1 Like

@Prototype nce I am learning how to have a hand on the stm32f103rb from a online tutorial, the click Line hasn’t been explained yet.

Of course @Administrator is right and I didn’t know how to enable the clock. Now I have just guessed from your code.

By the Way, in order to enable de clock on stm32f103rb: RCC->APB2ENR |= RCC_APB2ENR_IOPAEN ;

1 Like

I did a mistake in my previous code.

In order to enable the clock for the GPIOA port, the second bit has to be set instead of the zeroth bit.
To enable the clock, use RCC -> APB2ENR |= (1<<2);

RCC_APB2ENR_IOPAEN is just a macro definition. You can find the definition in the device header file stm32f10x.h.

If you take a closer look at the stm32f10x.h header file, you can see,
`#define RCC_APB2ENR_IOPAEN ((uint32_t)0x00000004).

2 Likes

Just to come back on your question concerning this :

I don’t know how the GPIO in your STM works without enabling its clock. Are you using real hardware or any kind of simulator?

As a beginner using NUCLEO board and whatching tutorials, There are some lines that have not been explained yet. But what is sure it does work. I will let you know when I am sure on how to enable the clock by using my microcontroller .

2 Likes