Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Turning off QSPI during sleep (nRF52840)
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Turning off QSPI during sleep (nRF52840)

by stmy on Sun Aug 30, 2020 6:35 pm

Hi everyone,

I saw that CircuitPython 6.0.0 alpha 3 introduced turning off the QSPI during sleep for the nRF52840. I am very interested in getting this to work since I have had to add a TPL5110 timer to a number of projects in the past to reduce power consumption.
The current during sleep using alpha 2 is around 2.5 mA (from battery) for my itsybitsy BLE (DotStar not yet removed) and I read that without the QSPI running it should be significantly lower.
So I built CircuitPython 6.0.0 alpha 3 with CIRCUITPY_ENABLE_MPY_NATIVE=1 to be able to use the @micropython.asm_thumb decorator but the code from https://github.com/adafruit/circuitpython/pull/3244 still uses the same amount of power during sleep. I did add a few lines to turn off the DotStar LED using the Adafruit library but I am not sure if that is the issue.

Am I doing something wrong or does the QSPI just not draw a lot of power? The measurements by xiongyihui show almost no current after turning it off but they were using a different board.

Thanks,

stmy

code by xiongyihui changed to turn off the DotStar LED:
Code: Select all | TOGGLE FULL SIZE
import time

#everything I added
import board
import adafruit_dotstar as dotstar
dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
dot[0] = (0, 0, 0)

@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(15)

stmy
 
Posts: 3
Joined: Sun Aug 30, 2020 6:11 pm

Re: Turning off QSPI during sleep (nRF52840)

by danhalbert on Sun Aug 30, 2020 7:10 pm

Hi, could you bring this up either in the PR or in a new issue? Thanks. Then xiongyihui could respond direclty.

danhalbert
 
Posts: 2118
Joined: Tue Aug 08, 2017 12:37 pm

Re: Turning off QSPI during sleep (nRF52840)

by stmy on Mon Sep 07, 2020 7:36 am

Just in case someone else stumbles on this thread in the future, this is the issue on Github: https://github.com/adafruit/circuitpython/issues/3360
It appeares that using the dotstar library to disable the status LED was (most of) the problem. After removing the LED physically, current during sleep dropped to 0.5 mA. However as I understand it anything that uses for example SPI will cause current during sleep afterwards to be higher again.

stmy
 
Posts: 3
Joined: Sun Aug 30, 2020 6:11 pm

Re: Turning off QSPI during sleep (nRF52840)

by danhalbert on Mon Sep 07, 2020 9:46 am

You can effectively turn off the status DotStar by doing `supervisor.set_rgb_status_brightness()`. I am sorry I didn't mention this earlier and you ended up removing it.
https://circuitpython.readthedocs.io/en ... brightness

danhalbert
 
Posts: 2118
Joined: Tue Aug 08, 2017 12:37 pm

Re: Turning off QSPI during sleep (nRF52840)

by stmy on Tue Sep 08, 2020 11:16 am

Don't worry about it. That would have still left me with the quiescent current of the LED so I probably would have ended up removing it sooner or later anyway. I just tested current during sleep after supervisor.set_rgb_status_brightness(0) using one of my itsybitsys with the LED intact and it is exactly 1 mA higher. But unlike using the dotstar library this way does not seem to turn on the HFCLK so still a very useful tip. Thanks!

stmy
 
Posts: 3
Joined: Sun Aug 30, 2020 6:11 pm

Please be positive and constructive with your questions and comments.