Skip to content
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

ChibiOS: enable UART FIFO on H7 and G4 by default #17959

Merged
merged 5 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libraries/AP_HAL/UARTDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class AP_HAL::UARTDriver : public AP_HAL::BetterStream {
OPTION_NODMA_RX = (1U<<8), // don't use DMA for RX
OPTION_NODMA_TX = (1U<<9), // don't use DMA for TX
OPTION_MAVLINK_NO_FORWARD = (1U<<10), // don't forward MAVLink data to or from this device
OPTION_NOFIFO = (1U<<11), // disable hardware FIFO
};

enum flow_control {
Expand Down
18 changes: 17 additions & 1 deletion libraries/AP_HAL_ChibiOS/UARTDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,16 @@ void UARTDriver::begin(uint32_t b, uint16_t rxS, uint16_t txS)
}
#endif

#if defined(USART_CR1_FIFOEN)
// enable the UART FIFO on G4 and H7. This allows for much higher baudrates
// without data loss when not using DMA
if (_last_options & OPTION_NOFIFO) {
_cr1_options &= ~USART_CR1_FIFOEN;
} else {
_cr1_options |= USART_CR1_FIFOEN;
}
#endif

/*
allocate the write buffer
*/
Expand Down Expand Up @@ -899,7 +909,13 @@ void UARTDriver::write_pending_bytes_DMA(uint32_t n)
chEvtGetAndClearEvents(EVT_TRANSMIT_DMA_COMPLETE);

