This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using serial port with free RTOS - receive issues

Hello,

I would like to use the serial port library with free RTOS. I read several threads that timeouts do not work when using free RTOS. So I tried to use the lib without it.

I always try to read one byte (in an own task). It works in general but every other byte I get wrong (something between 0xE0 and 0xFF). I use a serial terminal to send some keyboard keys.

I am using SDK Version 15.3 with the PCA10056.

NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uarte0_drv_config,
                      RX_PIN_NUMBER,ARDUINO_SCL_PIN,
                      RTS_PIN_NUMBER, CTS_PIN_NUMBER,
                      NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED,
                      NRF_UART_BAUDRATE_38400,
                      UART_DEFAULT_CONFIG_IRQ_PRIORITY);

#define SERIAL_FIFO_TX_SIZE 128
#define SERIAL_FIFO_RX_SIZE 128

NRF_SERIAL_QUEUES_DEF(serial0_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE);


#define SERIAL_BUFF_TX_SIZE 1
#define SERIAL_BUFF_RX_SIZE 1

NRF_SERIAL_BUFFERS_DEF(serial0_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE);



NRF_SERIAL_CONFIG_DEF(serial0_config, NRF_SERIAL_MODE_DMA,
                      &serial0_queues, &serial0_buffs, NULL, NULL);


NRF_SERIAL_UART_DEF(serial0_uarte, 0);


// Task method
void UART_Read_E10_Task()
{
  char c;
  ret_code_t ret;

  while(true)
  {
    ret = nrf_serial_read(&serial0_uarte, &c, sizeof(c), NULL,0);
    if (ret == NRF_SUCCESS)
    {
   
    NRF_LOG_DEBUG("READ E10 %c %i %i",c,c)   
    }
  }
}

Does anyone know what I am doing wrong? Or does anyone have the same problem?

The best would be a working example using both UARTs with free RTOS...

Thanks,

Andreas

  • Hi,

    Thank you for your support. 

    Attached is the example I am talking about. I am using SES with PCA10056. If you run the example you should see that the first call to "nrf_serial_read "does not timeout untill a byte is sent  (I tested with a serial terminal, baud rate 38400).. after the first byte is read the method does return with an error...

    blinky_freertos - Sample.7z

  • Hi,

    Regarding the subsequent error, this is caused by recreating the app-timer every time, which is not correct. You can fix that in a quick and dirty way using this modification:,

    diff --git a/components/libraries/serial/nrf_serial.c b/components/libraries/serial/nrf_serial.c
    index 3b6f471..98fdcfc 100644
    --- a/components/libraries/serial/nrf_serial.c
    +++ b/components/libraries/serial/nrf_serial.c
    @@ -313,7 +313,7 @@ static ret_code_t timeout_setup(nrf_serial_t const * p_serial,
         ret_code_t ret = app_timer_create(p_timer_id,
                                           APP_TIMER_MODE_SINGLE_SHOT,
                                           serial_timeout_handler);
    -    if (ret != NRF_SUCCESS)
    +    if (ret != NRF_SUCCESS && ret != NRF_ERROR_INVALID_STATE)
         {
             return ret;
         }
    

    I also fixed a warning in your main.c file just because it was annoying. Your My_cdc_acm_user_ev_handler() prototype should look like this:

    void My_cdc_acm_user_ev_handler(struct nrf_serial_s const * p_serial,
                                    nrf_serial_event_t event);

    ...and the implementation should look like this:

    void My_cdc_acm_user_ev_handler(struct nrf_serial_s const * p_serial,
                                    nrf_serial_event_t event)
    {
        switch (event)
        {
            case NRF_SERIAL_EVENT_DRV_ERR:
                break;
            default:
                break;
        }
    }

    I have tested a bit more, but I still have not found the reason for the missing timeout. I need to look more into that and get back to you. Have you had any progress on your side?

Related