-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: Usart
driver enhancements
#10
Merged
Merged
+981
−64
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
752b8ca
to
57d8407
Compare
`USART_RX_ERROR_COUNTERS_ENABLE` option
shadow578
commented
Feb 29, 2024
Usart
driver enhancements
shadow578
commented
Mar 1, 2024
reduces memory used for unused usart peripherals
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this PR introduces various enhancements to the
Usart
driver.enhancements listed in this PR are listed in the chronological order they were added in.
Usart
clock divider and Oversampling auto-configThe Problem
currently, the
Usart
driver uses a fixed clock divider of 1 and 8x oversampling.due to limitations in the usart peripheral baud rate generator, this configuration may cause sub-optimal internal baud rate generation.
given a PCLK1 clock of 50MHz and a target baud rate of 115200, the actual baud rate would be closer to ~114995 baud.
using a different configuration (clkdiv=4 and 16x oversampling) this error can be minimized.
additionally, with the current configuration baud rates <= 19200 baud are not possible.
Solution
to solve this limitation, an automatic configuration of the clock divider and oversampling setting are added.
this new function can be enabled using the
USART_AUTO_CLKDIV_OS_CONFIG
define.at runtime, the algorithm calculates the actually achived baud rate according to the formulars given in the HC32F460 reference manual (ref 1.5, page 621, Table 25-9 and Table 25-10) for every clock divider and oversampling setting.
it then selects a configuration such that the error between target and achived baud rate is minimal.
in a real-world application (Marlin host-print with Octoprint), the serial error rate was reduced to below 0,4% with these changes.
Usart
RX line noise filteringthe HC32 supports enabling noise filtering on the usarts RX line.
this option will now be enabled by default, but can be disabled by setting
rxNoiseFilter=false
inUsart::begin(uint32_t baud, const stc_usart_uart_init_t *config, const bool rxNoiseFilter)
.Usart
receive DMA supportwhen defining
USART_RX_DMA_SUPPORT
, theUsart
driver can be configured to use DMA for receiving data.to enable RX DMA,
Usart::enableRxDma(M4_DMA_TypeDef *dma, en_dma_channel_t channel)
must be called before callingUsart::begin
.in a real-world application (Marlin host-print with Octoprint), enabling receive DMA reduced the error rate to >0.01% (in preliminary testing no errors occured)
Usart
error counterswhen defining
USART_RX_ERROR_COUNTERS_ENABLE
, theUsart
driver keeps track of receive errors.the counters can be accessed using the
Usart::getFramingErrorCount()
,Usart::getParityErrorCount()
,Usart::getOverrunErrorCount()
andUsart::getDroppedDataErrorCount()
functions.Misc.
change to IRQ RX handler
the IRQ RX handler was updated to match the behaviour of the DMA RX handler.
previously, when the RX ring buffer was full and new data was received, the new data was discarded.
from now on, the new data will be pushed into the buffer and the oldest entry is discarded instead.
when data is discarded, a
RxDataDropped
is occured and theDroppedDataErrorCount
counter is incremented.added config for USART4 peripheral
the HC32 has four USART peripheral, but until now the core only included configurations for USART1 - 3.
with this PR, the configuration for USART4 was added.