Skip to content

Commit e6e6a4a

Browse files
committed
v1.11.3: Increase watchdog timeout to 256ms and optimize USB chunking
- Increased watchdog timeout from 128ms to 256ms for better stability - Reduced USB chunk timeout from 10ms to 3ms to prevent blocking - Prevents watchdog timeouts during USB reconnection on app restart - Total USB blocking time now ~30ms (well within 256ms watchdog limit)
1 parent 57c197d commit e6e6a4a

File tree

7 files changed

+40
-9
lines changed

7 files changed

+40
-9
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
All notable changes to the Pressboi firmware will be documented in this file.
44

5+
## [1.11.3] - 2025-11-26
6+
7+
### Changed
8+
- **Watchdog timeout increased to 256ms**: Doubled from 128ms to provide better stability during USB reconnection
9+
- **USB chunking timeout reduced**: Lowered per-chunk timeout from 10ms to 3ms to prevent blocking (total ~30ms vs previous ~100ms)
10+
11+
### Fixed
12+
- **Watchdog timeout on app restart**: Prevents main loop blocking during USB reconnection when TX queue processes large messages
13+
14+
## [1.11.2] - 2025-11-24
15+
16+
### Changed
17+
- **NVM dump output**: Added polarity information to `dump_nvm` command summary
18+
19+
## [1.11.1] - 2025-11-24
20+
21+
### Changed
22+
- Updated compiled binaries with latest source changes
23+
24+
## [1.11.0] - 2025-11-24
25+
26+
### Added
27+
- **`set_polarity` command**: Allows flipping coordinate system between 'normal' and 'inverted' modes, saved to NVM
28+
529
## [1.10.5] - 2025-11-21
630

731
### Fixed

Debug/pressboi.bin

0 Bytes
Binary file not shown.

Debug/pressboi.elf

64 Bytes
Binary file not shown.

Debug/pressboi.uf2

0 Bytes
Binary file not shown.

