1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 08:15:30 +03:00

Fix 303 serial inversion and bidir mode

- USART_HalfDuplexCmd must be called only when USART is disabled
- input should be PullDown for inverted serial
- INVERTED BIDIR mode changed to GPIO_OType_PP (not opendrain) - opendrain won't work well for inverted serial; USART releases pin when transmission is done, so PP is OK
This commit is contained in:
Petr Ledvina 2015-03-31 14:48:17 +02:00
parent 1bac2830aa
commit 4c60f6c795
2 changed files with 22 additions and 23 deletions

View file

@ -52,18 +52,11 @@ static void usartConfigurePinInversion(uartPort_t *uartPort) {
#ifdef STM32F303xC
uint32_t inversionPins = 0;
// Inversion when using OPTION_BIDIR not supported yet.
if (uartPort->port.options & SERIAL_BIDIR) {
// Clear inversion on both Tx and Rx
inversionPins |= USART_InvPin_Tx | USART_InvPin_Rx;
inverted = false;
} else {
if (uartPort->port.mode & MODE_TX) {
inversionPins |= USART_InvPin_Tx;
}
if (uartPort->port.mode & MODE_RX) {
inversionPins |= USART_InvPin_Rx;
}
if (uartPort->port.mode & MODE_TX) {
inversionPins |= USART_InvPin_Tx;
}
if (uartPort->port.mode & MODE_RX) {
inversionPins |= USART_InvPin_Rx;
}
USART_InvPinCmd(uartPort->USARTx, inversionPins, inverted ? ENABLE : DISABLE);
@ -93,6 +86,11 @@ static void uartReconfigure(uartPort_t *uartPort)
usartConfigurePinInversion(uartPort);
if(uartPort->port.options & SERIAL_BIDIR)
USART_HalfDuplexCmd(uartPort->USARTx, ENABLE);
else
USART_HalfDuplexCmd(uartPort->USARTx, DISABLE);
USART_Cmd(uartPort->USARTx, ENABLE);
}
@ -182,11 +180,6 @@ serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback,
USART_Cmd(s->USARTx, ENABLE);
if (options & SERIAL_BIDIR)
USART_HalfDuplexCmd(s->USARTx, ENABLE);
else
USART_HalfDuplexCmd(s->USARTx, DISABLE);
return (serialPort_t *)s;
}