TFTP Bootloader for Simplecortex

About a week ago a topic on the LPCXpresso forum was brought to my attention. A TFTP boot loader, now that’s something I’d really like to have!

Whenever the MCU is (re-)started the boot loader will try to download a specific file from a specific TFTP server. If the boot loader can successfully download a valid file, it will flash the MCU and jump to the ‘user code’ at a predefined address.

So I mentioned this TFTP boot loader on the Simplecortex forum to see if anyone had already tried it. Nope, I was the 1st one, but one of the forum admins was so kind to have a look and created a project for it.

Lets see if I can get this working…

Setting up the environment was easy. I created a small project that uses interrupts to blink LEDs 6 to 9 at different intervals. In the project configuration I had to set the start address to a different value and decrease the size as well:

User code project settings

This is necessary so that the ‘user code’ won’t be flashed from address 0x00000000 which would result in the boot loader being overwritten – the start address had to be set to 0x0010000 (64 kb). This way the TFTP boot loader (which does start at 0x00000000) will stay intact and the ‘user code’ will be in the flash memory after the boot loader.

I copied the resulting .bin file to my TFTP server, flashed a Simplecortex with the TFTP boot loader and watched …

TFTP boot loader downloading file

OK, the first part works fine; I saw the file being downloaded by the Simplecortex. But that was all… nothing happened!

The boot loader has a built-in diagnostic option of a LED that blinks a number of times, depending on the kind of problem it encounters. LEDs see what this LED can reveal…

I changed the LED port to 0.26 (the easiest/closest pin to 3.3V) and I got 1 blink, meaning that the download was successful but the user code was invalid. Reading the code that validated the user code, I saw some sort of checksum being calculated. Ah, yes, I saw a checksum being mentioned somewhere. But I don’t have a ‘checksum’ program? I searched the web and I found a ‘lpcrc’ tool that was able to calculate the checksum of a .bin file and write that checksum into the .bin file: 4 bytes, starting at position 0x1c. Time for a post-build script:

Post build script

lpcrc Debugbin%1.bin
copy Debugbin%1.bin c:TFTP-Roottest.bin

Now the user code .bin file contained the correct checksum; retry!

New tests confirmed that the boot loader does jump to the user code at address 0x00010000 now, but the user code runs ‘crippled’ – where it should toggle LEDs 6..9 each with its own interval, only LED9 is working…. and why? Dunno yet… something that needs to be reinitialized, reset, ??? A big mystery…

Interrupts maybe? The user code makes use of 4 TIMER interrupts; only TIMER3 seems to be working? I hope I can find out what is going wrong here…

#include "LPC17xx.h"
#include "lpc_types.h"
#include "GPIO.h"
#include "timer.h"

uint32_t toggle = 1;
uint32_t toggle1 = 1;
uint32_t toggle2 = 1;
uint32_t toggle3 = 1;

int main(void)
  init_timer(0, 15000000);
  init_timer(1, 30000000);
  init_timer(2, 60000000);
  init_timer(3, 120000000);
  GPIOSetDir(1, 18, 1);GPIOSetValue(1, 18, toggle);   // LED6
  GPIOSetDir(1, 19, 1);GPIOSetValue(1, 19, toggle1);  // LED7
  GPIOSetDir(1, 24, 1);GPIOSetValue(1, 24, toggle2);  // LED8
  GPIOSetDir(1, 25, 1);GPIOSetValue(1, 25, toggle3);  // LED9
void TIMER0_IRQHandler (void){
  toggle = ~toggle;
  GPIOSetValue(1, 18, toggle);
void TIMER1_IRQHandler (void){
  toggle1 = ~toggle1;
  GPIOSetValue(1, 19, toggle1);
void TIMER2_IRQHandler (void){
  toggle2 = ~toggle2;
  GPIOSetValue(1, 24, toggle2);
void TIMER3_IRQHandler (void){
  toggle3 = ~toggle3;
  GPIOSetValue(1, 25, toggle3);
Tagged . Bookmark the permalink.

4 Responses to TFTP Bootloader for Simplecortex

  1. Pingback: TFT boot loader for Simplecortex is working - Digits Domotica Blog

  2. Pingback: Putting it all together - Digits Domotica Blog

  3. Nagaraj says:


    I am working on lpc1768 for TFTP server/client the file has to be copied from lpc1768 board to PC.

    Please help me, if you have sample example share it to me.

    Thanks and Regards
    Nagaraj Baddi

Leave a Reply

Your email address will not be published. Required fields are marked *