inc/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* @name General System Behavior
4747
* @{
4848
*/
49-
#define FIRMWARE_VERSION "1.11.2" ///< Pressboi firmware version
49+
#define FIRMWARE_VERSION "1.11.3" ///< Pressboi firmware version
5050
#define STATUS_MESSAGE_BUFFER_SIZE 256 ///< Standard buffer size for composing status and error messages.
5151
/** @} */
5252

@@ -173,7 +173,7 @@
173173
* @{
174174
*/
175175
#define WATCHDOG_ENABLED true ///< Enable/disable watchdog timer. When enabled, system must call safety check regularly or motors will be disabled.
176-
#define WATCHDOG_TIMEOUT_MS 100 ///< Watchdog timeout period in milliseconds. System will reset if not fed within this time.
176+
#define WATCHDOG_TIMEOUT_MS 256 ///< Watchdog timeout period in milliseconds. System will reset if not fed within this time.
177177
#define WATCHDOG_RECOVERY_FLAG 0xDEADBEEF ///< Magic number written to backup register to indicate watchdog recovery.
178178

179179
// Breadcrumb codes to identify where the watchdog timeout occurred

src/comms_controller.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void CommsController::processUsbSerial() {
138138
static int usbBufferIndex = 0;
139139
static bool usbFirstData = false; // Track if we've seen first data
140140

141-
// Limit characters processed per call to prevent watchdog timeout (128ms)
141+
// Limit characters processed per call to prevent watchdog timeout (256ms)
142142
int charsProcessed = 0;
143143
const int MAX_CHARS_PER_CALL = 32;
144144

@@ -355,6 +355,13 @@ void CommsController::processTxQueue() {
355355
// Large message - send in chunks with continuation markers
356356
// Format: "MSG_PART_1/3: first_50_chars"
357357
int totalChunks = (msgLen + CHUNK_SIZE - 1) / CHUNK_SIZE;
358+
359+
// Reduce timeout during USB reconnection to prevent watchdog timeout
360+
// During reconnection, USB buffer is often small (e.g. 63 bytes)
361+
// Limit total blocking time to ~30ms max (3ms per chunk × 10 chunks worst case)
362+
// With 256ms watchdog, this provides ample safety margin (30ms << 256ms)
363+
const uint32_t CHUNK_TIMEOUT_MS = 3; // Reduced from 10ms to 3ms
364+
358365
for (int chunk = 0; chunk < totalChunks; chunk++) {
359366
int offset = chunk * CHUNK_SIZE;
360367
int chunkLen = (msgLen - offset > CHUNK_SIZE) ? CHUNK_SIZE : (msgLen - offset);
@@ -367,10 +374,10 @@ void CommsController::processTxQueue() {
367374
strncat(chunkMsg, msg.buffer + offset, chunkLen);
368375
chunkMsg[headerLen + chunkLen] = '\0';
369376

370-
// Wait for buffer space (with timeout to prevent watchdog)
377+
// Wait for buffer space (with shorter timeout to prevent watchdog)
371378
uint32_t startWait = Milliseconds();
372379
while (ConnectorUsb.AvailableForWrite() < (int)strlen(chunkMsg) + 1) {
373-
if (Milliseconds() - startWait > 10) {
380+
if (Milliseconds() - startWait > CHUNK_TIMEOUT_MS) {
374381
// Timeout - skip this chunk to prevent blocking
375382
break;
376383
}

src/pressboi.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ void Pressboi::loop() {
254254
case WD_BREADCRUMB_LWIP_INPUT: breadcrumb_name = "LWIP_INPUT"; break;
255255
case WD_BREADCRUMB_LWIP_TIMEOUT: breadcrumb_name = "LWIP_TIMEOUT"; break;
256256
}
257-
snprintf(recoveryMsg, sizeof(recoveryMsg), "Watchdog timeout in %s - main loop blocked >128ms. Motors disabled. Send RESET to clear.", breadcrumb_name);
257+
snprintf(recoveryMsg, sizeof(recoveryMsg), "Watchdog timeout in %s - main loop blocked >256ms. Motors disabled. Send RESET to clear.", breadcrumb_name);
258258
reportEvent(STATUS_PREFIX_RECOVERY, recoveryMsg);
259259
}
260260

@@ -1009,7 +1009,7 @@ void Pressboi::handleWatchdogRecovery() {
10091009
case WD_BREADCRUMB_LWIP_INPUT: breadcrumb_name = "LWIP_INPUT"; break;
10101010
case WD_BREADCRUMB_LWIP_TIMEOUT: breadcrumb_name = "LWIP_TIMEOUT"; break;
10111011
}
1012-
snprintf(recoveryMsg, sizeof(recoveryMsg), "Watchdog timeout in %s - main loop blocked >128ms. Motors disabled. Send RESET to clear.", breadcrumb_name);
1012+
snprintf(recoveryMsg, sizeof(recoveryMsg), "Watchdog timeout in %s - main loop blocked >256ms. Motors disabled. Send RESET to clear.", breadcrumb_name);
10131013
m_comms.reportEvent(STATUS_PREFIX_RECOVERY, recoveryMsg);
10141014

10151015
// Keep LED on solid to indicate recovered state
@@ -1042,8 +1042,8 @@ void Pressboi::initializeWatchdog() {
10421042
// Configure watchdog:
10431043
// - For timeout at 1kHz WDT clock
10441044
// - Period values: 0x3 = 64 cycles (~64ms), 0x4 = 128 cycles (~128ms), 0x5 = 256 cycles (~256ms)
1045-
// - Use 0x4 for ~128ms - aggressive timeout to catch real hangs quickly
1046-
uint8_t per_value = 0x4; // 128 cycles ≈ 128ms at 1kHz
1045+
// - Use 0x5 for ~256ms - provides margin for USB reconnection without being too lenient
1046+
uint8_t per_value = 0x5; // 256 cycles ≈ 256ms at 1kHz
10471047

10481048
// Configure watchdog with early warning interrupt
10491049
WDT->CONFIG.reg = WDT_CONFIG_PER(per_value);

0 commit comments

Comments
 (0)