10000 Nordic reset reason after deep sleep by dhalbert · Pull Request #10344 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Nordic reset reason after deep sleep #10344

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

Conversation

dhalbert
Copy link
Collaborator

nordic doesn't really deep sleep: it light-sleeps with low current draw. There was some logic that tried to be careful about determining the micrcontroller.cpu.reset_reason in such cases, but it didn't work when micrcontroller.reset() was called. This clears some saved state to make sure the reset reason is correct.

Found when helping @bradanlane with a BLE HID problem.

Tested on a CPB that this fix works, using the following test program, which was cobbled from @bradanlane's test program for something else. Before this fix, the program would get stuck in a reset loop, because the reset reason was stuck on ResetReason.DEEP_SLEEP_ALARM even after microcontroller.reset(). Now it properly goes to ResetReason.SOFTWARE.

import time
import board
import busio
import digitalio
import alarm
import microcontroller

uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=0)

# usage: uart_print(f"string stuff {variable} ... \n")
def uart_print(msg):
    global uart
    print(msg)
    uart.write(bytes(msg + "\r\n", "utf-8"))
    # return

uart_print("--------------")

reason = microcontroller.cpu.reset_reason
uart_print(str(reason))
time.sleep(1)
if reason is microcontroller.ResetReason.DEEP_SLEEP_ALARM:
    microcontroller.reset()

wake = alarm.pin.PinAlarm(pin=board.BUTTON_B, value=True, pull=True)
uart_print("Sleep in two seconds")
time.sleep(2)
alarm.exit_and_deep_sleep_until_alarms(wake)

@dhalbert dhalbert added this to the 10.0.0 milestone May 14, 2025
@dhalbert dhalbert force-pushed the nordic-reset-reason-after-deep-sleep branch from e7e6fa4 to 2105432 Compare May 14, 2025 18:46
tannewt
tannewt previously approved these changes May 14, 2025
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.

Thank you!

@dhalbert dhalbert force-pushed the nordic-reset-reason-after-deep-sleep branch from 2105432 to 86c5680 Compare May 14, 2025 20:38
@dhalbert
Copy link
Collaborator Author

Force-pushed a commit to fix simmel build. Needed to guard when CIRCUITPY_ALARM was not set.

@dhalbert dhalbert requested a review from tannewt May 14, 2025 20:48
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.

Ok!

@tannewt tannewt merged commit bbefbd6 into adafruit:main May 14, 2025
67 checks passed
@dhalbert dhalbert deleted the nordic-reset-reason-after-deep-sleep branch May 15, 2025 19:53
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
0