I using ChiobiOS from stable_19.1.x branch and STM32F303 MCU.
I was found the problem: the callback for gpt is called several times for GPT with common IRQ Vectors. For example, GPTD1 and GPTD16 has common irq at VectorA4:
File ../os/hal/ports/STM32/STM32F303xx/stm32_isr.c
Code: Select all
...
243 /**
244 * @brief TIM1-UP, TIM16 interrupt handler.
245 *
246 * @isr
247 */
248 OSAL_IRQ_HANDLER(VectorA4) {
249
250 OSAL_IRQ_PROLOGUE();
251
252 #if HAL_USE_GPT
253 #if STM32_GPT_USE_TIM1
254 gpt_lld_serve_interrupt(&GPTD1);
255 #endif
256 #if STM32_GPT_USE_TIM16
257 gpt_lld_serve_interrupt(&GPTD16);
258 #endif
259 #endif
260 #if HAL_USE_ICU
261 #if STM32_ICU_USE_TIM1
262 icu_lld_serve_interrupt(&ICUD1);
263 #endif
264 #endif
265 #if HAL_USE_PWM
266 #if STM32_PWM_USE_TIM1
267 pwm_lld_serve_interrupt(&PWMD1);
268 #endif
269 #if STM32_PWM_USE_TIM16
270 pwm_lld_serve_interrupt(&PWMD16);
271 #endif
272 #endif
273
274 OSAL_IRQ_EPILOGUE();
275 }
...
I am using both GPTD1 and GPTD16 in my project. I setup GPTD1 in GPT_ONESHOT mode and wait for the callback. It is called first time in line 254 and second time in line 257.
Code for the gpt_lld_serve_interrupt is (file ../os/hal/ports/STM32/LLD/TIMv1/hal_gpt_lld.c):
Code: Select all
...
1117 /**
1118 * @brief Shared IRQ handler.
1119 *
1120 * @param[in] gptp pointer to a @p GPTDriver object
1121 *
1122 * @notapi
1123 */
1124 void gpt_lld_serve_interrupt(GPTDriver *gptp) {
1125
1126 gptp->tim->SR = 0;
1127 if (gptp->state == GPT_ONESHOT) {
1128 gptp->state = GPT_READY; /* Back in GPT_READY state. */
1129 gpt_lld_stop_timer(gptp); /* Timer automatically stopped. */
1130 }
1131 gptp->config->callback(gptp);
1132 }
...
Callback is called in line 1131 without any condition.
It seems this problem is actual not only for GPT but ICU and PWM drivers too and not only for TIM1/TIM16.