Click on our menu buttons immediately below to find MegaSquirt® information quickly:
MicroSquirt® Module
V1/V2 MicroSquirt®
Important Safety Information
MicroSquirt® Support Forum
- MShift™ TCU
- MShift™ Intro
- GPIO Build Guide for 4L60E
- Base circuits
- GPO1, GPO2, GPO3,
GPO4 (gear LEDs)
- VB1, VB2, VB3, VB4
- PWM1, PWM2, PWM3, PWM4
- GPI1, GPI2, GPI5
(2/4WD, Input2, downshift)
- GPI3 (Temperature)
- GPI4 (Brake sense)
- EGT1, EGT2, EGT3,
EGT4 (non-CAN Load, line pressure, Input3, Input1)
- VR1 (Vehicle
Speed Sensor)
- VR2 (Upshift button)
- Finishing Touches
- Testing your
GPIO Board
- External Wiring Guide for 4L60E
- Current Release Code
- User Settings
- βeta Code
- Code Archives
- Purchase a
GPIO kit
- Working with the Shift Table
- Serial
Connection Troubleshooting
- CANbus
Set-Up
- Solving VSS
Issues
- Ports, pins, circuits, connections
- MShift™ Discussion
Forums
- Misc. MShift™
Topics
- MShift™ sitemap
- Template Project Code
- GPIO Board Intro
- MShift™/GPIO
Support Forum
|
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:
- serial and CAN communications infrastructure fully compatible with existing tuning software and other MegaSquirt® CAN-enabled controllers already in place,
- ALL the MS-II®/MicroSquirt®/etc. output variables are read into the GPIO and are available for use in conditions, etc. (some are not yet assigned to variables, comments in the source code show how to do this),
- the analog-digital converter (ADC), pulse width modulation (PWM), timer and digital I/O ports are set up,
- there are many, many comments in the code itself that explain the existing code and assist with changes to the code.
Here is the Codewarrior project file:
(Contains the Monitor.abs.s19 file you load to your GPIO, it is in the /BIN/ folder.)
Notes:
- 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).
- 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:
- 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
- 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).
- 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:
- #define REMOVE_DIGITAL_LEVER // remove digital lever code
- #define REMOVE_ADC_LEVER // remove analog lever code
///// Should keep ONE of the above! ///////////////////////////
- #define REMOVE_SHIFTER_BUTTONS // remove digital lever code
- #define REMOVE_ADC_SHIFTER // remove analog lever code
///// Should keep ONE of the above! ///////////////////////////
- #define REMOVE_SPARE_PORTS // remove user spare port code
- #define REMOVE_CANBUS_RETARD // remove CANbus retard code (for engine ECU)
- #define REMOVE_ESTIMATED_RATIO // remove calculated ratio code (not used for much at present)
- #define REMOVE_SPI_FUNCTION // remove serial port interface code
- #define REMOVE_LUF_CODE // remove lock-up feel code
- #define REMOVE_NAG_MODE // remove NAG mode code (currently incomplete and untested)
- #define REMOVE_MICROTCU // remove micro TCU code
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..
- 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.
- 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!).
- 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.
- 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:
- The unused variables and procedures that you might consider eliminating to save space. Note that it will not tell you which of the inpram./in2ram./outpc. parameters aren't used, since the inpram./in2ram./outpc. structures themselves are still being used (and to the compiler/linker/locater the individual parameters are just offsets within those structures).
- The very last line of the file tells you the compiled size of the code. The limit for the special edition of Codewarrior is 32K (32768 bytes).
- 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:
- Opening a new or exiting TunerStudio project that you will use for your template code,
- Using the menus to get to TunerStudio's 'Project -> Project Properties',
- Click on 'Show Advanced/Offline Setup'
- Click on 'Other/Browse',
- 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):
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:
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:
©2016 Al Grippo and Bruce Bowling - All rights reserved. MegaSquirt® and MicroSquirt® are registered trademarks.