Monday, April 23rd 2018, 10:57pm UTC+2

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

rbphilip

Beginner

Date of registration: Mar 16th 2018

Posts: 2

1

Saturday, March 17th 2018, 12:28pm

[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;
}

SEGGER - Nino

Super Moderator

Date of registration: Jan 2nd 2017

Posts: 949

2

Monday, March 19th 2018, 9:31am

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: http://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 purposes 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: https://www.segger.com/about-us/contact-us/


rbphilip

Beginner

Date of registration: Mar 16th 2018

Posts: 2

3

Monday, March 19th 2018, 9:52am

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





This post has been edited 1 times, last edit by "rbphilip" (Mar 19th 2018, 10:10am)


SEGGER - Nino

Super Moderator

Date of registration: Jan 2nd 2017

Posts: 949

4

Monday, March 26th 2018, 9:13am

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 purposes 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: https://www.segger.com/about-us/contact-us/