cancel
Showing results for 
Search instead for 
Did you mean: 

Why is 'HAL_GPIO_EXTI_Callback' defined but not used [-Wunused-function]

nickdzi
Associate II

Learning how to use the STM32WB55RG alongside the 'Mastering STM32' by Carmine Noviello. I followed the instructions for setting up interrupts to use the NUCLEO hardware buttons, but when I build, I get a warning that 'HAL_GPIO_EXTI_Callback' defined but not used [-Wunused-function]. I have pasted some snippets of my code to help.

I have added toggling the state of an LED to the Handler functions to ensure they are being called. What seems to happen is that the __weak function is called, despite me placing a definition of the callback in main... any help is appreciated.

EDIT: I should also mention that the interrupts do not work, the callback is not called as per the warning

static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
 
  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, LD2_Pin|LD3_Pin|LD1_Pin, GPIO_PIN_RESET);
 
  /*Configure GPIO pin : B1_Pin */
  GPIO_InitStruct.Pin = B1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
 
  /*Configure GPIO pins : LD2_Pin LD3_Pin LD1_Pin */
  GPIO_InitStruct.Pin = LD2_Pin|LD3_Pin|LD1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
  /*Configure GPIO pins : B2_Pin B3_Pin */
  GPIO_InitStruct.Pin = B2_Pin|B3_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
 
  /* EXTI interrupt init*/
  HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI0_IRQn);
 
  HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI1_IRQn);
 
}
 
//===============================================================
// from main
 MX_GPIO_Init();
  MX_USART1_UART_Init();
  MX_USB_PCD_Init();
  /* USER CODE BEGIN 2 */
  void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
  {
	  if (GPIO_Pin == B2_Pin)
	  {
		  HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
	  }
	  else if (GPIO_Pin == B3_Pin)
	  {
		  HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
	  }
  }
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  uint16_t speed = 100;
  uint16_t counter = 0;
 
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
	  if (counter % speed == 0)
	  {
		  HAL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
	  }
	  if (counter % (uint16_t)(speed * 2.5) == 0)
	  {
		  //HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
	  }
	  if (counter % (uint16_t)(speed * 10) == 0)
	  {
		  //HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
		  counter = 0;
	  }
 
	  HAL_Delay(1);
	  counter++;
  }
//===========================================================
void EXTI0_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI0_IRQn 0 */
	//HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
  /* USER CODE END EXTI0_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(B2_Pin);
  /* USER CODE BEGIN EXTI0_IRQn 1 */
 
  /* USER CODE END EXTI0_IRQn 1 */
}
 
/**
  * @brief This function handles EXTI line1 interrupt.
  */
void EXTI1_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI1_IRQn 0 */
	//HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
  /* USER CODE END EXTI1_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(B3_Pin);
  /* USER CODE BEGIN EXTI1_IRQn 1 */
 
  /* USER CODE END EXTI1_IRQn 1 */
}

1 ACCEPTED SOLUTION

Accepted Solutions
RBENF.1
ST Employee

Hello @nickdzi​,

This is because your HAL_GPIO_EXTI_Callback definition is inside main(). It needs to be outside, for instance in the USER CODE 4 section.

Regards,

Ryan

View solution in original post

2 REPLIES 2
RBENF.1
ST Employee

Hello @nickdzi​,

This is because your HAL_GPIO_EXTI_Callback definition is inside main(). It needs to be outside, for instance in the USER CODE 4 section.

Regards,

Ryan

That seemed to do the trick! Thanks so much for your keen eyes