Pages: [1]   Go Down
Author Topic: printf() function for Arduino Due  (Read 605 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using Arduino Due IDE 1.5.2 with Eclipse Juno and Arduino Eclipse Plugin V2. I am trying to implement the Relic Toolkit library on Due. But it requires printf() support. Whenever I am trying to implement the below code

int serial_putchar(char c, FILE* f) {
    if (c == '\n') serial_putchar('\r', f);
    return Serial.write(c) == 1? 0 : 1;
}

FILE serial_stdout;

void setup(){
    Serial.begin(115200);

    // Set up stdout
    fdev_setup_stream(&serial_stdout, serial_putchar, NULL, _FDEV_SETUP_WRITE);[/b]
    stdout = &serial_stdout;

    printf("My favorite number is %6d!", 12);
}

I get the error message as
_FDEV_SETUP_WRITE' was not declared in this scope
Symbol '_FDEV_SETUP_WRITE' could not be resolved.

Can anybody help to resolve this issue.

Your help will be highly appreciated.
Logged

US
Offline Offline
Full Member
***
Karma: 4
Posts: 182
Electronics are the new Legos
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you want to be able to define different serial devices as stdout?  Or hard code to say the main USB port?

You could define printf as just sending the char to the usb - open usb at the baud rate in Begin - Serial.begin(baudrate) then printf would send the char as a Serial.print(c); (the file handle would be ignored if you share a code base).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually i need printf() support for implementing Relic Toolkit library. Even on including stdio.h header file, why is printf() not working. Can you please explain your approach of having a way out.
Logged

Pages: [1]   Go Up
Jump to: