Hello Everyone,
I am using Keil uversion4 for writing my embedded program. I have written a sample program for STM32F437 micro controller(content of which is not important), after compiling my sample code i am getting a hex file along with the .axf file. Now I am trying to built a C program in Visual Studio, that would take this hex or .axf file(not yet decided) as input, extract the staring & ending address of the flash where the code will reside(along with the vector tables), then create an structure that would hold these values, this structure will also contain the entry point to the code.
As per my information the vector table of STM32F4 starts at an address multiple of 128 bytes, So if my flash starts at address 0x08000000 & my vector table starts from address 0x08000128 followed by the code, then I want to place the Structure, that i have created using Visual studio, at memory address 0x8000000, as the 1st structure element is an entry point to the embedded code so i think it won't be a problem to place it at the start of the sector.
I want my Visual studio application to xtract the desired information from the hex file, create a structure that would hold these value(along with some essential information such as the entry point value) & then I want to burn the code along with Structure to my STM32F4 such that in the flash the Structure would be placed 1st(at 0x08000000) followed by some padding, followed by the vector table(0x08000128) & Code.
So kindly suggest me some process through which i can combine the structure with the hex file & burn it to my micro controller flash in the desired sequence
Please help me out guys...as u could see Im in real mess
Thanks & Regards, Amit
The .HEX file should be easier to parse, the .AXF (ELF) format is reasonably well documented. Adding data records to the .HEX would definitely be the simpler route.
The Vector table needs to be on a 512 byte boundary, ie 0x08000000, 0x08000200, 0x08000400, etc
I normally add extra information to the last memory addresses of the flash - hex files allows address range holes, so having a record at the end doesn't make much of the difference in amount of data to program into the chip.
I can then also store some checksum information, to allow both a boot loader and the main application to verify the validity of the application.
Thank You Westonsupermare Pier for replying..
After going through the Keil support document "How to read Intel HEX file" i also feel that going with the HEX file will be a more suitable option, as from the file we can determine the start & end address of our application.
As per my plan in the PC application i would first fetch the start & end address of the application from the HEX file then create a structure whose 1st element will hold the entry point to my embedded application, followed by structure elements that would hold the start & end addresses.
As in a HEX file data are written in horizontal rows known as record Now I need to convert this Structure in to records so that i could write it to the hex file at a predetermined offset followed by some padding.
if you could help me figure out a way to convert the structure in to hex records, then that would solve my problem.
Eagerly waiting for reply.
Thanks & regards, Amit mahapatra
Thank You Per Westermark.
But in my case i need to add some records at the start of the sector & I will be accessing the structure elements at regular interval during the execution of my embedded code.
If you could suggest me some way to convert the structure to a hex record, that would of great help.
Thanks & Regards, Amit mahapatra
If you have read the documentation for the hex file format, then you would see how trivial it is to dump some binary data into hex records.
You could even use existing programs to do it, if you first generate your record as a block of binary data, and then use a program that takes a start offset as a command-line parameter, so it knows what address range to use when generating the hex data.
Most tools do not require the lines in a hex file to be in strictly increasing address order. So it is normally ok, to add extra data just before the final line of a hex file - the last line is a special end-of-file marker so a programming tool can spot a partial file and complain.
It's even allowed to have lines of different length.
The main thing that isn't allowed is to have overlapping address ranges.
By the way - you haven't managed to explain why you must have this extra data first. Quite often, people "must" things just because they think that they must.
Dumping out a structure in Intel HEX format might take a few hundred lines of C, it's not at all complicated. Simple enough to do on a 1970-1980 era CPU in assembler.
There's an open source app called "srecord" as I recall, and probably plenty of other code in the public domain if you need inspiration.