Hello,
I am trying to use HAL GPIO interrupt in mbed using cpp, but with no success. once I give some rising edges to gpio MCU stops working, it hangs as it seems and I couldn’t find the problem. I am using HAL interrupt because I was trying to use DMA on mbed and there was the same problem and this was easiest way to find what is wrong.
Here is the source code:
#include "mbed.h"
#include "TraceVSPI.h"
#define debug_printf TraceVSPI::printf
extern "C" void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOE_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_RESET);
/*Configure GPIO pin : PE3 */
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/*Configure GPIO pin : PE10 */
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/* EXTI interrupt init*/
//NVIC_SetVector(EXTI15_10_IRQn, (uint32_t) HAL_GPIO_EXTI_IRQHandler);
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}
extern "C" void EXTI15_10_IRQHandler(void)
{
/* USER CODE BEGIN EXTI15_10_IRQn 0 */
debug_printf("!");
HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_10);
/* USER CODE END EXTI15_10_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
/* USER CODE BEGIN EXTI15_10_IRQn 1 */
/* USER CODE END EXTI15_10_IRQn 1 */
}
extern "C" void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
/* System interrupt init*/
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
int main()
{
HAL_Init();
MX_GPIO_Init();
TraceVSPI::init();
debug_printf("Trace Init Done -- \r\n");
ThisThread::sleep_for(500ms);
debug_printf("Relay Init -- \r\n");
while (1){
debug_printf("time pass -- \r\n");
ThisThread::sleep_for(500ms);
}
}