feat:implement brownout detection on STM32L433 host#4
Conversation
Bucknalla
left a comment
There was a problem hiding this comment.
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) |
| if (syncAcquireI2C(500)) { | ||
| stateSetShutdownReason("pvd"); | ||
| stateSave(); | ||
| notecardEnterSleep(); | ||
| // notecardEnterSleep() cuts power via ATTN/EN — should not return | ||
| syncReleaseI2C(); | ||
| } |
There was a problem hiding this comment.
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
No description provided.