2021-01-13 06:04 AM
I'm trying to get TIM7 interrupts working with the STM32MP157C-DK2 kit. I've added the necessary configuration to the DTS file:
&m4_timers7 {
pinctrl-names = "rproc_default";
pinctrl-0 = <&timer7_pins>;
status = "okay";
};
Do I need to enable the interrupt in the DTS file as well? I see in the M4 example DTS there is some configuration for a GPIO interrupt:
&m4_rproc {
m4_system_resources {
status = "okay";
button {
compatible = "rproc-srm-dev";
interrupt-parent = <&gpioa>;
interrupts = <14 2>;
interrupt-names = "irq";
status = "okay";
};
m4_led: m4_led {
compatible = "rproc-srm-dev";
pinctrl-names = "rproc_default", "rproc_sleep";
pinctrl-0 = <&leds_orange_pins>;
pinctrl-1 = <&leds_orange_sleep_pins>;
status = "okay";
};
};
};
On the M4 side: I've configured TIM7 in CubeMX (prescalar: 10000, period: 100, interrupt enabled). The only configuration I see for TIM7 comes from MX_TIM7_Init():
void MX_TIM7_Init(void)
{
TIM_MasterConfigTypeDef sMasterConfig = {0};
htim7.Instance = TIM7;
htim7.Init.Prescaler = 10000;
htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
htim7.Init.Period = 100;
htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
}
But I don't see anything about interrupts here. There is another function HAL_TIM_Base_MspInit() that I've tried to use without success. I tried calling this function after the init function above was called.
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
{
if(tim_baseHandle->Instance==TIM7)
{
/* USER CODE BEGIN TIM7_MspInit 0 */
/* USER CODE END TIM7_MspInit 0 */
/* TIM7 clock enable */
__HAL_RCC_TIM7_CLK_ENABLE();
/* TIM7 interrupt Init */
HAL_NVIC_SetPriority(TIM7_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(TIM7_IRQn);
/* USER CODE BEGIN TIM7_MspInit 1 */
/* USER CODE END TIM7_MspInit 1 */
}
}
Anyone have an idea what might be going on that the interrupt isn't firing?
Solved! Go to Solution.
2021-01-18 11:56 PM
Hi,
did you started the timer in your main code (e.g. HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim) ) ?
Maybe missing the interrupt handler in stm32mp1xx_it.c
Please have a look to examples in STM32CubeMP1, e.g. in Projects\STM32MP157C-EV1\Examples\LPTIM\LPTIM_PulseCounter (although not TIM, but usage at HAL level is very similar).
STM32CubeMP1 is usually already loaded in your PC by CubeMX (e.g. on W10 in C:\Users\xxxx\STM32Cube\Repository) or could be loaded manually on st.com or on Github
Regards.
2021-01-18 11:56 PM
Hi,
did you started the timer in your main code (e.g. HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim) ) ?
Maybe missing the interrupt handler in stm32mp1xx_it.c
Please have a look to examples in STM32CubeMP1, e.g. in Projects\STM32MP157C-EV1\Examples\LPTIM\LPTIM_PulseCounter (although not TIM, but usage at HAL level is very similar).
STM32CubeMP1 is usually already loaded in your PC by CubeMX (e.g. on W10 in C:\Users\xxxx\STM32Cube\Repository) or could be loaded manually on st.com or on Github
Regards.
2021-01-21 09:22 AM
HAL_TIM_Base_Start_IT() was missing. Thanks for the reply