Just4Trionic - CAN and BDM FLASH programmer for Saab cars

Dependencies:   mbed

Committer:
Just4pLeisure
Date:
Tue Jun 07 12:23:28 2011 +0000
Revision:
3:92dae9083c83
Parent:
2:bf3a2b29259a
Child:
4:682d96ff6d79
Basic T7 CAN DUMP and FLASH for P-BUS connection only
Requires MyBooty V2.x for T5 CAN FLASHing at 1 Mbps

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