3 Replies Latest reply on Sep 27, 2017 7:38 AM by dast_1961951

    stm32f4x:  platform_uart_receive_bytes stuck in race condition

    dast_1961951

      occasionally, function platform_uart_receive_bytes() gets stuck in the do-while loop where it attempts to copy data from driver->rx_buffer to the provided buffer.  execution stays in this tight loop until the UART in question receives datga.

       

      it appears this function is reached when there is no data available from the UART on the buffer.   I currently have no code to reproduce, but have seen this condition..

       

       

      workaround diff:

       

      @@ -531,18 +531,22 @@ platform_result_t platform_uart_receive_bytes( platform_uart_driver_t* driver, u

                       }

                   }

       

       

      -            *expected_data_size -= transfer_size;

      -

                   // Grab data from the buffer

                   do

                   {

                       uint8_t* available_data;

                       uint32_t bytes_available;

       

       

      +                if (ring_buffer_used_space( driver->rx_buffer ) < transfer_size)

      +                {

      +                    break;

      +                }

      +

                       ring_buffer_get_data( driver->rx_buffer, &available_data, &bytes_available );

                       bytes_available = MIN( bytes_available, transfer_size );

                       memcpy( data_in, available_data, bytes_available );

                       transfer_size -= bytes_available;

      +                *expected_data_size -= bytes_available;

                       data_in = ( (uint8_t*) data_in + bytes_available );

                       ring_buffer_consume( driver->rx_buffer, bytes_available );

                   } while ( transfer_size != 0 );