Skip to content

video: introduction of STM32 DCMIPP driver #89407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 6, 2025

Conversation

avolmat-st
Copy link
Collaborator

@avolmat-st avolmat-st commented May 2, 2025

This PR is the introduction of the DCMIPP (camera pipeline) for STM32. It currently supports the STM32N6, however it is also applicable on some other SOCs such as STM32H7RS or STM32MP13xx. (for those latter ones, some modifications are necessary since they have simpler pipelines and no CSI hence new compatible will be needed).

This PR depends on the PR fixing the 8 bit raw bayer formats: #89397

Some TODOs / FIXME remains within the driver which I plan to correct prior to merging this PR however I first publish the PR to hopefully get some first comments.

Some points might benefit to other drivers as well and as such would be candidate to go to the video-common part. For example I've added a macro to get the COLORSPACE from a pixelformat in order to know if it is YUV / RGB or Bayer. Moreover, as far as I know Zephyr video format currently do not have yet information about quantization which would be necessary in order to know if a format is encoded on the limited or full range. Indeed, the DCMIPP performs color-conversion and conversion matrix depends on the range (for now I've only kept simple color conversion while waiting for quantization).

I also chose to add Kconfig entries in otder to define what is expected to be use for the sensor format. Indeed, since the DCMIPP can perform format conversion, I feel that it makes the driver (hence code size) much simpler to be able to define which format / size is to be used from the sensor rather than having to figure out that within the driver. Here as well, some other camera pipeline might benefit from it, in which case thise could go to the common Kconfig.

Copy link
Collaborator

@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.

I will have to come back to it as ran out of time but hopefully this can help in the meantime!
Looking forward to try this DK!

Copy link
Collaborator

@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.

Actually here is one thing you might be interested in:

  • Adding the board to the "build_all" video driver test, so that CI always checks that it at least build when someone else changes i.e. some API.

-> https://github.com/zephyrproject-rtos/zephyr/tree/main/tests/drivers/build_all/video/boards
-> https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/build_all/video/testcase.yaml

[EDIT: I flagged as "change requested" just to raise awareness, but it is not up to me to decide I think]

@josuah josuah self-requested a review May 5, 2025 23:54
@avolmat-st
Copy link
Collaborator Author

Thank you for all those comments. I am almost done with the addition of the parallel interface addition so I'll push an update of the driver with parallel interface / possibility to instanciate it on other SOCs (with single pipe) and take care of the comments you provided. Thanks again.

Comment on lines 419 to 518
if (fmt->pitch != fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE) {
LOG_ERR("Format pitch (%d) does not match with format", fmt->pitch);
return -EINVAL;
}

