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

Realy strange printf over UART loggin behaviour

I'm trying to setup logging with printf() over UART and I got totaly blocked by following realy strange situation.

Let's have following very simple log_test.c:

#include "boards.h"
#include "nrf_delay.h"
#include "app_uart.h"
#include "app_error.h"

int _write(int file, const char * p_char, int len) {
  int i;
  for (i = 0; i < len; i++) app_uart_put(*p_char++);
  return len;
}

static void uart_error_handle(app_uart_evt_t * p_event) { /* nothing here */ }

int main(void) {
  ret_code_t err_code;

  const app_uart_comm_params_t comm_params = {
    RX_PIN_NUMBER,
    TX_PIN_NUMBER,
    0,
    0,
    APP_UART_FLOW_CONTROL_DISABLED,
    false,
    UART_BAUDRATE_BAUDRATE_Baud9600
  };

  APP_UART_FIFO_INIT(&comm_params, 1024, 1024, uart_error_handle, APP_IRQ_PRIORITY_MID, err_code); 
  UNUSED_VARIABLE(err_code);

  printf("\r\nHello");
  
  while (true) {
    nrf_delay_ms(1000);
    printf(".");
  }
}

Then I have a putty configured as a hyper terminal and can watch the COM port traffic...

When I compile and run this log_test.c, I can see that ONLY THE CONTROL CHARACTERS \r and \n are sent over UART. I can't see the "Hello" string and the dots "." in the while loop.

BUT when I comment out this line:

    // nrf_delay_ms(1000);

I start to see all printf() logs: the control characters, the "Hello" and the dots ".".

Any idea what is going wrong?

Related