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

Problem with retarget.c

Hi

I'm using PCA10028. it has nrf51422 with softdevice s110. For getting printf in console I'm using 'app_uart.c with FIFO' and 'retarget.c'. When i try to print something I'm getting only the first character in console.

printf("starting");
printf("TWI initialized \n");

If I'm printing the above I will get output as

sT

I tried to edit the function fputc(int ch, FILE * p_file) in retarget.c as below,

UNUSED_PARAMETER(p_file);

// UNUSED_VARIABLE(app_uart_put((uint8_t)ch));
	
while(app_uart_put((uint8_t)ch) != NRF_SUCCESS);
		
return ch;

Then I'm getting the output on the console correctily. But I'm using an app_timer in the program. When this timer expires one handler will be called. Inside this handler I'm using printf. When it starts printing it gets stuck at

while(app_uart_put((uint8_t)ch) != NRF_SUCCESS);

This app_uart_put((uint8_t)ch) never returns NRF_SUCCESS and keeps on iterating.

Please help me...

Parents
  • Hi @eq

    What's your setup? SDK version? IDE? Keil? GCC? I have tried to reconstruct your problem on my system, but it just works for me. I use Keil, SDK 8.0.0, app_uart.h, app_uart_fifo.c and retarget.c. I have attached an example main.c file. It is based on the ble_template example in the SDK. My fputc() function in retarget.c looks like this:

    int fputc(int ch, FILE * p_file)
    {
        UNUSED_PARAMETER(p_file);
    
        UNUSED_VARIABLE(app_uart_put((uint8_t)ch));
        return ch;
    }
    

    main.c retarget.c

Reply
  • Hi @eq

    What's your setup? SDK version? IDE? Keil? GCC? I have tried to reconstruct your problem on my system, but it just works for me. I use Keil, SDK 8.0.0, app_uart.h, app_uart_fifo.c and retarget.c. I have attached an example main.c file. It is based on the ble_template example in the SDK. My fputc() function in retarget.c looks like this:

    int fputc(int ch, FILE * p_file)
    {
        UNUSED_PARAMETER(p_file);
    
        UNUSED_VARIABLE(app_uart_put((uint8_t)ch));
        return ch;
    }
    

    main.c retarget.c

Children
Related