2020-01-27 06:07 AM
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
2020-01-27 06:51 AM
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;
2020-01-29 01:28 AM
Oh i see, thank you for your quick answer!
2020-01-29 02:23 AM
"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"?
2020-01-30 07:14 AM
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"