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

Issue with CR when using CLI and RTT logger

Hi

I have a project that uses several protocols, including UART and USB CLI

As such, I had to move the nRF logger to work on RTT, so that everything could work properly

My issue is that if I get the RTT logger working, my CLI printing break (they are going diagonally instead of as new lines)

I investigated and found the issue was related to the define NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED in sdk_config.h

according to nrf_log not working on SES, I need to set the define to 0 for RTT prints to work correctly

however, according to cli new line problem, I need to set the define to 1 for CLI prints to look correct

I tried changing the syntax of my CLI prints, but I think some of the formatting is tied to the CLI functions in the SDK, which I don't want to change

Is there any way to get both a functioning RTT logger in SES, as well as organized prints in my CLI interface, in the same project?

Any and all help will be appreciated

Thanks in advance

Aviv

Parents
  • Hi Aviv,

    I have reported this to the SDK developers.

    The natural place to fix this would be in <SDK>\external\fprintf\nrf_fprintf_format.c. You could check if an \r has proceeded the \n, and only add it if it has not. As you can see it is not just a matter of changing buffer_add() though, as that function works on single characters. You either have to rewrite a bit more or consider a hack where you use a static variable to hold the previous character or similar.

  • I couldn't figure how to change nrf_fprintf_fmt, so I decided to change buffer_add instead as it was simpler

    I've attached the code changes I made, and it seems that it works with NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED set to 1 for both CLI and RTT logs

    so I believe this is the simplest solution to this situation, though let me know if you have a better one

    static char prev_char = '\0';
    
    static void buffer_add(nrf_fprintf_ctx_t * const p_ctx, char c)
    {
    #if NRF_MODULE_ENABLED(NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF)
        if (c == '\n'
    		&& prev_char != '\r')
        {
            buffer_add(p_ctx, '\r');
        }
    
    	prev_char = c;
    #endif
        p_ctx->p_io_buffer[p_ctx->io_buffer_cnt++] = c;
    
        if (p_ctx->io_buffer_cnt >= p_ctx->io_buffer_size)
        {
            nrf_fprintf_buffer_flush(p_ctx);
        }
    }

Reply
  • I couldn't figure how to change nrf_fprintf_fmt, so I decided to change buffer_add instead as it was simpler

    I've attached the code changes I made, and it seems that it works with NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED set to 1 for both CLI and RTT logs

    so I believe this is the simplest solution to this situation, though let me know if you have a better one

    static char prev_char = '\0';
    
    static void buffer_add(nrf_fprintf_ctx_t * const p_ctx, char c)
    {
    #if NRF_MODULE_ENABLED(NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF)
        if (c == '\n'
    		&& prev_char != '\r')
        {
            buffer_add(p_ctx, '\r');
        }
    
    	prev_char = c;
    #endif
        p_ctx->p_io_buffer[p_ctx->io_buffer_cnt++] = c;
    
        if (p_ctx->io_buffer_cnt >= p_ctx->io_buffer_size)
        {
            nrf_fprintf_buffer_flush(p_ctx);
        }
    }

Children
No Data
Related