if ((fmt->pitch * fmt->height) > CONFIG_VIDEO_BUFFER_POOL_SZ_MAX) {
LOG_ERR("Frame too large for VIDEO_BUFFER_POOL");
return -EINVAL;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

checking against a format based on another utility function e.g., video_bits_per_pixel() seems not robust as the format can be valid but may not present in the utility function, for example, I can define my own bbp in my driver:

static const struct mtk_camsv_format_info mtk_camsv_format_info[] = {
	{
		.fourcc = V4L2_PIX_FMT_MTISP_SBGGR12,
		.code = MEDIA_BUS_FMT_SBGGR12_1X12,
		.packed = true,
		.bpp = 12,
	}, {
		.fourcc = V4L2_PIX_FMT_MTISP_SGBRG12,
		.code = MEDIA_BUS_FMT_SGBRG12_1X12,
		.packed = true,
		.bpp = 12,
	}, {

Moreover, this check will be done in the sensor driver, (ii) checking against the heap size will be done when allocating buffers as it is another aspect, I think.

FYI, in aa9607e, format pitch is decided by the bridge driver rather by the application, so here and in get_fmt(), we can determine it rather than checking it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On a general basis I'd rather rely on a generic function such as the one already available (video_bits_per_pixel) rather having to reimplement all the format informations within each and every drivers. If the receiver knows the formats it accept as an input, there there is no problem at adding specifically those formats within the driver in addition to the other ones for example. But even that, such format is that THAT common I think. Here, in the example above, this seems to be a packed version of the RAW12. We already have then within our enum.

Regarding the HEAP / pitch, yes I agree, same as within the Video misc PR.

@avolmat-st avolmat-st force-pushed the video_dcmipp_driver branch from da3fb47 to c6bc027 Compare May 25, 2025 20:25
@github-actions github-actions bot requested a review from etienne-lms May 25, 2025 20:26
@josuah josuah self-requested a review May 25, 2025 20:28
@avolmat-st avolmat-st force-pushed the video_dcmipp_driver branch from c6bc027 to dfb23cb Compare May 25, 2025 20:31
@avolmat-st
Copy link
Collaborator Author

Rebased now on top of HEAD.

DCMIPP driver now supports both CSI & Parallel input and has been tested on STM32N6 (in CSI version) and STM32MP13 (single pipe / parallel input). It should be also possible to use it on stm32h7rs however I haven't tested it on this platform.

@avolmat-st avolmat-st force-pushed the video_dcmipp_driver branch from dfb23cb to 09bda9c Compare May 25, 2025 20:42
@avolmat-st
Copy link
Collaborator Author

Small fix to correct compliance check.

@avolmat-st avolmat-st force-pushed the video_dcmipp_driver branch from 704e426 to 29cbd90 Compare June 3, 2025 20:40
@avolmat-st
Copy link
Collaborator Author

Rebased on top of HEAD since video CMakefiles / Kconfig were conflicting

Alain Volmat added 7 commits June 3, 2025 23:08
The STM32 Digital Camera Memory Interface Pixel Processor (DCMIPP)
is a multi-pipeline camera interface allowing to capture
and process frames from parallel or CSI interfaces depending on its
version.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Add weak functions and their call within the dcmipp driver so that
externally provided ISP control functions can be called by the
driver at right timing in order to perform the control of the
ISP part of the DCMIPP.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Add node describing the dcmipp in stm32n6.dtsi

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Add configuration of the IC17 and IC18 clock dividers, used
by the dcmipp and csi IPs in the stm32n6.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Add csi_22pins_connector and related label in order to use
shields relying on csi_pins_connector.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Add node describing the DCMIPP available on stm32mp135.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Add configuration for the STM32N6 DCMIPP driver which currently
requires to have the sensor pixel format and resolutions set via
KConfig

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
@avolmat-st avolmat-st force-pushed the video_dcmipp_driver branch from 29cbd90 to 1b54d25 Compare June 3, 2025 21:08
Copy link
Collaborator

@ngphibang ngphibang left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for adding this first "complex" driver !

Comment on lines +37 to +55
/* Weak function declaration in order to interface with external ISP handler */
void __weak stm32_dcmipp_isp_vsync_update(DCMIPP_HandleTypeDef *hdcmipp, uint32_t Pipe)
{
}

int __weak stm32_dcmipp_isp_init(DCMIPP_HandleTypeDef *hdcmipp, const struct device *source)
{
return 0;
}

int __weak stm32_dcmipp_isp_start(void)
{
return 0;
}

int __weak stm32_dcmipp_isp_stop(void)
{
return 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

For my better knowledge, could you give some more details about the external ISP handler who could override these functions ? Is it supposed to be the application, the drivers or some library ? Thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The application (or a library linked together with the application) would implement those function which perform the ISP configuration via the DCMIPP HAL code. There are already available library for that purpose, such as

https://wiki.st.com/stm32mcu/wiki/ISP:ISP_middleware
https://github.com/STMicroelectronics/STM32CubeN6/tree/v1.1.0/Middlewares/ST/STM32_ISP_Library

So the Zephyr DCMIPP driver is performing all the pipeline configuration and the ISP part (aka, statistics analysis, configuration of various ISP blocks) are done via those handler.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like we need some thing equivalent to libcamera mechanisms in the future to support these cases generically

ngphibang
ngphibang previously approved these changes Jun 4, 2025
Copy link
Collaborator

@ngphibang ngphibang left a comment

Choose a reason for hiding this comment

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

As in #90919 (review), CI failure is not due to the PR change.

@josuah josuah self-requested a review June 4, 2025 12:41
@github-actions github-actions bot added area: Devicetree area: Samples Samples area: USB Universal Serial Bus labels Jun 4, 2025
@josuah josuah force-pushed the video_dcmipp_driver branch from 1e01198 to 1b54d25 Compare June 4, 2025 13:44
@josuah
Copy link
Collaborator

josuah commented Jun 4, 2025

I did not mean to push these two commits on avolmat-st branch, but on my own fork of Zephyr as I test the board!

I did not even know it was possible, probably due to the fact that the branch was flagged "editable by maintainers".

We are now back to the original 1b54d25 (an occasion to re-trigger CI...)

Copy link

sonarqubecloud bot commented Jun 4, 2025

@josuah josuah requested a review from ngphibang June 4, 2025 14:38
@josuah josuah requested a review from erwango June 4, 2025 18:09
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

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

Nice, LGTM.

It would be welcomed to document feature support at board level (fact that feature is available with the shield), but I won't block at this stage. Please add it in a follow up PR though.

@kartben kartben merged commit 48a8716 into zephyrproject-rtos:main Jun 6, 2025
47 of 49 checks passed
josuah added a commit to tinyvision-ai-inc/zephyr that referenced this pull request Jul 7, 2025
During zephyrproject-rtos#89407 a driver-specific header stm32_dcmipp.h got introduced to
support new functionnalities not yet covered by video APIs.
Move this header into a new <include/zephyr/drivers/video/> include
direcctory like what other driver classes do.

Signed-off-by: Josuah Demangeon <me@josuah.net>
danieldegrasse pushed a commit that referenced this pull request Jul 9, 2025
During #89407 a driver-specific header stm32_dcmipp.h got introduced to
support new functionnalities not yet covered by video APIs.
Move this header into a new <include/zephyr/drivers/video/> include
direcctory like what other driver classes do.

Signed-off-by: Josuah Demangeon <me@josuah.net>
seyoungjeong pushed a commit to seyoungjeong/zephyr that referenced this pull request Jul 11, 2025
During zephyrproject-rtos#89407 a driver-specific header stm32_dcmipp.h got introduced to
support new functionnalities not yet covered by video APIs.
Move this header into a new <include/zephyr/drivers/video/> include
direcctory like what other driver classes do.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree area: Samples Samples area: Shields Shields (add-on boards) area: USB Universal Serial Bus area: Video Video subsystem platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants