Just4Trionic - CAN and BDM FLASH programmer for Saab cars

Dependencies:   mbed

Committer:
Just4pLeisure
Date:
Tue Dec 14 21:50:35 2010 +0000
Revision:
2:bf3a2b29259a
Parent:
1:d5452e398b76
Child:
3:92dae9083c83
Update for change to BDM DSO connection (and removed DS) fixed a bug that prevented BDM mode detecting Trionic 7 ECUs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Just4pLeisure 0:e0b964252a05 1 /*******************************************************************************
Just4pLeisure 0:e0b964252a05 2
Just4pLeisure 1:d5452e398b76 3 Just4Trionic by Just4pLeisure
Just4pLeisure 0:e0b964252a05 4 *****************************
Just4pLeisure 1:d5452e398b76 5 (c) 2010 by Sophie Dexter
Just4pLeisure 0:e0b964252a05 6
Just4pLeisure 0:e0b964252a05 7 Whilst I have written this program myself I could not have done it without
Just4pLeisure 0:e0b964252a05 8 a lot of help and the original ideas and programs written by:
Just4pLeisure 0:e0b964252a05 9 Dilemma - Author of the Trionic Suite software programs and general Guru
Just4pLeisure 0:e0b964252a05 10 http://trionic.mobixs.eu/ and http://www.ecuproject.com.
Just4pLeisure 0:e0b964252a05 11 General Failure - Author of the T5CANlib software and regular contributor at
Just4pLeisure 0:e0b964252a05 12 http://www.ecuproject.com.
Just4pLeisure 0:e0b964252a05 13 Tomi Liljemark - Lots of information and programs about the Saab CAN bus
Just4pLeisure 0:e0b964252a05 14 http://pikkupossu.1g.fi/tomi/projects/projects.html.
Just4pLeisure 0:e0b964252a05 15 Scott Howard - Author of the BDM software.
Just4pLeisure 1:d5452e398b76 16 Janis Silins - Valued contributor at http://www.ecuproject.com and creator of
Just4pLeisure 1:d5452e398b76 17 USBBDM. For sharing his BDM software (which also had a very useful method of
Just4pLeisure 1:d5452e398b76 18 entering commands)
Just4pLeisure 1:d5452e398b76 19 Plus inspiration and ideas from many others...
Just4pLeisure 0:e0b964252a05 20
Just4pLeisure 0:e0b964252a05 21 Sophie x
Just4pLeisure 0:e0b964252a05 22
Just4pLeisure 0:e0b964252a05 23 ********************************************************************************
Just4pLeisure 0:e0b964252a05 24
Just4pLeisure 0:e0b964252a05 25 WARNING: Use at your own risk, sadly this software comes with no guarantees.
Just4pLeisure 0:e0b964252a05 26 This software is provided 'free' and in good faith, but the author does not
Just4pLeisure 0:e0b964252a05 27 accept liability for any damage arising from its use.
Just4pLeisure 0:e0b964252a05 28
Just4pLeisure 0:e0b964252a05 29 ********************************************************************************
Just4pLeisure 0:e0b964252a05 30
Just4pLeisure 2:bf3a2b29259a 31 Version 1.2 (12/2010) - Only a very small update
Just4pLeisure 2:bf3a2b29259a 32
Just4pLeisure 2:bf3a2b29259a 33 Fixed since Version 1.1:
Just4pLeisure 2:bf3a2b29259a 34 My method of detecting the FLASH type didn't work for T7 ECUs
Just4pLeisure 2:bf3a2b29259a 35 Now that that I have corrected this bug it is possible to
Just4pLeisure 2:bf3a2b29259a 36 FLASH Trionic 7 ECUs using the BDM connection
Just4pLeisure 2:bf3a2b29259a 37 See the 'get_flash_id' function in bdmtrionic.cpp
Just4pLeisure 2:bf3a2b29259a 38
Just4pLeisure 2:bf3a2b29259a 39 Changes since Verion 1.2
Just4pLeisure 2:bf3a2b29259a 40 I have removed everything to do with the BDM DS connection
Just4pLeisure 2:bf3a2b29259a 41 I have changed the mbed pin number for the BDM DSO connection
Just4pLeisure 2:bf3a2b29259a 42 Now all BDM connections are part of the same MBED 'port'
Just4pLeisure 2:bf3a2b29259a 43 Being part of one port makes it possible to change all
Just4pLeisure 2:bf3a2b29259a 44 connections simulataneously so speeding up BDM
Just4pLeisure 2:bf3a2b29259a 45 See 'interfaces.cpp' for details of how the mbed pins connect.
Just4pLeisure 2:bf3a2b29259a 46 Uglybug's wiring circuit has these connections (thanks Uglybug)
Just4pLeisure 2:bf3a2b29259a 47
Just4pLeisure 2:bf3a2b29259a 48 ********************************************************************************
Just4pLeisure 2:bf3a2b29259a 49
Just4pLeisure 1:d5452e398b76 50 Version 1.1 (09/2010) - Still very crude way of doing things
Just4pLeisure 1:d5452e398b76 51
Just4pLeisure 1:d5452e398b76 52 Additions since Version 1:
Just4pLeisure 1:d5452e398b76 53 The BDM interface is now working
Just4pLeisure 1:d5452e398b76 54 Based on Janis Silin's BDM software with modifications and additions
Just4pLeisure 1:d5452e398b76 55 Detect which type of FLASH chip is fitted to work out type of ECU
Just4pLeisure 1:d5452e398b76 56 Modifications to FLASH algorithms - I think my algorithms are
Just4pLeisure 1:d5452e398b76 57 closer to the datasheet methods. Still to do:
Just4pLeisure 1:d5452e398b76 58 Separate pulse counters for 28Fxxx erase
Just4pLeisure 1:d5452e398b76 59 DQ7 and DQ5 checking method for 29Fxxx FLASH
Just4pLeisure 1:d5452e398b76 60 Works for T5.5 ECUs with 28F010 and 29F010 chips
Just4pLeisure 1:d5452e398b76 61 Probably works with T5.2 ECUs (chip detection method)
Just4pLeisure 1:d5452e398b76 62 MAY work with T7 ECUs ('prep' method may need changes - I can't test T7)
Just4pLeisure 1:d5452e398b76 63 NOTE: Some of Janis' original BDM commands may not work, or at least
Just4pLeisure 1:d5452e398b76 64 not as originally intended
Just4pLeisure 1:d5452e398b76 65 Lawicell CAN232 interface partially working
Just4pLeisure 1:d5452e398b76 66 Only a few Lawicell message types to open/close, set speed and write
Just4pLeisure 1:d5452e398b76 67 Trionic5 CAN functions
Just4pLeisure 1:d5452e398b76 68 All-in-one 'D' and 'F' commands to DUMP and FLASH BIN files
Just4pLeisure 1:d5452e398b76 69 Lots of checking for errors, either works or says it failed
Just4pLeisure 1:d5452e398b76 70 No need to interpret the cryptic CAN messages anymore
Just4pLeisure 1:d5452e398b76 71 Should now work for T5.2 and T5.5 ECUs
Just4pLeisure 1:d5452e398b76 72 Detects FLASH chip type and works out which ECU is connected T5.2/5.5
Just4pLeisure 1:d5452e398b76 73
Just4pLeisure 1:d5452e398b76 74 ********************************************************************************
Just4pLeisure 1:d5452e398b76 75
Just4pLeisure 1:d5452e398b76 76 Version 1 (04/2010)- The basic CAN functions are working
Just4pLeisure 0:e0b964252a05 77
Just4pLeisure 0:e0b964252a05 78 I have decided to 'release' this software somewhat prematurely because the FLASH
Just4pLeisure 0:e0b964252a05 79 chips in my spare ECU have 'died' and I don't know when I will be able to do
Just4pLeisure 0:e0b964252a05 80 carry on improving and 'polishing' it. This way others will be able to use and
Just4pLeisure 0:e0b964252a05 81 enhance it without having to wait for me.
Just4pLeisure 0:e0b964252a05 82
Just4pLeisure 0:e0b964252a05 83 For now, only option '5' Trionic ECU CAN interface is working. BDM and Lawicell
Just4pLeisure 0:e0b964252a05 84 CAN232 functions are dummies. The intention is to build a complete suite of CAN
Just4pLeisure 0:e0b964252a05 85 software for Trionic5, 7 and 8 ECU types as well as adding a BDM interface to
Just4pLeisure 0:e0b964252a05 86 make an 'all-in-one' USB programming tool.
Just4pLeisure 0:e0b964252a05 87
Just4pLeisure 0:e0b964252a05 88 To make this you will need an mbed system and the CAN circuit from this page:
Just4pLeisure 0:e0b964252a05 89 http://mbed.org/projects/cookbook/wiki/CanBusExample1
Just4pLeisure 0:e0b964252a05 90
Just4pLeisure 0:e0b964252a05 91 Some ideas for the truly creative and adventurous of you is to make a gizmo that
Just4pLeisure 0:e0b964252a05 92 doesn't even need to be connected to a laptop or PC to use, maybe even a self-
Just4pLeisure 0:e0b964252a05 93 contained vesion of Dilemma's CarPC using ideas from this pages:
Just4pLeisure 0:e0b964252a05 94
Just4pLeisure 0:e0b964252a05 95 http://mbed.org/projects/cookbook/wiki/PS2Keyboard
Just4pLeisure 0:e0b964252a05 96 http://mbed.org/projects/cookbook/wiki/PS2Mouse
Just4pLeisure 0:e0b964252a05 97 http://mbed.org/projects/cookbook/wiki/MobileLCD
Just4pLeisure 0:e0b964252a05 98 http://mbed.org/projects/cookbook/wiki/SDCard
Just4pLeisure 0:e0b964252a05 99
Just4pLeisure 0:e0b964252a05 100 *******************************************************************************/
Just4pLeisure 0:e0b964252a05 101
Just4pLeisure 0:e0b964252a05 102 #include "mbed.h"
Just4pLeisure 1:d5452e398b76 103 //
Just4pLeisure 1:d5452e398b76 104 #include "common.h"
Just4pLeisure 1:d5452e398b76 105 #include "bdm.h"
Just4pLeisure 1:d5452e398b76 106 #include "can232.h"
Just4pLeisure 1:d5452e398b76 107 #include "t5can.h"
Just4pLeisure 0:e0b964252a05 108
Just4pLeisure 1:d5452e398b76 109 // constants
Just4pLeisure 1:d5452e398b76 110 #define CMD_BUF_LENGTH 32 ///< command buffer size
Just4pLeisure 0:e0b964252a05 111
Just4pLeisure 1:d5452e398b76 112 // static variables
Just4pLeisure 1:d5452e398b76 113 static char cmd_buffer[CMD_BUF_LENGTH]; ///< command string buffer
Just4pLeisure 0:e0b964252a05 114
Just4pLeisure 1:d5452e398b76 115 // private functions
Just4pLeisure 1:d5452e398b76 116 uint8_t execute_just4trionic_cmd();
Just4pLeisure 1:d5452e398b76 117 void show_just4trionic_help();
Just4pLeisure 0:e0b964252a05 118
Just4pLeisure 0:e0b964252a05 119 int main() {
Just4pLeisure 0:e0b964252a05 120 // fast serial speed
Just4pLeisure 0:e0b964252a05 121 // pc.baud(921600);
Just4pLeisure 0:e0b964252a05 122 pc.baud(115200);
Just4pLeisure 1:d5452e398b76 123
Just4pLeisure 1:d5452e398b76 124 // the address of the function to be attached (leds_off) and the interval (0.1 seconds)
Just4pLeisure 1:d5452e398b76 125 // This 'ticker' turns off the activity LEDs so that they don't stay on if something has gone wrong
Just4pLeisure 1:d5452e398b76 126 ticker.attach(&leds_off, 0.1);
Just4pLeisure 1:d5452e398b76 127
Just4pLeisure 1:d5452e398b76 128 // clear incoming buffer
Just4pLeisure 1:d5452e398b76 129 // sometimes TeraTerm gets 'confused'. johnc does this in his code
Just4pLeisure 1:d5452e398b76 130 // hopefully this will fix the problem
Just4pLeisure 1:d5452e398b76 131 // unfortunately it doesn't, but it seems like a good idea
Just4pLeisure 1:d5452e398b76 132 char rx_char;
Just4pLeisure 1:d5452e398b76 133 while (pc.readable())
Just4pLeisure 1:d5452e398b76 134 rx_char = pc.getc();
Just4pLeisure 1:d5452e398b76 135
Just4pLeisure 1:d5452e398b76 136 show_just4trionic_help();
Just4pLeisure 1:d5452e398b76 137
Just4pLeisure 1:d5452e398b76 138 // main loop
Just4pLeisure 1:d5452e398b76 139 *cmd_buffer = '\0';
Just4pLeisure 1:d5452e398b76 140 char ret;
Just4pLeisure 1:d5452e398b76 141 while (true) {
Just4pLeisure 1:d5452e398b76 142 // read chars from USB
Just4pLeisure 1:d5452e398b76 143 // send received messages to the pc over USB connection
Just4pLeisure 1:d5452e398b76 144 // This function displays any CAN messages that are 'missed' by the other functions
Just4pLeisure 1:d5452e398b76 145 // Can messages might be 'missed' because they are received after a 'timeout' period
Just4pLeisure 1:d5452e398b76 146 // or because they weren't expected, e.g. if the T5 ECU resets for some reason
Just4pLeisure 1:d5452e398b76 147 t5_can_show_can_message();
Just4pLeisure 1:d5452e398b76 148 if (pc.readable()) {
Just4pLeisure 1:d5452e398b76 149 // turn Error LED off for next command
Just4pLeisure 1:d5452e398b76 150 led4 = 0;
Just4pLeisure 1:d5452e398b76 151 rx_char = pc.getc();
Just4pLeisure 1:d5452e398b76 152 switch (rx_char) {
Just4pLeisure 1:d5452e398b76 153 // end-of-command reached
Just4pLeisure 1:d5452e398b76 154 case TERM_OK :
Just4pLeisure 1:d5452e398b76 155 // execute command and return flag via USB
Just4pLeisure 1:d5452e398b76 156 timer.reset();
Just4pLeisure 1:d5452e398b76 157 timer.start();
Just4pLeisure 1:d5452e398b76 158 ret = execute_just4trionic_cmd();
Just4pLeisure 1:d5452e398b76 159 show_just4trionic_help();
Just4pLeisure 1:d5452e398b76 160 pc.putc(ret);
Just4pLeisure 1:d5452e398b76 161 // reset command buffer
Just4pLeisure 1:d5452e398b76 162 *cmd_buffer = '\0';
Just4pLeisure 1:d5452e398b76 163 // light up LED
Just4pLeisure 1:d5452e398b76 164 // ret == TERM_OK ? led_on(LED_ACT) : led_on(LED_ERR);
Just4pLeisure 1:d5452e398b76 165 ret == TERM_OK ? led3 = 1 : led4 = 1;
Just4pLeisure 1:d5452e398b76 166 break;
Just4pLeisure 1:d5452e398b76 167 // another command char
Just4pLeisure 1:d5452e398b76 168 default:
Just4pLeisure 1:d5452e398b76 169 // store in buffer if space permits
Just4pLeisure 1:d5452e398b76 170 if (StrLen(cmd_buffer) < CMD_BUF_LENGTH - 1) {
Just4pLeisure 1:d5452e398b76 171 StrAddc(cmd_buffer, rx_char);
Just4pLeisure 1:d5452e398b76 172 }
Just4pLeisure 1:d5452e398b76 173 break;
Just4pLeisure 1:d5452e398b76 174 }
Just4pLeisure 1:d5452e398b76 175 }
Just4pLeisure 0:e0b964252a05 176 }
Just4pLeisure 0:e0b964252a05 177 }
Just4pLeisure 0:e0b964252a05 178
Just4pLeisure 1:d5452e398b76 179 //-----------------------------------------------------------------------------
Just4pLeisure 1:d5452e398b76 180 /**
Just4pLeisure 1:d5452e398b76 181 Executes a command and returns result flag (does not transmit the flag
Just4pLeisure 1:d5452e398b76 182 itself).
Just4pLeisure 1:d5452e398b76 183
Just4pLeisure 1:d5452e398b76 184 @return command flag (success / failure)
Just4pLeisure 1:d5452e398b76 185 */
Just4pLeisure 1:d5452e398b76 186 uint8_t execute_just4trionic_cmd() {
Just4pLeisure 1:d5452e398b76 187
Just4pLeisure 1:d5452e398b76 188
Just4pLeisure 1:d5452e398b76 189 // uint8_t cmd_length = strlen(cmd_buffer);
Just4pLeisure 1:d5452e398b76 190 // command groups
Just4pLeisure 1:d5452e398b76 191 switch (*cmd_buffer) {
Just4pLeisure 1:d5452e398b76 192 // CHECK_ARGLENGTH(0);
Just4pLeisure 1:d5452e398b76 193 case 'b':
Just4pLeisure 1:d5452e398b76 194 case 'B':
Just4pLeisure 1:d5452e398b76 195 bdm();
Just4pLeisure 1:d5452e398b76 196 return TERM_OK;
Just4pLeisure 1:d5452e398b76 197 case 'o':
Just4pLeisure 1:d5452e398b76 198 case 'O':
Just4pLeisure 1:d5452e398b76 199 can232();
Just4pLeisure 1:d5452e398b76 200 return TERM_OK;
Just4pLeisure 1:d5452e398b76 201 case '5':
Just4pLeisure 1:d5452e398b76 202 t5_can();
Just4pLeisure 1:d5452e398b76 203 return TERM_OK;
Just4pLeisure 1:d5452e398b76 204 case 'h':
Just4pLeisure 1:d5452e398b76 205 case 'H':
Just4pLeisure 1:d5452e398b76 206 return TERM_OK;
Just4pLeisure 1:d5452e398b76 207 default:
Just4pLeisure 1:d5452e398b76 208 break;
Just4pLeisure 1:d5452e398b76 209 }
Just4pLeisure 1:d5452e398b76 210
Just4pLeisure 1:d5452e398b76 211 // unknown command
Just4pLeisure 1:d5452e398b76 212 return TERM_ERR;
Just4pLeisure 1:d5452e398b76 213 }
Just4pLeisure 1:d5452e398b76 214
Just4pLeisure 1:d5452e398b76 215 void show_just4trionic_help() {
Just4pLeisure 0:e0b964252a05 216 printf("Just4Trionic Command Menu\r\n");
Just4pLeisure 0:e0b964252a05 217 printf("=========================\r\n");
Just4pLeisure 1:d5452e398b76 218 printf("b/B - Start BDM interface\r\n");
Just4pLeisure 1:d5452e398b76 219 printf("o/O - Open Lawicel CAN232 type interface\r\n");
Just4pLeisure 0:e0b964252a05 220 printf("5 - Start Trionic5 ECU CAN interface\r\n");
Just4pLeisure 0:e0b964252a05 221 printf("\r\n");
Just4pLeisure 0:e0b964252a05 222 printf("h/H - show this help menu\r\n");
Just4pLeisure 1:d5452e398b76 223 printf("\r\n");
Just4pLeisure 0:e0b964252a05 224 return;
Just4pLeisure 1:d5452e398b76 225 }