Is mbed codes compatible with LPC1769
Topic last updated
25 Jul 2012, by
IntelliSense .io.
14 replies
Hello,
I am working on the NxP LPC1769 and am hoping to reuse my code that I have written for the mbed.
1) Firstly, are the mbed codes compatible with the LPC?
2) If so, may I know how I can map the pins on the LPC1769, for example the P0[0], to an equivalent for the mbed code?
3) Lastly, can I simply compile the mbed code using the online compiler then use the LPCXpresso to flash the binary onto the LPC?
Thank you very much in advance!
Replies
buckeyes1997
#
02 Jul 2012
Yes code for the LPC1768 will download and work for the LPC1769. I have tested it with my own custom board and works well.
You will need to convert the .bin output from online compiler to .hex with something like Bin2Hex program available online and then download with something like FlashMagic.
There are examples of using mbed to flash custom boards.....search on the mbed forum for "prototype to production" to get started.
There some differences:
- printf() will not work, because this uses the magic chip on the mbed (you can use pc.println, where pc is a Serial object)
- network may not work (due to differences in the MAC chip)
- local file system won't work, because it uses the magic chip on the mbed - use a SD card instead
Thank you very much for your advice! May I know how i can map the pins on the LPC1769 to an mbed equivalent? For example, I will like to use pins P0[0] and P0[1] on the LPC1769 as UART3 pins, what pins should i use/type in the mbed code, Serial uart(p?, p?)
Thank you!
The pin mapping is simple:
- if it is a mbed pin, you can use the normal names (e.g. p10)
- for all other pins like P0[0]/P0[1] it is P0_0 / P0_1
So you would write
I have managed to compile and convert the BIN file to HEX. However, I have problems locating the COM port number for me device. I have tried looking it up in the device manager(I am using Windows 7), but it is not showing up there.
Just for clarification, I am using the bare LPC1769 board as it is. I am not sure what an ISP is, is it required in order to flash the LPC?
If not, what should I select under the Interface setting in Step 1?
Thank you very much for your help! =D
If you use the LPCXpresso, the easiest way is to use the LPC-Link together with the CodeRed-IDE to transfer you file to the LPC1769. Otherwise you need either a JTAG adapter, or use the serial port. For that, see http://mbed.org/cookbook/Prototype-To-Hardware.
The LPCXpresso doesn't provide a serial-to-USB converter, so you either need:
- such a converter (e.g. as a cable, or a FT232 board, or a CP2102 board)
- a serial level converter (e.g. MAX3232) connected to the serial port you want to use
Thank you very much Hendrik! I have managed to download codes from the mbed and flash it onto my LPC1769.
I am now trying to write a binary file to the LPC1769 and get the MCU to boot from the new firmware. I have found several forum threads on this, but when i tried to open a file to write or read, the program seems to be stuck. The following is the code i am using:
#include "mbed.h"
Serial *pUart_PC;
Serial uart_PC(P0_2,P0_3);
LocalFileSystem local("local"); // Create the local filesystem under the name "local"
void InitUart() {
uart_PC.baud(9600);
uart_PC.format(8,Serial::None,1);
uart_PC.printf("FILE IO test!!!\r\n");
pUart_PC = &uart_PC;
}
int main()
{
InitUart();
pUart_PC->printf("opening file\r\n");
FILE *fp = fopen("/local/test.txt", "wb"); // Open "out.txt" on the local file system for writing
if(fp ==NULL)
pUart_PC->printf("Write File open fail: \r\n");
else
{
pUart_PC->printf("write file OK: \r\n");
fputc(0x99,fp);
fputc(0x15,fp);
fclose(fp);
}
FILE *rp = fopen("/local/test.txt", "rb");
if(rp ==NULL)
pUart_PC->printf("Read File open fail: \r\n");
else
{
pUart_PC->printf("read file OK: \r\n");
fputc(0x99,fp);
fputc(0x15,fp);
fclose(fp);
}
char c;
c = fgetc(rp);
pUart_PC->printf("Read from file: \r\n");
pUart_PC->printf("%x ",c);
c = fgetc(rp);
pUart_PC->printf("%x ",c);
}
However, when i flash this mbed code onto my LPC7169, the program gets stuck when it is trying to open test.txt for writing right at the beginning.
Can someone please let me know where i went wrong and advise i could go about this?
Thank you very much in advance!
The LocalFileSystem doesn't work on anything else then the mbed. It uses the 'magic chip' which makes the mbed visible as Flash drive. If you really need this, use an SD card (and one of the SD card file systems).
Writing the internal flash is not what the LocalFileSystem does. The latter one has a flash memory chip attached to the 'magic chip'. The mbed processor then communicates with this chip to read the data. For that, the mbed firmware is used, which gets compiled into every program you create on the mbed platform. But since your '1769 board has no such magic chip, it just hangs.
Wyh do you want to write to the internal flash of the LPC, and then start a program from there? If you want to upload your program, use one of the methods described above. If you you want to store additional data, use an external memory (e.g. a SD card).
I wish to be able to upgrade/change the firmware on the LPC1769 wirelessly. I have a wireless device that I am connecting to the LPC using UART0, and I am sending the new binary file in segments of bytes.
I wish to write these bytes into the flash memory of the LPC, and then get the LPC to boot into the new firmware. I am also looking for a way to keep the old firmware in the flash memory, so that I can fall back in the event that the new firmware fails.
Is there a way to go about this?
Thank you very much!
So you need a boot loader. There is an application note from NXP, maybe this help you (also with source for the USB boot loader). Also the Code Red) may help you.
There also seems to be a Ethernet boot loader from FlashMagic, but I can find only the LPC2000 version of it. But it might still help you.
If you have a wireless device, which can handle 2 additional signal lines (RTS and DTR preferrably) you can use the normal boot loader for the LPC1768 (connect DTR to reset, TX to P0.3, Rx to P0.2 and RTS to P2.10). There is also a cookbook.
Hello Hendrik,
Thank you very much for your quick reply. Just to clarify, for the third method, I just have to send the UU-encoded data through the wireless device to the LPC1769 and pull the respective pins in the cookbook and I should be able to boot the LPC1769? Will I require any other hardware other than the LPC1769?
I have come across FreeRTOS, which I believe is a mini-OS that can be run on the LPC1769. Can FreeRTOS be used to handle the flashing? What i thought of was:
1) Run the current firmware using FreeRTOS
2) If there is a new firmware, send an interrupt to RTOS, which will then pull the new binary onto LPC1769
3) Flash the new binary onto a sector different from the current firmware
4) Reboot the FreeRTOS and tell it to run the newest firmware
May I know if this can be done?
Thank you very much for your time and help! I really appreciate it =D
The boot loader is an internal program, which you normally don't touch (I think you can overwrite it via JTAG though). It has nothing to do with the program you are executing, so you don't program anything special.
Yes, your wireless device should be enough to upload a program, provided you set the other pins correctly to start the boot loader.
I don't think it will be that easy to update a program on the fly - it would overwrite itself. You would need a schema where two versions of the program co-exist in the flash memory, and only one gets chosen at reset.
Please log in to post a reply.
Hello,
I am working on the NxP LPC1769 and am hoping to reuse my code that I have written for the mbed.
1) Firstly, are the mbed codes compatible with the LPC?
2) If so, may I know how I can map the pins on the LPC1769, for example the P0[0], to an equivalent for the mbed code?
3) Lastly, can I simply compile the mbed code using the online compiler then use the LPCXpresso to flash the binary onto the LPC?
Thank you very much in advance!