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

Bug Report: non-blocking operation in retarget.c

I'm developing an UART with SD110. I've updated the SDK to the newest 7.1 and I'm using MDK Pack-Installer.

I found a problem in app_uart.c and retarget.c.

retarget.c retargets printf, which calls fputc to send a single char.

int fputc(int ch, FILE * p_file) {
    UNUSED_PARAMETER(p_file);

    UNUSED_VARIABLE(app_uart_put((uint8_t)ch));
    return ch; 
}

It calls app_uart_put

uint32_t app_uart_put(uint8_t byte)
{
    uint32_t err_code = NRF_SUCCESS;

    if (m_current_state != UART_READY)
    {
      err_code = NRF_ERROR_NO_MEM;
    }
    else
    {
      m_tx_byte = byte;
      on_uart_event(ON_UART_PUT);
    }

    return err_code;
}

If the UART transmission is not done, this function will return NRF_ERROR_NO_MEM. However, fputc doesn't process this error and will continue sending in new characters. As a result, becuase UART operation is slow, it's possible to send only the first character in a string and lose the others.

Here I only suggest a temporary fix for this issue,

int fputc(int ch, FILE * p_file)
{
    UNUSED_PARAMETER(p_file);

    int err_code;
    do
    {
        err_code = app_uart_put((uint8_t)ch);
    } while (err_code != NRF_SUCCESS);
    
    return ch;
}

It will block operations during the transmission of UART. It works for UART w/o flow control. For UART with flow control, the program may stuck if the flow control request is not responded. I know this is not a good solution. Hope Nordic can fix this problem soon.

Parents Reply Children
No Data
Related