fix(trainer): SBUS trainer context ownership (#7699)

Co-authored-by: raphaelcoeffic <1050031+raphaelcoeffic@users.noreply.github.com>
This commit is contained in:
Raphael Coeffic
2026-08-26 13:06:17 +10:00
committed by GitHub
co-authored by raphaelcoeffic
parent fcd4b8d2e4
commit 878f414975
8 changed files with 152 additions and 44 deletions
@@ -315,7 +315,8 @@ static void* stm32_serial_init(void* hw_def, const etx_serial_init* params)
static void stm32_serial_deinit(void* ctx)
{
auto st = (stm32_serial_state*)ctx;
if (!st) return;
// !st->sp: state already freed, make de-init idempotent
if (!st || !st->sp) return;
stm32_usart_deinit(st->sp->usart);
stm32_serial_free_state(st);
@@ -528,7 +528,13 @@ void stm32_usart_deinit(const stm32_usart_t* usart)
}
if ((int32_t)(usart->IRQn) >= 0) {
// An IRQ latched before (or in flight across) NVIC_DisableIRQ() would
// still be taken, and would then access a de-initialised, clock-gated
// peripheral. Barrier + clear pending closes that window.
NVIC_DisableIRQ(usart->IRQn);
__DSB();
__ISB();
NVIC_ClearPendingIRQ(usart->IRQn);
}
LL_USART_DeInit(usart->USARTx);
disable_usart_clock(usart->USARTx);