From 0b6b2f3c12a3df3cf1e6c1d614890de4ae3a0ead Mon Sep 17 00:00:00 2001 From: Simon Kueppers Date: Fri, 21 Oct 2022 18:39:16 +0200 Subject: [PATCH] Implemented disabling UART transmitter when PTT1 is asserted, because they share a line --- stm32/aioc-fw/Src/usb_serial.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/stm32/aioc-fw/Src/usb_serial.c b/stm32/aioc-fw/Src/usb_serial.c index 788ea73..500c02c 100644 --- a/stm32/aioc-fw/Src/usb_serial.c +++ b/stm32/aioc-fw/Src/usb_serial.c @@ -142,6 +142,13 @@ void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding) // Invoked when cdc when line state changed e.g connected/disconnected void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { + if (dtr ^ rts) { + /* In case any PTT is asserted, disable UART transmitter due to those sharing the same lines */ + __disable_irq(); + USB_SERIAL_UART->CR1 &= (uint32_t) ~USART_CR1_TE; + __enable_irq(); + } + if (dtr & !rts) { /* PTT1 */ HAL_GPIO_WritePin(USB_SERIAL_UART_GPIO, USB_SERIAL_UART_PIN_PTT1, GPIO_PIN_SET); @@ -159,6 +166,13 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) HAL_GPIO_WritePin(USB_SERIAL_UART_GPIO, USB_SERIAL_UART_PIN_PTT2, GPIO_PIN_RESET); LED_SET(0, 0); } + + if ( !(dtr ^ rts) ) { + /* Enable UART transmitter again, when no PTT is asserted */ + __disable_irq(); + USB_SERIAL_UART->CR1 |= USART_CR1_TE; + __enable_irq(); + } } void USB_SerialInit(void)