cancel
Showing results for 
Search instead for 
Did you mean: 

PingPong Example, failing to run GPIO ISR

sgabran
Associate III

Hi

I have been trying to activate the callback function for the pushbutton in the SubGHz PingPong example, but with no luck.

I am using the BSP_PB_Init() to configure the pushbutton:

void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
{
  GPIO_InitTypeDef GPIO_InitStruct;
 
  /* Enable the BUTTON Clock */
  BUTTONx_GPIO_CLK_ENABLE(Button);
  __HAL_RCC_SYSCFG_CLK_ENABLE();
 
  if (ButtonMode == BUTTON_MODE_GPIO)
  {
    /* Configure Button pin as input */
    GPIO_InitStruct.Pin = BUTTON_PIN[Button];
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_PULLDOWN;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
  }
 
  if (ButtonMode == BUTTON_MODE_EXTI)
  {
    /* Configure Button pin as input with External interrupt */
GPIO_InitStruct.Pin = PushButton_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(PushButton_GPIO_Port, &GPIO_InitStruct);
 
/* Enable and set Button EXTI Interrupt to the lowest priority */
NVIC_SetPriority(EXTI2_3_IRQn, 0);
HAL_NVIC_EnableIRQ(EXTI2_3_IRQn);
}
}
 
Then I implemented  the callback function:
{
HAL_UART_Transmit(&huart2, "TEST: ", 7, 100);
}
 
But there is no response.
I am missing something to configure ?
thanks
6 REPLIES 6
Karl Yamashita
Lead II

You say you implemented the callback but the code you show doesn't show a callback function. So we don't know if you are using the correct callback?

If you find my answers useful, click the accept button so that way others can see the solution.

Sorry, i didn't paste the function header by mistake, here it is:

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
HAL_UART_Transmit(&huart2, "TEST: ", 7, 100);
}

These are the only steps I did so far:

1. Configure BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI)

2. Call the BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);

3. Implement the callback function void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

I am not sure if I have to do something else, for example, enable an IRQ somewhere. I am using the SubGHz example.

thanks

Don't put blocking functions in interrupts / callbacks.

Also consider setting flags, or using queue, as the EXTI interrupt might occur in the middle of some other blocking, or pending, UART function, and you really need to sequence interactions.

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

Hi Tesla, thanks for the tips. I need temporary user feedback to troubleshoot the ISR issue, so i choose UART. The same ISR fails with LEDs.

So my question is, if someone has experience with STM32 or with the SubGHz PingPong example, what did I miss to make the ISR operate and execute as expected ?

thanks

My scope of experience is fairly broad. I've used the STM32L0 in the Murata based LoRa DISCO. Using the earlier LRWAN libraries, and not auto-generating the code / framework.

Have you established that the UART works and outputs? Do the EXTI enter when the button is pressed? Call-backs occur under interrupt context, so other interrupts will be blocked unless they have priority that will preempt. You should probably flag that you got the EXTI, and respond / react elsewhere, say in the main() loop.

I'd probably feed the UART via a ring-buffer, and it's own interrupts.

Which pin is the button on? Do you have the right EXTI? Is the EXTI shared with other pins or DIO from the Semtech SX1276? There are perhaps CUBEL0 examples of EXTI for this or similar boards, review those in context.

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

Hi Tesla

Awesome, I am sure you will be able to help me out, as I am a new comer to STM32.

UART works normally in other parts of the code.

I did several LED blink test within the callback of the pushbutton to check if its callback is executed, but it is not. It has priority of zero, so it should be executed.

Button is on pin PB2 (the LoRa devkit). and it is not shared with other resources.

While using ARM from PSoC, there is a global interrupt function that i have to call to enable global interrupts, but i couldn't find a similar procedure in the STM32 help or examples. So I was wondering if I am missing a step to enable the ISR.