-
Notifications
You must be signed in to change notification settings - Fork 143
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
[uart] Refactor STM32 USART HAL and make TX/RX buffer optional #564
[uart] Refactor STM32 USART HAL and make TX/RX buffer optional #564
Conversation
Nice work, but are you aware this is a silent breaking change for users on F1/F4 that have been using even/odd parity? With the refactored version It would be possible to add an additional |
|
417e273
to
5d9c2a7
Compare
I made the |
0e423af
to
13a2f3d
Compare
I would want to merge this before the SCons thing, so do a review on this first. |
b43d014
to
ab6d025
Compare
template<class SystemClock, modm::baudrate_t baudrate> | ||
void modm_always_inline | ||
modm::platform::{{ name }}::initialize(Parity parity) | ||
template<class SystemClock, modm::baudrate_t baudrate, modm::percent_t tolerance> |
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.
If tolerance
is added here, shouldn't we actually check it? Adding the baudrate calculation with compile-time checking would be quite straight forward, it's pretty similar to STM32.
There are also 8x and 16x oversampling modes, selected by setting {{ peripheral }}->USART.CTRLA.bit.SAMPR
(16x: 0x1
, 8x: 0x3
), see SAMD5/E5 manual, page 830,854,862. The prescaler has a 3 bit fractional and 13 bit integral part for both x8 and x16 oversampling (configured in line 87, 88 of this file).
It looks like there is a copy-paste bug in these lines anyway, they always configure the instance SERCOM0->USART
, not {{ peripheral }}->USART
. That should definitively be fixed.
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 fixed this, but I still need to test this in hardware, since it may be off by a factor or 2.
a278eff
to
5c208aa
Compare
static inline void | ||
initialize({% if buffered %}uint32_t interruptPriority, {% endif %}Parity parity, WordLength length) |
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.
Can we please change the interface here to make code portable between buffered and unbuffered Uart?
static inline void | |
initialize({% if buffered %}uint32_t interruptPriority, {% endif %}Parity parity, WordLength length) | |
static inline void | |
initialize(Parity parity, WordLength length{% if buffered %}, uint32_t interruptPriority, {% endif %}) |
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.
Yes, please. I was uncertain about breaking backwards compatibility.
I'm not at all in favor of bundling NVIC settings with the interfaces, mostly because of the issue with shared interrupts, which completely breaks the API promises (ie. effectively showing the same shared IRQ as different IRQs).
I would perhaps leave it like that for now, since it's backwards compatible and instead add a new driver call NVIC, that perhaps exposes IRQ handling in a better way. (perhaps with a connect-like API or something like that).
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.
Well… actually, we're already breaking the API with the lbuild option changes, so it makes sense to fix this now!
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.
If I were a user not closely monitoring modm development, I would generally prefer to have some changelogs telling me if and how my code gets broken. Could we get the xpcc changelog back without much effort, could we generate it semi-automatically? People are putting modm into real products, so we should care somehow ...
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.
Yes, I need to bring the changelog back… Ideally as part of the PR approval somehow, so that the mountain of work doesn't dull my motivation to do quarterly releases.
https://twitter.com/modm_embedded/status/1345396075813859328
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'm bringing Sexy Changelog back
Them other boys libs don't know how to act
template< class SystemClock, baudrate_t baudrate, percent_t tolerance=pct(1) > | ||
static inline void | ||
initialize({% if buffered %}uint32_t interruptPriority = 12, {% endif %}Parity parity = Parity::Disabled) |
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.
Same as above
9ad2c8d
to
8b34cf0
Compare
I broke the initialize API and removed the automatic enable/disable Operation calls. Also collapsed a few HAL functions into one place, like the UART baudrate computation and the |
8b34cf0
to
2c9d925
Compare
UsartHal
class for STM32 for clarity and less boilerplate and fixes an issue with word length selection.:platform:uart:N:buffered
option for STM32, and instead allows thebuffer.tx
andbuffer.rx
options to be set to0
, which removes the atomic queue and IRQ code separately for both.:platform:uart:N:buffered
option for AVRs as well, as it was never used.0
, to not waste code/memory unnecessarily. This is breaking change, so in some examples thebuffer.tx
option needs to be manually set. All of our BSPs with a logger output already set this option