Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
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:
- 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.
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 14 Mar 2014One 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 14 Mar 201410 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 14 Mar 2014How 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 19 Mar 2014You 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 19 Mar 2014After 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 20 Mar 2014After 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 20 Mar 2014The 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 21 Mar 2014Hmm, 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 21 Mar 2014Was 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 01 Apr 2014Ok, good to hear that it has been fixed. Some notes:
- mbed mass storage will only show up on ''link'' port
- It will only show when JP3 is removed.
- 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.
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 08 Apr 2014
LPC1549 mbed-interface flash program only 4Kbyte ? Via ISP USB boot mode is no problem.
posted by Norimasa Okamoto 14 Mar 2014Yes, 4400 bytes to be exact. Using mBed drag&drop to program the board.
posted by Display Module 14 Mar 2014