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:
USB Communication Indicator: It blinks during data transfer between the PC and the ST-LINK part of the board.
ST-LINK Status: It indicates the status of the debugger/programmer.
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(orPA5on 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:
- On most Nucleo boards (like Nucleo-F103RB, Nucleo-F411RE, etc.), LD3 is connected to pin PA5. This is a standard GPIO pin.
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:
Find the pin
PA5in the pinout view.Set it to
GPIO_Output.Give it a user-friendly label like "USER_LED".
Generate the code. The pin will be initialized, and you can use the
HAL_GPIOfunctions to control it.
Summary Table
| Feature | LD1 (Green) | LD3 (Red) |
| Primary Role | System/ST-LINK Status | User Application LED |
| Controlled By | ST-LINK MCU (by default) | Main STM32 Target MCU |
| Color | Green | Red / Orange |
| Default Connection | PB0 (or PA5) via solder bridge | PA5 (direct connection) |
| Ease of Use | Requires checking solder bridge | Very Easy (plug & play) |
| Typical Use Case | Monitoring USB communication, advanced user control | Blinking, debugging, program status |
Practical Advice for Beginners
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.
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.
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.




