9 years, 10 months ago.

How to use printf over usb-serial ?

Hi,

I bought this board http://international.switch-science.com/catalog/1714/

But I don't know how to print over usb serial, such that I can see output on terminal when I connect it to usb.

Here is my code

#include "mbed.h"

#define ADR 0x58

I2C i2c( dp5, dp27 ); // sda, scl
Serial pc(dp16, dp15); // tried dp15,dp16 and dp16,dp15 and USBTX, USBRX

int main() {
    pc.baud(115200);
    i2c.frequency(100000);
    
    char v;
    char cmd = 0x00;
    
    pc.printf("Loop\r\n");
    while(1) {
        pc.printf("Loop\r\n");
        i2c.write( ADR, &cmd , 1);
        i2c.read( ADR, &v, 1 );
        
        wait(1);
        //pc.printf("v = %d %%\t", v);    
     }
}

I hope this board does not need extra USB-Serial adapter, that actually kills the point of paying for it. Would be nice if someone could explain why it does not work.

Thanks

Question relating to:

The LPC1114FN28 is an ARM Cortex-M0 based, low-cost 32-bit MCU, designed for 8/16-bit microcontroller applications, offering performance, low power, simple instruction set and memory addressing together with reduced code size …

.

posted by Mateusz Kaduk 08 Jun 2014

Sorry I kept you waiting so long. Probably, this issue was solved by today's fix. Please try latest firmware. https://mbed.org/teams/Switch-Science/wiki/Firmware-LPC1114FN28

posted by Yoshihiro TSUBOI 21 Jun 2014

Your update instructions do not mention that firmware.bin should be overwritten.

mateusz@astro:$ dd bs=1024 conv=nocreat,notrunc if=/Desktop/lpc11u35_lpc1114_if_2014062100.bin of=/media/mateusz/CRP\ DISABLD/firmware.bin 32+1 records in 32+1 records out 32892 bytes (33 kB) copied, 0.107167 s, 307 kB/s mateusz@astro:$

Now I can see mbed folder, and my code works. Thanks,

posted by Mateusz Kaduk 21 Jun 2014

Nice. I'm guessing the point is using dd. Anyway, thanks for your cooperation.

posted by Yoshihiro TSUBOI 21 Jun 2014

2 Answers

9 years, 10 months ago.

I tried to test UART with this code,

#include "mbed.h"
 
Serial pc(dp16, dp15); // tx, rx
 
int main() {
    pc.baud(9600);
    while (1) {
        wait(5);
        pc.printf("Hello World!\r\n");
    }
}


And it works. I'm not sure why your LPC1114FN28 is keeping silent. If you could, could you try to erase flash?
You can erase flash with SWD or ISP. When you want to use SWD, you can use CMSIS-DAP with MDK-ARM. When you want to use ISP, you may need USB-UART bridge and Flash Magic. I wrote brief instruction about ISP. https://mbed.org/users/ytsuboi/notebook/getting-started-with-mbed-lpc1114/

/media/uploads/ytsuboi/---------_2014-06-09_21.37.44.png


- 2014-06-21 Update
Sorry I kept you waiting so long. Probably, this issue was solved by today's fix. Please try latest firmware. https://mbed.org/teams/Switch-Science/wiki/Firmware-LPC1114FN28

Accepted Answer

(1) Can you please try this code ?

#include "mbed.h"
 
#define ADR 0x58
 
I2C i2c( dp5, dp27 ); // sda, scl
Serial pc(dp16, dp15); // tried dp15,dp16 and dp16,dp15 and USBTX, USBRX
 
int main() {
    pc.baud(115200);
    i2c.frequency(100000);
    
    char v;
    char cmd = 0x00;
    
    pc.printf("Loop\r\n");
    while(1) {
        pc.printf("Loop\r\n");
        i2c.write( ADR, &cmd , 1);
        i2c.read( ADR, &v, 1 );
        
        wait(1);
        //pc.printf("v = %d %%\t", v);    
     }
}

After running this one, serial stopped working (I didn't physicaly touch chip, that worked before flashing this I2C code).

(2) Is it possible to erase with bus-pirate or bus-blaster ?

Thanks, Mateusz

posted by Mateusz Kaduk 09 Jun 2014

1) What I2C device did you connect?
2) I'm not sure bus-pirate is enough to use ISP. I used FTDI Breakout.
Oops, I remember you are using Linux. So, you can use ISP with lpc21isp. http://sourceforge.net/projects/lpc21isp/

posted by Yoshihiro TSUBOI 09 Jun 2014

Dear Yoshihiro,

1) There is nothing connected to the chip, besides USB cable to program it at the moment. Just flashing this code, that does something with I2C, and the chip became silent.

2) I will try that if I figure out how to. At this moment the link you gave, does not contain instructions how to erase the chip, but only that there is a possibility of using isp and command you used to flash hex file.

posted by Mateusz Kaduk 09 Jun 2014

I found a problem, maybe on Drag&Drop programing function. It may need a time to solve this bug.
If you want quick solution, please export your project from online compiler to Keil uVision 4. And try to build and flash with uVision 4 via interface's CMSIS-DAP function. You can use uVision 4 for free if the target binary is less than 32kB. https://www.keil.com/demo/eval/armv4.htm

posted by Yoshihiro TSUBOI 09 Jun 2014

I followed instruction how to update firmware, and no I don't see mbed folder to drop program. I can enter in ISP mode to CRD DISABLED folder, but nothing else works now.

posted by Mateusz Kaduk 21 Jun 2014

I added instruction for Linux. Please update the interface firmware. https://mbed.org/teams/Switch-Science/wiki/Firmware-LPC1114FN28

posted by Yoshihiro TSUBOI 21 Jun 2014
9 years, 10 months ago.

The board has a lpc11U35 that functions as serial to USB interface. The dp15,dp16 pair is the serial port for the USB interface. However, you may want to check that two solder bridges (SJ1, SJ2) are in place to actually connect the LPC1114 serial port to the USB interface. Obviously you also need to install the mbed windows serial driver and check the device drivers on the PC to make sure everything has installed correctly.

Well I actually can flash the chip so it I think that happens via dp16/dp15 right ? Bridges are connected, I checked schematics. Also I am not using Windows, but GNU/Linux and gtkterm. I know my terminal works with bus pirate, I don't know why I dont see anything from this lpc1114 though.

Even this simple example does not show anything after pressing reset.

#include "mbed.h"              
 
//Serial pc(USBTX, USBRX); // tx, rx
Serial pc(dp16, dp15); // tx, rx
 
int main() {
    pc.printf("Hello World1!\n");
    printf("Hello World2!\n");
}
posted by Mateusz Kaduk 08 Jun 2014

Oops. I've never tested HDK (the interface firmware) with Linux... As well as I know, UART bridge function with OS X have some trouble. I'm so sorry for the inconvenience.

posted by Yoshihiro TSUBOI 08 Jun 2014

Flashing does NOT use dp16, dp15. Check that the PC recognises the virtual com port provided by the LPC11u35 interface chip after installing the serial port driver for mbed. Make sure that the baudrate is OK.

posted by Wim Huiskamp 08 Jun 2014

Ok, with the new chip it worked for like 30min. Flashing the code that sets I2C bricks the mcu.

posted by Mateusz Kaduk 08 Jun 2014

Assigned to Yoshihiro TSUBOI 9 years, 10 months ago.

This means that the question has been accepted and is being worked on.