Skip to content

Commit

Permalink
Enable WDT in Pipboy firmware, allow BTN10 (power) to stop kicking it…
Browse files Browse the repository at this point in the history
… and force a reboot
  • Loading branch information
gfwilliams committed Nov 21, 2024
1 parent 5d6ae8d commit 1aed934
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions README_BuildProcess.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ This is a partial list of definitions that can be added in a `BOARD.py` file's `
* `ESPR_MIN_WFI_TIME_MS` - STM32: default 0.1ms, but if set, Espruino won't enter __WFI sleep unless the next setInterval is more than this number of milliseconds away
* `ESPR_GRAPHICS_SELF_INIT` - Should the Graphics library instantiate itself with its own `g` instance?
* `ESPR_LCD_MANUAL_BACKLIGHT` - STM32/FSMC: Don't turn the backlight on and leave code to do this manually
* `ESPR_DISABLE_KICKWATCHDOG_PIN=BTN1_PININDEX` - If this pin is 1, skip kickWatchdog calls (which would eventually force a reboot if WDT enabled)


There are some specifically that are useful for cutting a few bytes out of the build:
Expand Down
1 change: 1 addition & 0 deletions boards/PIPBOY.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'DEFINES+=-DESPR_RTC_ALWAYS_TRY_LSE', # If we boot and RTC is initialised but using LSI, try again at starting LSE
'DEFINES+=-DESPR_FS_LARGE_WRITE_BUFFER', # speeds up SD card writes ~3x
'DEFINES+=-DESPR_LCD_MANUAL_BACKLIGHT', # Pipboy handles LCD backlight on/off so we can reduce flicker
'DEFINES+=-DESPR_DISABLE_KICKWATCHDOG_PIN=BTN10_PININDEX', # If the power button is held, don't kick watchdog so we reboot
'DEFINES+=-DESPR_OFFICIAL_BOARD', # Don't display the donations nag screen
'STLIB=STM32F407xx',
'-DHSE_VALUE=9000000',
Expand Down
3 changes: 3 additions & 0 deletions libs/pipboy/jswrap_pipboy.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "jshardware.h"
#include "jswrap_graphics.h"
#include "jswrap_interactive.h"
#include "jswrap_espruino.h"
#include "jspin.h"
#include "jsflags.h"
#include "jshardware.h"
Expand Down Expand Up @@ -1219,6 +1220,8 @@ JsVar *jswrap_pb_streamPlaying() {
"generate" : "jswrap_pb_init"
}*/
void jswrap_pb_init() {
// Enable watchdog
jswrap_espruino_enableWatchdog(15, NULL); // init watchdog, auto mode
// splash screen
const unsigned char img_raw[] = {199, 17, 2, 0, 0, 31, 255, 255, 255, 255, 255, 255, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 255, 255, 255, 255, 255, 255, 233, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47, 255, 255, 255, 255, 255, 255, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 91, 255, 213, 85, 85, 111, 255, 192, 11, 255, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 86, 255, 249, 85, 85, 85, 255, 252, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 253, 0, 0, 0, 191, 253, 0, 127, 255, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 255, 128, 0, 0, 7, 255, 208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 255, 224, 0, 0, 7, 255, 224, 127, 255, 224, 2, 255, 255, 255, 255, 255, 233, 0, 0, 0, 0, 0, 0, 0, 0, 255, 248, 0, 0, 0, 63, 254, 0, 107, 255, 255, 255, 232, 0, 191, 255, 255, 224, 127, 255, 255, 248, 0, 0, 63, 255, 255, 255, 255, 255, 254, 7, 255, 255, 192, 47, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 15, 255, 255, 255, 255, 255, 255, 224, 127, 255, 255, 255, 255, 253, 91, 255, 255, 255, 131, 255, 255, 255, 224, 0, 3, 255, 255, 255, 255, 255, 255, 224, 26, 255, 252, 0, 107, 255, 250, 170, 170, 255, 248, 0, 170, 170, 170, 170, 168, 0, 191, 255, 255, 255, 255, 255, 248, 7, 255, 250, 170, 171, 255, 255, 255, 255, 255, 252, 47, 255, 255, 254, 0, 0, 47, 255, 191, 255, 255, 234, 80, 0, 7, 255, 192, 0, 47, 255, 0, 0, 11, 255, 192, 11, 255, 255, 255, 255, 224, 11, 255, 234, 170, 170, 171, 255, 240, 63, 253, 0, 0, 31, 255, 255, 253, 191, 255, 0, 127, 255, 208, 0, 0, 2, 255, 244, 0, 0, 0, 0, 0, 0, 127, 253, 0, 1, 255, 244, 0, 0, 191, 252, 0, 21, 85, 85, 85, 85, 0, 127, 254, 0, 0, 0, 31, 255, 67, 255, 224, 0, 0, 255, 245, 85, 64, 255, 253, 31, 255, 244, 0, 0, 0, 31, 255, 128, 0, 0, 0, 0, 0, 3, 255, 208, 0, 31, 255, 64, 0, 7, 255, 208, 0, 0, 0, 0, 0, 0, 7, 255, 224, 0, 0, 0, 255, 248, 47, 255, 0, 0, 15, 255, 128, 0, 1, 255, 255, 255, 248, 0, 0, 0, 85, 255, 248, 0, 0, 0, 0, 0, 0, 127, 254, 81, 20, 255, 249, 64, 5, 127, 255, 213, 64, 0, 0, 0, 0, 17, 127, 255, 64, 0, 5, 95, 255, 130, 255, 245, 85, 85, 255, 248, 0, 0, 2, 255, 255, 254, 0, 0, 0, 15, 255, 255, 192, 0, 0, 0, 0, 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 64, 0, 0, 0, 3, 255, 255, 255, 255, 255, 255, 255, 248, 15, 255, 255, 255, 255, 255, 128, 0, 0, 3, 255, 255, 128, 0, 0, 0, 127, 255, 252, 0, 0, 0, 0, 0, 11, 255, 255, 255, 255, 255, 255, 255, 255, 255, 250, 255, 224, 0, 0, 0, 0, 31, 255, 255, 255, 255, 255, 255, 249, 0, 11, 255, 255, 255, 255, 144, 0, 0, 0, 127, 255, 208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 255, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47, 255, 244, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47, 255, 253, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 255, 253, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 255, 255, 208, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 255, 254, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 170, 128, 0, 0, 0, 0, 0, 0};
JsVar *img = jsvNewNativeString((char*)&img_raw[0], sizeof(img_raw));
Expand Down
3 changes: 3 additions & 0 deletions targets/esp32/jshardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ void jshEnableWatchDog(JsVarFloat timeout) {

// Kick the watchdog
void jshKickWatchDog() {
#ifdef ESPR_DISABLE_KICKWATCHDOG_PIN // if this pin is asserted, don't kick the watchdog
if (jshPinGetValue(ESPR_DISABLE_KICKWATCHDOG_PIN)) return;
#endif
if (wdt_enabled)
esp_task_wdt_reset();
}
Expand Down
3 changes: 3 additions & 0 deletions targets/nrf5x/jshardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,9 @@ void jshEnableWatchDog(JsVarFloat timeout) {
}

void jshKickWatchDog() {
#ifdef ESPR_DISABLE_KICKWATCHDOG_PIN // if this pin is asserted, don't kick the watchdog
if (jshPinGetValue(ESPR_DISABLE_KICKWATCHDOG_PIN)) return;
#endif
NRF_WDT->RR[0] = 0x6E524635;
}

Expand Down
3 changes: 3 additions & 0 deletions targets/stm32/jshardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -3007,6 +3007,9 @@ void jshEnableWatchDog(JsVarFloat timeout) {

// Kick the watchdog
void jshKickWatchDog() {
#ifdef ESPR_DISABLE_KICKWATCHDOG_PIN // if this pin is asserted, don't kick the watchdog
if (jshPinGetValue(ESPR_DISABLE_KICKWATCHDOG_PIN)) return;
#endif
IWDG_ReloadCounter();
}

Expand Down

0 comments on commit 1aed934

Please sign in to comment.