-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
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
Fix BLTOUCH and SPEAKER conflict on SKR E3 boards #15781
Fix BLTOUCH and SPEAKER conflict on SKR E3 boards #15781
Conversation
…ware#15547) Previous fix https://github.com/MarlinFirmware/Marlin/pull/15547/commits solved the conflict when both SERVO0 and FAN0 PWM were using TIMER 1 by assigning TIMER 8 to SERVO0. However, when SPEAKER is enabled on SKR E3 boards, TIMER 8 is actually used by libmaple's tone.cpp to generate tones. This fix changes `SERVO0_TIMER_NUM` to TIMER 3 on SKR E3 boards. As far as I can tell this timer is not used by any other functionality. See also this discussion: MarlinFirmware#15547 (comment)
I would love to test this change myself, since I made the last change to this. Unfortunately that board is disconnected right now, as I have been working on SKR Pro issues. |
@sustmi or/and @sjasonsmith do we have links to issues that this PR might solve? |
I don't think so. Even when I made the original fix I couldn't find any, even though the BTT repo and reddit had reports of BLTouch issues everywhere. @sustmi commented on my original PR that he discovered there was still an issue and posted a PR, without bothering to report an issue, I think. |
I myself have questioned whether it is better to report an issue and follow it with a PR, or just post the PR if I already intend to fix it immediately. |
Co-Authored-By: Jason Smith <jason.inet@gmail.com>
@boelle: The original PR #15547 from @sjasonsmith may have fixed these issues:
But I did not find any issue (except the @sjasonsmith's PR) in https://github.com/MarlinFirmware/Marlin/ that would describe exactly this problem. Speaking of my pull request, as the @sjasonsmith's PR was merged only 22 days ago and Creality Ender 3 printers only have buzzer (not speaker) by default, I guess that nobody run into any issue with the BLTOUCH and SPEAKER conflict yet because nobody with SKR E3 board probably enabled Side note: Actually, I found this potential timer collision only because I noticed that my printer made a different noise when turned on after applying @sjasonsmith's fix. I started to dig deep into the code and found that SPEAKER would use TIMER 8 too. |
those 2 links point to outside marlin?? |
That is what we are saying. Issues were very widespread, but all the reports went to the BTT repo. I don't use BTT firmware, so I debugged and fixed the original issue here. |
talk about confusion..... :-D |
Some people use those BigTreeTech's GitHub projects to track issues with SKR boards (whether hardware or software ones). |
Oh no. Do not merge this PR! Until now, I tested this change only by leveling the bed. This is strange. Maybe TIMER 3 is already used by something else. |
Well, I found that TIMER 3 is actually not used but it gets disabled in SPI.cpp when "Print from Media" menu item is selected. On SKR E3 board, SD card is connected to SPI1.
which both correspond to TIMER 3. I was trying to find the reason why are the timers disabled but I only found that the SPI code was copied from https://github.com/rogerclarkmelbourne/Arduino_STM32/tree/master/STM32F1/libraries/SPI in PR #15002 . So it looks like SPI code also "eats" timers. Btw: The hang happens when a command is then sent to BLTOUCH over SERVO0 after the timer channel was disabled. Because when timer channel gets disabled by I need to sleep on this. 😪 |
These timers are such a pain. As we learn more about what these frameworks do, I think we need to find a way to break the build if conflicting timers are selected. |
Oh, I didn't realize that was actually Marlin code doing that. I thought that when used for GPIO the pins would be muxed away from the timer, so actually interfering with the timer would be unnecessary. |
It is our destiny that we will have to make our own SPI, Servo, and Serial classes for use within Marlin in order to get control over which timers we can use. It would be a good idea to have a class for general timer allocation so that we can grab the "best available" timer / channel / interrupt for each feature. |
I would just like to add that I think the reason why there are not many issues reported on this is because BigTreeTech instructs us to disable SPEAKER and enable SOFT_FAN_PWM : In addition, their default firmware that comes preloaded and also available for download from their github has SPEAKER disabled as well. So this is still important despite the lack of reports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thinkyhead : Thank you for your corrections in the comment.
However, I think that you may have been too fast to merge this PR. The situation with timers allocation is quite messy and I needed more time to wrap my head around it. I did not expect this to be merged since @boelle added the "Do not merge" label.
Did you test the changes with a real machine? I am afraid that this change may cause hangs and thermal runaway with some boards.
Now that timers are overhauled, concerns about timer allocation should be resolved. |
Can you be more specific what do you mean, @thinkyhead ? |
Perhaps referring to the changes made in HAL_STM32, although those wouldn't impact these boards using HAL_STM32F1. |
Oh, I found that platformio/platform-ststm32 v5.7.0 now uses stm32duino/Arduino_Core_STM32 v1.7.0 and this version brings a new API for timers: https://github.com/stm32duino/wiki/wiki/HardwareTimer-library
Are they already? My build env is By searching for example |
They "should" be. But you will have to confirm whether they are. |
Marlin still has us use tool-stm32duino which is using the libs from rogerclarkmelbourne's repo, so no we are not seeing any benefits of the new API |
Trying to wrap my head around this issue. This pull request changes the SERVO0_TIMER_NUM to TIMER3 which is disabled by SPI? |
Hello @minosg . Sorry for a late reply.
Well, actually not. I think that the This pull request originally tried to change the Then the code in this PR got updated by @thinkyhead who changed it almost to it's final form. Don't feel bad if the final code does not make much sense to you. It does not actually do what it says in the PRs title. It does not fix the conflict with the |
Description
Previous fix https://github.com/MarlinFirmware/Marlin/pull/15547/commits solved the conflict when both SERVO0 and FAN0 PWM were using TIMER 1 by assigning TIMER 8 to SERVO0.
However, when SPEAKER is enabled on SKR E3 boards, TIMER 8 is actually used by libmaple's tone.cpp to generate tones.
This fix changes
SERVO0_TIMER_NUM
to TIMER 3 on SKR E3 boards. As far as I can tell this timer is not used by any other functionality.See also this discussion: #15547 (comment) .
Benefits
This PR fixes possible problems with BLTOUCH on SKR E3 boards when
SPEAKER
is enabled inConfiguration.h
.Related Issues