Skip to content

Wait for STM32 timer output to be enabled before returning from enable procedure. #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

liampwll
Copy link
Contributor

RM0440 Rev 8 28.3.18 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.

…e procedure.

RM0440 Rev 8 28.3.18 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.
@liampwll
Copy link
Contributor Author

The same also applies to BKE and BKP as noted by the previous paragraph in the reference manual:

When the BKEx and BKPx bits are written, a delay of 1 APB clock cycle is applied before the writing is effective. Consequently, it is necessary to wait 1 APB clock period to correctly read back the bit after the write operation.

It's very likely that this is causing issues in the following code in stm32-timers.adb, but I haven't tested this since we don't use it:

      This.BDTR.Automatic_Output_Enabled      := Automatic_Output_Enabled;
      This.BDTR.Break_Polarity                := Break_Polarity;
      This.BDTR.Break_Enable                  := Break_Enabled;
      This.BDTR.Off_State_Selection_Run_Mode  := Off_State_Selection_Run_Mode;

@liampwll
Copy link
Contributor Author

liampwll commented Nov 17, 2024

Note that this is an upstream issue so it might make sense to wait for a complete fix there. (AdaCore/Ada_Drivers_Library#437)

@JCGobbi JCGobbi merged commit 73f2072 into JCGobbi:master Nov 18, 2024
@JCGobbi
Copy link
Owner

JCGobbi commented Nov 18, 2024

For now, the Pull request is accepted, but I will upload a new file that takes into account the Break_Polarity and Break_Enable bits when configuring BDTR register.
When the upstream issue is corrected, I will review this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants