Just4Trionic - CAN and BDM FLASH programmer for Saab cars

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers bdm.cpp Source File

bdm.cpp

00001 /*******************************************************************************
00002 
00003 bdm.cpp
00004 (c) 2010 by Sophie Dexter
00005 
00006 BDM functions for Just4Trionic by Just4pLeisure
00007 
00008 A derivative work based on:
00009 //-----------------------------------------------------------------------------
00010 //    Firmware for USB BDM v2.0
00011 //    (C) johnc, 2009
00012 //    $id$
00013 //-----------------------------------------------------------------------------
00014 
00015 ********************************************************************************
00016 
00017 WARNING: Use at your own risk, sadly this software comes with no guarantees.
00018 This software is provided 'free' and in good faith, but the author does not
00019 accept liability for any damage arising from its use.
00020 
00021 *******************************************************************************/
00022 
00023 #include "bdm.h"
00024 
00025 // constants
00026 #define CMD_BUF_LENGTH      32              ///< command buffer size
00027 
00028 // LED constants and macros
00029 #define LED_ONTIME          5               ///< LED 'on' time, ms    
00030 #define LED_TCNT            (255 - (unsigned char)((unsigned long)(LED_ONTIME * 1000L)  \
00031                             / (1000000L / (float)((unsigned long)XTAL_CPU / 1024L))))
00032 
00033 // command characters
00034 #define CMDGROUP_ADAPTER    'a'             ///< adapter commands 
00035 #define CMD_VERSION         'v'             ///< firmware version
00036 #define CMD_PINSTATUS       's'             ///< momentary status of BDM pins
00037 #define CMD_BKPTLOW         '1'             ///< pull BKPT low
00038 #define CMD_BKPTHIGH        '2'             ///< pull BKPT high
00039 #define CMD_RESETLOW        '3'             ///< pull RESET low
00040 #define CMD_RESETHIGH       '4'             ///< pull RESET high
00041 #define CMD_BERR_LOW        '5'             ///< pull BERR low
00042 #define CMD_BERR_HIGH       '6'             ///< pull BERR high
00043 #define CMD_BERR_INPUT      '7'             ///< make BERR an input
00044 
00045 
00046 #define CMDGROUP_MCU        'c'             ///< target MCU management commands
00047 #define CMD_STOPCHIP        'S'             ///< stop
00048 #define CMD_RESETCHIP       'R'             ///< reset
00049 #define CMD_RUNCHIP         'r'             ///< run from given address
00050 #define CMD_RESTART         's'             ///< restart
00051 #define CMD_STEP            'b'             ///< step
00052 
00053 #define CMDGROUP_FLASH      'f'
00054 #define CMD_GETVERIFY       'v'             ///< gets verification status
00055 #define CMD_SETVERIFY       'V'             ///< sets verification on/off
00056 #define CMD_DUMP            'd'             ///< dumps memory contents
00057 #define CMD_ERASE           'E'             ///< erase entire flash memory            
00058 #define CMD_WRITE           'w'             ///< writes to flash memory
00059 
00060 #define CMDGROUP_MEMORY     'm'             ///< target MCU memory commands
00061 #define CMD_READBYTE        'b'             ///< read byte from memory
00062 #define CMD_READWORD        'w'             ///< read word (2 bytes) from memory
00063 #define CMD_READLONG        'l'             ///< read long word (4 bytes) from memory
00064 #define CMD_DUMPBYTE        'z'             ///< dump byte from memory
00065 #define CMD_DUMPWORD        'x'             ///< dump word from memory
00066 #define CMD_DUMPLONG        'c'             ///< dump long word from memory
00067 #define CMD_WRITEBYTE       'B'             ///< write byte to memory
00068 #define CMD_WRITEWORD       'W'             ///< write word to memory
00069 #define CMD_WRITELONG       'L'             ///< write long word to memory
00070 #define CMD_FILLBYTE        'f'             ///< fill byte in memory
00071 #define CMD_FILLWORD        'F'             ///< fill word in memory
00072 #define CMD_FILLLONG        'M'             ///< fill long word in memory 
00073 
00074 #define CMDGROUP_REGISTER   'r'             ///< register commands
00075 #define CMD_READSYSREG      'r'             ///< read system register
00076 #define CMD_WRITESYSREG     'W'             ///< write system register
00077 #define CMD_READADREG       'a'             ///< read A/D register
00078 #define CMD_WRITEADREG      'A'             ///< write A/D register
00079 #define CMD_DISPLAYREGS     'd'             ///< BD32 like display all registers
00080 
00081 #define CMDGROUP_TRIONIC    'T'
00082 #define CMD_TRIONICDUMP     'D'             ///< dumps memory contents
00083 #define CMD_TRIONICWRITE    'F'             ///< writes to flash memory
00084 
00085 // static variables
00086 static char cmd_buffer[CMD_BUF_LENGTH];     ///< command string buffer
00087 static uint32_t cmd_addr;                   ///< address (optional)
00088 static uint32_t cmd_value;                  ///< value    (optional)
00089 static uint32_t cmd_result;                 ///< result
00090 
00091 // private functions
00092 uint8_t execute_bdm_cmd();
00093 
00094 void bdm_show_help();
00095 void bdm_show_full_help();
00096 
00097 // command argument macros
00098 #define CHECK_ARGLENGTH(len) \
00099     if (cmd_length != len + 2) \
00100         return TERM_ERR
00101 
00102 #define GET_NUMBER(target, offset, len)    \
00103     if (!ascii2int(target, cmd_buffer + 2 + offset, len)) \
00104         return TERM_ERR
00105 
00106 
00107 void bdm()
00108 {
00109 
00110     bdm_show_help();
00111     // set up LED pins
00112 //    SETBIT(LED_DIR, _BV(LED_ERR) | _BV(LED_ACT));
00113     // set up USB_RD and USB_WR pins
00114 //    SETBIT(USB_RXTX_DIR, _BV(USB_RD) | _BV(USB_WR));
00115 
00116     // enable interrupts
00117 //    sei();
00118 
00119     // load configuration from EEPROM
00120 //    verify_flash = eeprom_read_byte(&ee_verify);
00121 
00122 // Set some initial values to help with checking if the BDM connector is plugged in
00123     PIN_PWR.mode(PullDown);
00124     PIN_NC.mode(PullUp);
00125 //    PIN_DS.mode(PullUp);
00126     PIN_FREEZE.mode(PullUp);
00127     PIN_DSO.mode(PullUp);
00128 
00129     verify_flash = true;
00130 
00131     // main loop
00132     *cmd_buffer = '\0';
00133     char ret;
00134     char rx_char;
00135     while (true) {
00136         // read chars from USB
00137         if (pc.readable()) {
00138             // turn Error LED off for next command
00139             led4 = 0;
00140             rx_char = pc.getc();
00141             switch (rx_char) {
00142                     // 'ESC' key to go back to mbed Just4Trionic 'home' menu
00143                 case '\e':
00144                     reset_chip();
00145                     return;
00146                     // end-of-command reached
00147                 case TERM_OK :
00148                     // execute command and return flag via USB
00149                     ret = execute_bdm_cmd();
00150                     pc.putc(ret);
00151                     // reset command buffer
00152                     *cmd_buffer = '\0';
00153                     // light up LED
00154 //                    ret == TERM_OK ? led_on(LED_ACT) : led_on(LED_ERR);
00155                     ret == TERM_OK ? led3 = 1 : led4 = 1;
00156                     break;
00157                     // another command char
00158                 default:
00159                     // store in buffer if space permits
00160                     if (StrLen(cmd_buffer) < CMD_BUF_LENGTH - 1) {
00161                         StrAddc(cmd_buffer, rx_char);
00162                     }
00163                     break;
00164             }
00165         }
00166     }
00167 }
00168 
00169 //-----------------------------------------------------------------------------
00170 /**
00171     Executes a command and returns result flag (does not transmit the flag
00172     itself).
00173 
00174     @return                    command flag (success / failure)
00175 */
00176 uint8_t execute_bdm_cmd()
00177 {
00178     uint8_t cmd_length = strlen(cmd_buffer);
00179     char cmd = *(cmd_buffer + 1);
00180 
00181     // command groups
00182     switch (*cmd_buffer) {
00183             // adapter commands
00184         case CMDGROUP_ADAPTER:
00185             CHECK_ARGLENGTH(0);
00186             switch (cmd) {
00187                     // get firmware version
00188                 case CMD_VERSION:
00189                     printf("%02x", FW_VERSION_MAJOR);
00190                     printf("%02x", FW_VERSION_MINOR);
00191                     printf("\r\n");
00192                     return TERM_OK;
00193 
00194                     // get momentary status of BDM pins 0...5 (for debugging)
00195                 case CMD_PINSTATUS:
00196 //                    printf("%02x", (BDM_PIN & 0x3f));
00197                     printf("PWR %d, ", PIN_PWR.read());
00198                     printf("NC %d, ", PIN_NC.read());
00199 //                    printf("DS %d, ", PIN_DS.read());
00200                     printf("FREEZE %d, ", PIN_FREEZE.read());
00201                     printf("DSO %d, ", PIN_DSO.read());
00202                     printf("\r\n");
00203                     return TERM_OK;
00204 
00205                     // pull BKPT low
00206                 case CMD_BKPTLOW:
00207                     return bkpt_low();
00208 
00209                     // pull BKPT high
00210                 case CMD_BKPTHIGH:
00211                     return bkpt_high();
00212 
00213                     // pull RESET low
00214                 case CMD_RESETLOW:
00215                     return reset_low();
00216 
00217                     // pull RESET high
00218                 case CMD_RESETHIGH:
00219                     return reset_high();
00220 
00221                     // pull BERR low
00222                 case CMD_BERR_LOW:
00223                     return berr_low();
00224 
00225                     // pull BERR high
00226                 case CMD_BERR_HIGH:
00227                     return berr_high();
00228 
00229                     // make BERR an input
00230                 case CMD_BERR_INPUT:
00231                     return berr_input();
00232             }
00233             break;
00234 
00235             // MCU management
00236         case CMDGROUP_MCU:
00237             switch (cmd) {
00238                     // stop target MCU
00239                 case CMD_STOPCHIP:
00240                     return stop_chip();
00241 
00242                     // reset target MCU
00243                 case CMD_RESETCHIP:
00244                     return reset_chip();
00245 
00246                     // run target MCU from given address
00247                 case CMD_RUNCHIP:
00248                     CHECK_ARGLENGTH(8);
00249                     GET_NUMBER(&cmd_addr, 0, 8);
00250                     return run_chip(&cmd_addr);
00251 
00252                     // restart
00253                 case CMD_RESTART:
00254                     return restart_chip();
00255 
00256                     // step
00257                 case CMD_STEP:
00258                     return step_chip();
00259             }
00260             break;
00261 
00262             // Trionic dumping and flashing
00263         case CMDGROUP_FLASH:
00264             switch (cmd) {
00265                     // get verification flag
00266                 case CMD_GETVERIFY:
00267                     CHECK_ARGLENGTH(0);
00268                     printf("%02x", (uint8_t)verify_flash);
00269                     printf("\r\n");
00270                     return TERM_OK;
00271 
00272                     // set verification flag
00273                 case CMD_SETVERIFY:
00274                     CHECK_ARGLENGTH(2);
00275                     GET_NUMBER(&cmd_addr, 0, 2);
00276                     verify_flash = (bool)cmd_addr;
00277 //                    eeprom_write_byte(&ee_verify, verify_flash);
00278                     return TERM_OK;
00279 
00280                     // dump flash contents as block
00281                 case CMD_DUMP:
00282                     CHECK_ARGLENGTH(16);
00283                     GET_NUMBER(&cmd_addr, 0, 8);
00284                     GET_NUMBER(&cmd_value, 8, 8);
00285                     return dump_flash(&cmd_addr, &cmd_value);
00286 
00287                     // erase entire flash memory
00288                 case CMD_ERASE:
00289                     CHECK_ARGLENGTH(22);
00290                     GET_NUMBER(&cmd_addr, 6, 8);
00291                     GET_NUMBER(&cmd_value, 14, 8);
00292                     return erase_flash(cmd_buffer + 2, &cmd_addr, &cmd_value);
00293 
00294                     // write data block to flash memory
00295                 case CMD_WRITE:
00296                     CHECK_ARGLENGTH(14);
00297                     GET_NUMBER(&cmd_addr, 6, 8);
00298                     return write_flash(cmd_buffer + 2, &cmd_addr);
00299             }
00300             break;
00301 
00302             // memory
00303         case CMDGROUP_MEMORY:
00304             if (cmd != CMD_FILLBYTE && cmd != CMD_FILLWORD &&
00305                     cmd != CMD_FILLLONG && cmd != CMD_DUMPBYTE && cmd != CMD_DUMPWORD &&
00306                     cmd != CMD_DUMPLONG) {
00307                 // get memory address
00308                 if (cmd_length < 10 || !ascii2int(&cmd_addr, cmd_buffer + 2, 8)) {
00309                     // broken parametre
00310                     return TERM_ERR;
00311                 }
00312 
00313                 // get optional value
00314                 if (cmd_length > 10 &&
00315                         !ascii2int(&cmd_value, cmd_buffer + 10, cmd_length - 10)) {
00316                     // broken parametre
00317                     return TERM_ERR;
00318                 }
00319             }
00320 
00321             switch (cmd) {
00322                     // read byte
00323                 case CMD_READBYTE:
00324                     if (cmd_length != 10 ||
00325                             memread_byte((uint8_t*)(&cmd_result), &cmd_addr) != TERM_OK) {
00326                         return TERM_ERR;
00327                     }
00328                     printf("%02x", (uint8_t)cmd_result);
00329                     printf("\r\n");
00330                     return TERM_OK;
00331 
00332                     // read word
00333                 case CMD_READWORD:
00334                     if (cmd_length != 10 ||
00335                             memread_word((uint16_t*)(&cmd_result), &cmd_addr) != TERM_OK) {
00336                         return TERM_ERR;
00337                     }
00338                     printf("%04X", (uint16_t)cmd_result);
00339                     printf("\r\n");
00340                     return TERM_OK;
00341 
00342                     // read long word
00343                 case CMD_READLONG:
00344                     if (cmd_length != 10 ||
00345                             memread_long(&cmd_result, &cmd_addr) != TERM_OK) {
00346                         return TERM_ERR;
00347                     }
00348                     printf("%08X", cmd_result);
00349                     printf("\r\n");
00350                     return TERM_OK;
00351 
00352                     // dump byte
00353                 case CMD_DUMPBYTE:
00354                     if (cmd_length != 2 ||
00355                             memdump_byte((uint8_t*)(&cmd_result)) != TERM_OK) {
00356                         return TERM_ERR;
00357                     }
00358                     printf("%02x", (uint8_t)cmd_result);
00359                     printf("\r\n");
00360                     return TERM_OK;
00361 
00362                     // dump word
00363                 case CMD_DUMPWORD:
00364                     if (cmd_length != 2 ||
00365                             memdump_word((uint16_t*)(&cmd_result)) != TERM_OK) {
00366                         return TERM_ERR;
00367                     }
00368                     printf("%04X", (uint16_t)cmd_result);
00369                     printf("\r\n");
00370                     return TERM_OK;
00371 
00372                     // dump long word
00373                 case CMD_DUMPLONG:
00374                     if (cmd_length != 2 ||
00375                             memdump_long(&cmd_result) != TERM_OK) {
00376                         return TERM_ERR;
00377                     }
00378                     printf("%08X", cmd_result);
00379                     printf("\r\n");
00380                     return TERM_OK;
00381 
00382                     // write byte
00383                 case CMD_WRITEBYTE:
00384                     return (cmd_length == 12 &&
00385                             memwrite_byte(&cmd_addr, cmd_value) == TERM_OK) ?
00386                            TERM_OK : TERM_ERR;
00387 
00388                     // write word
00389                 case CMD_WRITEWORD:
00390                     return (cmd_length == 14 &&
00391                             memwrite_word(&cmd_addr, cmd_value) == TERM_OK) ?
00392                            TERM_OK : TERM_ERR;
00393 
00394                     // write long word
00395                 case CMD_WRITELONG:
00396                     return (cmd_length == 18 &&
00397                             memwrite_long(&cmd_addr, &cmd_value) == TERM_OK) ?
00398                            TERM_OK : TERM_ERR;
00399 
00400                     // fill byte
00401                 case CMD_FILLBYTE:
00402                     if (cmd_length != 4 || !ascii2int(&cmd_value, cmd_buffer + 2, 2)) {
00403                         return TERM_ERR;
00404                     }
00405                     return (memfill_byte(cmd_value));
00406 
00407                     // fill word
00408                 case CMD_FILLWORD:
00409                     if (cmd_length != 6 || !ascii2int(&cmd_value, cmd_buffer + 2, 4)) {
00410                         return TERM_ERR;
00411                     }
00412                     return (memfill_word(cmd_value));
00413 
00414                     // fill long word
00415                 case CMD_FILLLONG:
00416                     if (cmd_length != 10 || !ascii2int(&cmd_value, cmd_buffer + 2, 8)) {
00417                         return TERM_ERR;
00418                     }
00419                     return (memfill_long(&cmd_value));
00420             }
00421             break;
00422 
00423             // registers
00424         case CMDGROUP_REGISTER:
00425             // get register code
00426             if (cmd_length == 2) {
00427                 if (cmd != CMD_DISPLAYREGS) {
00428                     // broken parametre
00429                     printf("err %s line: %d, cmd_length %d\r\n", __FILE__, __LINE__, cmd_length);
00430                     return TERM_ERR;
00431                 }
00432             } else if (cmd_length < 4 || !ascii2int(&cmd_addr, cmd_buffer + 3, 1)) {
00433                 // broken parametre
00434                 printf("err %s line: %d, cmd_length %d\r\n", __FILE__, __LINE__, cmd_length);
00435                 return TERM_ERR;
00436             }
00437             // get optional value
00438             if (cmd_length > 4 && !ascii2int(&cmd_value, cmd_buffer + 4, 8)) {
00439                 // broken parametre
00440                 printf("err %s line: %d, cmd_length %d\r\n", __FILE__, __LINE__, cmd_length);
00441                 return TERM_ERR;
00442             }
00443 
00444             switch (cmd) {
00445                     // read system register
00446                 case CMD_READSYSREG:
00447                     if (cmd_length != 4 ||
00448                             sysreg_read(&cmd_result, (uint8_t)cmd_addr) != TERM_OK) {
00449                         printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00450                         return TERM_ERR;
00451                     }
00452                     printf("%08X", cmd_result);
00453                     printf("\r\n");
00454                     return TERM_OK;
00455 
00456                     // write system register
00457                 case CMD_WRITESYSREG:
00458                     return (cmd_length == 12 &&
00459                             sysreg_write((uint8_t)cmd_addr, &cmd_value) == TERM_OK) ?
00460                            TERM_OK : TERM_ERR;
00461 
00462                     // read A/D register
00463                 case CMD_READADREG:
00464                     if (cmd_length != 4 ||
00465                             adreg_read(&cmd_result, (uint8_t)cmd_addr) != TERM_OK) {
00466                         printf("err %s line: %d, cmd_length %d\r\n", __FILE__, __LINE__, cmd_length);
00467                         return TERM_ERR;
00468                     }
00469                     printf("%08X", cmd_result);
00470                     printf("\r\n");
00471                     return TERM_OK;
00472 
00473                     // write A/D register
00474                 case CMD_WRITEADREG:
00475                     return (cmd_length == 12 &&
00476                             adreg_write((uint8_t)cmd_addr, &cmd_value) == TERM_OK) ?
00477                            TERM_OK : TERM_ERR;
00478 
00479                     // Display all registers
00480                 case CMD_DISPLAYREGS:
00481                     printf(" Register Display\r\n");
00482                     printf(" D0-7");
00483                     for (uint8_t i = 0; i < 8; i++) {
00484                         if (adreg_read(&cmd_result, i) != TERM_OK) {
00485                             printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00486                             return TERM_ERR;
00487                         }
00488                         printf(" %08X", cmd_result);
00489                     }
00490 //
00491                     printf("\r\n");
00492                     printf(" A0-7");
00493                     for (uint8_t i = 8; i < 16; i++) {
00494                         if (adreg_read(&cmd_result, i) != TERM_OK) {
00495                             printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00496                             return TERM_ERR;
00497                         }
00498                         printf(" %08X", cmd_result);
00499                     }
00500                     printf("\r\n");
00501 //
00502                     if (sysreg_read(&cmd_result, 0x0) != TERM_OK) {
00503                         printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00504                         return TERM_ERR;
00505                     }
00506                     printf("  RPC %08X", cmd_result);
00507                     if (sysreg_read(&cmd_result, 0xC) != TERM_OK) {
00508                         printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00509                         return TERM_ERR;
00510                     }
00511                     printf("     USP %08X", cmd_result);
00512                     if (sysreg_read(&cmd_result, 0xE) != TERM_OK) {
00513                         printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00514                         return TERM_ERR;
00515                     }
00516                     printf("     SFC %08X      SR 10S--210---XNZVC\r\n", cmd_result);
00517 //
00518                     if (sysreg_read(&cmd_result, 0x1) != TERM_OK) {
00519 
00520                         printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00521                         return TERM_ERR;
00522                     }
00523                     printf("  CPC %08X", cmd_result);
00524                     if (sysreg_read(&cmd_result, 0xD) != TERM_OK) {
00525                         printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00526                         return TERM_ERR;
00527                     }
00528                     printf("     SSP %08X", cmd_result);
00529                     if (sysreg_read(&cmd_result, 0xF) != TERM_OK) {
00530                         printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00531                         return TERM_ERR;
00532                     }
00533                     printf("     DFC %08X", cmd_result);
00534                     if (sysreg_read(&cmd_result, 0xB) != TERM_OK) {
00535                         printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00536                         return TERM_ERR;
00537                     }
00538                     printf("    %04X ", cmd_result);
00539                     for (uint32_t i = 0; i < 16; i++) {
00540                         cmd_result & (1 << (15-i)) ? printf("1") : printf("0");
00541                     }
00542                     printf("\r\n");
00543 //
00544                     if (sysreg_read(&cmd_result, 0xA)!= TERM_OK) {
00545                         printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00546                         return TERM_ERR;
00547                     }
00548                     printf("  VBR %08X", cmd_result);
00549                     if (sysreg_read(&cmd_result, 0x8)!= TERM_OK) {
00550                         printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00551                         return TERM_ERR;
00552                     }
00553                     printf("   ATEMP %08X", cmd_result);
00554                     if (sysreg_read(&cmd_result, 0x9) != TERM_OK) {
00555                         printf("err %s line: %d\r\n", __FILE__, __LINE__ );
00556                         return TERM_ERR;
00557                     }
00558                     printf("     FAR %08X\r\n", cmd_result);
00559 //
00560                     printf(" !CONNNECTED:%d", PIN_NC.read());
00561                     printf(" POWER:%d", PIN_PWR.read());
00562                     printf(" !RESET:%d", PIN_RESET.read());
00563                     printf(" !BUSERR:%d", PIN_BERR.read());
00564                     printf(" BKPT/DSCLK:%d", PIN_BKPT.read());
00565                     printf(" FREEZE:%d", PIN_FREEZE.read());
00566                     printf(" DSO:%d", PIN_DSO.read());
00567                     printf(" DSI:%d", PIN_DSI.read());
00568                     printf("\r\n");
00569 //
00570                     return TERM_OK;
00571             }
00572             break;
00573 
00574             // Trionic dumping and flashing
00575         case CMDGROUP_TRIONIC:
00576 
00577             switch (cmd) {
00578 
00579                     // dump flash contents to a bin file
00580                 case CMD_TRIONICDUMP:
00581                     CHECK_ARGLENGTH(0);
00582                     return dump_trionic();
00583 
00584                     // write data block to flash memory
00585                 case CMD_TRIONICWRITE:
00586                     CHECK_ARGLENGTH(0);
00587                     return flash_trionic();
00588             }
00589 
00590             // show help for BDM commands
00591         case 'H':
00592             bdm_show_full_help();
00593             return TERM_OK;
00594         case 'h':
00595             bdm_show_help();
00596             return TERM_OK;
00597         default:
00598             bdm_show_help();
00599     }
00600 
00601 // unknown command
00602     return TERM_ERR;
00603 }
00604 
00605 void bdm_show_help()
00606 {
00607     printf("Just4Trionic BDM Command Menu\r\n");
00608     printf("=============================\r\n");
00609     printf("TD - and DUMP T5 FLASH BIN file\r\n");
00610     printf("TF - FLASH the update file to the T5\r\n");
00611 //    printf("TF - FLASH the update file to the T5 (and write SRAM)\r\n");
00612 //    printf("Tr - Read SRAM adaption (not done).\r\n");
00613 //    printf("Tw - Write SRAM adaptation (not done).\r\n");
00614     printf("\r\n");
00615     printf("'ESC' - Return to Just4Trionic Main Menu\r\n");
00616     printf("\r\n");
00617     printf("h  - Show this help menu\r\n");
00618     printf("\r\n");
00619     return;
00620 }
00621 void bdm_show_full_help()
00622 {
00623     printf("Just4Trionic BDM Command Menu\r\n");
00624     printf("=============================\r\n");
00625     printf("TD - and DUMP T5 FLASH BIN file\r\n");
00626     printf("TF - FLASH the update file to the T5\r\n");
00627 //    printf("TF - FLASH the update file to the T5 (and write SRAM)\r\n");
00628 //    printf("Tr - Read SRAM adaption (not done).\r\n");
00629 //    printf("Tw - Write SRAM adaptation (not done).\r\n");
00630     printf("\r\n");
00631     printf("Adapter Commands - a\r\n");
00632     printf("====================\r\n");
00633     printf("av - display firmware version\r\n");
00634     printf("as - display status of BDM pins\r\n");
00635     printf("a1 - pull BKPT low\r\n");
00636     printf("a2 - pull BKPT high\r\n");
00637     printf("a3 - pull RESET low\r\n");
00638     printf("a4 - pull RESET high\r\n");
00639     printf("a5 - pull BERR low\r\n");
00640     printf("a6 - pull BERR high\r\n");
00641     printf("a7 - make BERR an input\r\n");
00642     printf("\r\n");
00643     printf("MCU Management Commands - c\r\n");
00644     printf("===========================\r\n");
00645     printf("cS - stop MCU\r\n");
00646     printf("cR - reset MCU\r\n");
00647     printf("cr - run from given address\r\n");
00648     printf("     e.g. crCAFEBABE run from address 0xcafebabe\r\n");
00649     printf("cs - restart MCU\r\n");
00650     printf("cb - step MCU\r\n");
00651     printf("\r\n");
00652     printf("MCU FLASH Commands - f\r\n");
00653     printf("======================\r\n");
00654     printf("fv - gets verification status (always verify)\r\n");
00655     printf("fV - sets verification on/off (always on)\r\n");
00656     printf("fd - DUMPs memory contents\r\n");
00657     printf("     e.g. fdSSSSSSSSEEEEEEEE S...E... start and end addresses\r\n");
00658     printf("     e.g. fd0000000000020000 to DUMP T5.2\r\n");
00659     printf("     e.g. fd0000000000040000 to DUMP T5.5\r\n");
00660     printf("     e.g. fd0000000000080000 to DUMP T7\r\n");
00661     printf("fE - Erases entire FLASH memory\r\n");
00662     printf("     e.g. fETTTTTTSSSSSSSSEEEEEEEE T...S...E type, start and end addresses\r\n");
00663     printf("     e.g. fE28f0100000000000020000 erase 28F512 in T5.2\r\n");
00664     printf("     e.g. fE28f0100000000000040000 erase 28F010 in T5.5\r\n");
00665     printf("     e.g. fE29f0100000000000040000 erase 29F010 in T5.5 (addresses not used)\r\n");
00666     printf("     e.g. fE29f4000000000000080000 erase 29F400 in T7 (addresses not used)\r\n");
00667     printf("fw - writes to FLASH memory\r\n");
00668     printf("     Write a batch of long words to flash from a start address\r\n");
00669     printf("     followed by longwords LLLLLLLL, LLLLLLLL etc\r\n");
00670     printf("     Send a break character to stop when doneg");
00671     printf("     e.g. fwTTTTTTSSSSSSSS T...S... type and start address\r\n");
00672     printf("     e.g. fw28f01000004000 start at address 0x004000 T5.2/5.5\r\n");
00673     printf("     e.g. fw29f01000004000 start at address 0x004000 T5.5 with 29F010\r\n");
00674     printf("     e.g. fw29f40000004000 start at address 0x004000 T7\r\n");
00675     printf("\r\n");
00676     printf("MCU Memory Commands - m\r\n");
00677     printf("=======================\r\n");
00678     printf("mbAAAAAAAA - read byte from memory at 0xaaaaaaaa\r\n");
00679     printf("mwAAAAAAAA - read word (2 bytes) from memory\r\n");
00680     printf("mlAAAAAAAA - read long word (4 bytes) from memory\r\n");
00681     printf("mz - dump byte from the next memory address\r\n");
00682     printf("mx - dump word from the next memory address\r\n");
00683     printf("mc - dump long word from the next memory address\r\n");
00684     printf("mBAAAAAAAADD - write byte 0xdd to memory 0xaaaaaaaa\r\n");
00685     printf("mWAAAAAAAADDDD - write word 0xdddd to memory 0xaaaaaaaa\r\n");
00686     printf("mLAAAAAAAADDDDDDD - write long word 0xdddddddd to memory 0xaaaaaaaa\r\n");
00687     printf("mfDD - fill byte 0xdd to next memory address\r\n");
00688     printf("mFDDDD - fill word 0xdddd to next memory address\r\n");
00689     printf("mMDDDDDDDD - fill long word 0xdddddddd to next memory address\r\n");
00690     printf("\r\n");
00691     printf("MCU Register Commands - r\r\n");
00692     printf("=========================\r\n");
00693     printf("rd     Display all registers (like BD32)\r\n");
00694     printf("rrRR - read system register RR\r\n");
00695     printf("       00 - RPC, 01 - PCC, 0B - SR, 0C - USP, 0D - SSP\r\n");
00696     printf("       0e - SFC, 0f - DFC, 08 - ATEMP, 09 - FAR, 0a - VBR\r\n");
00697     printf("rWRRCAFEBABE - write 0xcafebabe system register RR\r\n");
00698     printf("raAD - read A/D register 0x00-07 D0-D7, 0x08-15 A0-A7\r\n");
00699     printf("rAADCAFEBABE - write 0xcafebabe to A/D register \r\n");
00700     printf("\r\n");
00701     printf("'ESC' - Return to Just4Trionic Main Menu\r\n");
00702     printf("\r\n");
00703     printf("H  - Show this help menu\r\n");
00704     printf("\r\n");
00705     return;
00706 }