AnalogIn and printf causes Runtime error

04 Jun 2012

Hi all,

I've found if I use the default printf() statement to print to the debug console (USB serial) in a program with AnalogIn it causes a runtime error:

Runtime Error - Output to generic stdout not allowed!
Trace (depth = 0):

Here's the code: (based on a handbook example http://mbed.org/handbook/AnalogIn with printf added)

// Analog input on p20 is displayed as bar chart brightness with on-board LEDs

#include "mbed.h"

AnalogIn ain(20);

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);

int main() {
    printf("test\n");

    while (1){
        led1 = (ain > 0.2) ? 1 : 0;
        led2 = (ain > 0.4) ? 1 : 0;
        led3 = (ain > 0.6) ? 1 : 0;
        led4 = (ain > 0.8) ? 1 : 0;
    }
}

If instead I add:

Serial pc(USBTX, USBRX);

Then printf to this Serial it works ok.

pc.printf("LDR test program\n");

Is this a bug or if I've missed the reason by the simple printf should not work? :)

Thanks!

Neil.

06 Jun 2012

I tried to reproduce this problem on my LPC11U24 and LPC1768 boards and they both appeared to work as expected and I didn't get that error message.

I did have to change this line to use p20 to get it to even compile.

AnalogIn ain(p20);
06 Jun 2012

Hi Adam,

Thanks for looking into this.

Looking at my setup in a little more detail I probably need to update my environment and my mbed controller. If I change the code to 'p20' per your note it doesn't compile. My mbed.h is dated 03 June 2008, and mbed controller is an LPC2368 which was part of the mbed beta program.

Can you point me at how to update the mbed.h? And is the LPC2368 still supported?

Thanks,

Neil.

06 Jun 2012

If you expand your program in the "Program Workspace" pane on the left and then click on the mbed library node, you should get a "Library Details" pane on the right hand side which shows you current version and if it is older than the latest, then you can press the "Upate to the latest revision" button and upgrade it. I used version 43 when I played around with it last night.

I have never heard that the 2368 wasn't being supported and I still see pre-compiled libraries for that platform with the latest versions of the mbed SDK. I would assume that it is still supported.

Hope that helps,

Adam

06 Jun 2012

Hi Adam,

Thanks. I found that the update option did not exist, possibly because I created this source program in the workspace back in 2008 and the options in the libary viewer are different comapred to a new program.

Instead I copied the source code into a completely new program and everything is good.

I appreciate the help, thanks!

Neil.

06 Jun 2012

Wow!! That is quite a snapshot of history you have there :)

Happy to hear that you got it working.

-Adam