8000 add an option to turn off QSPI when sleep by xiongyihui · Pull Request #3244 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

add an option to turn off QSPI when sleep #3244

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 5 commits into from
Aug 10, 2020
Merged

Conversation

xiongyihui
Copy link

To reduce power consumption of nRF52840, we can turn off QSPI when USB is not connected and MCU is going to sleep.
nRF52840 will consume less than 10 uA current in sleep mode if all peripherals using high frequency clock (HFCLK) are disabled.

Copy link
@jepler jepler left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! The failure in the CI system appears to be unrelated, but I have a few comments and areas you can improve.

jepler
jepler previously requested changes Aug 5, 2020
Copy link
@jepler jepler left a comment

Choose a reason for hiding this comment

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

[I intended to Request Changes with my earlier review, but failed to do so]

By the way I pre-ordered the PCB for this keyboard so I am excited about your work on it! Thanks again.

@xiongyihui
Copy link
Author

Thanks. I will make a change based on your suggestions.

@xiongyihui
Copy link
Author

Didn't add MICROPY_QSPI_OFF_WHEN_SLEEP or CIRCPY_QSPI_OFF_WHEN_SLEEP to py/circuitpy_mpconfig.mk yet, as it is not a module and is only for nrf port. Maybe add it to somewhere else.

Copy link
Member
@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

This looks like an awesome improvement! Thank you! Just a couple comments.

@xiongyihui
Copy link
Author

The feature is enabled by default now. To test it, we can turn off other peripherals(USB, PWM and etc) using high frequency clock (HFCLK), and then go to sleep. The current will decrease sharply.

tannewt reacted with thumbs up emoji

@xiongyihui
Copy link
Author

Tested the feature on a nrf52840 m2 devkit, here is a current graph

image

The code is:

import time

@micropython.asm_thumb
def mem(r0):
    ldr(r0, [r0, 0])

@micropython.asm_thumb
def mem_write(r0, r1):
    str(r1, [r0, 0])

peripherals = {
'RADIO': 0x40001000,
'UART0': 0x40002000,
'UARTE0': 0x40002000,
'SPI0': 0x40003000,
'SPIM0': 0x40003000,
'SPIS0': 0x40003000,
'TWI0': 0x40003000,
'TWIM0': 0x40003000,
'TWIS0': 0x40003000,
'SPI1': 0x40004000,
'SPIM1': 0x40004000,
'SPIS1': 0x40004000,
'TWI1': 0x40004000,
'TWIM1': 0x40004000,
'TWIS1': 0x40004000,
'NFCT': 0x40005000,
'GPIOTE': 0x40006000,
'SAADC': 0x40007000,
'TIMER0': 0x40008000,
'TIMER1': 0x40009000,
'TIMER2': 0x4000A000,
'RTC0': 0x4000B000,
'TEMP': 0x4000C000,
'RNG': 0x4000D000,
'ECB': 0x4000E000,
'AAR': 0x4000F000,
'CCM': 0x4000F000,
'WDT': 0x40010000,
'RTC1': 0x40011000,
'QDEC': 0x40012000,
'COMP': 0x40013000,
'LPCOMP': 0x40013000,
'EGU0': 0x40014000,
'SWI0': 0x40014000,
'EGU1': 0x40015000,
'SWI1': 0x40015000,
'EGU2': 0x40016000,
'SWI2': 0x40016000,
'EGU3': 0x40017000,
'SWI3': 0x40017000,
'EGU4': 0x40018000,
'SWI4': 0x40018000,
'EGU5': 0x40019000,
'SWI5': 0x40019000,
'TIMER3': 0x4001A000,
'TIMER4': 0x4001B000,
'PWM0': 0x4001C000,
'PDM': 0x4001D000,
'ACL': 0x4001E000,
'NVMC': 0x4001E000,
'PPI': 0x4001F000,
'MWU': 0x40020000,
'PWM1': 0x40021000,
'PWM2': 0x40022000,
'SPI2': 0x40023000,
'SPIM2': 0x40023000,
'SPIS2': 0x40023000,
'RTC2': 0x40024000,
'I2S': 0x40025000,
'FPU': 0x40026000,
'USBD': 0x40027000,
'UARTE1': 0x40028000,
'QSPI': 0x40029000,
'CC_HOST_RGF': 0x5002A000,
'CRYPTOCELL': 0x5002A000,
'PWM3': 0x4002D000,
'SPIM3': 0x4002F000
}

# turn off PWM0
mem_write(peripherals['PWM0'] + 0x500, 0)

# turn off rgb led
mem_write(0x50000700 + 4 * 29, 2)
mem_write(0x50000700 + 4 * 30, 2)
mem_write(0x50000700 + 4 * 31, 2)

for name, addr in peripherals.items():
    print('{}: {}'.format(name, mem(addr + 0x500)))

while True:
    time.sleep(1)

@tannewt tannewt requested a review from jepler August 10, 2020 20:55
Copy link
Member
@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! @jepler please approve and merge if your concerns have been addressed.

@jepler jepler dismissed their stale review August 10, 2020 21:06

thank you for addressing my changes

@jepler jepler merged commit 807f049 into adafruit:main Aug 10, 2020
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.

3 participants
0