cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo blue user button and exti in HAL

sergey2
Associate II
Posted on February 24, 2015 at 16:05

Is it possible to configure external interrupt for blue user button on Nucleo bord (which is PC13) using HAL library?

As given in examples for EXTI_Line0 connected to PA.00 pin: 

GPIO_InitTypeDef   GPIO_InitStructure;

__HAL_RCC_GPIOA_CLK_ENABLE();

GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;

GPIO_InitStructure.Pull = GPIO_NOPULL;

GPIO_InitStructure.Pin = GPIO_PIN_0;

HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);

HAL_NVIC_SetPriority(EXTI0_IRQn, 2, 0);

HAL_NVIC_EnableIRQ(EXTI0_IRQn);

Theoretically for PC13 it should look like:

GPIO_InitTypeDef   GPIO_InitStructure;

__HAL_RCC_GPIOC_CLK_ENABLE();

GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;

GPIO_InitStructure.Pull = GPIO_NOPULL;

GPIO_InitStructure.Pin = GPIO_PIN_13;

HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);

HAL_NVIC_SetPriority(EXTI13_IRQn, 2, 0);

HAL_NVIC_EnableIRQ(EXTI13_IRQn);

But EXTI13 doesn't exist in HAL library. Any solution?

3 REPLIES 3
Posted on February 24, 2015 at 16:15

> But EXTI13 doesn't exist in HAL library. Any solution?

>

Yes: read the manual.

[STM32Cube]\Repository\STM32Cube_FW_F4_V1.4.0\Drivers\BSP\STM32F4xx-Nucleo\stm32f4xx_nucleo.h :

/**

 * @brief Key push-button

 */

#define KEY_BUTTON_PIN                          GPIO_PIN_13

#define KEY_BUTTON_GPIO_PORT                    GPIOC

#define KEY_BUTTON_GPIO_CLK_ENABLE()            __GPIOC_CLK_ENABLE()

#define KEY_BUTTON_GPIO_CLK_DISABLE()           __GPIOC_CLK_DISABLE()

#define KEY_BUTTON_EXTI_IRQn                    EXTI15_10_IRQn

sergey2
Associate II
Posted on February 24, 2015 at 19:57

Thank you!

sergey2
Associate II
Posted on February 26, 2015 at 14:29

To help someone a lammer like me, that's how I did it:

void MX_GPIO_Init(void)

{

GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */

  __GPIOC_CLK_ENABLE();

   __GPIOA_CLK_ENABLE();

  /*Configure GPIO pin : PC13 */

  GPIO_InitStruct.Pin = GPIO_PIN_13;

  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pin : PA5 */

  GPIO_InitStruct.Pin = GPIO_PIN_5;

  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 

HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0);

 

HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);

}

void EXTI15_10_IRQHandler(void)

{

if(__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_13) != RESET) 

__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_13);

HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);

    }

}