if (dma_handle->has_contention()) {
if (_baudrate <= 115200) {
// on boards with a hw fifo we can use a higher threshold for disabling DMA
#if defined(USART_CR1_FIFOEN)
const uint32_t baud_threshold = 460800;
#else
const uint32_t baud_threshold = 115200;
#endif
if (_baudrate <= baud_threshold) {
contention_counter += 3;
if (contention_counter > 1000) {
// more than 25% of attempts to use this DMA
Expand Down
24 changes: 15 additions & 9 deletions libraries/AP_SerialManager/AP_SerialManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const AP_Param::GroupInfo AP_SerialManager::var_info[] = {
// @Param: 1_OPTIONS
// @DisplayName: Telem1 options
// @Description: Control over UART options. The InvertRX option controls invert of the receive pin. The InvertTX option controls invert of the transmit pin. The HalfDuplex option controls half-duplex (onewire) mode, where both transmit and receive is done on the transmit wire. The Swap option allows the RX and TX pins to be swapped on STM32F7 based boards.
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from, 11: DisableFIFO
// @User: Advanced
// @RebootRequired: True
AP_GROUPINFO("1_OPTIONS", 14, AP_SerialManager, state[1].options, 0),
Expand All @@ -241,7 +241,7 @@ const AP_Param::GroupInfo AP_SerialManager::var_info[] = {
// @Param: 2_OPTIONS
// @DisplayName: Telem2 options
// @Description: Control over UART options. The InvertRX option controls invert of the receive pin. The InvertTX option controls invert of the transmit pin. The HalfDuplex option controls half-duplex (onewire) mode, where both transmit and receive is done on the transmit wire.
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from, 11: DisableFIFO
// @User: Advanced
// @RebootRequired: True
AP_GROUPINFO("2_OPTIONS", 15, AP_SerialManager, state[2].options, 0),
Expand All @@ -251,7 +251,7 @@ const AP_Param::GroupInfo AP_SerialManager::var_info[] = {
// @Param: 3_OPTIONS
// @DisplayName: Serial3 options
// @Description: Control over UART options. The InvertRX option controls invert of the receive pin. The InvertTX option controls invert of the transmit pin. The HalfDuplex option controls half-duplex (onewire) mode, where both transmit and receive is done on the transmit wire.
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from, 11: DisableFIFO
// @User: Advanced
// @RebootRequired: True
AP_GROUPINFO("3_OPTIONS", 16, AP_SerialManager, state[3].options, 0),
Expand All @@ -261,7 +261,7 @@ const AP_Param::GroupInfo AP_SerialManager::var_info[] = {
// @Param: 4_OPTIONS
// @DisplayName: Serial4 options
// @Description: Control over UART options. The InvertRX option controls invert of the receive pin. The InvertTX option controls invert of the transmit pin. The HalfDuplex option controls half-duplex (onewire) mode, where both transmit and receive is done on the transmit wire.
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from, 11: DisableFIFO
// @User: Advanced
// @RebootRequired: True
AP_GROUPINFO("4_OPTIONS", 17, AP_SerialManager, state[4].options, 0),
Expand All @@ -271,7 +271,7 @@ const AP_Param::GroupInfo AP_SerialManager::var_info[] = {
// @Param: 5_OPTIONS
// @DisplayName: Serial5 options
// @Description: Control over UART options. The InvertRX option controls invert of the receive pin. The InvertTX option controls invert of the transmit pin. The HalfDuplex option controls half-duplex (onewire) mode, where both transmit and receive is done on the transmit wire.
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from, 11: DisableFIFO
// @User: Advanced
// @RebootRequired: True
AP_GROUPINFO("5_OPTIONS", 18, AP_SerialManager, state[5].options, 0),
Expand All @@ -281,7 +281,7 @@ const AP_Param::GroupInfo AP_SerialManager::var_info[] = {
// @Param: 6_OPTIONS
// @DisplayName: Serial6 options
// @Description: Control over UART options. The InvertRX option controls invert of the receive pin. The InvertTX option controls invert of the transmit pin. The HalfDuplex option controls half-duplex (onewire) mode, where both transmit and receive is done on the transmit wire.
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from, 11: DisableFIFO
// @User: Advanced
// @RebootRequired: True
AP_GROUPINFO("6_OPTIONS", 19, AP_SerialManager, state[6].options, 0),
Expand Down Expand Up @@ -328,7 +328,7 @@ const AP_Param::GroupInfo AP_SerialManager::var_info[] = {
// @Param: 7_OPTIONS
// @DisplayName: Serial7 options
// @Description: Control over UART options. The InvertRX option controls invert of the receive pin. The InvertTX option controls invert of the transmit pin. The HalfDuplex option controls half-duplex (onewire) mode, where both transmit and receive is done on the transmit wire.
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from, 11: DisableFIFO
// @User: Advanced
// @RebootRequired: True
AP_GROUPINFO("7_OPTIONS", 25, AP_SerialManager, state[7].options, 0),
Expand All @@ -353,7 +353,7 @@ const AP_Param::GroupInfo AP_SerialManager::var_info[] = {
// @Param: 8_OPTIONS
// @DisplayName: Serial8 options
// @Description: Control over UART options. The InvertRX option controls invert of the receive pin. The InvertTX option controls invert of the transmit pin. The HalfDuplex option controls half-duplex (onewire) mode, where both transmit and receive is done on the transmit wire.
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from
// @Bitmask: 0:InvertRX, 1:InvertTX, 2:HalfDuplex, 3:Swap, 4: RX_PullDown, 5: RX_PullUp, 6: TX_PullDown, 7: TX_PullUp, 8: RX_NoDMA, 9: TX_NoDMA, 10: Don't forward mavlink to/from, 11: DisableFIFO
// @User: Advanced
// @RebootRequired: True
AP_GROUPINFO("8_OPTIONS", 28, AP_SerialManager, state[8].options, 0),
Expand Down Expand Up @@ -569,7 +569,13 @@ AP_HAL::UARTDriver *AP_SerialManager::find_serial(enum SerialProtocol protocol,
return nullptr;
}
const uint8_t serial_idx = _state - &state[0];
return hal.serial(serial_idx);

// set options before any user does begin()
AP_HAL::UARTDriver *port = hal.serial(serial_idx);
if (port) {
port->set_options(_state->options);
tridge marked this conversation as resolved.
Show resolved Hide resolved
}
return port;
}

// find_baudrate - searches available serial ports for the first instance that allows the given protocol
Expand Down