Skip to content

Conversation

@fabiobaltieri
Copy link
Member

@fabiobaltieri fabiobaltieri commented Apr 28, 2025

Add support for direct control of STM32 gpios to the DP driver.


Tested on an F3 and on an H7, should work on all of them.

@fabiobaltieri
Copy link
Member Author

Okay did a bit of refactoring, platforms have specific headers now, only one guard in the main file.

@fabiobaltieri fabiobaltieri force-pushed the dp-stm32 branch 2 times, most recently from 006d110 to df8bff6 Compare May 2, 2025 12:10
keith-zephyr
keith-zephyr previously approved these changes May 2, 2025
erwango
erwango previously approved these changes May 5, 2025
Move the nrf specific functions to a separate file so that every soc has
a dedicated header.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Add support for direct control of STM32 gpios to the DP driver.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
@fabiobaltieri
Copy link
Member Author

Added hsem locking, for multi-core devices, same as gpio_stm32.c

@sonarqubecloud
Copy link

Comment on lines +40 to +46
z_stm32_hsem_lock(CFG_HW_GPIO_SEMID, HSEM_LOCK_DEFAULT_RETRY);

val = LL_GPIO_ReadOutputPort(gpio);
val |= BIT(pin);
LL_GPIO_WriteOutputPort(gpio, val);

z_stm32_hsem_unlock(CFG_HW_GPIO_SEMID);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it significantly faster than just GPIO API? I guess z_stm32_hsem_lock/unlock will be optimized away on single core?

Copy link
Member Author

@fabiobaltieri fabiobaltieri May 12, 2025

Choose a reason for hiding this comment

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

Yes and yes, I think about 250khz vs 550khz on the C0, something like 800 on the H7 can't remember right now but yeah decent boost, I can take a trace if you want me to. Lock and lock are indeed no-ops on single cores, and those are all fast parts, otherwise it would have killed the poor C0.

Copy link
Contributor

@jfischer-no jfischer-no left a comment

Choose a reason for hiding this comment

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

Thanks

@fabiobaltieri fabiobaltieri merged commit bd3aff2 into zephyrproject-rtos:main May 13, 2025
26 checks passed
@fabiobaltieri fabiobaltieri deleted the dp-stm32 branch May 13, 2025 17:38
Copy link
Contributor

@mathieuchopstm mathieuchopstm left a comment

Choose a reason for hiding this comment

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

Comment on lines +42 to +44
val = LL_GPIO_ReadOutputPort(gpio);
val |= BIT(pin);
LL_GPIO_WriteOutputPort(gpio, val);
Copy link
Contributor

Choose a reason for hiding this comment

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

LL_GPIO_SetOutputPin is a single write and performs RMW atomically in hardware. Am I missing some context, or couldn't it be used here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, brilliant, so no lock needed. Thanks for pointing that out I'll send a followup to use that instead and drop the locks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing is ever easy #90211 (comment)

Comment on lines +56 to +58
val = LL_GPIO_ReadOutputPort(gpio);
val &= ~BIT(pin);
LL_GPIO_WriteOutputPort(gpio, val);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto but with LL_GPIO_ResetOutputPin instead.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants