Skip to content
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

Bug 1668 v2 - Provide method to prevent init of SYS_CLK, when left on during 'lightsleep' #1672

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

mungewell
Copy link

During 'lightsleep' user may want to keep some clocks running (for example PIOs), but at present microPython calls 'clock-init()' causing the SYS_CLK to be reinitialized.

This patch allows microPython to provide the previously used 'sleep_en0 & sleep_en1' signifying which clocks stayed on. As most are dependant of SYS_CLK it can be inferred that this does NOT need to (/should NOT) be re-initialized.

…ing 'lightsleep'

During 'lightsleep' user may want to keep some clocks running (for example PIOs),
but at present microPython calls 'clock-init()' causing the SYS_CLK to be reinitialised.

This patch allows microPython to provide the previously used 'sleep_en0 & sleep_en1'
signifying which clocks stayed on. As most are dependant of SYS_CLK it can be
inferred that this does NOT need to (/should NOT) be re-initilised.
@mungewell
Copy link
Author

Yes, should be a logical "&&".

I'll update PR and add some documentation. Thanks.

@mungewell
Copy link
Author

I removed the tabs.

Do you want the whole series resubmitted (_v3?) as a single patch/pull request?

@lurch
Copy link
Contributor

lurch commented Mar 23, 2024

That's not my decision to make, so leave it as-is for now unless asked otherwise 🙂

@kilograham
Copy link
Contributor

fixes #1668

@kilograham kilograham added this to the 1.6.0 milestone May 19, 2024
Comment on lines 217 to 226
/// \tag::configure_clk_sys[]
// CLK SYS = PLL SYS (usually) 125MHz / 1 = 125MHz
clock_configure(clk_sys,
CLOCKS_CLK_SYS_CTRL_SRC_VALUE_CLKSRC_CLK_SYS_AUX,
CLOCKS_CLK_SYS_CTRL_AUXSRC_VALUE_CLKSRC_PLL_SYS,
SYS_CLK_KHZ * KHZ,
SYS_CLK_KHZ * KHZ);
if (init_sys_clock) {
clock_configure(clk_sys,
CLOCKS_CLK_SYS_CTRL_SRC_VALUE_CLKSRC_CLK_SYS_AUX,
CLOCKS_CLK_SYS_CTRL_AUXSRC_VALUE_CLKSRC_PLL_SYS,
SYS_CLK_KHZ * KHZ,
SYS_CLK_KHZ * KHZ);
}
/// \end::configure_clk_sys[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "tag" is used to auto-include this code snippet into page 191 of https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf
Screenshot from 2024-05-20 10-55-44

So in order not to clutter that example, it might make sense to move your new if check to outside of the tag? i.e.

    if (init_sys_clock) {
        /// \tag::configure_clk_sys[]
        // CLK SYS = PLL SYS (usually) 125MHz / 1 = 125MHz
        clock_configure(clk_sys,
                        CLOCKS_CLK_SYS_CTRL_SRC_VALUE_CLKSRC_CLK_SYS_AUX,
                        CLOCKS_CLK_SYS_CTRL_AUXSRC_VALUE_CLKSRC_PLL_SYS,
                        SYS_CLK_KHZ * KHZ,
                        SYS_CLK_KHZ * KHZ);
        /// \end::configure_clk_sys[]
    }

@projectgus
Copy link

projectgus commented Jun 25, 2024

If this patch was extended to also check and selectively init PLL_USB then it would also meet the use case in #1746. Looks like a good approach to reuse the sleep bits this way.

@peterharperuk peterharperuk modified the milestones: 1.6.1, 1.7.0 Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants