[SOLVED] scanf or fscanf on Nordic nRF52840

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] scanf or fscanf on Nordic nRF52840

    Hey...

    I'm trying to use fscanf & fprintf in code compiled with Embedded Studio and run on a Nordic nRF52840.

    I managed to derive that fprintf ultimately calls __write with a file handle as a parameter, and so I'm able to differentiate between stdout and stderr and send them to the correct UART.

    But it is unclear how to create the correct code for scanf (or fscanf).

    I created the workaround function as suggested in the manual (see below) and it works - but I had to make up my external declaration for __vfscanf and at the end of the day I'd just as soon use the built-in fscanf rather than a workaround.

    Is there a way to find/populate the system equivalent of the iod below?


    int uart0_scanf(const char *fmt, ...)
    {
    __stream_scanf_t iod;
    va_list a;
    int n;
    va_start(a, fmt);
    iod.is_string = 0;
    iod.getc_fn = uart0_getc;
    iod.ungetc_fn = uart0_ungetc;
    n = __vfscanf((__stream_scanf_t *)&iod, (const unsigned char *)fmt, a);
    va_end(a);
    return n;
    }
  • Hello,

    Thank you for your inquiry.
    The documentation about the scanf and vscanf implementation in Embedded Studio can be found in the help section under <stdio.h> API Summary.
    An online version is also available here: studio.segger.com/stdio_h.htm
    You can also rewrite all API functions as they are defined as weak and can be overwritten by user code.

    Best regards,
    Nino
    Please read the forum rules before posting: Forum Rules

    Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support contact us per e-mail.
    The following contact form can be used for this: Contact Us

  • Thanks for the quick reply, Nino.


    I've done some further research of my own, and have found the solution.


    I discovered last week, using the debugger, that fprintf ultimately calls a function called __write that is defined in __libc.h



    It turns out that there is a corresponding function called __read that is called by fscanf





    The post was edited 1 time, last by rbphilip ().

  • Hi,

    Great to hear that you are up and running again.
    We will consider this thread as solved now.

    Best regards,
    Nino
    Please read the forum rules before posting: Forum Rules

    Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support contact us per e-mail.
    The following contact form can be used for this: Contact Us