MegaSquirt-II Command Line Compiling

Compiling code using the command line (instead of an Integrated Development Environment like DevC++) generally requires typing line entry with a large number of 'switches' (parameters entered after the command to tell it what to do). We may have to repeat this for several files, and in a particular order, if we want the program to work. To make the whole process easier, you can use a 'makefile'.

A makefile is like an old DOS batch file, but is read by make.exe, rather than the operating system. The makefile contains all the switches and decisions you would have to make manually, so using it saves a lot of time if you are going to compile your code more than once. Makefiles can do things like create 'dependencies', such as "if file X has been altered, then check the state of file Y to make sure it is up-to-date as well". Phil's code contains a number of switches (like -m68hcs12) and dependencies (these are the tabbed lines), and should not need many changes in most cases.

Here's a listing of Phil's Makefile:

#*******************************************************************
#* Makefile for MSII
#* 
#* COPYRIGHT: Philip L Johnson 2004
#* This header must appear on all derivatives of this file.
#*
#*******************************************************************

CC = /usr/local/m6812-elf/bin/m6812-elf-gcc
OBJCOPY = /usr/local/m6812-elf/bin/m6812-elf-objcopy
OBJDUMP = /usr/local/m6812-elf/bin/m6812-elf-objdump

CFLAGS  = -g -Os -Wall -fomit-frame-pointer -m68hcs12 -mshort -msoft-reg-count=32 -mauto-incdec -DGCC_BUILD
LDFLAGS = -Wl,-defsym,vectors_addr=0xff80,-m,m68hc12elfb
 
CSRCS=main.c
ASRCS=vectors.s msii_flash_gcc.s

OBJS=$(CSRCS:.c=.o)
AOBJS= $(ASRCS:.s=.o)

all:    msii.dmp msii.elf msii.s19

$(AOBJS): %.o: %.s
        $(CC) $(CFLAGS) -c $<

$(OBJS): %.o: %.c cltfactor.inc egofactor.inc matfactor.inc hcs12def.h flash.h
        $(CC) $(CFLAGS) -c $<

msii.elf:       $(OBJS)  $(AOBJS)
        $(CC) $(CFLAGS) $(LDFLAGS) -o msii.elf $(OBJS) $(AOBJS)

msii.s19: msii.elf
         $(OBJCOPY) --output-target=srec --only-section=.text \
        --only-section=.rodata --only-section=.vectors --only-section=.eeprom \
        msii.elf msii.s19

msii.dmp: msii.elf
         $(OBJDUMP) -Ssdp msii.elf > msii.dmp

.PHONY: clean
clean:
        $(RM) -f msii.elf
        $(RM) -f msii.s19
        $(RM) -f msii.dmp
        $(RM) -f $(OBJS) $(AOBJS)
        

For more on makefiles, click this link.

  • Open a 'Command Prompt' or 'DOS' window, usually by going to
    'Start/All Programs/Accessories/...'.

  • Navigate to the directory holding the GCC code source files for MegaSquirt-II, C:\MSII in the above example, by typing 'cd \MSII' and pressing the enter key.

  • Type "path=c:\cygwin\usr\local\m6812-elf\bin;C:\cygwin\bin\;" (or wherever you put the make.exe file if you didn't use the default directory locations) and press <enter>, this allows the operating system to find the make file.

    Note that you can change your 'environment variables' so that you don't have to type the path command every time you open a command prompt. You do this by right clicking on 'My Computer' and selecting 'Environment Variables' button under 'Advanced'. Find "Path=..." in the system variables, click it and add c:\cygwin\usr\local\m6812-elf\bin;C:\cygwin\bin\; to the end of whatever is already there.

    If you use Windows95/98/Me, you may need to open the 'autoexec.bat' file in the 'c:\' directory and edit the 'Path=" statement there to include c:\cygwin\usr\local\m6812-elf\bin;C:\cygwin\bin\; (add these to the end, don't delete anything that might be there), then reboot.

  • Type "make" and press <enter> (if you used the default folders) and an .s19 file will be created from your code.

    Typing 'make+<enter>' runs the make.exe file in the C:\cygwin\bin directory, but acts on the makefile in the current directory (which you navigated to above). The compiled .s19 file will be located in the folder where the source files are located (i.e., the current directory). It will be called msii.s19, but you can change the name by editing the Makefile or simply by renaming the msii.s19 file after compiling.
    The MegaSquirt-II Code Downloader

    You can also run the code downloader for MegaSquirt-II .s19 files independently of DevC++, either in a GUI version or from the command line.

    You can find the downloader installer (that transfers the file over the serial port to MegaSquirt-II, sort of like download.exe for Megasquirt) and source zip at www.not2fast.com/megasquirt/ms2dl/. It requires that your processor have the serial monitor installed, and will not work with blank processors (much like the bootloader code in MegaSquirt). It is known to work with code generated by both CodeWarrior and GCC.

    The scripts and other support files for using Inno Setup to create the installer can be found in gms2dl_installer.zip. (If you get Inno Setup, also install the QuickStart Pack.)

    The installer itself is in ms2dl200_setup.exe.

    To use the downloader,

    1. Install the downloader:
      • click on the link: ms2dl200_setup.exe
      • Click the 'Run' button when the window appears,
      • Click 'yes' to any security warnings.
      A blue MS-II Download 2.00 icon should appear on your desktop.
    2. Remove the power from MegaSquirt® (i.e., unplug the stim),
    3. Short the "B/LD" jumper on the MS-II board. The jumper should connect both pins,
    4. Turn the power back on to MegaSquirt® EFI Controller,
    5. Command Line:
      Along with the obvious graphical version, there is a command line version of the MegaSquirt-II download utility. It is in the same directory as the graphical utility, usually:
      C:/Program Files/MegaSquirt/MS-II Download XXX/ms2dl.exe

      where "XXX" is the version number of the installation. You could move it into your bin directory to avoid messing with your path, or just leave it there and run it with a full file spec. In any case, running it with "-h" gives you all the command line switches (which are a superset of the settings presented in the graphical interface).
    6. OR
    7. GUI:
      • Click on the blue MS-II Download 1.00 icon that the installation program created on your desktop (or search for it in the C:\Program Files\MegaSquirt\... folder),
      • Select the com port you use with MegaSquirt® under the 'File/Settings' menu item (COM1 is the default)
      • In the menu, select File->Open, and navigate to the .s19 file you want to load (such as Monitor.abs.s19),
      • The software will go through an erase/write/verify sequence.
    8. Remove the power from MegaSquirt® EFI Controller,
    9. Remove the 'B/LD' jumper,
    10. You are done, and have loaded new code to your MegaSquirt-II!



    MegaSquirt® and MicroSquirt® controllers are experimental devices intended for educational purposes.
    MegaSquirt® and MicroSquirt® controllers are not for sale or use on pollution controlled vehicles. Check the laws that apply in your locality to determine if using a MegaSquirt® or MicroSquirt® controller is legal for your application.
    ©2004, 2005 Bruce Bowling and Al Grippo. All rights reserved. MegaSquirt® and MicroSquirt® are registered trademarks.