Conversation
The timer IRQ handler macros indexed timerCtx[] with (timer number - 1), which assumes the hardware timers are numbered without gaps. STM32H7 has no TIM9..TIM11 and AT32F43x adds TMR20 after TMR14, so their tables are packed and the handlers for the timers behind the gap picked up a foreign context or read past the end of the array. Add TIMER_INDEX(), a per MCU compile time mapping from timer number to table slot, and use it both for timerDefinitions[] and for the handlers, so both sides can no longer drift apart. A STATIC_ASSERT in the handler macros keeps an out of range index from compiling. Fixes iNavFlight#11368
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoDerive timer interrupt context indices from platform timer tables
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can switch off images and animations for a plain-text comment |
Problem
On STM32H7 the timer IRQ handlers index
timerCtx[]withtimer number - 1, but H7 has no TIM9..TIM11 and its table is packed into 14 slots.TIM15_IRQHandler..TIM17_IRQHandlertherefore readtimerCtx[14..16], past the end of the array, and the TIM12..TIM14 handlers get the context of TIM15..TIM17. Assigning PPM/PWM RC input or ESC RPM telemetry to a TIM15/16/17 pad on an H7 board enables that IRQ and can hard fault (#11368, found by code analysis; the reporter has no H7 board). AT32F43x has the same defect:TMR20_CH_IRQHandlerreadstimerCtx[19]in a 15-entry array.Cause
src/main/drivers/timer_impl.h:61on maintenance-10.x (also :54-55, and :28-29/:35 for AT32):impl_timerCaptureCompareHandler(TIM ## i, timerCtx[i - 1]);. The H7 tabletimer_stm32h7xx.c:43-48places TIM12..TIM17 in slots 8..13.timer_impl_hal.c:254callstimerCtx->ch[0].cb->callbackEdgeguarded only by a NULL check ontimerCtxitself (:235), so a foreign or out-of-bounds context faults.Change
timer.hgainsTIMER_INDEX(n)per MCU family (n-1on F4/F7;n<9 ? n-1 : n-4on H7;n<20 ? n-1 : 14on AT32F43x). The four platform tables use it as their array designators and both handler macros intimer_impl.husetimerCtx[TIMER_INDEX(i)], so table and ISR share one mapping. ASTATIC_ASSERTin each handler macro rejects an index outsideHARDWARE_TIMER_DEFINITION_COUNT, each platform file asserts its last timer lands in the last slot, andtimer_impl.hincludescommon/utils.hforSTATIC_ASSERT. F4/F7 indices are unchanged.Test
Not run on hardware. Cause verified by reading
timer_impl.h:61,timer_stm32h7xx.c:43-48andtimer_impl_hal.c:235-254on maintenance-10.x. The upstream "Build firmware" run is waiting for maintainer approval: https://github.com/iNavFlight/inav/actions/runs/34511424067. Built by fork CI: pending. Compiled for all targets and the four SITL builds on the fork, green: https://github.com/Raffi1202/inav/actions/runs/34770670426Flash / RAM
Builds clean on all targets. No size comparison yet: the fork build has no baseline for this branch, and the upstream size report runs once CI is released for this PR.
Docs
No documentation change needed: internal driver indexing with no setting, CLI or user-visible option; the only docs mention of
HARDWARE_TIMER_DEFINITION_COUNT(docs/development/msp/README.md:3451) is unaffected.