This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to (easily) flash a custom .hex file with debugger?

Hello,

I am developping on a firmware using a bootloader which verifies main application's CRC prior to let it start. To do this, I am generating an extra .hex file with data for bootloader added to the .hex file created by Keil. 

I thought I just had to rename my .hex file with data to the name of the one generated by keil... But Keil's debugger is loading the .axf file, not the .hex one :-(

The only workaround I found was to load my .hex with data with another flash programmer, and then start debugging with Keil to have debug symbols. 

Does anyone know how I could do this directly with Keil ?

Thanks a lot in advance!

  • The tools I built can generate .HEX and .ELF(AXF) files when they checksum/sign the images.

    I seem to recall that the debugger, and scripting, has a LOAD command that will take .HEX files, although admittedly I've only tested this on RAM

    http://www.keil.com/support/man/docs/uv4/uv4_cm_load.htm

  • I think you can go to Project -> Options For Target ->Output tab, and change the name from "My_project" to. "My_project.hex"  - that should load the hex file. 

    Otherwise, you can write a simple script to load the hex file: www.keil.com/.../1936.htm

    Some other possibly relevant links: http://www.keil.com/support/docs/2310.htm 

    Using Srecord to make a CRC check, and other tricks: www.keil.com/.../4038.htm

  • Just curious, what were you using to make the CRC with for the hex file? 

  • Hi Ron,

    Thank you for the reply.

    I succeeded to load my custom .hex file with the debugger, but as it does not contain any debug information, this will not be very useful for debugging.

    Basically, I need to :

    1.  load a .hex file with application's CRC to be able to start the application

    2.  load application's .axf file which contains debugging data for application to be able to debug it.

    I manage to do step 1 or step 2 independently, but not one after the other with keil's debugger.

    Regards,

    Aina

  • I am generating a .bin file with fromELF after my build process (I need it to load my application with the bootloader), then I compute its CRC  and write it to the data zone with a "home made" script.

  • Hi Pier,

    I am trying to use the LOAD command, but I get the error : "cannot open file". I trhed with the syntax "LOAD Myfile.hex", "LOAD "Myfile.hex"", "LOAD <relative path to my file with and without double quotes and double \\>", but none of these succeeded.

    Any idea of what I am doing wrong?

    Also, I saw that in this case, the debugger is loading .axf file prior to load .hex. Will the debugging informations (included in .axf file) be erased by the loading of the .hex?

  • I succeded to make keil load my .hex with the command "LOAD $L\Myfile.hex INCREMENTAL", but it responds "Target memory verification failure", although loading this file through STM32CubeProgrammer succeeds. Any idea of what is going wrong?

  • Other strange thing: if I first flash my target with STM32CubeProgrammer, there is no error when starting debugging. 

  • If this is purely for debug, consider having your firmware understand this is the case via a magic value in RAM or the vector table, so it can skip the signing/checksum test for debugging. Perhaps probe the ITM/DWT registers to understand it is running via a debugger.

    The script may be able to LOAD two images (.AXF). I've not needed the symbols for both (loader/app) in order to run them and understand what's happening in the debugger, but if I did, I'd merge the .ELF/AXF files and the symbol tables.

  • I am going to go backwards  (i.e. Start from a boards that has your bootloader and hex file already loaded)

    1) To start debugging this, you need to be in your Kiel project with the associated axf file. Edit your debug options and make sure that Download to flash is not checked.  When you select Debug, your symbols in the axf file will be loaded and you will connect to the board, but nothing will be over written on the board.

    2) Select LOAD to load your hex File.

    2) I would create a utility that will burn the hex file to your board.  you will add this to the Configure Flash Menu command.  You want to "Use External Tool for Flash Programming.

    3) I would create 2nd project that the name of the executable something like "burnhex.hex"  from the command line you can do something like C:\Keil_V5\UV4\Uv4.exe -f burnhex.uprojx.  When you execute this .bat file, it will burn your hex file to the board.  This is the Command you want to add to the Use External Tool for Flash Programming option.

    4) Add User after build run option that will likely create a Bin file, add a CRC and then create a hex file (i.e. run  your "home made" script.) 

    So here is what it looks like in practice

    1) Compile your program as you do any Keil Project.  (This will create a hex file combining bootloader with Application with CRC)

    2) Load your program to flash (Click load, it will load the Hex file using your "external programming tool" - which is just Keil to load the hex file)

    3) Select Debug.  This will connect to the board and load your symbols from the AXF file, but since you have turned off Loading the flash, it will still have the Hex file you just loaded.  Debugging of the App works fine.  Note: doing this you will not have access to debug symbols for the Bootloader.  If you want to debug the bootloader you will need to load the Hex file as you do, but use the Bootloader axf file and debug without loading to the flash and you can debug it.

    You may want to consider making the bootloader a totally separate project that you even load totally separately. 

  • You could also you the INCREMENTAL option with the LOAD debug command to load more than one hex file at once, without needing to merge / rerun a CRC on the result

  • This is what I am doing, but loading of my first .hex file (the one containing application's CRC) fails with keil's debugger, although I have no problem while loading it with STM32CubeProgrammer.

    I am getting the error "target memory verification failure", followed by "error 57: illegal address (0x800C000). (Note: 0x800C000 is my application's starting point)

    Other strange thing: if I first load my .hex with STM32CubeProgrammer, and then start a debug session with Keil, I get no error.

  • Hi Robert,

    Thank you for your reply.

    Just a question:

    3) I would create 2nd project that the name of the executable something like "burnhex.hex"  from the command line you can do something like C:\Keil_V5\UV4\Uv4.exe -f burnhex.uprojx.  When you execute this .bat file, it will burn your hex file to the board.  This is the Command you want to add to the Use External Tool for Flash Programming option.

    But every time my application is modified, I will need to re-build the second project to flash the right CRC on the board. Right?

    You may want to consider making the bootloader a totally separate project that you even load totally separately. 

    This is what I am doing

  • If your bootloader was a totally separate project, you would never need to combine it with your application. 

    You would build the bootloader and load your bootloader.  

    The application being totally separate would mean that you build the application, add the CRC and create hex file.  load the application hex file. Then Debug the Application using the *.axf debug symbols. (without loading code when  you start the debugger since  you already have the code you want loaded, you just need to symbols)

  • If your bootloader was a totally separate project, you would never need to combine it with your application. 

    You would build the bootloader and load your bootloader.  

    This is what I am doing, but as bootloader is executing before the application, and is testing application's CRC, every time I change application's binary, I need to update its CRC, otherwise my bootloader would refuse to start the application. 

    The application being totally separate would mean that you build the application, add the CRC and create hex file.  load the application hex file. Then Debug the Application using the *.axf debug symbols. (without loading code when  you start the debugger since  you already have the code you want loaded, you just need to symbols)

     

    This is what I am doing, but as I already explained twice in this thread, loading of my first .hex file (the one containing application's CRC) fails with keil's debugger, although I have no problem while loading it with STM32CubeProgrammer.

    I am getting the error "target memory verification failure", followed by "error 57: illegal address (0x800C000). (Note: 0x800C000 is my application's starting point)

    Other strange thing: if I first load my .hex with STM32CubeProgrammer, and then start a debug session with Keil, I get no error.