Just4Trionic - CAN and BDM FLASH programmer for Saab cars

Dependencies:   mbed

Committer:
Just4pLeisure
Date:
Wed Sep 11 11:55:51 2013 +0000
Revision:
4:682d96ff6d79
Parent:
3:92dae9083c83
Child:
5:1775b4b13232
This update adds T8 CAN DUMP and FLASH capability (recovery still to do)

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 4:682d96ff6d79 31 Version 1.4 (07/2013)
Just4pLeisure 4:682d96ff6d79 32
Just4pLeisure 4:682d96ff6d79 33 Changes since Verion 1.3
Just4pLeisure 4:682d96ff6d79 34 Progress indication shown as a percentage, slightly slower but more informative
Just4pLeisure 4:682d96ff6d79 35 T8 BDM Functionality
Just4pLeisure 4:682d96ff6d79 36
Just4pLeisure 4:682d96ff6d79 37 Changes since Verion 1.3
Just4pLeisure 4:682d96ff6d79 38 T7 CAN FLASH algorithm changed to only send 4 Bytes at a time
Just4pLeisure 4:682d96ff6d79 39 Slightly slower but more reliable especially with I-Bus connection
Just4pLeisure 4:682d96ff6d79 40
Just4pLeisure 4:682d96ff6d79 41 ********************************************************************************
Just4pLeisure 4:682d96ff6d79 42
Just4pLeisure 3:92dae9083c83 43 Version 1.3 (06/2011) - Basic T7 CAN support and faster T5 CAN bootloader
Just4pLeisure 3:92dae9083c83 44
Just4pLeisure 4:682d96ff6d79 45 Changes since Verion 1.2
Just4pLeisure 3:92dae9083c83 46 New T7 CAN menu provides some very basic T7 CAN DUMP and FLASH functions
Just4pLeisure 3:92dae9083c83 47 T5 CAN uses Mybooty version 2 for 1 Mbps CAN speed
Just4pLeisure 3:92dae9083c83 48 Get MyBooty version 2.x from forum.ecuproject.com
Just4pLeisure 3:92dae9083c83 49 Does not work with version MyBooty 1.x
Just4pLeisure 3:92dae9083c83 50
Just4pLeisure 3:92dae9083c83 51 ********************************************************************************
Just4pLeisure 3:92dae9083c83 52
Just4pLeisure 2:bf3a2b29259a 53 Version 1.2 (12/2010) - Only a very small update
Just4pLeisure 2:bf3a2b29259a 54
Just4pLeisure 2:bf3a2b29259a 55 Fixed since Version 1.1:
Just4pLeisure 2:bf3a2b29259a 56 My method of detecting the FLASH type didn't work for T7 ECUs
Just4pLeisure 2:bf3a2b29259a 57 Now that that I have corrected this bug it is possible to
Just4pLeisure 2:bf3a2b29259a 58 FLASH Trionic 7 ECUs using the BDM connection
Just4pLeisure 2:bf3a2b29259a 59 See the 'get_flash_id' function in bdmtrionic.cpp
Just4pLeisure 2:bf3a2b29259a 60
Just4pLeisure 3:92dae9083c83 61 Changes since Verion 1.1
Just4pLeisure 2:bf3a2b29259a 62 I have removed everything to do with the BDM DS connection
Just4pLeisure 2:bf3a2b29259a 63 I have changed the mbed pin number for the BDM DSO connection
Just4pLeisure 2:bf3a2b29259a 64 Now all BDM connections are part of the same MBED 'port'
Just4pLeisure 2:bf3a2b29259a 65 Being part of one port makes it possible to change all
Just4pLeisure 2:bf3a2b29259a 66 connections simulataneously so speeding up BDM
Just4pLeisure 2:bf3a2b29259a 67 See 'interfaces.cpp' for details of how the mbed pins connect.
Just4pLeisure 2:bf3a2b29259a 68 Uglybug's wiring circuit has these connections (thanks Uglybug)
Just4pLeisure 2:bf3a2b29259a 69
Just4pLeisure 2:bf3a2b29259a 70 ********************************************************************************
Just4pLeisure 2:bf3a2b29259a 71
Just4pLeisure 1:d5452e398b76 72 Version 1.1 (09/2010) - Still very crude way of doing things
Just4pLeisure 1:d5452e398b76 73
Just4pLeisure 1:d5452e398b76 74 Additions since Version 1:
Just4pLeisure 1:d5452e398b76 75 The BDM interface is now working
Just4pLeisure 1:d5452e398b76 76 Based on Janis Silin's BDM software with modifications and additions
Just4pLeisure 1:d5452e398b76 77 Detect which type of FLASH chip is fitted to work out type of ECU
Just4pLeisure 1:d5452e398b76 78 Modifications to FLASH algorithms - I think my algorithms are
Just4pLeisure 1:d5452e398b76 79 closer to the datasheet methods. Still to do:
Just4pLeisure 1:d5452e398b76 80 Separate pulse counters for 28Fxxx erase
Just4pLeisure 1:d5452e398b76 81 DQ7 and DQ5 checking method for 29Fxxx FLASH
Just4pLeisure 1:d5452e398b76 82 Works for T5.5 ECUs with 28F010 and 29F010 chips
Just4pLeisure 1:d5452e398b76 83 Probably works with T5.2 ECUs (chip detection method)
Just4pLeisure 1:d5452e398b76 84 MAY work with T7 ECUs ('prep' method may need changes - I can't test T7)
Just4pLeisure 1:d5452e398b76 85 NOTE: Some of Janis' original BDM commands may not work, or at least
Just4pLeisure 1:d5452e398b76 86 not as originally intended
Just4pLeisure 1:d5452e398b76 87 Lawicell CAN232 interface partially working
Just4pLeisure 1:d5452e398b76 88 Only a few Lawicell message types to open/close, set speed and write
Just4pLeisure 1:d5452e398b76 89 Trionic5 CAN functions
Just4pLeisure 1:d5452e398b76 90 All-in-one 'D' and 'F' commands to DUMP and FLASH BIN files
Just4pLeisure 1:d5452e398b76 91 Lots of checking for errors, either works or says it failed
Just4pLeisure 1:d5452e398b76 92 No need to interpret the cryptic CAN messages anymore
Just4pLeisure 1:d5452e398b76 93 Should now work for T5.2 and T5.5 ECUs
Just4pLeisure 1:d5452e398b76 94 Detects FLASH chip type and works out which ECU is connected T5.2/5.5
Just4pLeisure 1:d5452e398b76 95
Just4pLeisure 1:d5452e398b76 96 ********************************************************************************
Just4pLeisure 1:d5452e398b76 97
Just4pLeisure 1:d5452e398b76 98 Version 1 (04/2010)- The basic CAN functions are working
Just4pLeisure 0:e0b964252a05 99
Just4pLeisure 0:e0b964252a05 100 I have decided to 'release' this software somewhat prematurely because the FLASH
Just4pLeisure 0:e0b964252a05 101 chips in my spare ECU have 'died' and I don't know when I will be able to do
Just4pLeisure 0:e0b964252a05 102 carry on improving and 'polishing' it. This way others will be able to use and
Just4pLeisure 0:e0b964252a05 103 enhance it without having to wait for me.
Just4pLeisure 0:e0b964252a05 104
Just4pLeisure 0:e0b964252a05 105 For now, only option '5' Trionic ECU CAN interface is working. BDM and Lawicell
Just4pLeisure 0:e0b964252a05 106 CAN232 functions are dummies. The intention is to build a complete suite of CAN
Just4pLeisure 0:e0b964252a05 107 software for Trionic5, 7 and 8 ECU types as well as adding a BDM interface to
Just4pLeisure 0:e0b964252a05 108 make an 'all-in-one' USB programming tool.
Just4pLeisure 0:e0b964252a05 109
Just4pLeisure 0:e0b964252a05 110 To make this you will need an mbed system and the CAN circuit from this page:
Just4pLeisure 0:e0b964252a05 111 http://mbed.org/projects/cookbook/wiki/CanBusExample1
Just4pLeisure 0:e0b964252a05 112
Just4pLeisure 0:e0b964252a05 113 Some ideas for the truly creative and adventurous of you is to make a gizmo that
Just4pLeisure 0:e0b964252a05 114 doesn't even need to be connected to a laptop or PC to use, maybe even a self-
Just4pLeisure 0:e0b964252a05 115 contained vesion of Dilemma's CarPC using ideas from this pages:
Just4pLeisure 0:e0b964252a05 116
Just4pLeisure 0:e0b964252a05 117 http://mbed.org/projects/cookbook/wiki/PS2Keyboard
Just4pLeisure 0:e0b964252a05 118 http://mbed.org/projects/cookbook/wiki/PS2Mouse
Just4pLeisure 0:e0b964252a05 119 http://mbed.org/projects/cookbook/wiki/MobileLCD
Just4pLeisure 0:e0b964252a05 120 http://mbed.org/projects/cookbook/wiki/SDCard
Just4pLeisure 0:e0b964252a05 121
Just4pLeisure 0:e0b964252a05 122 *******************************************************************************/
Just4pLeisure 0:e0b964252a05 123
Just4pLeisure 0:e0b964252a05 124 #include "mbed.h"
Just4pLeisure 1:d5452e398b76 125 //
Just4pLeisure 1:d5452e398b76 126 #include "common.h"
Just4pLeisure 1:d5452e398b76 127 #include "bdm.h"
Just4pLeisure 1:d5452e398b76 128 #include "can232.h"
Just4pLeisure 1:d5452e398b76 129 #include "t5can.h"
Just4pLeisure 3:92dae9083c83 130 #include "t7can.h"
Just4pLeisure 4:682d96ff6d79 131 #include "t8can.h"
Just4pLeisure 0:e0b964252a05 132
Just4pLeisure 1:d5452e398b76 133 // constants
Just4pLeisure 1:d5452e398b76 134 #define CMD_BUF_LENGTH 32 ///< command buffer size
Just4pLeisure 0:e0b964252a05 135
Just4pLeisure 1:d5452e398b76 136 // static variables
Just4pLeisure 1:d5452e398b76 137 static char cmd_buffer[CMD_BUF_LENGTH]; ///< command string buffer
Just4pLeisure 0:e0b964252a05 138
Just4pLeisure 1:d5452e398b76 139 // private functions
Just4pLeisure 1:d5452e398b76 140 uint8_t execute_just4trionic_cmd();
Just4pLeisure 1:d5452e398b76 141 void show_just4trionic_help();
Just4pLeisure 0:e0b964252a05 142
Just4pLeisure 4:682d96ff6d79 143 int main()
Just4pLeisure 4:682d96ff6d79 144 {
Just4pLeisure 0:e0b964252a05 145 // fast serial speed
Just4pLeisure 4:682d96ff6d79 146 //pc.baud(921600);
Just4pLeisure 0:e0b964252a05 147 pc.baud(115200);
Just4pLeisure 1:d5452e398b76 148
Just4pLeisure 1:d5452e398b76 149 // the address of the function to be attached (leds_off) and the interval (0.1 seconds)
Just4pLeisure 1:d5452e398b76 150 // This 'ticker' turns off the activity LEDs so that they don't stay on if something has gone wrong
Just4pLeisure 1:d5452e398b76 151 ticker.attach(&leds_off, 0.1);
Just4pLeisure 1:d5452e398b76 152
Just4pLeisure 1:d5452e398b76 153 // clear incoming buffer
Just4pLeisure 1:d5452e398b76 154 // sometimes TeraTerm gets 'confused'. johnc does this in his code
Just4pLeisure 1:d5452e398b76 155 // hopefully this will fix the problem
Just4pLeisure 1:d5452e398b76 156 // unfortunately it doesn't, but it seems like a good idea
Just4pLeisure 1:d5452e398b76 157 char rx_char;
Just4pLeisure 1:d5452e398b76 158 while (pc.readable())
Just4pLeisure 1:d5452e398b76 159 rx_char = pc.getc();
Just4pLeisure 1:d5452e398b76 160
Just4pLeisure 4:682d96ff6d79 161 #ifdef DEBUG
Just4pLeisure 4:682d96ff6d79 162 printf("*************************\r\n");
Just4pLeisure 4:682d96ff6d79 163 printf("** RUNNING DEBUG BUILD **\r\n");
Just4pLeisure 4:682d96ff6d79 164 printf("*************************\r\n");
Just4pLeisure 4:682d96ff6d79 165 #else
Just4pLeisure 4:682d96ff6d79 166 printf("Running... this is a release build.\r\n");
Just4pLeisure 4:682d96ff6d79 167 #endif
Just4pLeisure 4:682d96ff6d79 168
Just4pLeisure 1:d5452e398b76 169 show_just4trionic_help();
Just4pLeisure 1:d5452e398b76 170
Just4pLeisure 1:d5452e398b76 171 // main loop
Just4pLeisure 1:d5452e398b76 172 *cmd_buffer = '\0';
Just4pLeisure 1:d5452e398b76 173 char ret;
Just4pLeisure 1:d5452e398b76 174 while (true) {
Just4pLeisure 1:d5452e398b76 175 // read chars from USB
Just4pLeisure 1:d5452e398b76 176 // send received messages to the pc over USB connection
Just4pLeisure 1:d5452e398b76 177 // This function displays any CAN messages that are 'missed' by the other functions
Just4pLeisure 1:d5452e398b76 178 // Can messages might be 'missed' because they are received after a 'timeout' period
Just4pLeisure 1:d5452e398b76 179 // or because they weren't expected, e.g. if the T5 ECU resets for some reason
Just4pLeisure 1:d5452e398b76 180 t5_can_show_can_message();
Just4pLeisure 1:d5452e398b76 181 if (pc.readable()) {
Just4pLeisure 1:d5452e398b76 182 // turn Error LED off for next command
Just4pLeisure 1:d5452e398b76 183 led4 = 0;
Just4pLeisure 1:d5452e398b76 184 rx_char = pc.getc();
Just4pLeisure 1:d5452e398b76 185 switch (rx_char) {
Just4pLeisure 1:d5452e398b76 186 // end-of-command reached
Just4pLeisure 1:d5452e398b76 187 case TERM_OK :
Just4pLeisure 1:d5452e398b76 188 // execute command and return flag via USB
Just4pLeisure 1:d5452e398b76 189 timer.reset();
Just4pLeisure 1:d5452e398b76 190 timer.start();
Just4pLeisure 1:d5452e398b76 191 ret = execute_just4trionic_cmd();
Just4pLeisure 1:d5452e398b76 192 show_just4trionic_help();
Just4pLeisure 1:d5452e398b76 193 pc.putc(ret);
Just4pLeisure 1:d5452e398b76 194 // reset command buffer
Just4pLeisure 1:d5452e398b76 195 *cmd_buffer = '\0';
Just4pLeisure 1:d5452e398b76 196 // light up LED
Just4pLeisure 1:d5452e398b76 197 // ret == TERM_OK ? led_on(LED_ACT) : led_on(LED_ERR);
Just4pLeisure 1:d5452e398b76 198 ret == TERM_OK ? led3 = 1 : led4 = 1;
Just4pLeisure 1:d5452e398b76 199 break;
Just4pLeisure 1:d5452e398b76 200 // another command char
Just4pLeisure 1:d5452e398b76 201 default:
Just4pLeisure 1:d5452e398b76 202 // store in buffer if space permits
Just4pLeisure 1:d5452e398b76 203 if (StrLen(cmd_buffer) < CMD_BUF_LENGTH - 1) {
Just4pLeisure 1:d5452e398b76 204 StrAddc(cmd_buffer, rx_char);
Just4pLeisure 1:d5452e398b76 205 }
Just4pLeisure 1:d5452e398b76 206 break;
Just4pLeisure 1:d5452e398b76 207 }
Just4pLeisure 1:d5452e398b76 208 }
Just4pLeisure 0:e0b964252a05 209 }
Just4pLeisure 0:e0b964252a05 210 }
Just4pLeisure 0:e0b964252a05 211
Just4pLeisure 1:d5452e398b76 212 //-----------------------------------------------------------------------------
Just4pLeisure 1:d5452e398b76 213 /**
Just4pLeisure 1:d5452e398b76 214 Executes a command and returns result flag (does not transmit the flag
Just4pLeisure 1:d5452e398b76 215 itself).
Just4pLeisure 1:d5452e398b76 216
Just4pLeisure 1:d5452e398b76 217 @return command flag (success / failure)
Just4pLeisure 1:d5452e398b76 218 */
Just4pLeisure 4:682d96ff6d79 219 uint8_t execute_just4trionic_cmd()
Just4pLeisure 4:682d96ff6d79 220 {
Just4pLeisure 1:d5452e398b76 221
Just4pLeisure 1:d5452e398b76 222
Just4pLeisure 1:d5452e398b76 223 // uint8_t cmd_length = strlen(cmd_buffer);
Just4pLeisure 1:d5452e398b76 224 // command groups
Just4pLeisure 1:d5452e398b76 225 switch (*cmd_buffer) {
Just4pLeisure 1:d5452e398b76 226 // CHECK_ARGLENGTH(0);
Just4pLeisure 1:d5452e398b76 227 case 'b':
Just4pLeisure 1:d5452e398b76 228 case 'B':
Just4pLeisure 1:d5452e398b76 229 bdm();
Just4pLeisure 1:d5452e398b76 230 return TERM_OK;
Just4pLeisure 1:d5452e398b76 231 case 'o':
Just4pLeisure 1:d5452e398b76 232 case 'O':
Just4pLeisure 1:d5452e398b76 233 can232();
Just4pLeisure 1:d5452e398b76 234 return TERM_OK;
Just4pLeisure 1:d5452e398b76 235 case '5':
Just4pLeisure 1:d5452e398b76 236 t5_can();
Just4pLeisure 1:d5452e398b76 237 return TERM_OK;
Just4pLeisure 3:92dae9083c83 238 case '7':
Just4pLeisure 3:92dae9083c83 239 t7_can();
Just4pLeisure 3:92dae9083c83 240 return TERM_OK;
Just4pLeisure 4:682d96ff6d79 241 case '8':
Just4pLeisure 4:682d96ff6d79 242 t8_can();
Just4pLeisure 4:682d96ff6d79 243 return TERM_OK;
Just4pLeisure 1:d5452e398b76 244 case 'h':
Just4pLeisure 1:d5452e398b76 245 case 'H':
Just4pLeisure 1:d5452e398b76 246 return TERM_OK;
Just4pLeisure 1:d5452e398b76 247 default:
Just4pLeisure 1:d5452e398b76 248 break;
Just4pLeisure 1:d5452e398b76 249 }
Just4pLeisure 1:d5452e398b76 250
Just4pLeisure 1:d5452e398b76 251 // unknown command
Just4pLeisure 1:d5452e398b76 252 return TERM_ERR;
Just4pLeisure 1:d5452e398b76 253 }
Just4pLeisure 1:d5452e398b76 254
Just4pLeisure 4:682d96ff6d79 255 void show_just4trionic_help()
Just4pLeisure 4:682d96ff6d79 256 {
Just4pLeisure 0:e0b964252a05 257 printf("Just4Trionic Command Menu\r\n");
Just4pLeisure 0:e0b964252a05 258 printf("=========================\r\n");
Just4pLeisure 1:d5452e398b76 259 printf("b/B - Start BDM interface\r\n");
Just4pLeisure 1:d5452e398b76 260 printf("o/O - Open Lawicel CAN232 type interface\r\n");
Just4pLeisure 0:e0b964252a05 261 printf("5 - Start Trionic5 ECU CAN interface\r\n");
Just4pLeisure 3:92dae9083c83 262 printf("7 - Start Trionic7 ECU CAN interface\r\n");
Just4pLeisure 4:682d96ff6d79 263 printf("8 - Start Trionic8 ECU CAN interface\r\n");
Just4pLeisure 0:e0b964252a05 264 printf("\r\n");
Just4pLeisure 0:e0b964252a05 265 printf("h/H - show this help menu\r\n");
Just4pLeisure 1:d5452e398b76 266 printf("\r\n");
Just4pLeisure 0:e0b964252a05 267 return;
Just4pLeisure 1:d5452e398b76 268 }