Skip to content
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

drivers: video: Add support for STM32 DCMI #71462

Merged

Conversation

CharlesDias
Copy link
Contributor

@CharlesDias CharlesDias commented Apr 13, 2024

Dear,

The goal is to provide the STM32 DCMI driver. I'm creating the sample to capture a frame image and sent it to LCD ( PR #71463). That sample has been tested on the mini_stm32h743 target with the OV2640 camera model.

Note: This current version was implemented only for STM32H7 family and doesn't support the JPEG pix format.

Related PR:

document_4958923842157282345.mp4

@CharlesDias
Copy link
Contributor Author

Dear, @erwango, @ABOSTM, and @FRASTM.

In the sample on the PR #71463 I declare the DCMI and MCO1 pins inside the overlay file because those pin's configuration don't exist on the ST pinctrl dtsi files.

@CharlesDias
Copy link
Contributor Author

Fix code style and remove the code to generate mock images.

@CharlesDias
Copy link
Contributor Author

Fix compliance errors.

dts/arm/st/h7/stm32h743.dtsi Outdated Show resolved Hide resolved
dts/bindings/video/st,stm32-dcmi.yaml Show resolved Hide resolved

vbuf->bytesused = data->pitch * data->height;

int err = HAL_DCMI_Start_DMA(&data->hdcmi, DCMI_MODE_SNAPSHOT,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any plan to support continuous capture?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have intention for this version. Maybe in a future as an improvement.

Both sample codes for video capture are based on performing an enqueue command before dequeue. In this way, I believe that a snapshot strategy is enough.

Copy link
Collaborator

Choose a reason for hiding this comment

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

what If i we enqueue two buffers? should'nt we start DMA transfer only for the first one? and restart internally on frame done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The function HAL_DCMI_Start_DMA can be called only on time. If this function is called again, the HAL_ERROR is returned.

In the ST sample code, only one video buffer is used. Below is described the workflow in those samples:

  1. Start the DCMI via HAL_DCMI_Start_DMA in DCMI_MODE_CONTINUOUS.
  2. When the HAL_DCMI_FrameEventCallback is trigger, call the HAL_DCMI_Suspend.
  3. Retrieve the video buffer.
  4. Resume the DCMI via HAL_DCMI_Resume.
  5. Repeat item 2.

I can try to reproduce that workflow, but I believe that the result will be the same. Please, let me know if I missed something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Think better, I believe it's more sensible to retain the existing workflow, since the video buffer is passed through the enqueue function. I mean, call the HAL_DCMI_Start_DMA inside the enqueue.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it work with the simple generic video capture sample in samples/subsys/video/capture/ ?

(If we enqueue several buffers, I would expect that seconds one is used once the first one as been completed, and so on.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created this sample version. It'll work if you enqueue just one buffer. Link to the sample code #71463.

Next week I'll try to look more into DCMI ST API to check if I can do better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, @loicpoulain.

I changed the driver to work as continuous capture and with more than one video framebuffer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since HAL_DCMI_Start_DMA can only work with one buffer, I created a dedicated buffer to store the frame data. This is the current workflow:

  1. application enqueue one or more buffers.
  2. call start capture function.
  3. The DCMI driver creates a buffer with CONFIG_VIDEO_BUFFER_POOL_SZ_MAX size to store the frame data and starts the capture in continuous mode.
  4. when the interrupt occurs, call DCMI suspend function
  5. If a video buffer is available, copy the frame data from the DCMI buffer to the video buffer.
  6. resume the DCMI capture.
  7. go to item 4.

This driver was tested with this sample code #71463

@ajarmouni-st ajarmouni-st removed the request for review from ABOSTM April 15, 2024 13:38
@decsny decsny removed their request for review April 15, 2024 22:37
@CharlesDias
Copy link
Contributor Author

Rebase the branch and small changes to the YAML to became similar to Linux YAML.

@CharlesDias
Copy link
Contributor Author

Add DCMI node to other DTSI files: stm32h723.dtsi; stm32h745.dtsi; stm32h750.dtsi; stm32h7a3.dtsi.

@CharlesDias
Copy link
Contributor Author

Update the driver to work in DCMI_MODE_CONTINUOUS and with more than one video framebuffer in the application.

@CharlesDias CharlesDias force-pushed the driver_stm32_dcmi branch 2 times, most recently from f660106 to eba3d80 Compare April 27, 2024 12:47
@CharlesDias CharlesDias marked this pull request as ready for review April 27, 2024 14:21
@CharlesDias
Copy link
Contributor Author

Add the capture-rate property. This allows us to set up the frame capture rate.

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.

A great thanks for this contribution.

drivers/video/video_stm32_dcmi.c Outdated Show resolved Hide resolved
drivers/video/video_stm32_dcmi.c Outdated Show resolved Hide resolved
drivers/video/video_stm32_dcmi.c Outdated Show resolved Hide resolved
drivers/video/video_stm32_dcmi.c Outdated Show resolved Hide resolved
drivers/video/video_stm32_dcmi.c Outdated Show resolved Hide resolved
dts/bindings/video/st,stm32-dcmi.yaml Show resolved Hide resolved
dts/bindings/video/st,stm32-dcmi.yaml Outdated Show resolved Hide resolved
dts/bindings/video/st,stm32-dcmi.yaml Outdated Show resolved Hide resolved
dts/bindings/video/st,stm32-dcmi.yaml Outdated Show resolved Hide resolved
dts/bindings/video/st,stm32-dcmi.yaml Outdated Show resolved Hide resolved
@CharlesDias
Copy link
Contributor Author

CharlesDias commented Apr 30, 2024

Implement the previous suggestions, except the one about changing the check for the config->sensor_dev value (I am waiting for feedback about my comments). Thanks @erwango

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.

Last round of comments and this'll be fine to me. Thanks again @CharlesDias !

dts/arm/st/h7/stm32h723.dtsi Outdated Show resolved Hide resolved
dts/bindings/video/st,stm32-dcmi.yaml Outdated Show resolved Hide resolved
Add the DCMI node into stm32h7.dtsi.

Signed-off-by: Charles Dias <charlesdias.cd@outlook.com>
erwango
erwango previously approved these changes May 3, 2024
drivers/video/video_stm32_dcmi.c Outdated Show resolved Hide resolved
drivers/video/video_stm32_dcmi.c Outdated Show resolved Hide resolved
drivers/video/video_stm32_dcmi.c Outdated Show resolved Hide resolved
drivers/video/video_stm32_dcmi.c Outdated Show resolved Hide resolved
drivers/video/video_stm32_dcmi.c Outdated Show resolved Hide resolved
drivers/video/video_stm32_dcmi.c Outdated Show resolved Hide resolved
drivers/video/video_stm32_dcmi.c Show resolved Hide resolved
Add Kconfig, DCMI driver, Yaml, and CMakeLists files

Signed-off-by: Charles Dias <charlesdias.cd@outlook.com>
@CharlesDias
Copy link
Contributor Author

Implement @fabiobaltieri's suggestions.

Copy link
Collaborator

@ajarmouni-st ajarmouni-st left a comment

Choose a reason for hiding this comment

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

Thanks !

interrupts:
required: true

sensor:
Copy link
Contributor

Choose a reason for hiding this comment

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

This got changed in #72623
Will need some new PR to update depending on the outcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: Video Video subsystem platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants