How to Configure the Sensor Driver#
Overview#
In the K230 RTOS SDK, whether the Sensor driver is built into the firmware, which CSI it is connected to, whether CSI0 uses 2-lane or 4-lane, whether the on-chip MCLK is used, and how ISP parameters are packaged and loaded are jointly determined by MPP Kconfig and the VICAP API.
The configuration entry point is uniformly accessed from the SDK root directory:
make menuconfig
# Docker workflow: k230 make menuconfig
Related code and configuration locations:
Content |
Path |
|---|---|
Sensor / CSI / ISP installation switches |
|
Sensor drivers and mode tables |
|
On-board |
|
Sensor type enumeration |
|
Application-layer Sensor information table / detection matching |
|
ISP calibration / tuning source files |
|
ISP installation rules |
|
ISP loading and parsing mode |
|
For an overview of models and resolutions, see the Image Sensor Support List. To add a new model from scratch, see How to Add a Sensor.
How to View the Currently Supported Sensors#
Method 2: Check the board-level defconfig#
grep CONFIG_MPP_ENABLE_SENSOR_ configs/<your_board>_defconfig
grep CONFIG_MPP_CSI0_LINK_MODE_ configs/<your_board>_defconfig
Example:
CONFIG_MPP_CSI0_LINK_MODE_2LANE=y
CONFIG_MPP_ENABLE_SENSOR_IMX335=y
CONFIG_MPP_ENABLE_SENSOR_GC2093=y
Method 3: On-board list_sensor (confirm whether the driver is enabled)#
list_sensor is an RT-Smart msh command exported by sensor_dev.c. It first prints the currently detected drivers, supported modes, and lane count for each CSI, then lists all configured Sensor types and marks them as SUPPORTED or NOT DETECTED.
After entering msh through the serial port, run:
list_sensor
Example output:
Detected Sensor Drivers:
CSI0: ov5647_csi0 (2 supported modes)
Sensor Type List:
7 -> OV5647_MIPI_CSI0 (..., 2 lanes)
CSI1: no sensor driver detected
CSI2: no sensor driver detected
All Configured Sensor Types:
[SUPPORTED] CSI0 7 -> OV5647_MIPI_CSI0 (..., 2 lanes)
[NOT DETECTED] 23 -> GC2093_MIPI_CSI0
Usage notes:
Symptom |
Meaning |
|---|---|
|
A driver has been detected on this CSI. The number in parentheses indicates the number of driver modes. |
|
No loaded Sensor driver has been detected on this CSI. |
|
The configured type appears in the detected driver mode table. |
|
The type has been configured, but the corresponding driver / mode was not detected on the current board. |
|
The number of MIPI lanes used by the currently detected mode. |
A type is present, but the preview is black |
The driver has been loaded. The problem is more likely related to hardware wiring, the MIPI link, or ISP parameters. |
When selecting a sensor at the application layer, use the name / type printed by list_sensor. Do not hard-code the volatile numeric sequence, as it changes with the Kconfig combination.
The types for CSI0 / CSI1 / CSI2 are isolated by CONFIG_MPP_ENABLE_CSI_DEV_n in the enumeration (k_sensor_comm.h), the list_sensor table, and the mpi_sensor.c adaptation table: when a CSI is not enabled, its corresponding types are not built into the firmware.
CSI0 LANE NUM(2LANE / 4LANE)#
At the top of Sensor Hardware Configuration, there is an independent option CSI0 LANE NUM (default: 2LANE):
MPP Configuration
└── Sensor Configuration
├── CSI0 LANE NUM (2LANE) --->
│ ├── (X) 2LANE # Default; the 4LANE option for each Sensor is hidden
│ └── ( ) 4LANE # CSI0 can use 2L+4L; each Sensor can enable 4LANE Configure
├── [*] Enable CSI0 ---> # GPIO / I2C / MCLK
├── [*] Enable CSI1 # Can be compiled to coexist; cannot be initialized simultaneously with CSI0 4LANE at runtime
└── [*] Enable CSI2
|
Macro |
Effect |
|---|---|---|
2LANE (default) |
|
Each |
4LANE |
|
CSI0 can retain both 2-lane and 4-lane modes; |
Hardware note: By default, using CSI0 for 4-lane aggregation on the board consumes the PHY shared with CSI1. The software no longer hides CSI1 for this reason, so that customers can use CSI1 after fly-wire modification or board revision; with the original factory wiring on an unmodified board, do not enable CSI0 4LANE and CSI1 simultaneously.
How to switch to 4LANE mode#
The models currently providing a per-sensor 4-lane switch include IMX335, OV13850, and IMX415 (the entire IMX415 sensor is visible only in 4LANE link mode).
make menuconfig→Sensor ConfigurationCSI0 LANE NUM→ select4LANEConfirm
[*] Enable CSI0Open the target Sensor and select
Enable 4LANE Configurein its submenu (IMX335 / OV13850 are enabled by default under 4LANE; IMX415 is enabled by default)(Optional) If CSI1 is still needed after modifying the board, you may continue to select
Enable CSI1
CSI0 LANE NUM (4LANE) --->
[*] Enable CSI0
[ ] Enable CSI1 # May remain unselected by default; enable it after fly-wire modification or board revision
[*] Enable IMX335
└── [*] IMX335 Enable 4LANE Configure
The same applies to OV13850 / IMX415.
Corresponding Kconfig macros:
Option |
Macro |
|---|---|
CSI0 2LANE |
|
CSI0 4LANE |
|
IMX335 4-lane mode |
|
OV13850 4-lane mode |
|
IMX415 4-lane mode |
|
IMX335 submenu example:

