
Note: MegaSquirt-II™ boards are generally shipped without embedded code loaded in them. Instead they just have the bootloader code installed. The bootloader allows you to load code through the serial connection (the same one used to communicate with the tuning laptop) using the downloader program (click the link to find out more about the downloader). In general, if the bootloader jumper on the MegaSquirt-II™ is across both the boot pins when you receive it new, this means no code has been installed. If the jumper is on one pin only, code may be installed. The reason the MegaSquirt-II™s are shipped without code is to make sure every user starts with the latest code available.
The MegaSquirt-II™ code has all the basic capabilities of MegaSquirt® EFI Controller, however it also has:
There are two hardware versions of MegaSquirt-II™, and two corresponding code versions. ALL MS-II™s sold since August 2005 are V2 MS-II™s (the vast majority of MS-II™s) have a blue solder mask and use the code and INI from the blue box below. Older MS-II™s with the green solder mask use the code and INI from the green box further down the page.
|
The most recent Codewarrior source file of the MegaSquirt-II™ code for the V2 (CAN) MS-II (with the blue solder mask) is here: The 'ready to load' .s19 file for uploading to MegaSquirt-II™(CAN) is here: (Right click and 'Save As') The 2.891 INI file is here (the tuning software may include a 2.8 INI file - but it will NOT be the correct version. Please upgrade to the latest version below):
(Right click and 'Save as' the target to your project folder (usually 'C:Program Files\MegaSquirt\Car1\mtCfg\') then rename it to: megasquirt-II.ini - ignore warnings about changing file extensions)
You will also want to copy the settings.ini file to your project's \mtCfg\ folder (usually 'C:Program Files\MegaSquirt\Car1\mtCfg\'). It will solve the "Conditional check references undefined value n2o" and "Conditional check references undefined value 'EXPANDED_CLT_TEMP'" errors.
Note that for the first thing you must do is set the ECU Type (under 'Fuel Set-Up/General') to match your hardware (MS-II™ or MicroSquirt™), the tuning software will not let you change anything else until you do this. Do not change settings, expect the stim to work, load an MSQ, etc., until you have set the ECU Type (MS-II™ = 1, MicroSquirt® = 2, the MS-II Sequencer™ will be 3). This setting applies to MS-II™ derivatives with code 2.88 or higher code only.
ECU Type setting was inserted to head off the potential MicroSquirt® problems due to the coils being turned on with the old default configuration. As of the 2.88 code, if ECU Type is not set, the code will put the ignition outputs in a safe state (cycling the rpm from 0 to 8000 rpm, and also flashing the fuel pump LED) and wait until a known ECU type is put in by the user. Alternatively, if you have the V2.00 Downloader, you can use the 'file/update' function to download both the S19 and INI from the internet ftp site ftp.megamanual.com/updates/MS-II/ and install them to the appropriate locations. Then you don't need to manually download and copy/rename the above files. See www.megamanual.com/ms2/downl2.htm for more info. Note that you will need to create a new MSQ by hand rather than rely on the tuning software to correctly interpret an old version (you can export/import the tables to save a lot of effort retyping the MSQ settings). Here is the help file for this code. The CodeWarrior project files are here: MSIIC_Proj.zip. This includes 2.3 main.c source file, (you can get the latest 2.890 main.c file by clicking the link), and the hcs12def.h, maffactor.inc, FLASH.H files as well. This is code for Codewarrior only. GCC isn't supported in any meaningful way anymore. The person that used to do the work to make it compatible with GCC doesn't do it anymore (and hasn't for quite a while). If you want to stick with GCC, you might have better luck with the extra code - which is apparently native to GCC. If you want to work with B&G code, you will need Codewarrior. The 2.890 code won't compile on the free 'special edition' of Codewarrior (it exceeds the limits of that edition), but you could remove some unused functionality to get it under the limit of 32K. |
|
The reason for two different codes is simple: to install CAN networking on the new MS-II™ we had to move the fuel and idle pins, since they were using the CAN pins as I/O. This does NOT mean any changes in wiring, because the new fuel and idle go to the same place on the motherboard. We are also using the C64 version of the processor, which has 4K of RAM vs. the 2K on the C32 (the C32 is the one populated on the V1 version of MS-II™). This has been the holdup for MS-II, we have been waiting all this time for the automotive-temp version of the C64 to arrive, and this is what we have populated on the V2 version of MS-II. The V2.0 code uses more than the 2K of RAM that the C32 had in order to get all of the CAN variables incorporated in the version 2 embedded code, so the C32 part used on the V1 version cannot handle this (without some condensing of variables, etc). This means you MUST install only v2.x software on the CAN MS2 and only v1.x software on non-CAN MS2.
The real issue between the first released boards (the 170 that were shipped in April 2005) and the ones from August 2005 is that the old boards did not have the CAN transceiver, the new version (V2) has CAN. But to use CAN, we had to move the signal lines on the processor for the fuel pump and fast idle - these happen to be the ones used for the CAN signals (CANH and CANL). So, to be able to use CAN (on V2 version), we had to move the fuel pump and fast idle to other spare I/O pins. This also affected the bootloader - this code has to make sure the fuel pump, injectors, ignition, etc, are off during a bootloader operation. Since the pins moved, we also had to move these as well in the bootloader. In fact, we are hand-programming each and every MegaSquirt-II with the bootloader through the BDM, just to verify this operation and processor/board health. Users still need to put in the version 2 embedded code into the MS-II once they receive it (we do spot check boards with the full code).
The best way to determine the MS-II™ version of any board is that the original boards had green LPI solder mask, where as the new V2 boards are now blue solder mask. So MegaSquirt-II version V1 is green, and the latest V2 (with CAN and the extra memory) is blue. The boards also have the "V2.0" or "V2.1" silkscreened onto the V1 boards and "V3.0" silk screened onto the V2 boards. |
|
The MegaSquirt-II™ current release code for the V1 MS-II (with the green solder mask) is here: As well, a 'ready to load' .s19 file for uploading to V1 MegaSquirt-II™ is here: (Right click and 'Save As') The INI file for 1.34 code is numbered 1.31, and is found here: megasquirt-II.ini.1.31 The complete Codewarrior project file is here: MSII_V1_Proj.zip |
To load a 'ready to load' .S19 file to your MegaSquirt-II™ over the serial port, you need to use Eric Fahlgren's MegaSquirt-II downloader program (click the link to download), which works from either a window or from the command line.
To use the downloader.exe:
(New code versions (2.889+) have their own INI, so for example 2.890 code (Monitor_v2.890.abs.s19) has a specific 2.980 INI (megasquirt-II.ini.2.890).
You will find the INI files here: http://www.megamanual.com/files/ini/ and the code S19 loadable files here: http://www.megamanual.com/files/code/
Note that all older 2.XY (prior to 2.889) use the same 2.X INI file. For example, the 2.35 code uses the 2.3 INI file. This is the way the older code upgrades are designed. Major revisions were incremented by +0.1 and require a new INI file, minor revisions (+0.01) use the same INI file.)
To use the v1.31 or v2.X code, see the configuration instructions for MegaTune here: www.megamanual.com/ms2/configure.htm
Writing Code for MS-II™
NOTE: The GCC compiler only worked directly with very old code. There was a user here who painstakingly converted the code to compile with GCC. However, this person has not done this for quite a long time. The last code converted to allow GCC to compile was 2.36.
The code is written on and compiled in Codewarrior from Freescale (www.freescale.com). Freescale offers a free 'special edition' of Codewarrior for the HCS12(x) that you can use to compile version of the code older than about 2.86. After that the 32K size limit is exceeded. However, you can also compile newer versions of the code by removing some unwanted or unused functions. There's more details in comments of the GPIO trans code source (which uses the same compiler set-up).
Codewarrior for Windows is easier to install and configure than GCC (for the novice or intermediate user, at least), and you don't have to convert anything at all.
|
GCC Code for MegaSquirt-II
Retained here primarily for reference. Dev-C++ is apparently no longer available. Users can use the freeware GCC compiler to create and run code customized for particular applications on the MegaSquirt-II and share them with others (think of things like the Dual Table code and MegaSquirt'nSpark-Extra for MegaSquirt). (Note that the 'standard' code above was created on the commercial Codewarrior compiler - which may be available free, but with some limitations.) To use GCC with Windows to write and compile new code for MegaSquirt-II, we need:
To use Linux, please see the sourceforge MS-II project site. To get and use these:
Congratulations, you are now a MegaSquirt-II programmer! |
You may also want to have a 'differencing tool'. This will highlight the differences between any two files (C source code, asm, .S19, etc., etc.) and can be very useful for determining what changes have be made, and whether two files are identical. One suitable Windows based differencing tool is WinMerge. The set-up file is WinMerge-2.2.0-Setup.exe, and you can read the documentation for it at http://winmerge.sourceforge.net/. The tools for Dev-C++ above include a link to WinMerge (you can delete that tool in Dev-C++ if you don't use WinMerge).
If you want to co-operate with other programmers in the development of MegaSquirt-II code, visit the sourceforge MS-II project site. Here are instructions on how the CVS (Concurrent Versions System) on Sourceforge works.
MS II Serial Interface Description
MegaSquirt-II uses a baud rate of 115200 to communicate with MegaTune. Communication is established when the MegaTune sends a command character - the particular character sets the mode:
The primary commands for sending and receiving data from MS II via the RS232 serial connection are all constructed using 3 initial bytes as follows:
Send 'r', <CANid>,
There are also some specialized commands for MS-II. These are:
For more details, see the source code.