cancel
Showing results for 
Search instead for 
Did you mean: 

LED2 (Blue) Doesnt Work

pb33
Visitor

Hello, 

I am using the H753zi board and cannot figure out why my blue led won't turn on. The green and red do work. Any ideas would be greatly appreciated. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
pb33
Visitor

Okay so I got them all to turn on. Instead of BSP, I used HAL, for example:

HAL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_PIN); // Green LED

View solution in original post

12 REPLIES 12
Andrew Neil
Super User

Welcome to the forum.

Please see How to write your question to maximize your chances to find a solution for best results.

 


@pb33 wrote:

I am using the H753zi board


Which H753zi board ?

If it's an ST board, documentation will be available on that board's Product Page:

  • User Manual on the 'Documentation' tab;
  • Schematics on the 'CAD Resources' tab.

either/both of those will tell you the correct GPIO pin for each LED.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Imen.D
ST Employee

Hello @pb33 ,

Check the board's User manual or Datasheet to confirm the pin assignment.

Ensure that the GPIO pin for the blue LED is correctly configured in your code and is not being used by another peripheral

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hi Imen, 

 

I looked at the schematic and its telling me PE1 is the pin I should be referencing. There is no other peripherals attached to that pin. 

this is in my main.h file:

#define LD2_Pin GPIO_PIN_1

#define LD2_GPIO_Port GPIOE
I am also doing this in my main.c:

__HAL_RCC_GPIOE_CLK_ENABLE();

/*Configure GPIO pin Output Level */

HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);

 

/*Configure GPIO pin : LD2_Pin */

GPIO_InitStruct.Pin = LD2_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);

You still haven't said what board you are using.

Please see How to insert source code for how to properly post source code (the instructions are also in How to write your question to maximize your chances to find a solution - please be sure to read that, too).

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Hi Andrew, 

I am using stm32h753zi. Attached is my main.c

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdlib.h>
#include <stdio.h>
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

COM_InitTypeDef BspCOMInit;
__IO uint32_t BspButtonState = BUTTON_RELEASED;
__IO uint32_t BspButtonStatePrev = BUTTON_RELEASED;

/* USER CODE BEGIN PV */
uint32_t lastGreen = 0;
uint32_t lastRed = 0;
uint32_t lastYellow = 0;

const uint8_t intervalGreen = 250;
const uint8_t intervalRed = 1000;
const uint8_t intervalYellow = 500;
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Initialize leds */
  BSP_LED_Init(LED_GREEN);
  BSP_LED_Init(LED_YELLOW);
  BSP_LED_Init(LED_RED);

  /* Initialize USER push-button, will be used to trigger an interrupt each time it's pressed.*/
  BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);

  /* Initialize COM1 port (115200, 8 bits (7-bit data + 1 stop bit), no parity */
  BspCOMInit.BaudRate   = 115200;
  BspCOMInit.WordLength = COM_WORDLENGTH_8B;
  BspCOMInit.StopBits   = COM_STOPBITS_1;
  BspCOMInit.Parity     = COM_PARITY_NONE;
  BspCOMInit.HwFlowCtl  = COM_HWCONTROL_NONE;
  if (BSP_COM_Init(COM1, &BspCOMInit) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }


  /* -- Sample board code to switch on leds ---- */
//  BSP_LED_On(LED_GREEN);
//  BSP_LED_On(LED_YELLOW);
//  BSP_LED_On(LED_RED);

  /* USER CODE END BSP */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {

	  // At the top of the while(1) loop:
	  if (BSP_PB_GetState(BUTTON_USER) == GPIO_PIN_SET) {
	      BspButtonState = BUTTON_PRESSED;
	  }
	  else {
	      BspButtonState = BUTTON_RELEASED;
	  }

      uint32_t time = HAL_GetTick();

      if (BspButtonState == BUTTON_PRESSED)
      {
          // Only turn LEDs ON if they weren't already on
          if (BspButtonStatePrev == BUTTON_RELEASED) {
              BSP_LED_On(LED_GREEN);
              BSP_LED_On(LED_YELLOW);
              BSP_LED_On(LED_RED);
              printf("LEDs ON. Button pressed.\n");
              fflush(stdout);
          }
      }
      else
      {
          // Blinking logic
          if (time - lastGreen >= intervalGreen) {
              BSP_LED_Toggle(LED_GREEN);
              lastGreen = time;
          }
          if (time - lastYellow >= intervalYellow) {
              BSP_LED_Toggle(LED_YELLOW);
              lastYellow = time;
          }
          if (time - lastRed >= intervalRed) {
              BSP_LED_Toggle(LED_RED);
              lastRed = time;
          }
      }

      BspButtonStatePrev = BspButtonState;
  }

  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Supply configuration update enable
  */
  HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);

  /** Configure the main internal regulator output voltage
  */
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);

  while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
                              |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
  RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief GPIO Initialization Function
  * @PAram None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  /* USER CODE BEGIN MX_GPIO_Init_1 */

  /* USER CODE END MX_GPIO_Init_1 */

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOE_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : LD2_Pin */
  GPIO_InitStruct.Pin = LD2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);


  /* USER CODE BEGIN MX_GPIO_Init_2 */

  /* USER CODE END MX_GPIO_Init_2 */
}

/* USER CODE BEGIN 4 */


/* USER CODE END 4 */

/**
  * @brief BSP Push Button callback
  * @PAram Button Specifies the pressed button
  * @retval None
  */
void BSP_PB_Callback(Button_TypeDef Button)
{
  if (Button == BUTTON_USER)
  {
    BspButtonState = BUTTON_PRESSED;
  }
  else {
	  BspButtonState = BUTTON_RELEASED;
  }
}

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @PAram  file: pointer to the source file name
  * @PAram  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

So your "blue" is 

LED_YELLOW

?  You changed the LEDs ?

If you feel a post has answered your question, please click "Accept as Solution".

>>I am using stm32h753zi. 

That's a CHIP, you're using the NUCLEO-H753ZI BOARD?

LD2 / PE1 should be a YELLOW LED if I'm not mistaken, and that's not working.

Not sure the schematic indicates anything would prevent PE1 changing. Put a scope on the Pin and watch it go high/low. Anything plugged into the headers?

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

@pb33 wrote:

I am using stm32h753zi.

As @Tesla DeLorean said, that's not a board - that's just a the part number of a chip.

The code you posted has  LED_GREEN, LED_YELLOW, and LED_RED - so which one do you think is BLUE ?

Have you tried just a simple loop which just sets the pin for each LED high and then low?

Step through that in the debugger - do the correct LEDs light?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Sorry I'm new to embedded systems. I changed the blue to yellow. I put the transistor and diode to a multimeter and it lights up. So hardware issues is out of the question. I ran the code again in the debugger and both red and yellow turned on when i only had red code uncommented.