AnsweredAssumed Answered

RTS flow control doesn't seem to work

Question asked by achterop.sietse on Feb 16, 2017
Latest reply on Oct 20, 2017 by Clive One

Dear List,


I am trying to get RTS/CTS flow control working on a discovery-stm32f407 board using cubemx generated software.
But when sending data from the PC to the UART2 the RTS signal never gets high as seen with a scope.
Constequently the data keep coming and soon there is an overrun error in the HAL_UART_ErrorCallback(). I use interrupts.
Sending data at slow enough speed is working perfectly.


I am testing with an usb-to-serial converter, ftdi-chip, between the PC and the board.
That side seems to work: if I make the CTS of the ftdi-chip (which is connected to the RTS of the UART2) high, the PC
immediately stops sending.


I configured RTS/CTS flow control in cubemx and also use interrupts here.
RTS is connected to Pin PD4 via cubemx


The configuration in MX_USART2_UART_Init(void):


huart2.Instance = USART2;
huart2.Init.BaudRate = 913085;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2) != HAL_OK) { Error_Handler(); }


The routine that I created to use it is:

__IO ITStatus Uart2RReady=RESET;
// non blocking, but will deliver the buffer in one piece in the end
int uart2_read(char *dst, int size) {

     static char inprogress=0;
      if (size == 0) return 0;

      if (!inprogress) {
          Uart2RReady = RESET;
          if (HAL_UART_Receive_IT(&huart2, (uint8_t *)dst, size) != HAL_OK)
          printf("uart2 read error\r\n"); // error_handler(nummer)
          inprogress = 1;
     if (Uart2RReady == SET) {
          inprogress = 0;
          debug_printf("Received: %d bytes\r\n", size);
          return size;
        } else return 0;

The question is why is RTS not set high when data keeps coming at a high enough rate?


 Thanks in advance,