Skip to content

More fixes for sleep and clocking stuff on MIMXRT105x #158

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 2 commits into from
May 12, 2023

Conversation

multiplemonomials
Copy link
Collaborator

@multiplemonomials multiplemonomials commented May 11, 2023

Summary of changes

I took some time to look into test failures on the MIMXRT105x with the sleep and ticker tests, and discovered a couple issues that need to get fixed.

First and foremost, incorrect logic in my new mimxrt_clock_adjustment.c file caused the PERCLK frequency to increase the first time that the chip came out of deep sleep. This clock drives both the GPT (used for lp ticker) and the PIT (used for us ticker), meaning that these tickers would tick like 4x faster (relative to, e.g. the RTOS clock) from that point on!

This is a pretty big issue by itself, and needs to get fixed so that timing behaves in a sane way on projects that use deep sleep.

Another issue I noticed is that, for a few peripherals, the clock settings were being manually changed at runtime to something different than the MCUXpresso-generated clock config file. This doesn't do any harm, but it's weird because the clocks displayed in the tool won't be accurate. I updated the tool to reflect the current actual clock settings, and removed these random init functions.

A third issue was that the PIT timer was not getting stopped when the core entered deep sleep mode. This violates the us ticker API, and was causing the deep sleep test to fail. Fixed that by manually stopping the PIT timer when we enter deep sleep and starting it immediately after.

Fourth, and finally, we were getting sleep-manager test failures because the core was taking an obscene amount of time (8+ milliseconds) to exit deep sleep. I did a bit of profiling, and was able to somewhat localize this to the fact that some code in lpm.c was calling SDK_DelayAtLeastUs(), a function that delays based on CPU clock without knowing that the CPU clock is currently like 20x slower than normal. Fixing this got rid of around half the delay, but it's still kinda slow. Might want to look into that later also.

With all these changes, we can now pass almost all sleep tests on MIMXRT1060_EVK. The only one still having trouble is mbed-hal-sleep, which works 1/3 of the time but hard faults the other 2/3. But when it sleeps it disconnects the debugger so might have to look into that one when I have more time later...

Impact of changes

Deep sleep should be significantly less buggy on MIMXRT105x targets

Migration actions required

None

Documentation

None


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

Reviewers


JohnK1987
JohnK1987 previously approved these changes May 11, 2023
Base automatically changed from dev/mimxrt105x-data-in-dtcm to master May 11, 2023 20:04
@multiplemonomials
Copy link
Collaborator Author

@JohnK1987 Can I get a re-approve? Had to rebase

@JohnK1987 JohnK1987 self-requested a review May 12, 2023 05:25
@multiplemonomials multiplemonomials merged commit b9c0481 into master May 12, 2023
@multiplemonomials multiplemonomials deleted the dev/mimxrt105x-sleep-fixes branch May 12, 2023 05:49
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