2024-07-28 01:01 PM
Hello, I am trying to get interrupt from additional Switches SW4 and SW5 on pins PC2 and PC3 similar to on board SW1-SW3.
See: https://github.com/stm32-hotspot/STM32WB-BLE-HID-Selfie.
I made the follow code changes:
in stm32wbxx_nucleo.h:
typedef enum
{
BUTTON_SW1 = 0,
BUTTON_SW2 = 1,
BUTTON_SW3 = 2,
BUTTON_SW4 = 3,
BUTTON_SW5 = 4,
} Button_TypeDef;
for SW1-SW5:
#define BUTTON_SW4_PIN GPIO_PIN_2
#define BUTTON_SW4_GPIO_PORT GPIOC
#define BUTTON_SW4_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define BUTTON_SW4_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
#define BUTTON_SW4_EXTI_LINE GPIO_PIN_2
#define BUTTON_SW4_EXTI_IRQn EXTI2_IRQn
#define BUTTON_SW5_PIN GPIO_PIN_3
#define BUTTON_SW5_GPIO_PORT GPIOC
#define BUTTON_SW5_GPIO_CLK_ENABLE() __HAL_RCC_GPIOD_CLK_ENABLE()
#define BUTTON_SW5_GPIO_CLK_DISABLE() __HAL_RCC_GPIOD_CLK_DISABLE()
#define BUTTON_SW5_EXTI_LINE GPIO_PIN_3
#define BUTTON_SW5_EXTI_IRQn EXTI3_IRQn
#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if ((__INDEX__) == BUTTON_SW1) BUTTON_SW1_GPIO_CLK_ENABLE(); else \
if ((__INDEX__) == BUTTON_SW2) BUTTON_SW2_GPIO_CLK_ENABLE(); else \
if ((__INDEX__) == BUTTON_SW3) BUTTON_SW3_GPIO_CLK_ENABLE(); else \
if ((__INDEX__) == BUTTON_SW4) BUTTON_SW4_GPIO_CLK_ENABLE(); else \
if ((__INDEX__) == BUTTON_SW5) BUTTON_SW5_GPIO_CLK_ENABLE();} while(0)
#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) do { if ((__INDEX__) == BUTTON_SW1) BUTTON_SW1_GPIO_CLK_DISABLE(); else \
if ((__INDEX__) == BUTTON_SW2) BUTTON_SW2_GPIO_CLK_DISABLE(); else \
if ((__INDEX__) == BUTTON_SW3) BUTTON_SW3_GPIO_CLK_DISABLE(); else \
if ((__INDEX__) == BUTTON_SW4) BUTTON_SW4_GPIO_CLK_DISABLE(); else \
if ((__INDEX__) == BUTTON_SW5) BUTTON_SW5_GPIO_CLK_DISABLE();} while(0)
#define BUTTONn 5
in stm32wbxx_nucleo.c
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {BUTTON_SW1_GPIO_PORT, BUTTON_SW2_GPIO_PORT, BUTTON_SW3_GPIO_PORT, BUTTON_SW4_GPIO_PORT, BUTTON_SW5_GPIO_PORT};
const uint16_t BUTTON_PIN[BUTTONn] = {BUTTON_SW1_PIN, BUTTON_SW2_PIN, BUTTON_SW3_PIN, BUTTON_SW4_PIN, BUTTON_SW5_PIN};
const uint8_t BUTTON_IRQn[BUTTONn] = {BUTTON_SW1_EXTI_IRQn, BUTTON_SW2_EXTI_IRQn, BUTTON_SW3_EXTI_IRQn, BUTTON_SW4_EXTI_IRQn, BUTTON_SW5_EXTI_IRQn};
in stm32wbxx_it.c for SW1-SW5
void PUSH_BUTTON_SW4_EXTI_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(BUTTON_SW4_PIN);
}
in app_entry.c
static void Button_Init( void )
{
BSP_PB_Init(BUTTON_SW1, BUTTON_MODE_EXTI);
BSP_PB_Init(BUTTON_SW2, BUTTON_MODE_EXTI);
BSP_PB_Init(BUTTON_SW3, BUTTON_MODE_EXTI);
BSP_PB_Init(BUTTON_SW4, BUTTON_MODE_EXTI);
BSP_PB_Init(BUTTON_SW5, BUTTON_MODE_EXTI);
}
But no call from SW4 or SW5 to void HAL_GPIO_EXTI_Callback( uint16_t GPIO_Pin )
I have checked the pin voltage - coming down from 3.3v to 0V after pressing the switch.
1. What did I miss?
2. And for pins like PB7 and PB8 - What BUTTON_SWX_EXTI_IRQn should be used - from EXTI0_IRQn to EXTI4_IRQn ?
Solved! Go to Solution.
2024-07-28 01:48 PM
Sorry, some error in my code. After 2 days it start working now!
2024-07-28 01:48 PM
Sorry, some error in my code. After 2 days it start working now!
2024-07-28 01:52 PM
Still a question:
2. And for pins like PB7 and PB8 - What BUTTON_SWX_EXTI_IRQn should be used - from EXTI0_IRQn to EXTI4_IRQn ?
2024-07-29 06:21 PM
Yes, I found:
EXTI15_10_IRQn = 40, /*!< EXTI Lines1[15:10 ]Interrupts
EXTI9_5_IRQn = 23, /*!< EXTI Lines [9:5] Interrupt