-
Notifications
You must be signed in to change notification settings - Fork 617
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
stm32/usart: Remove BasicInstance generic #2836
Conversation
a455098
to
524e7e9
Compare
524e7e9
to
6dc2822
Compare
489e4b0
to
5e8cf7c
Compare
I renamed "info" to more descriptive "vtable" and rebased to |
f9443bd
to
dac21df
Compare
Hey! thanks for the PR and sorry for the late reply, work on this from my side has stalled a bit becuase other priorities. I do agree we really should remove the instance generics from all drivers, it'll make the API much easier to use and help code size. I'd prefer to avoid function pointers, because they hurt perf a bit (both due to the indirect jump and due to preventing compiler optimizations because no inlining), and because they're not very friendly to stack usage analysis tools. so ideally we need find "not-function-pointer" replacements of everything in the vtable (I called the vtable "info" in #2835. vtable only makes sense if it's function pointers). These are:
In #2835 I tried to solve that by adding a The problem is currently some RCC bits are "reference counted". The refcount logic is generated by build.rs, according to this logic:
This refcounting is not compatible with the idea of
I'm sort of leaning towards option 3. |
okay i've merged #2835 #2974 which do the generic removal for spi and i2c respectively. I think the approach works, we're ready to do it for all embassy-stm32. Could you do these changes for uart?
|
Awesome, I will try to do it today :) |
I have a related question on your PR that introduced the |
Looking at the |
I reworked the PR, following the same approach as you used for SPI and I2C. Some comments:
|
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!
Looks like the CI failed, but the error doesn't seem related to the PR. Is it a spurious failure, or did I introduce some subtle breakage? |
spurious failure probably |
In Embassy, all driver structs (such as
UartRx
orI2c
) are generic in the underlying peripheral. This has some disadvantages:I2c
driver) must be generic inT: BasicInstance
, which leads to a lot of clutter.This is an experimental PR that removes the
T: BasicInstance
generic from the USART drivers. I'm well aware that this is a large change in how embassy-stm32 is structured, so I started with just a single driver to gather feedback whether this is the right approach.The implementation in this PR is directly inspired by #980. The UART driver stores
&'static Vtable
, whereVtable
is a struct that contains all information that was previously accessed using theT
type argument, such as a pointer to the register block (Regs
) or a function to disable the peripheral in the RCC (T::disable()
).I tested this PR on my Nucleo H743ZI2 board and it works with the code in my project. I'm not sure how to test the changes better, I'd welcome any suggestions on how Embassy code should be tested.
Finally, thanks for all the work that went into Embassy! :-)