Skip to main content

Command Palette

Search for a command to run...

What does LD3 and LD1 do on a STM32 Nucleo?

Published
4 min read
What does LD3 and LD1 do on a STM32 Nucleo?

LD1 and LD3 are user LEDs on the Nucleo board, but they serve two very different primary purposes.

Here’s a detailed breakdown:


LD1: The System Status / Communication LED

Color: Green

This is the more complex of the two LEDs. Its behavior is controlled by the ST-LINK/V2-1 interface MCU (the chip that handles programming and USB communication), not by your main STM32 target microcontroller.

Its primary roles are:

  1. USB Communication Indicator: It blinks during data transfer between the PC and the ST-LINK part of the board.

  2. ST-LINK Status: It indicates the status of the debugger/programmer.

  3. User-Controllable (after configuration): Once you program your main STM32, you can often take control of this LED for your own purposes.

Common Default Behaviors (before you program anything):

  • Rapid Blinking: The board is powered, but the ST-LINK is not connected to the PC via USB.

  • Continuous On: The ST-LINK is connected to the PC and has been recognized by the OS (e.g., the ST-LINK drivers are installed correctly).

  • Slow Blinking: Data is being transferred over USB (e.g., during programming or when using the Virtual COM Port).

How to Use it in Your Code:
In your firmware, the pin for LD1 is often defined as LED_GREEN or similar. However, it is not connected to a standard GPIO pin of your main STM32. It is connected to a pin that is shared with the SB13 solder bridge.

  • To control LD1 from your main STM32 code, you must ensure the SB13 solder bridge is closed (which it is by default on most boards). This connects the LED to pin PB0 (or PA5 on some older boards).

  • You can find the exact pin in the board-specific header file (e.g., #include "stm32f4xx_nucleo.h") or by checking your board's user manual.

Example Code (STM32CubeIDE):

c

// After initializing the HAL, you can control it.
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET); // Turn LD1 ON
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); // Turn LD1 OFF
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0); // Toggle LD1

LD3: The User LED

Color: Red (sometimes Orange/Yellow on newer boards)

This LED is much simpler. It is directly connected to a GPIO pin of your main STM32 target microcontroller and is intended for you, the user, to control in your application.

Its primary role is:

  • General-Purpose Indicator: Use it to blink a heartbeat, signal an error, indicate a state in your program, or for simple debugging.

Common Connection:

How to Use it in Your Code:
This is the LED you will use most often for learning and debugging. It's straightforward to control.

Example Code (STM32CubeIDE):

c

// Inside main.c, typically in the main loop
while (1) {
  HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); // Toggle LD3
  HAL_Delay(500); // Wait 500 ms
  /* Your application code here */
}

Using the STM32CubeMX Auto-Generated Code:
If you use STM32CubeMX to generate your initialization code, you can:

  1. Find the pin PA5 in the pinout view.

  2. Set it to GPIO_Output.

  3. Give it a user-friendly label like "USER_LED".

  4. Generate the code. The pin will be initialized, and you can use the HAL_GPIO functions to control it.


Summary Table

FeatureLD1 (Green)LD3 (Red)
Primary RoleSystem/ST-LINK StatusUser Application LED
Controlled ByST-LINK MCU (by default)Main STM32 Target MCU
ColorGreenRed / Orange
Default ConnectionPB0 (or PA5) via solder bridgePA5 (direct connection)
Ease of UseRequires checking solder bridgeVery Easy (plug & play)
Typical Use CaseMonitoring USB communication, advanced user controlBlinking, debugging, program status

Practical Advice for Beginners

  1. Start with LD3 (the Red one): When you are writing your first "Blink" program, use LD3. It's simpler and guaranteed to work without any hardware configuration checks.

  2. Use LD1 for more advanced status: Once you are comfortable, you can use LD1 as a second status indicator in your application, but always double-check the solder bridge settings for your specific board.

  3. Check your Board's User Manual: The exact pins for LD1 and LD3 can vary slightly between different Nucleo models (e.g., Nucleo-F0, F1, F4, H7). Always consult the "User Manual" (UM) for your specific Nucleo board for the definitive information. You can find this on the STMicroelectronics website.

So, in your code, LD3 is your best friend for simple feedback and debugging.

More from this blog

A

Ampheo Electronic Blog-Chip and component knowledge sharing

181 posts

Original and Genuine Electronic Components Distributor