Doug Leppard (DLeppard@CCCI.Org )
When I was first doing research for my robot, I kept coming across the S-Record. I had no clue what it was. Then as I was booting up my robot for the first time I realized that knowing this format became very important.
The S-Record format was designed to be used loading the data from the host computer to the receiving computer. It is designed to be visually readable and even though it looks like mumble jumble it is very readable once you know how.
Below is an example of an S-Record:
Each line is individually loadable and can be cut out and added to other S-Record files. Each line has five parts:
Type - Type of line. Two bytes. For the 68HC912B32 it only uses S0, S1 or S9. Others are ignored. S0 record holds the description of the file. The S0 line is ignored and not loaded. The S1 line holds the data that is being loaded into your chip. S9 tells the receiving computer that the send is done.
Record Length - Two bytes. It tells the number of bytes in the line after the record length.
Address - 4, 6 or 8 bytes (for my B32 it is always 4). This tells the loading program where to load this line into memory. This is the key bytes to look at if you have loading problems.
Code/Data - Actual data loading into the receiving computer.
Checksum - 2 bytes. This is error checking for this line. What they do is add up all bytes that are loaded into the receiving computer and then check it against the checksum. If they dont agree then a loading problem must have occurred and an error is given. What it means to you is that you can not change any bytes in a line without adjusting the checksum.
Below is an example of one line from the S-Record. It is a S1 line. $13 bytes in length. It loads the data starting at $8000. Last two characters on the line $13 is the checksum. If you look at the file speed.lst file you will see the object code and see the data in the object code that corresponds to it.
S1 record line with corresponding listing.
8000 cf 0b ff lds #stkbeg initialize the stack pointer
8003 cd 0b df ldy #stkbeg-$20 initialize the data stack pointer
8006 06 80 09 jmp lbl999
8009 cc 00 08 ldd #$0008
800c 5b 16 stab $0016
* speed12.bas(8): poke sc0bdh,52 '9600 baud
800e cc 00 34 ldd #$0034
When downloading the S-Record to your robot, the loader (at least on the 68HC912B32) gives an "*" whenever it wants another line. So what you get is a series of asterisks. If it stops and says it can not program it, you can count the number of asterisks and that corresponds to the line in the S-Record. Then look at the address being loaded and see if it trying to load that line out of the range of the memory or into a protected area.
Another thing you can do is cut out a line and or load that line individually. I was loading a program into my B32s EEPROM. But it had a interrupt which means the secondary vector must be loaded which is in the flash. When I first tried to load the program it gave me an error. Tracing it to the line I saw that I was trying to load into the flash memory along with the EEPROM and that was not permitted. So I cut that line out and loaded the EEPROM error free. Then I took the line and loaded that into the flash memory.
Knowing the S-Record format can be very helpful in debugging you robot. It is not as hard to understand it as it first may seem.
68EVB912B32UM/D Manual for Motorola evaluation board for the B32. It has an section that explains the S-Record.