6 years, 3 months ago.

Can't get LED to turn on on STM32 nucleo board with STM32F446RE MCU

Hello,

I'm just learning STM programming. I bought a STM32F446RE board and I'm trying to light up an LED connected to port D12.

My IDE is Keil uVision 5.

What have I done: - created new project and selected device for target: 'STM32F446/STM32F446RETx'. I'm assuming this is my board but I'm not sure because of the 'Tx' at the end mine is named simply 'STM32F446RE' - at manage run-time envioroment I have checked 'Startup' to have my startup code initialised - when creating the project when I was asked about my oscillator value I have selected 8Mhz

- I have written the following code:

[code]#include <stdint.h>

  1. include "stm32f4xx.h"
  2. define RCC_AHB1ENR_OFFSET 0x30
  3. define RCC_BASE_ADDR (0x40023800)
  4. define RCC_AHB1ENR_ADDR *( (volatile unsigned long *)(RCC_BASE_ADDR + RCC_AHB1ENR_OFFSET) )
  1. define GPIOD_MODER_OFFSET 0x00
  2. define BASE_ADDR_GPIOD (0x40020C00)
  3. define GPIOD_MODER *( (volatile unsigned long *)(BASE_ADDR_GPIOD + GPIOD_MODER_OFFSET) )
  4. define OFFSET_OF_OUTPU_DATA_REG 0x14
  5. define GPIOD_OPDATAREG *( (volatile unsigned long *)(BASE_ADDR_GPIOD + OFFSET_OF_OUTPU_DATA_REG) ) int main(void) { 1. Enable the clock for GPIOD port RCC_AHB1ENR_ADDR |= (1<<3); bit 3 enables the clock for GPIOD port

2. Configure the GPIO PIN to output mode using MODE register GPIOD_MODER |= ( 1 << (12 * 2) ); set 24th and 25th bit to 0x01 to make 12pin output

3. use the DATA REGISTER of GPIOD port to write to or read from LED GPIOD_OPDATAREG |= (1<<12); turn the led on

return 0; }[/code]

As you can see I tried making the port as output then turn it on. However when I flash this the LED stays off :( I have connected the LED in this way: The anode to the output of PORTD12 of the microcontroller and the cathode to a 'GND' on the board. The led works I have tested it by connecting it to '5v' and 'GND' of the board. So there must be a problem with my code or my setup.

Thank you for reading! Please, if possible, help me identify and correct the problem. Thank you!

I have uploaded a picture of how I have connected the LED: [IMG]http://i65.tinypic.com/2s6mwz5.jpg[/IMG]

1 Answer

6 years, 3 months ago.

You're at the Mbed forums here. The NUCLEO-F446RE is a supported Mbed platform, so it's probably easier to use Mbed rather than raw STM32 SDK.

To run blinky on D12, do the following:

  1. Go to the NUCLEO-F446RE platform page.
  2. Click *Add to your Mbed compiler*.
  3. Go to mbed-os-example-blinky project page and click *Import into Compiler*.
  4. In the compiler import the project and verify that NUCLEO-F446RE is selected as platform (top right corner).
  5. In main.cpp change LED1 to D12.
  6. Click *Compile*.

Drag the file to your dev board (mounted as USB drive) to flash the application.

To export to uVision from here, right click on the project in Online Compiler, select *Export > uVision 5*. After that you'll have uvproj file that you can load into uVision. This will have all clock configuration, pin configuration and startup already configured correctly for the F446RE.