Monday, July 4, 2011

How to generate .hex files from Code Red's LPCXpresso to use with FlashMagic

Recently I struggled to be able to use with the LPC serial bootloader and FlashMagic with the LPCXpresso software from Code Red. All I wanted was a .hex file to load onto an LPC1759. LPCXpresso generates a binary AXF file. FlashMagic requires an ihex file. The hex file actually is just the binary file converted to an ascii file. Unfortunately, due to the rich features of LPCXpresso, you have to dig to figure out how to automatically convert the .axf into a .hex. These steps should bring you a step closer to flashing code to your LPC chip over serial.

Official Code Red and LPCXpresso Documentation


Code Red provides two links with information on how to convert your program into a usable .hex for FlashMagic.

  1. Generating srec (Motorola S format), binary, ihex (Intel Hex) files
  2. Post-processing your linked application

Changing the project settings


In order to begin, you need to open your project settings. Once the project properties are open, choose 'C/C++ Build' -> 'Settings'. On the right, select the 'Build Steps' tab.


Now, edit the 'Post-build steps' command and add the steps to create a .hex that FlashMagic can use.

Steps to go from a ELF to a FlashMagic compatible HEX file


I got these steps from a thread on NXP's user forum. They agree with the knowledge base article.

Add the following steps to your Post-build Steps -> Commands
  1. ELF=>BIN without CRC:

    arm-none-eabi-objcopy -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin";

  2. BIN=>BIN with CRC (this is useful for USB ISP mode with LPC13xx parts):

    checksum -v "${BuildArtifactFileBaseName}.bin";

  3. BIN with CRC => HEX with CRC:

    arm-none-eabi-objcopy -I binary "${BuildArtifactFileBaseName}.bin" -O ihex "${BuildArtifactFileBaseName}.hex";

  4. Save your project properties, and then repeat for your other Build Configurations (Debug/Release).

Now, when you rebuild your project, LPCXpresso should generate a .hex file that FlashMagic will be able to use.

Next, getting your code to actually run...

6 comments:

  1. It helps to add " around the filename parts, otherwise you can have problems with paths including spaces.

    ReplyDelete
    Replies
    1. Good call. I've always avoided spaces and special characters from my command line days so I've never run into this. I'll update my instructions to reflect it.

      Delete
  2. Wonder Ful. Excellent, Cool, Good Job. Thanks.
    Succeeded to make HEX with CodeRed LPC Expresso

    ReplyDelete
  3. I cant get hex file.... what is this error


    Invoking: MCU Archiver
    arm-none-eabi-ar -r "libUARThome.a" ./src/main.o ./src/serial.o
    c:\nxp\LPCXpresso_5.0.14_1109\lpcxpresso\tools\bin\arm-none-eabi-ar.exe: creating libUARThome.a
    Finished building target: libUARThome.a

    make --no-print-directory post-build
    Performing post-build steps
    arm-none-eabi-objcopy -I binary "libUARThome.bin" -O ihex "libUARThome.hex";
    c:\nxp\LPCXpresso_5.0.14_1109\lpcxpresso\tools\bin\arm-none-eabi-objcopy.exe: 'libUARThome.bin': No such file
    make[1]: [post-build] Error 1 (ignored)

    ReplyDelete
    Replies
    1. Sounds like you are trying to convert a library file to a HEX file. This won't work, because a library is not a valid ELF executable. You only need to convert your final executable (that has been linked to your libUARThome.a) into the HEX that you can then transfer to your target.

      Delete
  4. Great..!!! It worked thanks a lot..!!! But the I found like, the CRC mismatches. It throws me error like checksum command not found. Which exe do I link the checksum..? Objcopy..?

    ReplyDelete

Youtube Channel

Loading...