Skip to main content
DKalm.1
Associate
January 27, 2020
Question

Configure GPIO on NUCLEO-L476RG without Cube MX

  • January 27, 2020
  • 4 replies
  • 1143 views

Hello,

i want to turn the Green USER LED on.

#include "stm32l4xx.h"
#include "stm32l4xx_nucleo.h"
			
 
int main(void)
{
		RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN;
		GPIOA->MODER |= GPIO_MODER_MODER5_0;
		GPIOA->ODR |= GPIO_ODR_OD5;
}

So i activated the clock for the Pin and setting the mode(Output) for the LED.

What  have i done wrong ?

thanks,

Dominik

This topic has been closed for replies.

4 replies

berendi
Principal
January 27, 2020

GPIO MODER registers are 0xFFFFFFFF after reset (check the register descriptions in the reference manual) to save some power if the pin is floating.

So the correct way is

GPIOA->MODER &= ~GPIO_MODER_MODER5_1;

or if you are not sure about the register state

GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER5) | GPIO_MODER_MODER5_0;

DKalm.1
DKalm.1Author
Associate
January 29, 2020

​Oh i see, thank you for your quick answer!

waclawek.jan
Super User
January 29, 2020

"Delay after an RCC peripheral clock enabling" erratum may apply, too, although it's not in the 'L4 errata (it's e.g. in the 'F4 errata).

JW

PS. What is "stm32l4xx_nucleo.h"?

DKalm.1
DKalm.1Author
Associate
January 30, 2020

Description from the stm32l4xx_nucleo.h file:

This file contains:

* - Configuration section that allows to select:

* - The STM32L4xx device used in the target application

* - To use or not the peripheral’s drivers in application code(i.e.

* code will be based on direct access to peripheral’s registers

* rather than drivers API), this option is controlled by

* "#define USE_HAL_DRIVER"