2024-10-08 11:59 PM - last edited on 2024-10-09 01:46 AM by SofLit
Hello,
I made a GPIO_EXTI test project referring to GPIO_EXTI sample.
For just check, I added entering Stop Mode int the GPIO_EXTI sample and HAL_GPIO_EXTI_Callback worked regularly like following.
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
while (1)
{
if(stop_flag == 1)
{
stop_flag = 0;
// Enter Stop Mode
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == KEY_BUTTON_PIN)
{
// Toggle LED3
BSP_LED_Toggle(LED3);
stop_flag = 1;
}
}
But in my project the HAL_GPIO_EXTI_Callback didn't occur.
So I checked difference for both initial settings in SystemClock_Config() and GPIO_Init() but I could only find difference __HAL_RCC_PWR_CLK_ENABLE() and __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1).
How should I resolve it?
Just for reference I'll write both settings.
SystemClock_Config() in the GPIO_EXTI sample
static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
// Enable Power Control clock
__HAL_RCC_PWR_CLK_ENABLE();
// Enable HSI Oscillator and activate PLL with HSI as source
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4;
RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV2;
RCC_OscInitStruct.HSICalibrationValue = 0x10;
if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
// Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | KTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
Error_Handler();
}
}
SystemClock_Config() in my project
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
// Configure the main internal regulator output voltage
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
// Initializes the RCC Oscillators according to the specified parameters in the RCC_OscInitTypeDef structure
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSI48;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
// Initializes the CPU, AHB and APB buses clocks
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
GPIO_Init in the GPIO_EXTI
static void EXTILine0_1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// Enable GPIOC clock
__HAL_RCC_GPIOA_CLK_ENABLE();
// Configure PA0 pin as input floating
GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Pin = GPIO_PIN_0;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
// Enable and set EXTI4_15 Interrupt to the lowest priority */
HAL_NVIC_SetPriority(EXTI0_1_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);
}
GPIO_Init in my project
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
// GPIO Ports Clock Enable
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
// Configure GPIO pin Output Level
HAL_GPIO_WritePin(LD_R_GPIO_Port, LD_R_Pin, GPIO_PIN_RESET);
// Configure GPIO pin Output Level
HAL_GPIO_WritePin(GPIOB, ePD1_RESET_Pin|ePD1_PWR_ENn_Pin|ePD1_D_C_Pin|LD_G_Pin, GPIO_PIN_RESET);
// Configure GPIO pin : B1_Pin
GPIO_InitStruct.Pin = B1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
// EXTI interrupt init
HAL_NVIC_SetPriority(EXTI0_1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);
}
2024-10-09 12:07 AM - edited 2024-10-09 01:51 AM
Hello @curiae and welcome to the community,
First, please use </> button to paste your code.
Second, you need to provide more details about the hardware you are using: mcu part number, what board you are using?
Third, since it’s an issue related to the EXTI forget about low power mode and try to isolate the issue by keeping just EXTI related code.
2024-10-09 01:43 AM
Sorry for insufficient information and I didn't know how to use this post since it's my first post.
I'm trying on STM32L0538-Discovery.
I made a project referring GPIO_EXTI sample that works normally after Stop mode with RTC.
But EXTI interrupt didn't work in my project.
That's the my situation.
Looking forward good answers.
Thanks
2024-10-09 01:50 AM
Hello,
Tips: remove all the code related to the low power mode and focus on the EXTI function.
When you press User button do you get the EXTI interrupt?
2024-10-09 01:59 AM
As per the board schematics, User button is active High, so I suggest to replace:
GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
by
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
2024-10-09 02:04 AM
Hello,
I don't use any low power mode except using HSI and GPIO_EXTI sample works with HSI.
As result after inserting __HAL_RCC_PWR_CLK_ENABLE() into SystemClock_Config(void) that isn't written generated SystemClock_Config(void), EXTI interrupt itself occurred.
Lacking it is the cause?
Thanks
2024-10-09 02:07 AM
@curiae wrote:
I don't use any low power mode except
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI)
Here you are using STOP mode (a low power mode) .