Stm32L151RCxxx USART Hang issue, Interrupt Based TX/RX simultaneously

4.6k views Asked by At

I am running USART3, on 921600 BaudRate, using RTS CTS, I am always facing system hang when I try to do RX and TX simultaneously. I have pasted the main and IRQ code. IRQ is designed to Transmit a char 'A' while dropping all received data. Hangs happens when we disable USART_ITConfig(USART3, USART_IT_TXE, DISABLE);

Uart_Configuration()...

USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(USART3, &USART_ClockInitStructure);

USART_InitStructure.USART_Mode = (USART_Mode_Tx|USART_Mode_Rx);
USART_InitStructure.USART_BaudRate = u32BaudRate;
USART_OverSampling8Cmd(USART3, DISABLE);
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS; 
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_Init(USART3, &USART_InitStructure);  
USART_ITConfig(USART3,USART_IT_TXE, DISABLE);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_Cmd(USART3, ENABLE);

Main.c ...

uint8_t UART_TransmitData(void)
{
   if(u8IntTxFlag==1)
   {
       u8IntTxFlag=0;
       USART_ITConfig(USART3, USART_IT_TXE, ENABLE);      
       return TRUE;
   }
   return FALSE;
}


void USART3_IRQHandler(void)
{
   /* Implemented full duplex serial communication */
   /*  UART RX  */
   if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
   {
     USART_ReceiveData(USART3);
   }

   /*    UART TX    */
   if(USART_GetITStatus(USART3, USART_IT_TXE) != RESET)
   {
     if(USART_GetFlagStatus(USART3, USART_FLAG_CTS) == RESET)
     {
         while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
         USART_SendData(USART3, 'A');
         while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);
         USART_ClearFlag(USART3, USART_FLAG_TC);
         USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
         u8IntTxFlag=1;
     }
     else
     {
        USART_ClearFlag(USART3, USART_FLAG_CTS);
     }
   }
}


int main(void)
{
  RCC_ClocksTypeDef RCC_Clocks;

  RCC_Configuration();
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000);

  NVIC_Configuration();

  Init_GPIOs();

  SerialUARTConfig(921600, 0, 1, 8, 1);

                while(1)
                {
                                UART_TransmitData();
                                f_SleepMs(5);

                }
                return 0;
}
1

There are 1 answers

0
kirill On

Maybe the USART_IT_TXE interrupt happens before you disable it? So the "Tx empty" interrupt pending flag is already set and there is no procedure inside your IRQHandler to clear that flag.