Skip to content

Conversation

@KATE-WANG-NXP
Copy link
Contributor

The previous initialization sequence fails to configure the module properly. Update the sequence using the code provided by vendor. The update is verified using the FRDM-MCXN947 SmartDMA camera case under samples/drivers/video/capture using command:

west build -b frdm_mcxn947/mcxn947/cpu0 samples/drivers/video/capture -DCONFIG_DEBUG_OPTIMIZATIONS=y -d n947_camera -DSHIELD="lcd_par_s035_8080;dvp_20pin_ov7670"

@KATE-WANG-NXP
Copy link
Contributor Author

This PR is meant to fix nxp-mcuxpresso/mcuxsdk-core#3

The previous initialization sequence fails to configure the module
properly. Update the sequence using the code provided by vendor.
The update is verified using the FRDM-MCXN947 SmartDMA camera case
under samples/drivers/video/capture.

Signed-off-by: Kate Wang <[email protected]>
@sonarqubecloud
Copy link

Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works very well!

Photo of the ceiling old wooden beam taken with it, using the UVC branch:
mpv-shot0002

west build samples/subsys/usb/uvc --board frdm_mcxn947/mcxn947/cpu0 --shield dvp_20pin_ov7670

It seems like there was an issue with how PCLK was driven. Good for us to know in the future.

@ngphibang
Copy link
Contributor

@KATE-WANG-NXP Thank you very much for helping fixing this (and @josuah for the test).
cc @danieldegrasse who originally made the driver as I am not sure too how it could work with the orignal version ...

@josuah josuah requested a review from danieldegrasse June 17, 2025 10:28
@kartben kartben merged commit e2d97c7 into zephyrproject-rtos:main Jun 19, 2025
26 checks passed
@hakehuang
Copy link
Contributor

hakehuang commented Jun 25, 2025

if fails at my board

west build -p -b frdm_mcxn947/mcxn947/cpu0 samples/drivers/video/capture -T sample.video.capture
*** Booting Zephyr OS build v4.1.0-5984-g544439ee6e27 ***

uart:~$ ^@*** Booting Zephyr OS build v4.1.0-6641-gfa732ece862a ***
I: Video device: video-sdma
I: - Capabilities:
I:   RGBP width [320; 320; 0] height [240; 240; 0]
I: - Video format: RGBP 320x240

uart:~$ I: - Supported frame intervals for the default format:
I: - Supported controls:
I:              device: ov7670@21
I:                  Horizontal Flip 0x00980914 (bool)   (flags=0x00) : min=0 max=1 step=1 default=0 value=0
I:              E: ***** USAGE FAULT *****
E:   Stack overflow (context area not valid)
E: r0/a1:  0xaaaaaaaa  r1/a2:  0xaaaaaaaa  r2/a3:  0x100121c0
E: r3/a4:  0x09100000 r12/ip:  0xaaaaaaaa r14/lr:  0xaaaaaaaa
E:  xpsr:  0xaaaaaa00
E: s[ 0]:  0xaaaaaaaa  s[ 1]:  0xaaaaaaaa  s[ 2]:  0x00000000  s[ 3]:  0x0000000a
E: s[ 4]:  0x300169f0  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x0000002d
E: s[ 8]:  0x00000000  s[ 9]:  0x10000c21  s[10]:  0x30016998  s[11]:  0x10013be7
E: s[12]:  0x00000000  s[13]:  0x00000000  s[14]:  0x100121b5  s[15]:  0x00000020
E: fpscr:  0x10014204
E: Faulting instruction address (r15/pc): 0xaaaaaaaa
E: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
E: Current thread: 0x30000bf8 (main)
E: Halting system

@zejiang0jason
Copy link
Contributor

Hi @KATE-WANG-NXP , could you please check the error @hakehuang mentioned? thanks.

@ngphibang
Copy link
Contributor

It fails right at pritnting controls ... maybe address2line would help to debug ?. I don't have a valid mcxn947 board now to test unfortunately

@marinjurjevic
Copy link
Contributor

Hi all.
I've been doing some quick tests using latest zephyr on which I rebased tinyvision-ai-inc/pr-usb-uvc provided by @josuah.

* 493d2614bdd (HEAD -> pr-usb-uvc) samples: usb: add new UVC sample
* 7e5f6806e07 usb: device_next: new USB Video Class implementation
* 594cb323179 boards: nicla_vision: add usbd test feature
* 0285cf4235c (origin/main, origin/HEAD, main) drivers: clock_control: update nrf2 lfosc_get_accuracy

