Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printf not working with megaAVR - fix #842

Closed
Cobalt6700 opened this issue May 18, 2022 · 2 comments
Closed

Printf not working with megaAVR - fix #842

Cobalt6700 opened this issue May 18, 2022 · 2 comments

Comments

@Cobalt6700
Copy link

Cobalt6700 commented May 18, 2022

Hi,

I have been playing around with Arduino Nano Every's using the Arduino megaAVR Baords Library.
I needed to debug and found radio.printDetails(); was not outputting to serial monitor.
Tried with the example code GettingStarted to confirm it was not my code that was causing the issue. Switched Registers Emulation to ATMEGA328 with no change. Swapping out with a 328P Nano worked fine.

Not sure if this is the correct way of doing it, however after a bit of research and testing, the below "if defined" additions to printf.h seem to solve the issue.

#if defined (ARDUINO_ARCH_AVR) || defined (__ARDUINO_X86__) || defined (ARDUINO_ARCH_MEGAAVR)

int serial_putc(char c, FILE *)
{
    Serial.write(c);
    return c;
}

#elif defined (ARDUINO_ARCH_MBED)
REDIRECT_STDOUT_TO(Serial);

#endif // defined (ARDUINO_ARCH_AVR) || defined (__ARDUINO_X86__) || defined (ARDUINO_ARCH_MBED) || defined (ARDUINO_ARCH_MEGAAVR)

void printf_begin(void)
{
    #if defined (ARDUINO_ARCH_AVR) || defined (ARDUINO_ARCH_MEGAAVR)
    fdevopen(&serial_putc, 0);

    #elif defined (__ARDUINO_X86__)
    // For redirect stdout to /dev/ttyGS0 (Serial Monitor port)
    stdout = freopen("/dev/ttyGS0", "w", stdout);
    delay(500);
    printf("Redirecting to Serial...");
    #endif // defined(__ARDUINO_X86__)
}
@2bndy5
Copy link
Member

2bndy5 commented May 18, 2022

I have no objections to this. A simple PR for this is welcome.

@Cobalt6700
Copy link
Author

Magic, PR open.

@TMRh20 TMRh20 closed this as completed May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants