From 63dc19d1e9ddefa07c50dd41f7a88fe5cfd87222 Mon Sep 17 00:00:00 2001 From: Liam Powell Date: Sun, 17 Nov 2024 20:15:06 +0800 Subject: [PATCH] Wait for STM32 timer output to be enabled before returning from enable procedure. RM0386 Rev 6 22.3.12 notes that there may be a delay before the BDTR.MOE bit reads as 1 after writing to it. The RM says that only a single instruction is needed, but testing has shown that this is incorrect. With the previous code, calling Enable_Main_Output and then immediately calling a procedure to set a different part of the register could result in the MOE bit being inadvertently set low. --- arch/ARM/STM32/drivers/stm32-timers.adb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/ARM/STM32/drivers/stm32-timers.adb b/arch/ARM/STM32/drivers/stm32-timers.adb index 9d58cd4b7..b4536c170 100644 --- a/arch/ARM/STM32/drivers/stm32-timers.adb +++ b/arch/ARM/STM32/drivers/stm32-timers.adb @@ -184,6 +184,10 @@ package body STM32.Timers is procedure Enable_Main_Output (This : in out Timer) is begin This.BDTR.Main_Output_Enabled := True; + + loop + exit when Main_Output_Enabled (This); + end loop; end Enable_Main_Output; -------------------------