-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
i2c: stm32: dma enhancement #81814
base: main
Are you sure you want to change the base?
i2c: stm32: dma enhancement #81814
Conversation
Hello @sgilbert182, and thank you very much for your first pull request to the Zephyr project! |
1adf73d
to
601d56f
Compare
@sgilbert182 Thanks for this contribution. We'll try to review in best delays. Meanwhile,please have a look at feedback reported by compliance scripts |
357f005
to
d465675
Compare
Hi, no worries. I tested this on a g4 |
@sgilbert182 Quick hint: |
d465675
to
57b1147
Compare
57b1147
to
057bc2b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial review attempt:
Mains request before going further:
Did you consider implementing I2C_CALLBACK
which is supposed to be the async version of I2C API while you're at?
If adding DMA support it would be more logical to make use of this API which allows truly async transfers rather than adding DMA support on a blocking API.
Reason I ask is to avoid current state of STM32 SPI driver which is in a similar state today with a sync API allowing use of DMA and ASYNC API effectively blocking.
(Note also that driver is supposed to get further changes to support RTIO API, so let's limit the changes to where it makes real sense)
Then let's club all DMA related additions to the driver in a single commit to make it easier to review.
Finally, if possible, let's rebase on top of #82015 (once merged) in order to get rid of clang-format suggestions.
I did not, I was porting over changes I was using for a project but I can take a look at this when I have time.
I will revert this
should I close this MR until this can be rebased and I've had a chance to look at the callback mechanism? |
057bc2b
to
94c6e1d
Compare
Would be great. Thanks
Not required. But for clarity, you can move it to draft. |
cfd0b0a
to
8c030ea
Compare
1405310
to
246d8b9
Compare
@@ -605,23 +687,20 @@ static int stm32_i2c_msg_write(const struct device *dev, struct i2c_msg *msg, | |||
stm32_i2c_enable_transfer_interrupts(dev); | |||
LL_I2C_EnableIT_TX(i2c); | |||
|
|||
if (k_sem_take(&data->device_sync_sem, | |||
K_MSEC(STM32_I2C_TRANSFER_TIMEOUT_MSEC)) != 0) { | |||
if (k_sem_take(&data->device_sync_sem, K_MSEC(STM32_I2C_TRANSFER_TIMEOUT_MSEC)) != 0) { | |||
stm32_i2c_master_mode_end(dev); | |||
k_sem_take(&data->device_sync_sem, K_FOREVER); | |||
is_timeout = true; | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For devices with DCACHE enabled and rx buffer is in cached mem, it think a cache invalidation should be done here
Another option would be to issue a log warning when transfer is started that memory should be non-cacheable like it is done in uart-stm32.c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added cache support, slightly modified from the UART implementation see if it makes sense where I put it. I don't have a platform at hand to test it though. I'll have to dig through my box of bits and see if I have something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use clean cache operation before starting DMA write and use invalidate cache after read DMA finishes
Also note that clean/invalidate addresses shall align with cache line size, 32 bytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, corrected
ba7b10e
to
d72fc63
Compare
d72fc63
to
af7b858
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sgilbert182 for the update.
Some comments on the code. Regarding the PR it self, there will be some more work required:
- Blocking: We don't merge fixup commits. So please directly fix initial commits.
- Not blocking: Regarding formatting, the clang formatting suggestions have now been disabled (they'll disappear if you rebase on top of latest main). So ideally, I'd suggest to drop the formatting changes.
ef3e9f3
to
1d0b5b1
Compare
Hi @erwango, thanks for your comments I've attempted to fix the initial commits (sorry for the flurry of forced pushes) but there's still a couple of commits I see as step changes rather than just fixes but you might feel differently. Let me know if you're happy or what still needs adjusting.
I've rebased but should the formatting changes be kept so the file is more in line with current style?
|
Thanks for the update. As mentioned on the code style, my personal taste would be to drop them, but they are done on a dedicated commit and maintain readability, so I don't have objective reason to block. Regarding implementation steps, to me they clearly falls under points 3 and 5 in https://docs.zephyrproject.org/latest/contribute/contributor_expectations.html#pr-requirements, so they should be squashed. Last, I didn't came back on this in last review, but in my initial review I was mentioning that use of |
Add option to enable DMA support Signed-off-by: Simon Gilbert <[email protected]>
1d0b5b1
to
6a98a6c
Compare
Add initial DMA settings structs to stm32 i2c config and data structs Signed-off-by: Simon Gilbert <[email protected]>
Add macrobatics to pull DMA settings from device tree Signed-off-by: Simon Gilbert <[email protected]>
Add DMA options (phandle-array and names) to yaml file Signed-off-by: Simon Gilbert <[email protected]>
Tidy up of i2c_stm32_transfer and added TX and RX semaphore inits Signed-off-by: Simon Gilbert <[email protected]>
Added stop DMA fot transmit complete or other master end conditions Signed-off-by: Simon Gilbert <[email protected]>
Clang format Signed-off-by: Simon Gilbert <[email protected]>
Add basic cache memory support Signed-off-by: Simon Gilbert <[email protected]>
6a98a6c
to
0267207
Compare
Add asynchronous callback function and supporting functions Signed-off-by: Simon Gilbert [email protected]
I've condensed the formats to a single commit, I could drop it here and create a follow up MR with those formatting changes but it feels heavy handed.
All fixits should now be merged into the initial commits.
I have had a little time over the last few days and have attempted to add the async support but I haven't enough time to fully exercise it. It's a single commit so can be dropped and I can create a new MR when I have more time to work with it.
|
Add DMA enhancement for stm32 i2c_v2 driver
Fix #34354