Skip to content

feat:implement brownout detection on STM32L433 host#4

Merged
bsatrom merged 2 commits intomainfrom
bds-brownout-detection
Apr 17, 2026
Merged

feat:implement brownout detection on STM32L433 host#4
bsatrom merged 2 commits intomainfrom
bds-brownout-detection

Conversation

@bsatrom
Copy link
Copy Markdown
Member

@bsatrom bsatrom commented Mar 13, 2026

No description provided.

Copy link
Copy Markdown

@Bucknalla Bucknalla left a comment

Choose a reason for hiding this comment

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

Nothing critical here but the graceful shutdown might accidentally become ungraceful under certain situations.

// Boot-loop prevention: if BORRSTF resets occur this many times within the window,
// enter a low-power hold to allow battery/charger to recover
#define BOOT_LOOP_MAX_COUNT 3 // Max consecutive brownout boots before hold
#define BOOT_LOOP_WINDOW_SEC 30 // Window to consider boots "consecutive" (seconds)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this is unused?

Comment on lines +176 to +182
if (syncAcquireI2C(500)) {
stateSetShutdownReason("pvd");
stateSave();
notecardEnterSleep();
// notecardEnterSleep() cuts power via ATTN/EN — should not return
syncReleaseI2C();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If this fails, then it falls through into default behaviour for BOR, so no state is saved? Maybe we could add a guard to the top of syncAcquireI2C() that suspends any task caller (that's not the main task) when g_pvdShutdownRequested is set:

  if (g_pvdShutdownRequested && xTaskGetCurrentTaskHandle() != g_mainTaskHandle) {
      vTaskSuspend(NULL);
  }

This prevents other tasks from starting new I2C transactions after PVD fires, so that the main task is guaranteed to acquire it.

You could also increase the 500ms timeout — since no new transactions will start, you're only potentially waiting for one Notecard transaction to complete. You could change this to NOTECARD_RESPONSE_TIMEOUT_MS to make the path much more reliable.

# Conflicts:
#	songbird-firmware/src/core/SongbirdState.h
@bsatrom bsatrom merged commit b55f792 into main Apr 17, 2026
1 check passed
@bsatrom bsatrom deleted the bds-brownout-detection branch April 17, 2026 02:14
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