cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 BSP Interrupts: Code Stuck in Default Handler

KMew
Senior III

Hello,

I am using the STM32H7B3I-EVAL evaluation board with a code generated by TouchGFX 4.20.0. My goal is as follows:

  • Using a button (in this case, the Wakeup button on the evaluation board), change a PWM's duty cycle in stages (0% -> 25% -> 50% -> 75% -> 100% -> 0% -> .....)
  • Display the current PWM duty cycle as a percentage on the display

To do this, I am using a timer (TIM2) set to PWM Generation CH1. The code below is how I initialize this timer.

static void MX_TIM2_Init(void)
{
 
  /* USER CODE BEGIN TIM2_Init 0 */
 
  /* USER CODE END TIM2_Init 0 */
 
  TIM_MasterConfigTypeDef sMasterConfig = {0};
  TIM_OC_InitTypeDef sConfigOC = {0};
 
  /* USER CODE BEGIN TIM2_Init 1 */
 
  /* USER CODE END TIM2_Init 1 */
  htim2.Instance = TIM2;
  htim2.Init.Prescaler = 280-1;
  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim2.Init.Period = 1000-1;
  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 0;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM2_Init 2 */
 
  /* USER CODE END TIM2_Init 2 */
  HAL_TIM_MspPostInit(&htim2);
 
}

I am using the BSP package to initialize the buttons and use their callback. I do so as follows:

In the main branch:

BSP_PB_Init(BUTTON_WAKEUP, BUTTON_MODE_EXTI);

The callback:

void BSP_PB_Callback(Button_TypeDef Button)
{
	if(LED_PWM_Percentage == PULSE0_VALUE)
		LED_PWM_Percentage = PULSE1_VALUE;
	else if(LED_PWM_Percentage == PULSE1_VALUE)
		LED_PWM_Percentage = PULSE2_VALUE;
	else if(LED_PWM_Percentage == PULSE2_VALUE)
		LED_PWM_Percentage = PULSE3_VALUE;
	else if(LED_PWM_Percentage == PULSE3_VALUE)
		LED_PWM_Percentage = PULSE4_VALUE;
	else
		LED_PWM_Percentage = PULSE0_VALUE;
 
	TIM2->CCR2 = LED_PWM_Percentage;
	uhLED_PWM = LED_PWM_Percentage;
}

When I run this, the display seems to work and I get no errors. However, when I click the wakeup button, the display freezes and I enter the default handler. I have set the wakeup button to the lowest priority on the interrupt (15). Does anyone know what would cause this?

0693W00000VOjtNQAT.png

1 ACCEPTED SOLUTION
6 REPLIES 6
KnarfB
Principal III

If an IRQ handler is not defined in the code, a default implementation is used in the interrupt vector table, the DefaultHandler. So it looks like the original IRQ handler for your button is not present.

Compare your project to the STM32Cube_FW_H7_V1.10.0\Projects\STM32H7B3I-EVAL\Examples\BSP example which comes with the firmware package.

hth

KnarfB

Hello KnarfB,

Thank you for the reponse! Yes, I did put a breakpoint in my BSP_PB_Callback and noticed it is never entered. So that confirms that.

I ran the example code you mentioned and it does work, but I cannot find a discernable difference between the two. The main does it as follows:

Initialization:

BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_EXTI);

Callback:

void BSP_PB_Callback(Button_TypeDef Button)
{
  if(Button == BUTTON_TAMPER)
  {
    ButtonState = 1;
  }
}

I initialize and use the callback in the exact same way. Yet mine freezes the display while theirs does not.

Hello Piranha,

Interesting, I thought the EXTI15_10_IRQHandler initialization would be handled in the BSP_Init, but I see I was mistaken.

I added this line and my code worked.

Thank you very much! ^.^

It is an actual interrupt handler. Everything else is just layers of abstraction and callbacks called from there. 🙂

That is good to know! Thank you 🙂