Skip to main content
Visitor
July 10, 2026
Solved

Struggling to set pins to high on NucleoF411RE

  • July 10, 2026
  • 2 replies
  • 51 views

EDIT: Solved. It seems to just be that one pin that isn’t working. I tried a couple other ones and they work fine.


Hello, sorry if this is a silly question, but I'm pretty new to all of this. I've recently picked up Israel Gbati's Bare-Metal Embedded C Programming. It gives a step-by-step walkthrough on how to turn on an LED using pin D12/PA5, but I'm struggling to connect to any of the other pins.

I've been trying to connect my LED to pin D0/PA3. My code is below.

#define PERIPH_BASE            (0x40000000UL)
#define AHB1PERIPH_OFFSET (0x00020000UL)
#define AHB1PERIPH_BASE (PERIPH_BASE + AHB1PERIPH_OFFSET)
#define GPIOA_OFFSET (0x0000UL)
#define GPIOA_BASE (AHB1PERIPH_BASE + GPIOA_OFFSET)
#define RCC_OFFSET (0x3800UL)
#define RCC_BASE (AHB1PERIPH_BASE + RCC_OFFSET)
#define AHB1EN_R_OFFSET (0x30UL)
#define RCC_AHB1EN_R (*(volatile unsigned int *) (RCC_BASE + AHB1EN_R_OFFSET))
#define MODE_R_OFFSET (0x00UL)
#define GPIOA_MODE_R (*(volatile unsigned int *) (GPIOA_BASE + MODE_R_OFFSET))
#define OD_R_OFFSET (0x14UL)
#define GPIOA_OD_R (*(volatile unsigned int *) (GPIOA_BASE + OD_R_OFFSET))
#define GPIOAEN (1U<<0)
#define PIN3 (1U<<3)
#define LED_PIN PIN3
int main(void)
{
// Enable clock access to GPIOA
RCC_AHB1EN_R |= GPIOAEN; //Set bit |=
GPIOA_MODE_R |= (1U << 6); // Set bit 6 to 1
GPIOA_MODE_R &= ~(1U << 7); // Set bit 7 to 0
// Blink LED
while(1) {
GPIOA_OD_R ^= LED_PIN;
for (int i=0; i<1000000; i++){}
}
}

I’ve only altered lines 15, 21, and 22 from the given example in the book (which works perfectly). 

the original lines are

#define PIN5                (1U<<5)

and

GPIOA_MODE_R |= (1U << 10);    // Set bit 10 to 1
GPIOA_MODE_R &= ~(1U << 11); // Set bit 11 to 0

I've been searching through the documentation but nothing has stood out to me. I figure that I've made some silly little beginners mistake and someone here would be able to catch it. Does anyone know what I've done wrong?

 

 

Best answer by Maxime MARCHETTO

EDIT: Solved. It seems to just be that one pin that isn’t working. I tried a couple other ones and they work fine.

 

Hello ​@Simons6209  I’m marking your edit as the solution to help increase its visibility.

Best,
Maxime

2 replies

Andrew Neil
Super User
July 10, 2026

EDIT: Solved. 

Rather than edit the opening post, it would be more helpful to put that in a Reply, and then mark that reply as the solution.

 

It seems to just be that one pin that isn’t working. I tried a couple other ones and they work fine.

Did you check the User Manual and/or schematics to see if that pin is actually used for something on the board?

 

 

https://www.st.com/resource/en/user_manual/um1724-stm32-nucleo64-boards-mb1136-stmicroelectronics.pdf#page=29

via: https://www.st.com/en/evaluation-tools/nucleo-f411re.html#documentation

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Maxime MARCHETTO
Maxime MARCHETTOBest answer
ST Community Manager
August 26, 2026

EDIT: Solved. It seems to just be that one pin that isn’t working. I tried a couple other ones and they work fine.

 

Hello ​@Simons6209  I’m marking your edit as the solution to help increase its visibility.

Best,
Maxime

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.