Skip to content

Commit

Permalink
AP_HAL_ChibiOS: use hardware serial inversion pins on F4 boards that …
Browse files Browse the repository at this point in the history
…support it

change mamba F405 to active high as per betaflight
fix UART pushpull when using hardware inversion
  • Loading branch information
andyp1per committed Aug 17, 2021
1 parent cb0b12f commit 3d5a717
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
16 changes: 15 additions & 1 deletion libraries/AP_HAL_ChibiOS/UARTDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1645,22 +1645,36 @@ bool UARTDriver::set_options(uint16_t options)
cr2 &= ~USART_CR2_SWAP;
_cr2_options &= ~USART_CR2_SWAP;
}
#else // STM32F4
#elif defined(STM32F4)
// F4 can do inversion by GPIO if enabled in hwdef.dat, using
// TXINV and RXINV options
if (options & OPTION_RXINV) {
if (sdef.rxinv_gpio >= 0) {
hal.gpio->write(sdef.rxinv_gpio, sdef.rxinv_polarity);
if (arx_line != 0) {
palLineSetPushPull(arx_line, PAL_PUSHPULL_PULLDOWN);
}
} else {
ret = false;
}
} else {
if (arx_line != 0) {
palLineSetPushPull(arx_line, PAL_PUSHPULL_PULLUP);
}
}
if (options & OPTION_TXINV) {
if (sdef.txinv_gpio >= 0) {
hal.gpio->write(sdef.txinv_gpio, sdef.txinv_polarity);
if (atx_line != 0) {
palLineSetPushPull(atx_line, PAL_PUSHPULL_PULLDOWN);
}
} else {
ret = false;
}
} else {
if (atx_line != 0) {
palLineSetPushPull(atx_line, PAL_PUSHPULL_PULLUP);
}
}
if (options & OPTION_SWAP) {
ret = false;
Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_HAL_ChibiOS/hwdef/KakuteF4/hwdef.dat
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ SERIAL_ORDER OTG1 USART6 USART1 UART4 UART5 USART3
PB11 TIM2_CH4 TIM2 RCININT FLOAT LOW
PB10 USART3_TX USART3

# SBUS inversion control pin, active low
PB15 SBUS_INVERT OUTPUT LOW
# SBUS inversion control pin, active high
PB15 USART3_RXINV OUTPUT LOW GPIO(78) POL(1)

# for FrSky S.PORT. Has builtin inverters and diode to combine
# RX and TX onto the one pin
Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_HAL_ChibiOS/hwdef/MambaF405v2/hwdef.dat
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ PA9 USART1_TX USART1 NODMA
# Alt config to allow RCIN on UART
PA10 USART1_RX USART1 NODMA ALT(1)

# SBUS inversion control pin, active low
PC0 USART1_RXINV OUTPUT HIGH GPIO(78) POL(0)
# SBUS inversion control pin, active high
PC0 USART1_RXINV OUTPUT LOW GPIO(78) POL(1)

# USART3
PB10 USART3_TX USART3
Expand Down
5 changes: 2 additions & 3 deletions libraries/AP_HAL_ChibiOS/hwdef/revo-mini-i2c/hwdef.dat
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ define HAL_BATT_CURR_PIN 11
define HAL_BATT_VOLT_SCALE 10.1
define HAL_BATT_CURR_SCALE 17.0


PC0 SBUS_INVERT OUTPUT LOW

# LEDs
PB5 LED_BLUE OUTPUT LOW GPIO(0)
PB6 LED_YELLOW OUTPUT LOW GPIO(1) # optional
Expand All @@ -52,6 +49,8 @@ PB4 LED_RED OUTPUT LOW GPIO(2)
# GPS port
PC6 USART6_TX USART6
PC7 USART6_RX USART6
# SBUS inversion control pin, active high
PC0 USART6_RXINV OUTPUT LOW GPIO(78) POL(1)

# USART3 (SERIAL2) on flexi port in BRD_ALT_CONFIG = 3 & 4 & 5
PB10 USART3_TX USART3 ALT(3)
Expand Down
5 changes: 2 additions & 3 deletions libraries/AP_HAL_ChibiOS/hwdef/revo-mini/hwdef.dat
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ define HAL_BATT_CURR_PIN 11
define HAL_BATT_VOLT_SCALE 10.1
define HAL_BATT_CURR_SCALE 17.0


PC0 SBUS_INVERT OUTPUT LOW

# LEDs
PB5 LED_BLUE OUTPUT LOW GPIO(0)
PB6 LED_YELLOW OUTPUT LOW GPIO(1) # optional
Expand All @@ -52,6 +49,8 @@ PB4 LED_RED OUTPUT LOW GPIO(2)
# GPS port disabled (PC6 used for RCIN)
#PC6 USART6_TX USART6
#PC7 USART6_RX USART6
# SBUS inversion control pin, active high
#PC0 USART6_RXINV OUTPUT LOW GPIO(78) POL(1)

# flexi port, setup as GPS
PB10 USART3_TX USART3
Expand Down

0 comments on commit 3d5a717

Please sign in to comment.