cancel
Showing results for 
Search instead for 
Did you mean: 

Configure GPIO on NUCLEO-L476RG without Cube MX

DKalm.1
Associate II

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

4 REPLIES 4
berendi
Principal

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
Associate II

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

"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"?

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"