Search code examples
armstm32keil

What is placed at the end of hex file generated by Keil


I've found a problem I cannot answer. I've been placing a table of 3 bytes after the section where my program lies:

const uint8 AppVersion[] __attribute__((at(0x08006E00))) = {1,1,3);

What I've get in hex generated by Keil was the table plus extra data: End of hex file after data added at arbitrary address.

Whereas while not using aforementioned table I've get the same "extra" data (364 bytes) at the end of the hex: End of hex file normally.

Could you tell me what is placed at the end of the application? I haven't found any clue in the .map file.

Thanks! Paweł


Solution

  • You have to look in the .map file to see what it's putting there. But it can be your code, or a library. You are using an absolute address, not a relative reference to the "end of image".

    Instead, use a custom linker file to explicitly link that table to the end of the image.

    LR_IROM1 0x08000000 0x0007000 {
        ; Program ROM Area
        ER_IROM1 0x08000000 (0x0007000-3) {
            *.o (RESET, +First)
            *(InRoot$$Sections)
            .ANY (+RO)
        }
    
        ; Program SRAM Area
        RW_IRAM1 0x20000000 0x00001000 {
            .ANY (+RW +ZI)
        }
    
        ; Version area
        VERSION (0x08000000 + (0x0007000-3)) 0x3 {
            version.o
        }
    }
    

    I have no idea about your target layout, adjust the numbers yourself.
    Once on a sunny day I wrote a little tool to read the map file. Maybe it works on your version of keil?

    Update:
    You've shared the .sct file (linker file).

    LR_IROM1 0x08000000 0x00008000 {
        ER_IROM1 0x08000000 0x00008000 { 
            *.o (RESET, +First) *(InRoot$$Sections) 
            .ANY (+RO) 
        } 
        RW_IRAM1 0x20000000 0x00001000 
        { 
            .ANY (+RW +ZI) 
        } 
    } 
    

    Your ROM region LR_IROM1 spans from 0x08000000 to 0x08007FFF.
    Therefore 0x08006E00 isn't the end of your image and the linker is allowed to put anything (.ANY) after the statically linked object AppVersion.

    If you don't want that, explicitly tell the linker to create a region only for your version object as in the example above.