Docs

Micro-controllers, wireless transmission and database

Head

Button GPIO Interrupt with Blue Pill using STM32CubeIDE

Prerequisites

This project assumes you have already installed STM32CubeIDE. You need to have previously done a basic blink sketch with blue-pill using STM32CubeIDE. I have made a complete video from installing STM32CubeIDE to LED blink program. You can watch it by clicking this link. https://www.youtube.com/watch?v=kXg467nVd_A

Wiring Diagram

Diagram

Image

STM32CubeIDE Settings

Set PA1 to GPIO_Output

Set PB1 to GPIO_EXTI1

Click NVIC → EXTI line1 interrupt → Enabled (Tick)

Additional code on top of STM32CubeIDE generated code

/* USER CODE BEGIN PV */
uint32_t previousMillis = 0;
uint32_t currentMillis = 0;
uint32_t counterOutside = 0; //For testing only
uint32_t counterInside = 0; //For testing only
/* USER CODE END PV */

/* USER CODE BEGIN 4 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  counterOutside++; //For testing only
  currentMillis = HAL_GetTick();
  if (GPIO_Pin == GPIO_PIN_1 && (currentMillis - previousMillis > 10))
  {
    counterInside++; //For testing only
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_1);
    previousMillis = currentMillis;
  }
}
/* USER CODE END 4 */