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

How to redirect printf to UART when using Segger Embedded Studio

The Segger Compiler is integrated with JLINK debugging software

Printf statements, when compiled, direct to the studio debugger terminal

How can I create code where they are directed to the UART?

Project options allow configuration of printf and scanf format but not its output

I am using the uart example in Nordic SDK 12.3. The only way so far that I have found to 'print' to the UART is using a custom print function:

void uart_printf(const char *fmt, ...)
{
char buf[200], *p;
va_list ap;
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
for (p = buf; *p; ++p)
app_uart_put(*p);
va_end(ap);
}

This works but seems laborious;  what is the elegant way?

Many thanks

Rob

  • Hi Andreas

    Thanks for the prompt.  I followed the tutorial importing the Keil project from examples/periperals/UART/blank - target NRF51822 QFAA

    However I do not remember modifying the internal files after the import.  Which ones should I use for this SoC?

    The tutorial is based upon the 52 series

    BW

    Rob

  • Hi.

    Can you use the files system_nrf51.c and system_nrf51.h found in \components\toolchain

    Download this zip file:embedded_studio.zip

    And place it like I have on my picture, in \components\toolchain

    Inside this file is a flash_placement.xml, ses_nrf51_startup.s and thumb_crt0.s which should work.

    Best regards,

    Andreas

  • Andreas,

    Many thanks. I am unsure what to do with the flash_placement.xml.

    I included the *.s files in the build and excluded the old ones:

    But I get the following build errors:

    Building ‘twi_master_using_app_twi_pca10028_sdk12’ from solution ‘twi_master_using_app_twi_pca10028_sdk12’ in configuration ‘nrf51422_xxac’
    1> Assembling ‘ses_nrf51_startup.s’
    2> Assembling ‘thumb_crt0.s’
    1> Linking twi_master_using_app_twi_pca10028_sdk12.elf
    1>
    1> Diagnostics:
    1> remark: increasing alignment of section .vectors from 1 to 2 because it contains executable instructions
    1> error: undefined symbol: __SEGGER_init_copy
    1> error: undefined symbol: __SEGGER_init_zero
    1> error: undefined symbol: __SRAM_segment_end__
    1> error: undefined symbol: __bss_end__
    1> error: undefined symbol: __bss_start__
    1> error: undefined symbol: __ctors_load_start__
    1> error: undefined symbol: __data_end__
    1> error: undefined symbol: __data_load_start__
    1> error: undefined symbol: __data_start__
    1> error: undefined symbol: __dtors_load_start__
    1> error: undefined symbol: __fast_end__
    1> error: undefined symbol: __fast_load_start__
    1> error: undefined symbol: __fast_start__
    1> error: undefined symbol: __rodata_end__
    1> error: undefined symbol: __rodata_load_start__
    1> error: undefined symbol: __rodata_start__
    1> error: undefined symbol: __stack_process_end__
    1> error: undefined symbol: __stack_process_start__
    1> error: undefined symbol: __text_end__
    1> error: undefined symbol: __text_load_start__
    1> error: undefined symbol: __text_start__
    Build failed

    It seems I should keep the Segger_thumb?

    But then I get errors:

    Building ‘twi_master_using_app_twi_pca10028_sdk12’ from solution ‘twi_master_using_app_twi_pca10028_sdk12’ in configuration ‘nrf51422_xxac’
    2> Assembling ‘SEGGER_THUMB_Startup.s’
    1> Linking twi_master_using_app_twi_pca10028_sdk12.elf
    1>
    1> Diagnostics:
    1> error: multiply defined global symbol _start
    1> error: defined by thumb_crt0.o
    1> error: and by SEGGER_THUMB_Startup.o
    1> remark: increasing alignment of section .vectors from 1 to 2 because it contains executable instructions
    1> error: undefined symbol: __SRAM_segment_end__
    Build failed

    Rob

  • As a check I reverted to the original files and the build completed

    Thanks again for helping with this. 

    For my education what is the broad purpose of these start-up files?  They seem to be the first instructions that the processor executes on power-up. 

    Are they in effect the boot file?

    Rob

  • As a recap of the problem I am trying to solve:  I would like to redirect printf (or stop its current redirection) so that the compiled code operates without Segger Studio, just with a UART connection

    Does stdio.h define the standard output destination for putchar()?

    Rob

Related