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
Tri-state USART TX output if load due to powered down peripheral is detected #12760
Conversation
This comment has been minimized.
This comment has been minimized.
AUTOMERGE: (FAIL)
|
GPS unit on port 4 isn't working with this change... investigating. |
This is due to the TX output being disabled using the UART_IT_TXE interrupt rather than UART_IT_TC interrupt which happens before the data has been fully transmitted. |
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.
- this PR may break hardware with pulldown on TX pin
- it is implemented very low level, overhed will be non-trivial
- it can be optimized if UART supports write(void*, len) semantics consistently
@@ -267,6 +267,12 @@ static void uartWrite(serialPort_t *instance, uint8_t ch) | |||
{ | |||
uartPort_t *uartPort = (uartPort_t *)instance; | |||
|
|||
// Check if the TX line is being pulled low by an unpowered peripheral | |||
if (uartPort->checkUsartTxOutput && !uartPort->checkUsartTxOutput(uartPort)) { |
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.
This is called for every byte, so may be worth optimizing - possibly by testing uart->txPinState == TX_PIN_MONITOR
first
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.
This is also used for VCP in which case uartPort->checkUsartTxOutput
won't be defined and uart->txPinState
won't be valid.
I think that a better optimisation of the serial code will be to remove the DMA support which isn't used, but has many checks being performed.
422e922
to
47d8cf0
Compare
GPS issue resolved. Tested and working on STM32 and AT32 processors. Debug now removed. |
79ee004
to
3d9174c
Compare
This comment has been minimized.
This comment has been minimized.
3d9174c
to
4edb186
Compare
Do you want to test this code? Here you have an automated build: |
…etected (betaflight#12760) Tri-state USART TX output if loaded due to powered down peripheral being detected
For the record, see below evidence of the timing of MSP traffic being sent to a WS VTX. The top trace is high when data is being transmitted, and it can be seen that updates are occurring at the expected 12Hz. uartTxMonitor() is only being called once transmission of a block of data has completed, so the transmission completion interrupt is only occurring infrequently and not adding significant load to the interrupt handling. |
…etected (betaflight#12760) Tri-state USART TX output if loaded due to powered down peripheral being detected
…ral is detected (betaflight#12760)" This reverts commit 4dc04d6.
…ral is detected (betaflight#12760)" This reverts commit 4dc04d6.
…etected (betaflight#12760) Tri-state USART TX output if loaded due to powered down peripheral being detected
Fixes: #12723
This PR monitors the state of the TX line when full duplex connections are used. When no data is being transmitted the TX line is set to be an input with pullup and when new data is to be transmitted the line is checked. It should always be high unless it is being excessively loaded. If the line is found to be pulled low, it is left tri-stated and the data discarded.
Note:
This build sets
debug[0]
todebug[3]
to indicate the status of UARTs 1 - 4 respectively.This debug will be removed once fix is tested/proven.