My toolchain info:

└─▶ west build -b frdm_mcxn947/mcxn947/cpu0 --shield dvp_20pin_ov7670 -p
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: /home/marin/code/zephyrproject/zephyr/samples/subsys/usb/uvc
-- CMake version: 4.0.3-dirty
-- Found Python3: /home/marin/code/zephyrproject/.venv/bin/python3 (found suitable version "3.13.3", minimum required is "3.12") found components: Interpreter
-- Cache files will be written to: /home/marin/.cache/zephyr
-- Zephyr version: 4.1.99 (/home/marin/code/zephyrproject/zephyr)
-- Found west (found suitable version "1.3.0", minimum required is "0.14.0")
-- Board: frdm_mcxn947, qualifiers: mcxn947/cpu0
-- Shield(s): dvp_20pin_ov7670
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.17.0 (/home/marin/.local/share/zephyr-sdk/zephyr-sdk-0.17.0)
-- Found toolchain: zephyr 0.17.0 (/home/marin/.local/share/zephyr-sdk/zephyr-sdk-0.17.0)
-- Found Dtc: /home/marin/.local/share/zephyr-sdk/zephyr-sdk-0.17.0/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6")

I've built sample with different log variants and they all exhibit different behavior. I've recorded logs from serial for all variants. Access to video device is done using ffplay. Below you'll find highlights I've found interesting from logs. Full logs for deferred and minimal logging are attached.

Deferred logging

Built with west build -b frdm_mcxn947/mcxn947/cpu0 --shield dvp_20pin_ov7670 -p

Due to deferred logging lot of messages is being dropped. I've recorded couple of runs trying to catch fault and it USAGE FAULT is escalated in main thread. Two warning messages are always present

