From 309999afba04740020c003be7f92f472c572ab1d Mon Sep 17 00:00:00 2001 From: RubenKelevra Date: Thu, 17 Jul 2025 16:49:37 +0200 Subject: [PATCH] cam_hal: add guard in cam_task() so DMA transfers cannot exceed image slot size Previously there is no limit how much data would be transferred via DMA from the camera. Added a DMA overflow detection block in cam_task() so the driver stops if the number of frame copies exceeds the is reaching the maximum amount of storage allocated in PSRAM. --- driver/cam_hal.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/driver/cam_hal.c b/driver/cam_hal.c index 815810343f..dda8383895 100644 --- a/driver/cam_hal.c +++ b/driver/cam_hal.c @@ -193,7 +193,6 @@ static void cam_task(void *arg) if (cam_obj->fb_size < (frame_buffer_event->len + pixels_per_dma)) { ESP_LOGW(TAG, "FB-OVF"); ll_cam_stop(cam_obj); - DBG_PIN_SET(0); continue; } frame_buffer_event->len += ll_cam_memcpy(cam_obj, @@ -207,6 +206,14 @@ static void cam_task(void *arg) cam_obj->state = CAM_STATE_IDLE; } cnt++; + // stop when too many DMA copies occur so the PSRAM + // framebuffer slot doesn't overflow from runaway transfers + if (cnt >= cam_obj->frame_copy_cnt) { + ESP_LOGE(TAG, "DMA overflow"); + ll_cam_stop(cam_obj); + cam_obj->state = CAM_STATE_IDLE; + continue; + } } else if (cam_event == CAM_VSYNC_EVENT) { //DBG_PIN_SET(1);