10 years, 1 month ago.

Can't use blinky with printf

Any idea why I can't use printf with blinky? Nothing at all happends, no blinks and no printout.

Entire source code:

  1. include "mbed.h"

DigitalOut myled(LED1);

int main() { while(1) { printf("test "); myled = 1; wait(0.2); myled = 0; wait(0.2); } }

Blinky works and printf works, but not together in the same program.

LPC1549 mbed-interface flash program only 4Kbyte ? Via ISP USB boot mode is no problem.

posted by Norimasa Okamoto 14 Mar 2014

Yes, 4400 bytes to be exact. Using mBed drag&drop to program the board.

posted by Display Module 14 Mar 2014

3 Answers

10 years, 1 month ago.

I have this program that I use with the LPC1768, and it works fine, using both printf(), and LED output, as well as Serial character input. The difference is that I define "pc" as a Serial device, using the USBTX and RX built-in ids.

#include "mbed.h"
 
Serial pc(USBTX, USBRX); // tx, rx
PwmOut R(p21);
PwmOut B(p22);
PwmOut G(p23);
 
float brightness = 0.0;
 
int main() {
    pc.printf("Press 'u' to turn brightness up, 'd' to turn it down\n");
 
    while(1) {
        char c = pc.getc();
        if((c == 'u') && (brightness < 0.5)) {
            brightness += 0.1;
            R = G = B = brightness;
        }
        if((c == 'd') && (brightness > 0.0)) {
            brightness -= 0.1;
            R = G = B = brightness;
        } 
    }
}

Thanks, tried defining the serial device as your program, still failed. After download, nothing happends.

posted by Display Module 14 Mar 2014

One thing to try: change

printf( "test " );

To:

printf( "test\n" );

I remember on some systems - this was a long time ago - some output would be held up until the buffer was flushed, either manually with fflush(), with enough characters to fill the buffer, or with a \n. It can't hurt to try it.

posted by Aaron Minner 14 Mar 2014

Tested it. No blinking and no print output.

posted by Display Module 14 Mar 2014

Hmmm. Well, it looks as if mbed will have to hand out a few 1549s so we can get to the bottom of this. :-)

posted by Aaron Minner 14 Mar 2014
10 years, 1 month ago.

Try flushing the printf buffer using fflush(stdout) or you can add a newline \n character to your string which will trigger the same.

Tested it now, still nothing happends. No blinking and no print output.

posted by Display Module 14 Mar 2014
10 years, 1 month ago.

This looks similar to the flash problems that I have seen with the LPC1549 board. See here. Can you still successfully flash and run anything on the LPC1549? Have you tried to flash the same binary using the USB bootloader mode as described in my link above and does it work in that case?

Thanks for info. I can reflash the board with other programs like blinky etc. and run them as usual. I haven't tried any other way than mbed drag&drop, I will test your way next chance I get.

posted by Display Module 14 Mar 2014

How to flash in USB bootloader mode? I get a Mass storage device "CRP DISABLD". 0 bytes free of 256KB with a 256KB firmware.bin file on it.

posted by Display Module 19 Mar 2014

You simply delete the firmware.bin on the CRP DISABLD device and then copy or download the bin file from the mbed compiler onto the device. Then press reset and your program will start.

Note that I have been in touch with mbed support. The error has been confirmed and mbed and Embedded Artist are fixing it. There should be new firmware for the mbed interface chip soon.

posted by Wim Huiskamp 19 Mar 2014

After setting in this mode I can no longer use it in "Normal Mode" (i.e. get the MBED mass storage device). But like you I can now run my program.

posted by Display Module 20 Mar 2014

After flashing the code you can plug the USB cable back into the original port and the mbed mass storage will show up again. You also need to use that port to get access to the virtual com port and see your printf() messages. Downloading new code still does not work on this USB port. We will have to wait until the firmware for the mass storage device interface has been fixed. I have been in touch with mbed staff and the problem is now known and a fix is expected soon.

posted by Wim Huiskamp 20 Mar 2014

The mbed mass storage does no longer show when I plug the USB cable back into the original port. I will wait for the new firmware. Thanks!

posted by Display Module 21 Mar 2014

Hmm, that is strange. Still shows on my boards. Are you sure the new (but incorrect) mbed firmware is installed. Make sure that jumper JP3 has been removed. Is the power LED still on when you connect the USB cable to the original port. Is the flashed target code still running.

posted by Wim Huiskamp 21 Mar 2014

Was not able to get any mass storage device from either "link" or "target", with or without JP3 fitted. I could flash the firmware again (http://mbed.org/teams/NXP/wiki/Updating-LPCXpresso-firmware), then it was working as before.

posted by Display Module 01 Apr 2014

Ok, good to hear that it has been fixed. Some notes:

  1. mbed mass storage will only show up on ''link'' port
  2. It will only show when JP3 is removed.
  3. JP3 should only be installed when you want to reflash the interface firmware. You need to remove it when reflash is complete and you want to use the new firmware.
posted by Wim Huiskamp 01 Apr 2014

The new firmware found at http://mbed.org/teams/NXP/wiki/Updating-LPCXpresso-firmware fixes the problem. Make sure to use the size 0x80000 and not 0x8000.

posted by Display Module 08 Apr 2014