More fixes for sleep and clocking stuff on MIMXRT105x #158
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Test results
Reviewers