Skip to content

xtensa/esp32s3: fix esp32s3_cam uninit/stop_capture bugs#18663

Closed
JianyuWang0623 wants to merge 1 commit intoapache:masterfrom
JianyuWang0623:fix/esp32s3-cam
Closed

xtensa/esp32s3: fix esp32s3_cam uninit/stop_capture bugs#18663
JianyuWang0623 wants to merge 1 commit intoapache:masterfrom
JianyuWang0623:fix/esp32s3-cam

Conversation

@JianyuWang0623
Copy link
Copy Markdown
Contributor

@JianyuWang0623 JianyuWang0623 commented Apr 2, 2026

Summary

Fix several issues in the ESP32-S3 CAM driver that cause heap corruption, IRQ mapping corruption, and stale DMA writes when using the camera example app with V4L2 USERPTR mode.

Changes

  • stop_capture: reset DMA channel, CAM module and AFIFO under spinlock to fully quiesce hardware before returning. Clear pending VSYNC interrupt to prevent stale ISR firing.

  • uninit: reset CAM/AFIFO before releasing DMA to prevent in-flight transfers after channel detach. Use esp_teardown_irq with correct peripheral ID (ESP32S3_PERIPH_LCD_CAM) instead of irq_detach which corrupts the shared IRQ mapping table. Mask interrupts and clear pending flags under spinlock before detaching handler.

  • uninit: preserve XCLK output so the sensor remains accessible via I2C for subsequent re-initialization.

  • set_buf/uninit: track driver-allocated vs user-provided frame buffers with fb_allocated flag to prevent double-free when using V4L2 USERPTR mode.

Impact

  • Fixes crash (StoreProhibitedCause) in mm_delayfree during camera app cleanup
  • Fixes IRQ 35 panic on second camera app invocation (irq_detach vs esp_teardown_irq)
  • Prevents potential DMA writes to freed buffers after stop_capture

Testing

Tested on lckfb-szpi-esp32s3 (ESP32-S3 + GC0308 sensor):

  • Camera example app: 10 captures + LCD preview + normal exit, no crash
  • Multiple consecutive runs stable
  • camcap (simple V4L2 capture) 3x consecutive pass
  • ADB stable throughout

Related PR

apps-side fix: apache/nuttx-apps#3446

Fix several issues in the ESP32-S3 CAM driver:

- stop_capture: reset DMA channel, CAM module and AFIFO under
  spinlock to fully quiesce hardware before returning. Clear
  pending VSYNC interrupt to prevent stale ISR firing.

- uninit: reset CAM/AFIFO before releasing DMA to prevent
  in-flight transfers after channel detach. Use esp_teardown_irq
  with correct peripheral ID (ESP32S3_PERIPH_LCD_CAM) instead of
  irq_detach which corrupts the shared IRQ mapping table. Mask
  interrupts and clear pending flags under spinlock before
  detaching handler.

- uninit: preserve XCLK output so the sensor remains accessible
  via I2C for subsequent re-initialization.

- set_buf/uninit: track driver-allocated vs user-provided frame
  buffers with fb_allocated flag to prevent double-free when
  using V4L2 USERPTR mode.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
@JianyuWang0623 JianyuWang0623 marked this pull request as draft April 2, 2026 03:09
@github-actions github-actions bot added Arch: xtensa Issues related to the Xtensa architecture Size: S The size of the change in this PR is small labels Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: xtensa Issues related to the Xtensa architecture Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant