cancel
Showing results for 
Search instead for 
Did you mean: 

Mask interrupt temporary

andreaspiezia9
Associate III

Hi All,

I need to enable interrupt on GPIO PC0 only for 1sec: before and later interrupt form PC0 must be ignored.

I've tried with disable the interrupt at the init and enable in a thread, wait for 1 sec and then disable again, but it doesn't work!

static void MX_GPIO_Init(void)
{
//...
  /*Configure GPIO pin : Passaggio_Pin */
  GPIO_InitStruct.Pin = Passaggio_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(Passaggio_GPIO_Port, &GPIO_InitStruct);
 
  /* EXTI interrupt init*/
  HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0);
//  HAL_NVIC_EnableIRQ(EXTI0_IRQn);
 
//....
}
 
 
void StartButtonTask(void const * argument)
{
  for(;;)
  {
	  osSignalWait (0x0001, osWaitForever);
	  HAL_NVIC_EnableIRQ(EXTI0_IRQn);
	  HAL_Delay(10000);
          HAL_NVIC_DisableIRQ(EXTI0_IRQn);
  }
  /* USER CODE END 5 */ 
}

4 REPLIES 4
Uwe Bonnes
Principal II

You are not consistant with the Interrupt numbers!

Thanks a lot Uwe,

It was just a typo, in my real code the interrupts number was the same, but it doesn't work the same.

Bob S
Principal

What "doesn't work"? What are you seeing happen vs. what you were expecting to happen.

And FYI - your HAL_Delay() call is for 10 seconds, not 1 second - unless this was another typo.

Hi Bob,

thank you very much for your reply.

Sorry for the misunderstanding. My code now working, it was just a typo.

Here below the code. I want count numbers of interrupt every 100 sec. for 10 sec. (timing windows for interrupts must be 10 sec. every 100 sec.)

Code generated with CobeMX for SW4STM32 env. for NUCLEO64 F401RE board.

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "cmsis_os.h"
 
/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart2;
 
osThreadId StartButtonHandle;
osThreadId SemaphoreTaskHandle;
/* USER CODE BEGIN PV */
int static volatile ContaPassaggi = 0;
int static volatile InterruptContaPassaggi = 0;
int static volatile FlagConta = 0;
 
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
void StartButtonTask(void const * argument);
void SemaphoreFunc(void const * argument);
 
int main(void)
{
 
  HAL_Init();
 
  SystemClock_Config();
  MX_GPIO_Init();
  MX_USART2_UART_Init();
 
  osThreadDef(StartButton, StartButtonTask, osPriorityNormal, 0, 128);
  StartButtonHandle = osThreadCreate(osThread(StartButton), NULL);
 
  osThreadDef(SemaphoreTask, SemaphoreFunc, osPriorityNormal, 0, 128);
  SemaphoreTaskHandle = osThreadCreate(osThread(SemaphoreTask), NULL);
 
  osKernelStart();
  while (1)
  {
  }
}
 
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = 16;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
  RCC_OscInitStruct.PLL.PLLQ = 7;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}
 
 
/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
  GPIO_InitStruct.Pin = SartButton_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(SartButton_GPIO_Port, &GPIO_InitStruct);
  GPIO_InitStruct.Pin = Passaggio_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(Passaggio_GPIO_Port, &GPIO_InitStruct);
  GPIO_InitStruct.Pin = LD2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
  HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0);
}
 
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	  InterruptContaPassaggi++;
}
 
void StartButtonTask(void const * argument)
{
   for(;;)
  {
	  HAL_Delay(100000);
	  InterruptContaPassaggi = 0;
	  //FlagConta = 1;
	  HAL_NVIC_EnableIRQ(EXTI0_IRQn);
	  HAL_Delay(10000);
	  //FlagConta = 0;
	  HAL_NVIC_DisableIRQ(EXTI0_IRQn);
	  ContaPassaggi = InterruptContaPassaggi;
 
  }
}
 
 
void SemaphoreFunc(void const * argument)
{
  /* USER CODE BEGIN SemaphoreFunc */
  /* Infinite loop */
  for(;;)
  {
 
    if(ContaPassaggi > 10)
    {
    	HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
    }
    else
    {
    	HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
    }
  }
}
 
 
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  /* USER CODE BEGIN Callback 0 */
 
  /* USER CODE END Callback 0 */
  if (htim->Instance == TIM1) {
    HAL_IncTick();
  }
}