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...

21 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
  5. I am getting this error
    make: *** [SPI_Master.axf] Error 1
    How am I gonna resolve it????

    ReplyDelete
  6. I am getting this error.
    Please help me out

    Building target: SPI_Master.axf
    Invoking: MCU Linker
    arm-none-eabi-gcc -nostdlib -L"C:\ALL_LPC1768\SPI_Workspace\CMSISv2p00_LPC17xx\Debug" -Xlinker -Map="SPI_Master.map" -Xlinker --gc-sections -mcpu=cortex-m3 -mthumb -T "SPI_Master_Debug.ld" -o "SPI_Master.axf" ./src/cr_startup_lpc176x.o ./src/main.o -lCMSISv2p00_LPC17xx
    c:/nxp/lpcxpresso_5.2.6_2137/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libcr_c.a(fpprintf.o): In function `printf':
    fpprintf.c:(.text.printf+0x3a): undefined reference to `__sys_write'
    c:/nxp/lpcxpresso_5.2.6_2137/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libcr_c.a(_deferredlazyseek.o): In function `__flsbuf':
    _deferredlazyseek.c:(.text.(float, long, short, bool, float __restrict)+0x8a): undefined reference to `__sys_istty'
    c:/nxp/lpcxpresso_5.2.6_2137/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libcr_c.a(_writebuf.o): In function `_Cwritebuf':
    _writebuf.c:(.text._Cwritebuf+0x16): undefined reference to `__sys_flen'
    _writebuf.c:(.text._Cwritebuf+0x2a): undefined reference to `__sys_seek'
    _writebuf.c:(.text._Cwritebuf+0x52): undefined reference to `__sys_write'
    c:/nxp/lpcxpresso_5.2.6_2137/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libcr_c.a(alloc.o): In function `malloc':
    alloc.c:(.text.malloc+0x70): undefined reference to `_sbrk'
    alloc.c:(.text.malloc+0x90): undefined reference to `_sbrk'
    c:/nxp/lpcxpresso_5.2.6_2137/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libcr_c.a(alloc.o): In function `_Csys_alloc':
    alloc.c:(.text._Csys_alloc+0xe): undefined reference to `__sys_write'
    alloc.c:(.text._Csys_alloc+0x12): undefined reference to `__sys_appexit'
    c:/nxp/lpcxpresso_5.2.6_2137/lpcxpresso/tools/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/armv7-m\libcr_c.a(fseek.o): In function `fseek':
    fseek.c:(.text.fseek+0x1a): undefined reference to `__sys_istty'
    fseek.c:(.text.fseek+0x3c): undefined reference to `__sys_flen'
    collect2: ld returned 1 exit status
    make: *** [SPI_Master.axf] Error 1

    ReplyDelete
  7. Another abnormal (yet intriguing) thing is that, however I've stacked Macromedia's Flash Player from the Internet I can't really discover the 'player' anyplace on my PC. anyconv.com

    ReplyDelete
  8. I am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy. hex To decimal Online convertor

    ReplyDelete
  9. Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging, Free TikTok Fans

    ReplyDelete
  10. I am grateful that I was able to learn something useful from this article. After reading it, I believe you possess excellent expertise. Thank you for sharing Hex To Decimal Converter. Keep up the good work.

    ReplyDelete
  11. I am pleased that this article provided me with some important information. Thank you so much for sharing it. Keep up the good work. tool polishing India

    ReplyDelete
  12. I always prefer to read the quality content and this thing I found in your post. I am really thankful to you for this post. Best Metal Polish Services India

    ReplyDelete
  13. Wow, your post is very useful thanks for sharing. It's informative. keep sharing more with us. find out Best Metal Polish Services India for more info visit our site.

    ReplyDelete
  14. I like this article. I was searching over search engines about Metal Polish India and found your blog and it really helps thank you very much.

    ReplyDelete
  15. Extremely useful information which you have shared here. This is a great way to enhance knowledge for us, and also helps to understand how we can increase followers on Instagram with polishing company India. Thankful to you for sharing an article like this.

    ReplyDelete
  16. I am grateful to this blog site providing special as well as useful understanding concerning this subject. Metal Polish company India

    ReplyDelete
  17. Can we use any kind of patch file to generate .hex files from Code Red's LPCXpresso? If so, what are the possible harms we may face? Coursework Writing Services

    ReplyDelete
  18. This post can help you in all your code-x files and how to generate them. Cheap assignment writing service uk.

    ReplyDelete
  19. • In 2009, Bitcoin was presented on the lookout, that turned into the first crypto cash that was acknowledged across the globe. In 2011 and later, a progression of a few other crypto monetary standards were presented. A portion of the well known ones incorporate, Litecoin, Dogecoin, Ethereum, Ripple, Zcash, Dash, etc. NFT Droppers

    ReplyDelete