Skip to content

Commit ab11f30

Browse files
committed
uart: Add check for prevent use software DE control if hardware DE control exists
Add support for configuring and enabling RS485 signaling by use software method of pin control. Signed-off-by: Nachiketa Kumar <[email protected]> Signed-off-by: Antonio Tessarolo <[email protected]> Signed-off-by: Sergey Grigorovich <[email protected]>
1 parent 01c4dba commit ab11f30

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

drivers/serial/uart_stm32.c

+35-11
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,20 @@ static void uart_stm32_irq_tx_enable(const struct device *dev)
930930
unsigned int key;
931931
#endif
932932

933-
if (config->de_enable) {
934-
gpio_pin_set(config->de_pin.port, config->de_pin.pin, config->de_invert);
935-
}
933+
#if HAS_DRIVER_ENABLE
934+
if (config->de_enable && IS_UART_DRIVER_ENABLE_INSTANCE(config->usart))
935+
{
936+
/* do nothing here for DE, hardware will handle it */
937+
}
938+
else
939+
#endif
940+
{
941+
/* Software DE control over GPIO */
942+
if (config->de_enable)
943+
{
944+
gpio_pin_set(config->de_pin.port, config->de_pin.pin, config->de_invert);
945+
}
946+
}
936947

937948
#ifdef CONFIG_PM
938949
key = irq_lock();
@@ -951,14 +962,27 @@ static void uart_stm32_irq_tx_disable(const struct device *dev)
951962
{
952963
const struct uart_stm32_config *config = dev->config;
953964
struct uart_stm32_data *data = dev->data;
954-
if (config->de_enable) {
955-
if (config->de_deassert_time_us) {
956-
k_timer_start(&data->rs485_timer, K_USEC(config->de_deassert_time_us),
957-
K_NO_WAIT);
958-
} else {
959-
gpio_pin_set(config->de_pin.port, config->de_pin.pin, !config->de_invert);
960-
}
961-
}
965+
966+
#if HAS_DRIVER_ENABLE
967+
if (!(config->de_enable && IS_UART_DRIVER_ENABLE_INSTANCE(config->usart)))
968+
{
969+
#endif
970+
if (config->de_enable)
971+
{
972+
if (config->de_deassert_time_us)
973+
{
974+
k_timer_start(&data->rs485_timer,
975+
K_USEC(config->de_deassert_time_us),
976+
K_NO_WAIT);
977+
}
978+
else
979+
{
980+
gpio_pin_set(config->de_pin.port, config->de_pin.pin, !config->de_invert);
981+
}
982+
}
983+
#if HAS_DRIVER_ENABLE
984+
}
985+
#endif
962986

963987
#ifdef CONFIG_PM
964988

0 commit comments

Comments
 (0)