Content
Goal
Our goal was to connect LPC1769 to iMX6 the way which will allow us to update the firmware of the microcontroller directly from the Linux running on Rex.
Hardware connection
For testing we used LCPXpresso board and connected it with iMX6 Rex Development board the following way:
iMX6 Rex | LPCXpresso | ||
UART2_RXD (J31 pin 3) | <<<< | TXD (J6 pin 21) | |
UART2_TXD (J31 pin 5) | >>>> | RXD (J6 pin 22) | |
GPIO 2 (J34 pin 4) | >>>> | ISP# (J6 pin 51) | |
GPIO 3 (J34 pin 5) | >>>> | RST# (J6 pin 4) | |
GND (J31 pin 9) | - – - - | GND (J6 pin 1) | |
+3.3V (J31 pin 10) | - – - - | +3.3V (J6 pin 28) |
Software – lpc21isp
There was an issue with the original lpc21isp code running under Linux, so we used the Senseg one.
To fix “error: ‘ISP_ENVIRONMENT’ has no member named ‘ProgramChip’ while compiling the code” we updated lpc21isp.h the following way:
//#if defined(_WIN32) && !defined(__CYGWIN__) //#define COMPILE_FOR_WINDOWS //#define COMPILED_FOR "Windows" //#elif defined(__CYGWIN__) //#define COMPILE_FOR_CYGWIN //#define COMPILED_FOR "Cygwin" //#elif (defined(__arm__) || defined(__thumb__)) && (!defined(__raspi__)) //#define COMPILE_FOR_LPC21 //#define COMPILED_FOR "ARM" //#define printf iprintf //#elif defined(__APPLE__) //#define COMPILE_FOR_LINUX //#define COMPILED_FOR "Apple MacOS X" //#elif defined(__FreeBSD__) //#define COMPILE_FOR_LINUX //#define COMPILED_FOR "FreeBSD" //#elif defined(__OpenBSD__) //#define COMPILE_FOR_LINUX //#define COMPILED_FOR "OpenBSD" //#else #define COMPILE_FOR_LINUX #define COMPILED_FOR "Linux" //#endif
There was also a problem with synchronization (the software was cutting out \n character) and we had to change lpcprog.c (function ReceiveComPort) to:
} while (((*RealSize) < MaxSize) && (SerialTimeoutCheck(IspEnvironment) == 0) && (nr_of_0x0A < WantedNr0x0A) && !eof);
Then just complile with:
$ make -f Makefile clean all
Programming procedure
To put RESET and ISP to LOW (don’t forget, these two signals we have connected to our GPIO expander), we used i2cset command:
$ i2cset 1 0x27 0x02 0xF3 // set GPIO 0.2 and GPIO 0.3 to low $ i2cset 1 0x27 0x06 0xF3 // set GPIO 0.2 and GPIO 0.3 as output
Release RESET to HIGH
$ i2cset 1 0x27 0x02 0xFB // set GPIO 0.3 to high
Now the NXP is in ISP mode. Run the lpc21isp tool:
$ ./lpc21isp -bin blink.bin /dev/ttymxc1 115200 12000 lpc21isp version 1.83 File blink.bin: loaded... image size : 10548 Image size : 10548 Synchronizing (ESC to abort).Answer Synchronized String:53 79 6E 63 68 72 6F 6E 69 7A 65 64 D A 0 OK Read bootcode version: 2 4 Read part ID: LPC1769, 512 kiB ROM / 64 kiB SRAM (0x26113F37) Read Unique ID: succeeded Will start programming at Sector 1 if possible, and conclude with Sector 0 to ensure that checksum is written last. Erasing sector 0 first, to invalidate checksum. OK Sector 1: ............................................................................................... Sector 2: ........................................................... Sector 0: .............................................................................................. Download Finished... taking 1 seconds Now launching the code
Release the board from ISP mode and go to RESET
$ i2cset 1 0x27 0x02 0xF7 // set GPIO 0.2 to high and GPIO 0.3 to low
Release RESET
$ i2cset 1 0x27 0x02 0xFF// set GPIO 0.2 and GPIO 0.3 to high
Now your new binary should be running on the NXP. We tested it with a simple blink program. You can find our version of the lpc21isp source code for iMX6 here or download here.