Skip to content

drivers: video: stm32u5x dcmi: enable dcmi support for stm32u5x family#94536

Open
cornway wants to merge 1 commit intozephyrproject-rtos:mainfrom
cornway:cornway/add-stm32u5x-dcmi-support
Open

drivers: video: stm32u5x dcmi: enable dcmi support for stm32u5x family#94536
cornway wants to merge 1 commit intozephyrproject-rtos:mainfrom
cornway:cornway/add-stm32u5x-dcmi-support

Conversation

@cornway
Copy link
Contributor

@cornway cornway commented Aug 15, 2025

Adding missing logic to handle stm32u5x dcmi interface

@github-actions
Copy link

Hello @cornway, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@avolmat-st
Copy link

Hi @cornway and thank you for this patch.
Could you explain the reason why specifically forcing the DCMI mode into snapshot here ?
FYI, there is currently an ongoing activity about making it possible to run in snapshot mode (cf PR #93797) so I think this might fit for your needs, even it isn't finalized yet.
I haven't yet looked at the other part DT / DMA configuration in detail hence will come back to you after.
Thank you again.

err = HAL_DCMI_Start_DMA(&data->hdcmi, DCMI_MODE_CONTINUOUS,
uint32_t dcmi_mode = DCMI_MODE_CONTINUOUS;
#if defined(CONFIG_SOC_SERIES_STM32U5X)
dcmi_mode = DCMI_MODE_SNAPSHOT;
Copy link
Contributor

@JarmouniA JarmouniA Aug 15, 2025

Choose a reason for hiding this comment

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

This is a video driver, why would you use Snapshot mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To the best of My knowledge GPDMA needs LL structure to run in circular mode
So as a shortcut I did DCMI_MODE_SNAPSHOT, and then restart dma each time frame is completed
I need more time to add proper LL
Thank you for pointing that out
Please let me know if that can be done in a separate commit/PR or you'd like to have it in one place

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be in this PR in my opinion.

};

#define GPDMA1_REQUEST_DCMI_PSSI 86U
#define DCMI_PSSI_IRQn 119
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't use #define in devicetree files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove, thank you

@cornway
Copy link
Contributor Author

cornway commented Aug 15, 2025

Hi @cornway and thank you for this patch. Could you explain the reason why specifically forcing the DCMI mode into snapshot here ? FYI, there is currently an ongoing activity about making it possible to run in snapshot mode (cf PR #93797) so I think this might fit for your needs, even it isn't finalized yet. I haven't yet looked at the other part DT / DMA configuration in detail hence will come back to you after. Thank you again.

Hi @cornway and thank you for this patch. Could you explain the reason why specifically forcing the DCMI mode into snapshot here ? FYI, there is currently an ongoing activity about making it possible to run in snapshot mode (cf PR #93797) so I think this might fit for your needs, even it isn't finalized yet. I haven't yet looked at the other part DT / DMA configuration in detail hence will come back to you after. Thank you again.

I need more time to configure GPDMA to run in circular mode, otherwise shapshot is just a short cut
Overall it runs continuously, since I restart dma once upon frame completion
Thank you
Please let me know if this needs to be added in the same PR

@avolmat-st
Copy link

Hi @cornway and thank you for this patch. Could you explain the reason why specifically forcing the DCMI mode into snapshot here ? FYI, there is currently an ongoing activity about making it possible to run in snapshot mode (cf PR #93797) so I think this might fit for your needs, even it isn't finalized yet. I haven't yet looked at the other part DT / DMA configuration in detail hence will come back to you after. Thank you again.

Hi @cornway and thank you for this patch. Could you explain the reason why specifically forcing the DCMI mode into snapshot here ? FYI, there is currently an ongoing activity about making it possible to run in snapshot mode (cf PR #93797) so I think this might fit for your needs, even it isn't finalized yet. I haven't yet looked at the other part DT / DMA configuration in detail hence will come back to you after. Thank you again.

I need more time to configure GPDMA to run in circular mode, otherwise shapshot is just a short cut Overall it runs continuously, since I restart dma once upon frame completion Thank you Please let me know if this needs to be added in the same PR

Thanks for the reply. In that case, it is better to have it run in continuous mode now to avoid introducing such U5 specific behavior code in the driver.

@cornway cornway force-pushed the cornway/add-stm32u5x-dcmi-support branch 2 times, most recently from 264da15 to 8478660 Compare August 24, 2025 18:02
@cornway
Copy link
Contributor Author

cornway commented Aug 24, 2025

Hi @cornway and thank you for this patch. Could you explain the reason why specifically forcing the DCMI mode into snapshot here ? FYI, there is currently an ongoing activity about making it possible to run in snapshot mode (cf PR #93797) so I think this might fit for your needs, even it isn't finalized yet. I haven't yet looked at the other part DT / DMA configuration in detail hence will come back to you after. Thank you again.

Hi @cornway and thank you for this patch. Could you explain the reason why specifically forcing the DCMI mode into snapshot here ? FYI, there is currently an ongoing activity about making it possible to run in snapshot mode (cf PR #93797) so I think this might fit for your needs, even it isn't finalized yet. I haven't yet looked at the other part DT / DMA configuration in detail hence will come back to you after. Thank you again.

I need more time to configure GPDMA to run in circular mode, otherwise shapshot is just a short cut
Overall it runs continuously, since I restart dma once upon frame completion
Thank you
Please let me know if this needs to be added in the same PR

Hello @cornway, and thank you very much for your first pull request to the Zephyr project! Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary. If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

Updated PR with removed shapshot mode (Added gpdma LL for sicrcular mode)
Although it still needs cleanup it is ready for review I think
Question: do you use any formatting tools like clang, as tutorial says this is mostly manual process
Thank you

@cornway cornway force-pushed the cornway/add-stm32u5x-dcmi-support branch from 8478660 to 2312148 Compare August 26, 2025 11:33
@cornway cornway requested a review from JarmouniA August 26, 2025 11:35
Adding missing logic to handle stm32u5x dcmi interface
Adding JPEG mode support:
affects all soc's for which dcmi has already been implemented


Signed-off-by: Roman Pustobaiev <romanpustobayev@gmail.com>
@cornway cornway force-pushed the cornway/add-stm32u5x-dcmi-support branch from 2312148 to 18c0a8b Compare August 26, 2025 12:01
@cornway
Copy link
Contributor Author

cornway commented Aug 28, 2025

@JarmouniA @avolmat-st
Kindly ask you to review this patch
Thank you

@josuah
Copy link
Contributor

josuah commented Sep 2, 2025

Several Zephyr developers were present at the OSS-EU conference or otherwise on a short leave. Hopefully more time for review from everyone coming through.

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.

Thanks for adding support for more hardware! Some feedback to try to take this PR further up.

Comment on lines +185 to +190
ret |= HAL_DMAEx_List_BuildNode(&pNodeConfig, &Node);
ret |= HAL_DMAEx_List_InsertNode_Tail(&Queue, &Node);
ret |= HAL_DMAEx_List_SetCircularMode(&Queue);
ret |= HAL_DMAEx_List_LinkQ(hdma, &Queue);

return ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

using ret |= is very compact, but if there are different error messages coming, then return ret; would become inaccurate, and then code that does do { ret = try_again(); } while (ret == -EAGAIN); can behave differently.

Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, ret here is a HAL return code value, not an errno value.

Suggestion:

	if (HAL_DMAEx_List_BuildNode(&pNodeConfig, &Node) != HAL_OK ||
	    HAL_DMAEx_List_InsertNode_Tail(&Queue, &Node) != HAL_OK ||
	    HAL_DMAEx_List_SetCircularMode(&Queue) != HAL_OK ||
	    HAL_DMAEx_List_LinkQ(hdma, &Queue) != HAL_OK) {
		return -EIO;
	}

	return 0;
Comment on lines +115 to +118
/*
* Stop DMA as in JPEG mode
* it may be still waiting for more data to come, so we can't restart it directly
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that really specific to STM32U5 or can it be used with other SoCs?

HAL_StatusTypeDef ret = HAL_OK;
DMA_NodeConfTypeDef pNodeConfig;

/* Set node configuration ################################################*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Every vendor/author might have their own decoration style, how about a plain comment /* Set node configuration */?

Comment on lines +413 to +416
/* Size of a framebuffer is unknown at the moment, assign maximum */
if (data->fmt.pixelformat == VIDEO_PIX_FMT_JPEG) {
buffer_size = vbuf->size;
} else if (buffer_size > vbuf->size) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would be tempted to split the JPEG support in a different commit.

  • The commit short subject does not talk about JPEG so harder to look at when it was introduced.
  • Sometimes commits are reverted upstream to fix CI or locally troubleshoot. Then either JPEG or STM32U5 would be reverted but not both.
Comment on lines +285 to +296
if (HAL_DMAEx_List_Init(&hdma) != HAL_OK) {
LOG_ERR("HAL_DMAEx_List_Init Failed");
return -EINVAL;
}
if (stm32_dma_list_init(&hdma) != HAL_OK) {
LOG_ERR("stm32_dma_list_init Failed");
return -EINVAL;
}
if (HAL_DMA_ConfigChannelAttributes(&hdma, DMA_CHANNEL_NPRIV) != HAL_OK) {
LOG_ERR("HAL_DMA_ConfigChannelAttributes Failed");
return -EINVAL;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticing the different style through the source, in case you were interested in smoothing it up:

  • above uses err = HAL_...(); if (err != HAL_OK) {}
  • here it uses if (HAL_...() != HAL_OK) {}
Comment on lines 165 to +273
#elif defined(CONFIG_SOC_SERIES_STM32L4X)
hdma.Instance = __LL_DMA_GET_CHANNEL_INSTANCE(config->dma.reg, config->dma.channel);
#elif defined(CONFIG_SOC_SERIES_STM32U5X)
hdma.Instance = LL_DMA_GET_CHANNEL_INSTANCE(config->dma.reg, config->dma.channel);
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be required after rebase on top of #94869

return -EIO;
}

#if defined(CONFIG_SOC_SERIES_STM32U5X)
Copy link
Member

Choose a reason for hiding this comment

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

I suggest checking if this DMAU5 compat shouldn't be check instead of U5 series.

@github-actions
Copy link

github-actions bot commented Nov 3, 2025

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Nov 3, 2025
return;
}

HAL_DCMI_Suspend(hdcmi);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should check the return value. If suspending fails, should return straight at least with an error level trace message?

static DMA_QListTypeDef Queue;

HAL_StatusTypeDef ret = HAL_OK;
DMA_NodeConfTypeDef pNodeConfig;
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer have all fields at least with known values.
Could you rename the variable using snake_case format (ditto for Node and Queue above: node, queue)?

Suggested change
DMA_NodeConfTypeDef pNodeConfig;
DMA_NodeConfTypeDef node_config = {0};
Comment on lines +185 to +190
ret |= HAL_DMAEx_List_BuildNode(&pNodeConfig, &Node);
ret |= HAL_DMAEx_List_InsertNode_Tail(&Queue, &Node);
ret |= HAL_DMAEx_List_SetCircularMode(&Queue);
ret |= HAL_DMAEx_List_LinkQ(hdma, &Queue);

return ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, ret here is a HAL return code value, not an errno value.

Suggestion:

	if (HAL_DMAEx_List_BuildNode(&pNodeConfig, &Node) != HAL_OK ||
	    HAL_DMAEx_List_InsertNode_Tail(&Queue, &Node) != HAL_OK ||
	    HAL_DMAEx_List_SetCircularMode(&Queue) != HAL_OK ||
	    HAL_DMAEx_List_LinkQ(hdma, &Queue) != HAL_OK) {
		return -EIO;
	}

	return 0;
Comment on lines +120 to +123
int err =
HAL_DCMI_Start_DMA(&dev_data->hdcmi, DCMI_MODE_CONTINUOUS,
(uint32_t)dev_data->vbuf->buffer, dev_data->vbuf->bytesused / 4);
if (err != HAL_OK) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ret should be of type HAL_StatusTypeDef.

Suggested change
int err =
HAL_DCMI_Start_DMA(&dev_data->hdcmi, DCMI_MODE_CONTINUOUS,
(uint32_t)dev_data->vbuf->buffer, dev_data->vbuf->bytesused / 4);
if (err != HAL_OK) {
if (HAL_DCMI_Start_DMA(&dev_data->hdcmi, DCMI_MODE_CONTINUOUS,
(uint32_t)dev_data->vbuf->buffer,
dev_data->vbuf->bytesused / 4) != HAL_OK) {
reg = <0x4202C000 0x400>;
interrupts = <119 0>;
interrupt-names = "dcmi";
clocks = <&rcc STM32_CLOCK(AHB2, 12U)>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking:

Suggested change
clocks = <&rcc STM32_CLOCK(AHB2, 12U)>;
clocks = <&rcc STM32_CLOCK(AHB2, 12)>;
};
};

dcmi: dcmi@4202C000 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use lower case on node name unit value:

Suggested change
dcmi: dcmi@4202C000 {
dcmi: dcmi@4202c000 {
@github-actions github-actions bot removed the Stale label Nov 4, 2025
@erwango erwango added this to the v4.4.0 milestone Nov 4, 2025
@JarmouniA JarmouniA closed this Dec 17, 2025
@JarmouniA JarmouniA reopened this Dec 17, 2025
@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Video Video subsystem platform: STM32 ST Micro STM32 Stale

7 participants