Skip to content

Commit 74e41d5

Browse files
committed
cam_hal: throttle WARN spam so cam_task reduces it's stack footprint
Background ---------- • Every bad frame produced an ESP_LOGW(): - “Unexpected NULL frame …” (non-S3) - “NO-EOI – JPEG end marker missing” • Each ESP_LOGW() invokes vsnprintf() once ⇒ ~300 B of stack for that call. What’s changed -------------- * First occurrence of each warning: ESP_DRAM_LOGW_ONCE() → zero stack after the first print. * Subsequent occurrences: count with a uint16_t and emit a **literal** ESP_LOGW() only every 100th event (~ 60 B stack usage). * Counters auto-reset at 10 000 to avoid wraparound. * On ESP32-S3 the “Giving up GDMA reset…” message is also moved to ESP_DRAM_LOGW_ONCE() to avoid stack usage. Effects ------- * Occasional diagnostics are still available: first warning and then a summary every 100 events.
1 parent c4204d3 commit 74e41d5

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

driver/cam_hal.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,12 @@ camera_fb_t *cam_take(TickType_t timeout)
481481
#if CONFIG_IDF_TARGET_ESP32S3
482482
uint16_t dma_reset_counter = 0;
483483
static const uint8_t MAX_GDMA_RESETS = 3;
484+
#else
485+
/* throttle repeated NULL frame warnings */
486+
static uint16_t warn_null_cnt;
484487
#endif
488+
/* throttle repeated NO-EOI warnings */
489+
static uint16_t warn_eoi_miss_cnt;
485490

486491
for (;;)
487492
{
@@ -506,12 +511,21 @@ camera_fb_t *cam_take(TickType_t timeout)
506511
continue; /* retry with queue timeout */
507512
}
508513
if (dma_reset_counter == MAX_GDMA_RESETS) {
509-
ESP_LOGW(TAG, "Giving up GDMA reset after %u tries", dma_reset_counter);
514+
ESP_DRAM_LOGW_ONCE(TAG, "Giving up GDMA reset after %u tries", dma_reset_counter);
510515
dma_reset_counter++; /* suppress further logs */
511516
}
512517
#else
513518
/* Early warning for misbehaving sensors on other chips */
514-
ESP_LOGW(TAG, "Unexpected NULL frame on %s", CONFIG_IDF_TARGET);
519+
if (warn_null_cnt == 0) {
520+
ESP_DRAM_LOGW_ONCE(TAG, "Unexpected NULL frame on " CONFIG_IDF_TARGET);
521+
}
522+
if (++warn_null_cnt % 100 == 0) {
523+
ESP_LOGW(TAG, "Unexpected NULL frame – 100 additional drops");
524+
}
525+
if (warn_null_cnt >= 10000) {
526+
ESP_LOGW(TAG, "Unexpected NULL frame log counter reset at 10000");
527+
warn_null_cnt = 0;
528+
}
515529
#endif
516530
vTaskDelay(1); /* immediate yield once resets are done */
517531
continue; /* go to top of loop */
@@ -525,7 +539,16 @@ camera_fb_t *cam_take(TickType_t timeout)
525539
return dma_buffer;
526540
}
527541

528-
ESP_LOGW(TAG, "NO-EOI");
542+
if (warn_eoi_miss_cnt == 0) {
543+
ESP_DRAM_LOGW_ONCE(TAG, "NO-EOI – JPEG end marker missing");
544+
}
545+
if (++warn_eoi_miss_cnt % 100 == 0) {
546+
ESP_LOGW(TAG, "NO-EOI – 100 additional misses");
547+
}
548+
if (warn_eoi_miss_cnt >= 10000) {
549+
ESP_LOGW(TAG, "NO-EOI counter reset at 10000");
550+
warn_eoi_miss_cnt = 0;
551+
}
529552
cam_give(dma_buffer);
530553
continue; /* wait for another frame */
531554
} else if (cam_obj->psram_mode &&

0 commit comments

Comments
 (0)