How to confirm after enabling#
In
.config/ defconfig, it isCONFIG_MPP_CSI0_LINK_MODE_4LANE=yUnder
Detected Sensor Driversin the on-devicelist_sensor, the corresponding*_CSI0_4LANE_*mode is present (along with the still-available CSI0 2LANE mode)When
Enable CSI1is not enabled,*_CSI1_*does not appear; after it is enabled, it appearsOn the application side, add
-lane 4when detecting the resolution, or specify the 4LANE type using-stype(see the next section)The module and ribbon cable must genuinely support 4-lane; if the software is enabled but the hardware supports only 2-lane, link errors or a black screen will occur
4K Sensors (such as OV13850 and IMX415) are also subject to the VICAP operating mode restrictions. See sensor_list.md.
How the Application Layer Matches Sensors by Resolution / FPS / Lane#
Samples such as sample_vicap_sensor probe modes by parameters through kd_mpi_sensor_adapt_get_ex(config, info, lane_pref) (mpi_sensor.c); you can also use -stype to force a specified enumeration. The legacy interface kd_mpi_sensor_adapt_get() is retained for compatibility, but it always uses ANY and cannot specify a lane preference.
Command-Line Parameters (sample_vicap_sensor)#
See VICAP Sensor Demo for the complete parameter table and examples. Common probe-related options include:
Parameter |
Meaning |
Default |
|---|---|---|
|
CSI port |
2 |
|
Expected resolution and frame rate |
1920 / 1080 / 30 |
|
Lane preference when resolutions are identical ( |
ANY (unrestricted; ties are ranked in favor of 2LANE) |
|
Force |
Not set |
|
CHN0: YUV / RGB888 / RGB888P / RAW |
0 |
|
Automatically dump n frames and then exit |
Interactive |
|
Force SW_TILE (debugging) |
0 |
Working mode summary: -ofmt 3 (RAW) defaults to ONLINE; YUV/RGB previews that exceed limits, such as 4K, use SW_TILE; -tile 1 can force SW_TILE.
Examples:
# IMX335 2592×1944@30,CSI0;默认 ANY,同分时选 2-lane
./sample_vicap_sensor.elf -c <connector> -s 0 -width 2592 -height 1944 -fps 30
# 同上分辨率,明确选 4-lane(需固件 CSI0 LANE NUM=4LANE 且已 Enable 4LANE Configure)
./sample_vicap_sensor.elf -c <connector> -s 0 -width 2592 -height 1944 -fps 30 -lane 4
# RAW Dump(ONLINE)并自动存 1 帧
./sample_vicap_sensor.elf -c <connector> -s 0 -ofmt 3 -dump 1
# 强制 type(以板端 list_sensor 打印为准)
./sample_vicap_sensor.elf -c <connector> -s 0 -stype <id>
kd_mpi_sensor_adapt_get_ex Matching Rules#
The probing structure k_vicap_probe_config contains conditions such as csi_num, width, height, and fps, and no longer contains lane_pref. The caller should zero out the structure and pass the lane preference through the third parameter of kd_mpi_sensor_adapt_get_ex(); when using VICAP_MIPI_LANE_PREF_ANY=0, candidates are not filtered by lane, so 4LANE-only sensors such as IMX415 / OV13850 at 1080p can still be detected.
Candidate filtering
The CSI port must equal the requested
csi_numlane_pref=ANY: no filtering;=2LANE: retain non-4LANE (including 1LANE);=4LANE: retain onlyVICAP_MIPI_4LANE; illegal values are treated asANY; 4LANE is supported only on CSI0Only sensors that can be successfully
opened become candidates (actually present on the board)
Ranking: higher fps → larger width → larger height → when resolutions are identical, 2LANE takes precedence over 4LANE
Matching priority
When
fps != 0, first find a match where width + height + fps are all equalThen find a match where width + height are equal (fps may differ)
Then find a larger resolution not smaller than the requested width and height
If none is found, fail
Therefore, for 2LANE / 4LANE at the same resolution: the default ANY ranking favors 2LANE; use -lane / lane_pref to force a specific option. On the compilation side, CSI0 LANE NUM determines whether the 4LANE type is compiled into the firmware; at application runtime, 4LANE cannot be requested on CSI1/CSI2, and CSI0 4LANE and CSI1 cannot be initialized simultaneously.
Common Options for CSI and Drivers#
Default CSI#
Default SENSOR on CSI:Default CSI port (0 / 1 / 2).
Sensor Hardware Configuration#
Option |
Description |
|---|---|
CSI0 LANE NUM |
|
Enable CSI0 |
When enabled, configure PowerDown / Reset / I2C / MCLK |
Enable CSI1 |
Can be compiled together with 4LANE; at runtime, CSI0 4LANE and CSI1 cannot be initialized simultaneously |
Enable CSI2 |
Has no PHY conflict with 4LANE and can be enabled as needed |
Common options for each CSI (after enabling):
Option |
Description |
|---|---|
PowerDown GPIO |
Power pin; set to |
Reset GPIO |
Reset pin; set to |
I2c Bus |
Such as |
MCLK num |
On-chip MCLK1/2/3, or an external crystal oscillator |
Sensor Sub-options#
Option |
Description |
|---|---|
|
Whether the Sensor uses the on-chip MCLK on the corresponding CSI |
|
Additionally compile the CSI0 4-lane mode; appears only when |
AutoFocus (optional)#
Enable AutoFocus → A voice coil motor driver can then be selected (such as DW9714P); this is required only when the hardware supports AF.
ISP Configuration: Switching Between bin and XML/JSON#
Source Files and Installation#
ISP parameter source file directory:
src/rtsmart/mpp/userapps/src/sensor/config/
Naming convention (using IMX335 2592×1944 as an example):
File |
Purpose |
|---|---|
|
Auto mode; one of the inputs for generating |
|
Manual mode |
|
XML calibration / tuning parameters |
The two installation switches at the top of Sensor Configuration:
Option |
Macro |
Function |
|---|---|---|
Install binary ISP configurations |
|
Generate and install |
Install JSON and XML ISP configurations |
|
Copy matching |
Only Enabled Sensors have their prefix-matched ISP files installed (see userapps/src/sensor/Makefile).
Build artifacts are generally located in:
output/<defconfig>/images/bin/
The path on the device is usually /bin/, for example, /bin/imx335-2592x1944.bin and /bin/imx335-2592x1944.xml.
Why bin Mode Cannot “Swap ISP Files in Real Time”#
Default logic (when no parsing mode is explicitly specified):
kd_mpi_vicap_init()probes for/bin/<database_name>.bin.If the
.binfile exists and loads successfully, bin mode is used (internally enumerated asVICAP_DATABASE_PARSE_HEADER).A bin file is the binary produced at build time by
gen_isp_config_binafter baking in the xml/json; changing the.xml/.jsonfiles on the device at runtime will not automatically be reflected in the loaded bin.To incorporate new parameters into the bin, you must modify the source files → run
makeagain to generate the bin → reflashing / replacing/bin/*.bin→ and then restart the application.
Therefore: During the tuning phase, if ISP parameters need to be changed frequently, switch to XML/JSON parsing mode.
How to Switch to XML/JSON Mode (Code)#
Call the following before kd_mpi_vicap_init():
#include "mpi_vicap_api.h"
#include "k_vicap_comm.h"
k_vicap_dev vicap_dev = VICAP_DEV_ID_0;
/* Force loading from /bin/<database>.xml and *_auto.json / *_manual.json */
ret = kd_mpi_vicap_set_database_parse_mode(vicap_dev, VICAP_DATABASE_PARSE_XML_JSON);
if (ret) {
printf("set_database_parse_mode failed, ret=%d\n", ret);
return ret;
}
ret = kd_mpi_vicap_init(vicap_dev);
Enum meanings (k_vicap_comm.h):
Enum |
Value |
Actual Behavior |
|---|---|---|
|
0 |
Use XML + JSON, without prioritizing bin |
|
1 |
Force bin; initialization fails if the bin does not exist |
In the API comments, HEADER once meant “header file mode”; in the current implementation, it corresponds to binary bin configuration.
Many examples in the SDK (such as examples/ai/yolo/src/pipeline.cc) explicitly set XML/JSON before vicap_init:
ret = kd_mpi_vicap_set_database_parse_mode(vicap_dev, VICAP_DATABASE_PARSE_XML_JSON);
ret = kd_mpi_vicap_init(vicap_dev);
Meanwhile, when programs such as sample_vicap_sensor do not call this interface, they automatically use bin if a .bin file is present.
How to Change Parameters in XML/JSON Mode#
Keep
Install JSON and XML ISP configurationsset to y in menuconfig to ensure that xml/json files are included in the image.In the application, switch to
VICAP_DATABASE_PARSE_XML_JSONas described in the previous section.Modify and replace the files on the device, for example:
# Push from the host (adjust the path according to the actual file system) adb push imx335-2592x1944.xml /bin/ adb push imx335-2592x1944_auto.json /bin/ adb push imx335-2592x1944_manual.json /bin/
Rerun the application (
vicap_initis required again). The ISP is loaded during init, so the active bin memory image cannot be hot-swapped while the same stream remains active.
The default loading paths are constructed from database_name (such as imx335-2592x1944) and the ISP config path (default: /bin/):
/bin/imx335-2592x1944.xml
/bin/imx335-2592x1944_auto.json
/bin/imx335-2592x1944_manual.json
Mode Selection Recommendations#
Scenario |
Recommendation |
|---|---|
Mass production / fast startup |
bin (default probing is sufficient), with parameters baked in |
ISP calibration / tuning / frequent parameter changes |
Set the code to |
Explicit requirement to use bin |
|
For calibration and tuning details, see:
Configuration Checklist#
CSI0 LANE NUM: Defaults to 2LANE; change it to 4LANE when CSI0 4-lane is required (CSI1 can be compiled, but cannot be initialized simultaneously with CSI0 4LANE).Enable CSIxmust match the board wiring (GPIO / I2C / MCLK).Check the target
Enable <Sensor>; under 4LANE, also confirmEnable 4LANE Configure.For 2L/4L at the same resolution: the default is
lane_pref=ANY(equal-score sorting favors 2LANE); use-lane 2|4or-stypeto force a preference.ISP: use bin for mass production; for tuning, switch to XML/JSON in code and ensure json/xml has been installed in
/bin/.make→ Flash →list_sensorto confirm the detected CSI / type / lane → Then run the VICAP / Sensor example.

