LPC11U24 Keil export problem with Valid User Code

16 Oct 2012

The exported Keil project is not creating any Valid User Code checksum. For this reason the hex file created after compile is not running on a custom made LPC11U24 board. If I will program the board via SWD then the program is running (because the debugger is creating the correct checksum)!

17 Oct 2012

Hi,

The Valid User Code checksum is usually inserted into the binary by the debug probe. This could be the ULINK2 if you are using something like MDK+ULINK2, or the mbed interface if you're using the mbed Microcontroller.

As it happens the on-line compiler automatically inserts the checksum when compiling for the LPC11U24. This is so that if you use the on chip mass storage boot loader, you have a valid binary.

I am not surprised that the HEX file you generate from MDK doesn't have a Valid User Code Checksum. However, I am surprised that whatever you are using to load the hex file into the LCP11U24 isn't inserting it for you. What are you using to load the hex file?

If it helps, I wrote this program to patch binaries.. it runs on an mbed, and patches files stored in the local file system.

http://mbed.org/users/chris/code/BinaryPatcher/

Thanks, Chris

17 Oct 2012

Hi, I am using the embedded USB bootloader of LPC11U24 (this is great feature!). This is the reason that the Valid User Code checksum is not generated during flash programming. I also create yesterday a binary patcher and now I can use the USB bootloader of LPC11U24!

/media/uploads/tmav123/bin_vuc.exe The syntax is the following: bin_vuc.exe [bin file without VUC] [patched bin file with VUC]

17 Oct 2012

HI,

Great to hear you are up and running...

Is your binary patcher a windwos or shell application, or a script in some language like python? Assuming it is something that is easy to use and reuse, would you be willing to share it?

Thanks, Chris

17 Oct 2012

This is a shell application in NI CVI. The code is the following:

#include <FORMATIO.h>
#include <ANSI_C.h>
#include <stdio.h>
#include <string.h>

////////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[] )
{
	char binfilename[500], cfilename[500];
	int binfile, cfile;
	int binsize, bytesread, status, byteswritten;
	char buf[1000000];
	unsigned long n;
	
	if (argc != 3)
	{
		printf("bin_VUC.exe [binfilename] [newbinfilename] for LPC11\n");
		return -1;
	}
	strcpy (binfilename, argv[1]);
	strcpy (cfilename, argv[2]);
	
	status = GetFileInfo (binfilename, &binsize);
	if (status != 1)
	{
		printf("Binary file %s not found\n", binfilename);
		return -1;
	}
	
	binfile = OpenFile (binfilename, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_BINARY);
	bytesread = ReadFile (binfile, buf, binsize);
	CloseFile (binfile);

    n = *((unsigned long *)(buf + 0x00)) +     
        *((unsigned long *)(buf + 0x04)) +     
        *((unsigned long *)(buf + 0x08)) +     
        *((unsigned long *)(buf + 0x0C)) +     
        *((unsigned long *)(buf + 0x10)) +     
        *((unsigned long *)(buf + 0x14)) +     
        *((unsigned long *)(buf + 0x18));

	*((unsigned long *)(buf + 0x1C)) = 0 - n;  // Valid User Code Checksum

	cfile = OpenFile (cfilename, VAL_WRITE_ONLY, VAL_TRUNCATE, VAL_BINARY);
	byteswritten = WriteFile (cfile, buf, binsize);
	CloseFile (cfile);
	if (byteswritten == bytesread)
		printf("File %s created with VUC = 0x%08X\n", cfilename, *((unsigned long *)(buf + 0x1C)));
	else
		printf("File %s creation ERROR!!!\n", cfilename);
	return 0;
}
////////////////////////////////////////////////////////////////////////////////