<wrn> usbd_uvc: Could not set the framerate of video-sdma
...
<wrn> uvc_sample: Failed to setup the signal on video-sdma output endpoint
Usage fault snippet from deferred logs
[00:00:21.368,000] <inf> usbd_uvc: Host sent a VideoStreaming PROBE control
[00:00:21.368,000] <inf> usbd_ch9: Handle control 0x3001b974 ep 0x00, len 0, s:0 d:0 s:1
[00:00:21.368,000] <inf> usbd_ch9: s-in-status finished
[00:00:21.368,000] <inf> usbd_ch9: Handle control 0x3001b974 ep 0x00, len 8, s:1 d:0 s:0
[00:00:21.368,000] <inf> usbd_uvc: Host sent a SET_CUR request, wValue 0x0100, wIndex 0x0001, wLength 48
[00:00:21.368,000] <inf> usbd_uvc: Host sent a VideoStreaming PROBE control
[00:00:21.368,000] <inf> usbd_ch9: spool 0x3001b998
[00:00:21.368,000] <inf> usbd_ch9: Handle control 0x3001b950 ep 0x80, len 0, s:0 d:0 s:1
[00:00:21.368,000] <inf> usbd_ch9: s-(out)-status finished
[00:00:21.368,000] <inf> usbd_ch9: Handle control 0x3001b950 ep 0x00, len 8, s:1 d:0 s:0
[00:00:21.368,000] <inf> usb[00:00:21.368,000] <inf> usbd_uvc: Host sent a VideoStreaming PROBE control
[00:00:21.368,000] <inf> usbd_ch9: Handle control 0x3001b998 ep 0x00, len 0, s:0 d:0 s:1
[00:00:21.368,000] <inf> usbd_ch9: s-in-status finished
[00:00:21.372,000] <inf> usbd_ch9: Handle control 0x3001b998 ep 0x00, len 8, s:1 d:0 s:0
[00:00:21.372,000] <inf> usbd_uvc: Host sent a SET_CUR request, wValue 0x0200, wIndex 0x0001, wLength 48
[00:00:21.372,000] <inf> usbd_uvc: Host sent a VideoStreaming COMMIT control
[00:00:21.372,000] <inf> usbd_uvc: Ready to transfer, setting source format to 'RGBP' 320x240
[00:00:21.374,000] <wrn> usbd_uvc: Could not set the framerate of video-sdma
[00:00:21.374,000] [00:00:21.377,000] <inf> uvc_sample: Starting the video transfer
--- 4 messages dropped ---
[00:00:21.471,000] <err> os: ***** USAGE FAULT *****
[00:00:21.471,000] <err> os:   Illegal load of EXC_RETURN into PC
[00:00:21.471,000] <err> os: r0/a1:  0x3cef3ce7  r1/a2:  0x5cef5cef  r2/a3:  0x3ce73cef
[00:00:21.471,000] <err> os: r3/a4:  0x3cef5de7 r12/ip:  0x3cef5de7 r14/lr:  0x5cef5cef
[00:00:21.471,000] <err> os:  xpsr:  0x5cef5c00
[00:00:21.471,000] <err> os: Faulting instruction address (r15/pc): 0x3cef5de7
[00:00:21.471,000] <err> os: >>> ZEPHYR FATAL ERROR 34: Unknown error on CPU 0
[00:00:21.471,000] <err> os: Current thread: 0x30002928 (unk*** Booting Zephyr OS build v4.0.0-rc3-13111-g493d2614bdd3 ***

log_mode_deferred.log

Immediate logging

Built with west build -b frdm_mcxn947/mcxn947/cpu0 --shield dvp_20pin_ov7670 -p -d build_log_minimal -- -DCONFIG_LOG_MODE_IMMEDIATE=y

This variant triggers stack overflow, again in main thread.

Usage fault snippet from immediate logs
*** Booting Zephyr OS build v4.0.0-rc3-13111-g493d2614bdd3 ***
[00:00:00.051,000] [00:00:00.053,000] <err> os: ***** USAGE FAULT *****
[00:00:00.058,000] <err> os:   Stack overflow (context area not valid)
[00:00:00.065,000] <err> os: r0/a1:  0x1000f96e  r1/a2:  0x09000000  r2/a3:  0x1000f969
[00:00:00.074,000] <err> os: r3/a4:  0x30017e48 r12/ip:  0x00000001 r14/lr:  0x10002183
[00:00:00.083,000] <err> os:  xpsr:  0x00000000
[00:00:00.088,000] <err> os: Faulting instruction address (r15/pc): 0x10002165
[00:00:00.096,000] <err> os: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
[00:00:00.104,000] <err> os: Current thread: 0x30002468 (unknown)
[00:00:00.110,000] <err> os: Halting system

Minimal logging

Built with west build -b frdm_mcxn947/mcxn947/cpu0 --shield dvp_20pin_ov7670 -p -d build_log_minimal -- -DCONFIG_LOG_MODE_MINIMAL=y

This variant keeps running even though same warning messages are present as with deferred logging.

Usage fault snippet from minimal logs
I: Handle control 0x3001b16c ep 0x00, len 8, s:1 d:0 s:0
I: Host sent a GET_CUR request, wValue 0x0100, wIndex 0x0001, wLength 48
I: Host sent a VideoStreaming PROBE control
I: Handle control 0x3001b190 ep 0x00, len 0, s:0 d:0 s:1
I: s-in-status finished
I: Handle control 0x3001b190 ep 0x00, len 8, s:1 d:0 s:0
I: Host sent a SET_CUR request, wValue 0x0200, wIndex 0x0001, wLength 48
I: Host sent a VideoStreaming COMMIT control
I: Ready to transfer, setting source format to 'RGBP' 320x240
W: Could not set the framerate of video-sdma
I: spool 0x3001b16c
I: Handle control 0x3001b148 ep 0x80, len 0, s:0 d:0 s:1
I: s-(out)-status finished
I: The host selected format 'RGBP' 320x240, preparing 2 buffers of 153600 bytes
W: Failed to setup the signal on video-sdma output endpoint
I: Starting the video transfer
I: Start of transfer, bytes used 19200, sending lines 0 to 0 out of 240
I: Start of transfer, bytes used 19200, sending lines 0 to 0 out of 240
I: Start of transfer, bytes used 19200, sending lines 0 to 0 out of 240
I: Start of transfer, bytes used 19200, sending lines 0 to 0 out of 240
I: Start of transfer, bytes used 19200, sending lines 0 to 0 out of 240
I: Start of transfer, bytes used 19200, sending lines 0 to 0 out of 240
I: Start of transfer, bytes used 19200, sending lines 0 to 0 out of 240
I: Start of transfer, bytes used 19200, sending lines 0 to 0 out of 240

log_mode_minimal.log

@josuah
Copy link
Contributor

josuah commented Jun 27, 2025

Thank you for the tests @marinjurjevic! I opened that issue for following-up on this:

It seems related to timing more than the OV7670 but did not dive in-depth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Video Video subsystem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants