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

Where is scanf defined?

Hi Nordic!

On the radio_test example, the functions scanf and printf are heavily used, however, I haven't found where they are defined. This example is reading the data from the UART port, but there doesnt seem to be any implementation of the scanf function to read from there.

I have found stdio.h on the gcc-arm folder, but no .c implementation. How is the data being read form the UART?

Parents
  • Hi,

    printf and scanf are, as you indicated, defined in the C library stdio.h. The communication on the UART interface is handled by the app_uart module, and more specific, the functions app_uart_put and app_uart_get. The stdio functions can be retargeted to use the app_uart module to read and write data using the UART interface. You can find the implementation of these functions in the file retarget.c. You will also have to enable retargeting in sdk_config.h, by setting #define RETARGET_ENABLED 1.

    Best regards,

    Jørgen

Reply
  • Hi,

    printf and scanf are, as you indicated, defined in the C library stdio.h. The communication on the UART interface is handled by the app_uart module, and more specific, the functions app_uart_put and app_uart_get. The stdio functions can be retargeted to use the app_uart module to read and write data using the UART interface. You can find the implementation of these functions in the file retarget.c. You will also have to enable retargeting in sdk_config.h, by setting #define RETARGET_ENABLED 1.

    Best regards,

    Jørgen

Children
Related