cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4xx: PD2 cannot use it as GPIO

enrico23
Associate
Posted on November 10, 2016 at 09:58

Hello all,

I have a problem that driving me crazy. I'm using STM32F446 with case LQFP64. I'm not able to use PD2 as output digital even if with others PIN I can do it (PC0, PC1, PC2, ...). This is my code to set PD2 as general GPIO output:

// LedS - Red

GPIOD->MODER   = (GPIOD->MODER  & 0xFFFFFFCF) | 0x00000010U;

GPIOD->OTYPER  = (GPIOD->OTYPER & 0xFFFFFFCF);

GPIOD->OSPEEDR = (GPIOD->OSPEEDR & 0xFFFFFFCF) | 0x00000030U;

GPIOD->PUPDR = (GPIOD->PUPDR & 0xFFFFFFCF);

GPIOD->ODR = (GPIOD->ODR & 0xFFFFFFFB);

I've attached a LED to this pin, then I try to switch on the led in this way:

GPIOD->BSRR = 0x00000010U;

Where I'm wrong ? Please help me.

Thanks and regards,

Enrico.

#gpio #stm32f4xx
2 REPLIES 2
troy1818
Senior
Posted on November 10, 2016 at 10:08

Did you activate the clock for GPIO port D ?

And should it not be 

GPIOD->BSRR = 0x00000004U;

e.g.

(1 <<2)
Posted on November 10, 2016 at 11:53

> GPIOD->OTYPER  = (GPIOD->OTYPER & 0xFFFFFFCF);

This is wrong, too, as OTYPER is one bit per pin. Although of no consequence here as the reset value is zero anyway.

It's better to use the predefined constants from the basic CMSYS device header, e.g.

GPIOD->OTYPER  = (GPIOD->OTYPER & (~GPIO_OTYPER_OT_2));

GPIOD->BSRR = GPIO_BSRR_BS_2;

etc.

JW