Click on our menu buttons immediately below to find MegaSquirt® information quickly:


MShift™ V5 DIY 'Template' Embedded Code

Below is a V5 do-it-yourself transmission control code for the GPIO hardware, in fact the entire Codewarrior project, that can be used to generate your own code for controlling a transmission's inputs and outputs for your own custom functions. These can be as complex or as simple as you like.

There are many hints in the comments included in the source code that explain how to change the existing configuration to suit your needs if you wish. The code has a number of example snippets on how to configure the inputs and outputs based on sample parameters to suit your application. In short, it is a quick step towards writing your own GPIO programs in the C programming language.

By writing your code in the C language, you will learn embedded programming. This is ultimately what the GPIO board and MShift™ code project are intended to encourage.

This template code project has:

Here is the Codewarrior project file:

MShift_V5_diy_Proj.zip
(Contains the Monitor.abs.s19 file you load to your GPIO, it is in the /BIN/ folder.)

Notes:

  1. This code is based on version 5.201 of the MShift™ code, and uses the 5.201 INI file (unless otherwise modified by the user).

  2. Once you have installed Codewarrior (see below), the .mcp file type should be linked to Codewarrior, and clicking on the 'MShift_V5diy.mcp' file (extracted from the zipped files above) will start Codewarrior and open the MShift project. MShift_V5diy.mcp is in one folder 'up' from the source file (the project file is a CW file, the source files are C files).

    To fix the warnings you get about files not being found, you need to:

    1. set the 'Monitor' as the target under 'Project -> Set Default Target'. This tells Codewarrior to make a Monitor.S19 file (and put it in the /BIN/ folder) that you can download to your GPIO board. And

    2. Edit the access paths to match the path where you have extracted the zip file on your machine. Edit them under 'Edit → Monitor Settings → Target → Access Paths'. Remove any line that has an entry like 'C:\Users\Lance\Desktop\MegaSquirt\Code Projects\C\9S12' in it (if such lines exist). Then replace 'C:\Users\Lance\Desktop\MegaSquirt\Code Projects\C\9S12' with an absolute address to the project folder where you have extracted the zip file. Do not edit, delete, or alter any lines that start with {Project}.

    You can change the access paths under the other targets (P&E ICD and Simulator) too (change the default target, then edit the settings), if you like, this may prevent some warnings in some situations (but these other warnings won't affect the .S19 file compile process).

  3. In order to compile this code within the restrictions allowed by the special edition of Codewarrior (32K and 16 files), some sections of the code have been disabled to save compile space. These are:

    These are used in the code (the above snippet is near the top of the main.c file) with structures like:

    #ifdef REMOVE_DIGTAL_LEVER
       
    // do nothing
    #else
    ...
    ... usual
    ... digital
    ... lever
    ... code
    ...
    #endif

    Note that you will need to keep some of the above options (keep an option in the code by 'commenting out' the associated #define - put preceding slashes, //, in front of it so that the compiler will treat it as a comment and ignore it).
    So you will likely have to remove more code to compile under the limit of the special edition of Codewarrior. This can be done by removing things like the CANbus OUT_MSG option, hard coding things like the shift output patterns, the 4L60e and 4L80e parameter presets in main.c, the ISS options, and/or more of the spare port output options, etc..

  4. The user parameters associated with the above code have been left in the inpram., in2ram., and outpc. structures. If you are sue you want to disable a section of the code, you can remove the associated parameters from the appropriate structure (be sure to remove them from the INI as well!). The INI must always match the inpram., in2ram., and outpc. structures. Make sure you understand how to do that before removing or adding parameters. There are copious notes in the source code and in the INI on this topic.

  5. Compile (F7) after every code change (to make sure you have written legal syntax) and test any changes on the bench before using to make sure it does what you want (which isn't necessarily what you think it will do, or what you told it to do!).

  6. Compiled code will be located in the /BIN/ sub-folder in a file labeled 'Monitor.abs.S19'. This is what you load to the GPIO using the downloader software.

  7. The /BIN/ folder will contain a file called 'Monitor.map'. This file will tell you the memory locations of all the variables. This file also tells you:

  8. Much simpler transmission control code to work with is here: GPIO_MShift_Proj1100.zip and INI file for TunerStudio. This earlier version of the MShift code has fewer options, the coding is deliberately simpler, and it is well under the special edition compiler's limits at 24646 bytes offering lots of room for additions without having to remove any existing code.

When you use this project, the first thing to do is to load the Monitor.abs.S19 file in the /BIN/ folder to the GPIO board. Set up a project in TunerStudio using the included GPIO.INI file. Load and run the code to verify that the CAN comms are working. For instructions (and a video) on setting up the CAN pass-through capability, see: the CAN Pass-Through web page.

Then compile the default project code (shortcut is press F7) without any changes. Load the resulting S19 file to the controller and test the serial and CAN comms. If that doesn't work, you need to figure out why it doesn't compile properly on your computer (since we know it works on other computers).

You load the template code like any other MShift/MicroSquirt code; the instructions are here: Bootloader Instructions

There is a compatible INI file (GPIO_MShift_5201.ini) for TunerStudio in the INI folder in the zip file above. You can get TunerStudio to activate this file for your template project by:

  1. Opening a new or exiting TunerStudio project that you will use for your template code,
  2. Using the menus to get to TunerStudio's 'Project -> Project Properties',
  3. Click on 'Show Advanced/Offline Setup'
  4. Click on 'Other/Browse',
  5. Locate the GPIO_MShift_5201.INI file and click on it to have TunerStudio activate it for your Project.

This code was developed on Freescale's (NXP) Codewarrior 4.7 software. The updated compiler (technically a "cross-compiler/linker/locator") is available for free as a Special Edition from Freescale/NXP (which used to be called Motorola):

http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=CW-HCS12X

You may have to register to get the software. (Note that the link may eventually become stale. If it does, start at the Codewarrior page, or the www.freescale.com home page and search for 'codewarrior HCS12(X) special edition')

The 'Special Edition' of Codewarrior has a 32 Kbyte (32767 bytes) code compile limit, and a maximum of 32 files (the number of files and code size are listed on the bottom left side of the Freescale Codewarrior IDE - integrated development environment). This code is under those limits at 16 files and 32023 bytes.

In addition to the many hints, tips, and examples in the source code itself, there is a draft introduction to programming in C for HCS12 embedded applications on B&G hardware here:

C.htm, a HCS12 C-language primer

as well as many, many others on the internet.

You will also want the MC9S12C Family Reference Manual, it contains much of the information you will need when programming the GPIO's processor (things like register definitions, etc.). You can get the reference manual here:

MC9S12C/MC9S12GC Family Reference Manual



©2016 Al Grippo and Bruce Bowling - All rights reserved. MegaSquirt® and MicroSquirt® are registered trademarks.