• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Unable to Turn on Pins of STM32F446RE


New Member

I have written the below code for my STM32F446RE Nucleo board. All I am trying to do is turn on Pin PA3, Pin PA2 and onboard LED Pin PA5. The code compiled and flashed successfully. But no success in turning on LED pins except onboard LED Pin PA5. I don't know why Pin PA3 and Pin PA2 is off?? Am I missing any register?? Need some help guys.

// Enable clock access to the port.

// Set pin mode

// Set pin as o/p

#include "stm32f4xx.h"                           // Device header

#define RED                       (1U << 3)      // PIN PA3

#define VIOLET                    (1U << 2)      // PIN PA2

#define GREEN                     (1U << 5)      // PIN PA5 Onboard LED

#define GPIOA_CLOCK               (1U << 0)

#define RED_OUT_BIT               (1U << 6)      // General purpose output

#define VIOLET_OUT_BIT            (1U << 4)      // General purpose output

#define GREEN_OUT_BIT             (1U << 10)     // General purpose output

int main() {




    while(1) {

        GPIOA -> ODR |= RED | VIOLET | GREEN;



Thank You

Nigel Goodwin

Super Moderator
Most Helpful Member
I can't say I know anything about your board or processor?, but for a 32 bit device you don't appear to be setting anything much up.

Even 8 bit modern PIC's have a plethora of settings you need to do to make them work at all - and I presume an STM32 will have even more (the Arduino IDE hides them, so you don't know they are there if you use the Arduino IDE).


New Member
I am not using Arduino. I am using Keil MDK for my development. Most of the setting is taken care of by Keil. MCU has an internal RC oscillator clocked at 16MHz. The default clock for the MCU is the internal RC oscillator. I have already enabled clocked for port GPIOA.


All the three pins change its sate in debug mode, but only the onboard LED turns on. LEDs connected to Pin PA3 and Pin PA2 is off.

Nigel Goodwin

Super Moderator
Most Helpful Member
I am not using Arduino. I am using Keil MDK for my development.
Which is your problem - the Arduino IDE makes it simple as everything is already done for you - looks like Keil isn't so friendly?.

Aren't there any Keil examples you could look at? - the classic 'hello world' type program is the usual starting point (called Blink on Arduino) which is what you're trying to do, surely there's a similar Keil example?.

Latest threads

EE World Online Articles