STM32 BSP Interrupts: Code Stuck in Default Handler
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?
