Keil Logo


Information in this article applies to:

  • C166 All Versions


In µVision, if I choose Options for Target and click on the Output tab I can specify the start and end address for the generated Hex file. My code ranges from 0xC00000 to 0xC073EF. However, the HEX file must include all bytes from 0xC00000h to 0xC0FFFFh (even unused bytes).

I specified start and end addresses for the Hex file of 0xC00000 to 0xC0FFFFh but the Hex file generated only had data up to 0xC073EFh.

How can I get a HEX file with a full 64K of data in it?


The start and end addresses may not be used in this way. They may only be used to truncate the Hex file.

However, there is a project called SRecord hosted on which contains utilities to convert Intel HEX files in many ways. The free of charge Windows version 1.64 or later can be downloaded here:

The command line utility srec_cat.exe is part of this package. It can be used to read an Intel HEX file which was created by Keil OH166. srec_cat.exe can fill up unused address areas in a certain range with a constant value. Usually a padding value of 0xFF is used which represents an erased Flash. This tool always stores Intel HEX records in ascending order.

Useful options for srec_cat:

  • -Disable_Sequence_Warnings
    This option suppresses a warning if records of the input Intel HEX file are not sorted in ascending address order. HEX file generated by OH51, OHX51, OH251 or OH166 are not sorted in ascending address order.
  • -address-length= 2 or 3 or 4
    Specifies the number of address bytes in the Intel HEX output file. By default, srec_cat generates extended address records (type 04) for an address range of up to 4GB. If you want to avoid the generation of extended address records, specify -address-length=2 before specifying the output file. This limits the max. address space to 64K and can be used for most 8051 applications.
  • -Output_Block_Size= ByteCount
    Specifies the length of each HEX record. By default, srec_cat generates lines containing up to 32 bytes of data. If you want to limit the max. line length to 16 byte (compatible to OH51, OHX51, OH251 or OH166), use -Output_Block_Size=16.
  • -fill FillValue StartAddress EndAddress
    Fills unused areas with the specified constant value. A fill value of 0xFF is often used with this option because it corresponds to erased Flash.
  • -Intel
    Can be used after an input or output filename to specify that an input file should be interpreted as an Intel HEX file or an output file should be generated as an Intel HEX file.
  • -Binary
    Can be used after an input or output filename to specify that an input file should be interpreted as a binary file or an output file should be generated as a binary file.
  • @CommandFile
    A command file can contain some of all invocation parameters of srec_cat. You can even use comments starting with '#' extending to the end of the line.

Example: If you need an Intel HEX file which covers exactly 64K (0xC00000 and 0xC0FFFF) of code and where all gaps in this area are filled with value 0xFF, you can use the following command file:

-Disable_Sequence_Warnings    #disable warning about hex records not in ascending order
MyHexFile.hex                 #input file name
-Intel                        #read input file in intel hex format
-fill 0xFF 0xC00000 0xC0FFFF  #fill gaps from 0xC00000-0xC0FFFF (64K) with value 0xFF
-Output_Block_Size=16         #generate hex records with 16 byte (default 32 byte)
-address-length=4             #generate extended adress records type 04
-o MyPaddedHexFile.hex        #output file name
-Intel                        #generate intel hex output file

You can then invoke srec_cat.exe with this command file:

srec_cat.exe @CommandFile

You can execute this tool after each project build/rebuild by specifying its invocation in the µVision dialog Options for Target - User - After Build/Rebuild. You may use µVision key sequences for the invocation.The key sequence '#H' can be used for the input hex file name. When using a command file for srec_cat.exe, be sure to double the '@' character, or µVision might interpret it as a key-sequence.



Last Reviewed: Tuesday, July 17, 2018

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.