this transfers data (which is stored in "bin" file in mbed storage) into LPC1114, LPC1115, LPC81x, LPC82x, LPC1768/LPC1769 and LPC11U68/LPC11E68 internal flash memory through ISP.

Dependencies:   mbed MODSERIAL DirectoryList

Information

日本語版がこのページ下半分にあります!

Japanese version is available lower half of this page.

Caution!

このプログラムでイカを焼くことはできません (^ ^;

"Ika-shouyu-poppoyaki" is a name of Japanese local food.
If I try to do a direct translation, it will be something like "Choo-choo grilled calamari with soy-sauce".
However, you may noticed already, it cannot be grilled by this program ;-)

ISP programming application on mbed

ISP program writes data into flash memory of target MCU.

This mbed program programs target MCU flash memory through UART. It uses "In-System Programming (ISP)" interface in target MCU (NXP LPC micro-controllers).

The ISP is done by PC with serial cable normally. The ISP protocol is executed software on a PC. The software reads a data file and transfers the data with the ISP protocol.
This program does same process of that. The mbed performs a function like "FlashMagic" or "lpc21isp".
(This program does not just copy the binary but also insert 4 byte checksum at address 0x1C.)

This program currently supports LPC1114, LPC1115, LPC81x, LPC82x, LPC1768/LPC1769 and LPC11U68/LPC11E68.

Information

For the LPC1768 and LPC1769, this program supports writing only. It cannot perform verifying.

Modification for targeting LPC82x series has been done by Mr. k4zuki. Thank you very much!
Modification for targeting LPC11U68/LPC11E68 has been done by HAPI- Tech. Thank you very much!!

/media/uploads/okano/copying_bin_e.png

How to execute

With this program, all you need to do is..

  1. Connect the mbed and the target (/RESET and /ISP_enable signals in are option. Those are not necessary if you set the target ISP mode manually)
  2. Rename your (binary) file to "bin" and copy into the mbed storage.
  3. Press reset button of mbed.
  • When the program completed successfully, you will find the LEDs on mbed blinks sequentially (LED1→LED2→LED3→LED4).
  • If it failed, the mbed reports it "Runtime error" by LEDs.
  • You can also monitor the progress and result on a terminal screen (mbed reports those by printf).
  • if you enabled "AUTO_PROGRAM_START", the program in the target will be started automatically.
  • from version 0.7, this program works as "USB-serial bridge" after the ISP writing done. The serial enabled target program (and if "AUTO_PROGRAM_START" is enabled, ) the UART will come up on the terminal screen after ISP completion. Please set "TARGET_OPERATION_BAUD_RATE" as baud rate of target program. The ISP speed can be set by "ISP_BAUD_RATE" separately.

/media/uploads/okano/files_in_storage_e.png

Information

If you don't have a file named "bin", the program will ask you which file you want to choose.
You will find a list of files on PC terminal and that interface let you select a file as source.
(The file names will appear in 8.3 format like old DOS.)

There are some options to bypassing the ISP to execute USB-serial through mode or erasing flash.

If there is a "bin" file, the program may work as usual.
(updated on 29-Jan-2015)

Sample of operation

Next picture is sample of the operation.

  1. The target (LPC1114) goes into ISP mode after first reset.
  2. mbed writes binary into flash in the target (binary size is 12668 bytes in this sample).
  3. when the writing completed, mbed starts reading the flash. the data is verified by comparing with original file.
  4. Asserting reset again with "ISP_enable pin" HIGH.
  5. The target starts to work with written binary (program). In this sample, the target sending character data on UART and toggling LED (GPIO) pin periodically.

/media/uploads/okano/isp_operation_sample_1114_e2.png

Recipe for adding chip support

Information

This section had been written by At_Zamasu_Zansu.
Thank you!

Describing how to add a target device.
Register new Device ID in target_table.cpp.

Targets defined in target_table.cpp.

target_table.cpp

target_param    target_table[]  = {
    { "unknown ttarget",        0xFFFFFFFF, 1024,    4096, 4096, UUENCODE, 0x10000200 },
    { "LPC1114FN28(FDH28)/102", 0x0A40902B, 4096,   32768, 4096, UUENCODE, 0x10000200 },
    { "LPC1114FN28(FDH28)/102", 0x1A40902B, 4096,   32768, 4096, UUENCODE, 0x10000200 },
    { "LPC810M021FN8",          0x00008100, 1024,    4096, 1024, BINARY,   0x10000300 },
    { "LPC811M001JDH16",        0x00008110, 2048,    8192, 1024, BINARY,   0x10000300 },
    { "LPC812M101JDH16",        0x00008120, 4096,   16384, 1024, BINARY,   0x10000300 },
    { "LPC812M101JD20",         0x00008121, 4096,   16384, 1024, BINARY,   0x10000300 },
    { "LPC812M101JDH20",        0x00008122, 4096,   16384, 1024, BINARY,   0x10000300 },
///added for LPC82x series
    { "LPC824M201JHI33",        0x00008241, 8192,   32768, 1024, BINARY,   0x10000300 },
    { "LPC822M101JHI33",        0x00008221, 4096,   16384, 1024, BINARY,   0x10000300 },
    { "LPC824M201JDH20",        0x00008242, 8192,   32768, 1024, BINARY,   0x10000300 },
    { "LPC822M101JDH20",        0x00008222, 4096,   16384, 1024, BINARY,   0x10000300 },
 
};

Structure of the table is defined in target_table.h.

target_table.h

typedef struct  taget_param_st {
    char            *type_name;
    int             id;
    int             ram_size;
    int             flash_size;
    int             sector_size;
    int             write_type;
    unsigned int    ram_start_address;
}

Items are defined in order of next sample in target_table.cpp

 {type_name, id, ram_size, flash_size, sector_size, write_type, ram_start_address}

Sample of how to do this

Data can be found in usermanual(UM) and datasheet. An example following.

In case of LPC82xx
UM10800 LPC82x User manual http://www.nxp.com/documents/user_manual/UM10800.pdf
LPC82x Product data sheet http://www.nxp.com/documents/data_sheet/LPC82X.pdf

  • type_name:
    • Table 322. Part identification numbers can be found by searching in UM. Pick up a device from the Table 322.
  • id:
    • Put a Hex coding value in Table 322.
  • ram_size:
    • Put target RAM size which can be found in datasheet by searching "Ordering options". Find the RAM size in Table2 (in bytes)
  • flash_size:
    • Put target flash size from the Table 2.
      The size should be calculated as "1KB = 1024" bytes.
  • sector_size:
    • A description of "The size of a sector is 1 KB and the size of a page is 64 Byte. One sector contains 16 pages" can be found in 25.5 General description, UM. Pick up taeget sector size and put it into the table in bytes. In this case, it will be 1024.
    • In case of LPC176x, the secotr size is 4KB for first 16 sectors and rest are 32K. So it cannot be defined by single value. For this type of targets, prepare a special value for the sector size. The program calculates the size when this value is detected.
  • ram_start_address:
    • Put an address of example which can be found by searching "UART ISP Write to RAM command" or "Write to RAM" in UM

Reference




イカ醤油ポッポ焼き

mbed用ISPプログラム

NXP製のマイコンは,内部フラッシュメモリへのプログラムの書き込みをUART経由で行うことができます.
通常,この作業はPC上のソフトウェア(たとえば"FlashMagic""lpc21isp"など)を用いて,PC上のファイルのデータを,UARTで接続したマイコンの内蔵フラッシュに書き込みます.

「イカ醤油ポッポ焼き」はmbedでそれらのソフトの代わりをさせるものです.mbedストレージ内に置いた「bin」と名付けられたファイルを読み,フラッシュへ書き込みます.
この書き込みを行う際には,アドレス0x1Cに置いておく必要のある4バイトのチェックサムも自動で追加されます.

現在サポートしているターゲットはLPC1114LPC1115LPC81xLPC82xLPC1768/LPC1769LPC11U68/LPC11E68です.

Information

LPC1768 and LPC1769 では書き込みのみがサポートされます.読み出し検証は実行されません.

LPC82xシリーズをターゲットとするための変更k4zukiさんがしてくださいました.ありがとうございます!
LPC11U68/LPC11E68をターゲットとするための変更HAPI- Techさんがしてくださいました.ありがとうございます!

/media/uploads/okano/copying_bin_j.png

美味しい料理法

このプログラムの動かし方は次の通り

  1. mbedとターゲット(書き込み対象のマイコン)を接続する (ターゲットを手動でISPモードに入れる場合には,/RESET と /ISP_enable は接続する必要はありません)
  2. 書き込みたいファイル(バイナリフォーマット)の名前を「bin」に変更して,mbed内にコピー
  3. mbedのリセットボタンを押す
  • 書き込みが無事に終了するとmbed上のLEDが順番に点滅を繰り返します(LED1→LED2→LED3→LED4).
  • もし何らかのエラーが発生して失敗した場合には"Runtime error"が発生した時のLED点灯となります.
  • またコンピュータのターミナルで状況や結果を確認することもできます(mbedがprintfで状況を出力しています)
  • "AUTO_PROGRAM_START"を有効にしてあれば,書き込み終了後,ターゲットのプログラムは自動的にスタートします.
  • バージョン0.7以降,このプログラムはISP書き込みの終了後にUSB-Serialブリッジとして動作するようにしてあります.ターゲットのプログラムがシリアルを使うもので(かつ"AUTO_PROGRAM_START"が有効で)あれば,入出力はそのままISP完了後のターミナルに現れます."TARGET_OPERATION_BAUD_RATE"はターゲットのプログラムが使うボーレートに合わせてください.ISPの書き込みに使うボーレートは "これとは別に"ISP_BAUD_RATE"で指定することができます.

/media/uploads/okano/files_in_storage_j2.png

Information

もし「bin」と名付けられたファイルが見つからなければ,(PCターミナル上で)どのファイルを選択するかが訊ねられます.
その表示を確認して,どのファイルを書き込むのかを選択してください.
「bin」ファイルが有れば,これまでと同じように動作します.(ファイル名はDOSのような8.3フォーマットで表示されます)

この他,ISPをバイパスしてシリアススルー・モードに行ったり,フラッシュを消すだけという操作も可能になっています.

(2015年1月29日にアップデートされました)

動作の例

次の図は動作の例です

  1. 最初のリセットによってターゲット(LPC1114)がISPモードに入ります
  2. mbedがターゲットのフラッシュにバイナリを書き込みます(この例では12668バイトのバイナリを書いています)
  3. 書き込みが終わるとフラッシュの読み出しを始めます.このデータを元のファイルとの比較し,検証を行います
  4. ISPイネーブル・ピンをHIGHにして再度リセットを行います
  5. ターゲットは書き込まれたプログラムの実行を開始します.この例ではターゲットは周期的にUARTへ文字データを送り,LEDを(GPIOピン)を点滅させます
  6. The target starts to work with written binary (program). The target sending character data on UART and toggling LED (GPIO) pin periodically.

/media/uploads/okano/isp_operation_sample_1114_j2.png


イカ醤油ポッポ焼き味付けレシピ

Information

この節はざますざんすさんが作成してくれました.
ありがとうございます!

これは,イカ醤油ポッポ焼きに新しいターゲットデバイスを追加する場合のレシピを纏めたものです.

必要事項:target_table.cpp へ新しいDevice ID register を追加する.

target_table.cppに記載されているターゲット一覧.

target_table.cpp

target_param    target_table[]  = {
    { "unknown ttarget",        0xFFFFFFFF, 1024,    4096, 4096, UUENCODE, 0x10000200 },
    { "LPC1114FN28(FDH28)/102", 0x0A40902B, 4096,   32768, 4096, UUENCODE, 0x10000200 },
    { "LPC1114FN28(FDH28)/102", 0x1A40902B, 4096,   32768, 4096, UUENCODE, 0x10000200 },
    { "LPC810M021FN8",          0x00008100, 1024,    4096, 1024, BINARY,   0x10000300 },
    { "LPC811M001JDH16",        0x00008110, 2048,    8192, 1024, BINARY,   0x10000300 },
    { "LPC812M101JDH16",        0x00008120, 4096,   16384, 1024, BINARY,   0x10000300 },
    { "LPC812M101JD20",         0x00008121, 4096,   16384, 1024, BINARY,   0x10000300 },
    { "LPC812M101JDH20",        0x00008122, 4096,   16384, 1024, BINARY,   0x10000300 },
///added for LPC82x series
    { "LPC824M201JHI33",        0x00008241, 8192,   32768, 1024, BINARY,   0x10000300 },
    { "LPC822M101JHI33",        0x00008221, 4096,   16384, 1024, BINARY,   0x10000300 },
    { "LPC824M201JDH20",        0x00008242, 8192,   32768, 1024, BINARY,   0x10000300 },
    { "LPC822M101JDH20",        0x00008222, 4096,   16384, 1024, BINARY,   0x10000300 },
 
};

上記コードは以下の構造を取っている.target_table.h に以下のコードがある.

target_table.h

typedef struct  taget_param_st {
    char            *type_name;
    int             id;
    int             ram_size;
    int             flash_size;
    int             sector_size;
    int             write_type;
    unsigned int    ram_start_address;
}

以下の順番にtarget_table.cppにコーディングする.

 {type_name, id, ram_size, flash_size, sector_size, write_type, ram_start_address}

作業の手順例

データはユーザマニュアル(UM)と Data sheet から検索する.以下に例を上げる.

LPC82xxの場合
UM10800 LPC82x User manual http://www.nxp.com/documents/user_manual/UM10800.pdf
LPC82x Product data sheet http://www.nxp.com/documents/data_sheet/LPC82X.pdf

  • type_name:
    • UMから Part identification numbers を検索すると,Table 322. Part identification numbersが現れる.Table 322より Table記載のDeviceを入力.
  • id:
    • UMから Part identification numbers を検索,Table 322. よりHex codingを入力.
  • ram_size:
    • Product data sheet よりOrdering options を検索しTable2より上記Deviceと同じターゲットのRAMサイズを記載(byte)
  • flash_size:
    • Product data sheet よりOrdering options を検索しTable2より上記Deviceと同じターゲットのFlashサイズを記載(byte)
      尚,1KBは1024byteにて計算
  • sector_size:
    • UMから Flash configuration を検索し25.5 General description に「The size of a sector is 1 KB and the size of a page is 64 Byte. One sector contains 16 pages.」と記載があるので,ターゲットのSectorサイズを記載(byte単位).今回の場合は1KBなので1024byte.
    • LPC176xシリーズのセクタサイズは,最初の16セクタが4KB,残りを32KBとしているため一定の値では表せません.これに対応するため特別な値を用意して,プログラム内でその値を検出した際には実際の構成に則した計算を行うようにしています.
  • ram_start_address:
    • UMからUART ISP Write to RAM command もしくは Write to RAM を検索.Example に書いてあるアドレスを記載する.

参考

日本語版だけの(何の役にも立たない)参考情報

Information

何故このプログラムが作られたか.そして何故こんな名前なのか.
こちらを御覧ください →→ イカ醤油ポッポ焼きはイカにして生まれたか(´(ェ)`;

このプログラムを作ってみるきっかけになったツイート.

(´(ェ)`)

Committer:
okano
Date:
Tue Nov 19 23:53:20 2013 +0000
Revision:
41:74b9ff21098f
Parent:
39:f68f9fa1e88e
Child:
44:568799eac6df
enabled to handle <0x300 (768) bytes data file

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 30:e0d7524661ca 1
okano 30:e0d7524661ca 2 #include "mbed.h"
okano 30:e0d7524661ca 3 #include "target_table.h"
okano 30:e0d7524661ca 4 #include "serial_utilities.h"
okano 30:e0d7524661ca 5 #include "command_interface.h"
okano 30:e0d7524661ca 6 #include "writing.h"
okano 30:e0d7524661ca 7 #include "uu_coding.h"
okano 30:e0d7524661ca 8 #include "target_handling.h"
okano 30:e0d7524661ca 9 #include "verification.h"
okano 30:e0d7524661ca 10 #include "isp.h"
okano 30:e0d7524661ca 11 #include "_user_settings.h"
okano 30:e0d7524661ca 12
okano 41:74b9ff21098f 13 #define CRP_WORD_OFFSET 0x2FC
okano 41:74b9ff21098f 14
okano 30:e0d7524661ca 15
okano 30:e0d7524661ca 16 BusOut leds( LED4, LED3, LED2, LED1 );
okano 30:e0d7524661ca 17 Ticker success;
okano 30:e0d7524661ca 18
okano 30:e0d7524661ca 19
okano 32:3700d5df4e18 20 int file_size( FILE *fp );
okano 33:ce9fff4cbf09 21 unsigned int read_crp( FILE *fp );
okano 32:3700d5df4e18 22 unsigned int crp_check( FILE *fp );
okano 32:3700d5df4e18 23 void success_indicator();
okano 30:e0d7524661ca 24
okano 33:ce9fff4cbf09 25
okano 30:e0d7524661ca 26 int isp_flash_write( char *file_name )
okano 30:e0d7524661ca 27 {
okano 30:e0d7524661ca 28 FILE *fp;
okano 30:e0d7524661ca 29 target_param *tpp;
okano 30:e0d7524661ca 30 int data_size;
okano 30:e0d7524661ca 31 int last_sector;
okano 30:e0d7524661ca 32 int transferred_size;
okano 30:e0d7524661ca 33 int err;
okano 30:e0d7524661ca 34
okano 30:e0d7524661ca 35 if ( NULL == (tpp = open_target( ISP_BAUD_RATE )) ) {
okano 30:e0d7524661ca 36 return ( ERROR_AT_TARGET_OPEN );
okano 30:e0d7524661ca 37 }
okano 30:e0d7524661ca 38
okano 30:e0d7524661ca 39 printf( " target device found : type = \"%s\"\r\n", tpp->type_name );
okano 39:f68f9fa1e88e 40 printf( " ID = 0x%08X\r\n", tpp->id );
okano 39:f68f9fa1e88e 41 printf( " RAM size = %10d bytes\r\n", tpp->ram_size );
okano 39:f68f9fa1e88e 42 printf( " flash size = %10d bytes\r\n", tpp->flash_size );
okano 30:e0d7524661ca 43
okano 30:e0d7524661ca 44 printf( " opening file: \"%s\"\r\n", file_name );
okano 30:e0d7524661ca 45
okano 30:e0d7524661ca 46 if ( NULL == (fp = fopen( file_name, "rb" )) ) {
okano 30:e0d7524661ca 47 return ( ERROR_AT_FILE_OPEN );
okano 30:e0d7524661ca 48 }
okano 30:e0d7524661ca 49
okano 30:e0d7524661ca 50 data_size = file_size( fp );
okano 41:74b9ff21098f 51
okano 38:cb95bfe0546a 52 if ( !data_size )
okano 38:cb95bfe0546a 53 return ( ERROR_DATA_SIZE_ZERO );
okano 41:74b9ff21098f 54
okano 38:cb95bfe0546a 55 last_sector = (data_size - 1) / tpp->sector_size;
okano 33:ce9fff4cbf09 56
okano 41:74b9ff21098f 57 if ( data_size < (CRP_WORD_OFFSET + sizeof( unsigned int )) ) {
okano 41:74b9ff21098f 58 printf( " CRP check is not performed because data size is less than 0x300(768) bytes\r\n" );
okano 41:74b9ff21098f 59 } else {
okano 41:74b9ff21098f 60 if ( crp_check( fp ) ) {
okano 41:74b9ff21098f 61 printf( " the CRP is enabled in the data source file\r\n" );
okano 33:ce9fff4cbf09 62
okano 33:ce9fff4cbf09 63 #ifdef CHECK_CRP_CODE
okano 41:74b9ff21098f 64 printf( " aborting execution by CRP warning\r\n" );
okano 33:ce9fff4cbf09 65
okano 41:74b9ff21098f 66 return ( WARNING_CRP_CODE_DETECTED );
okano 33:ce9fff4cbf09 67 #else
okano 41:74b9ff21098f 68 printf( " this program continues to write the CRP enabled binary into the target flash\r\n" );
okano 33:ce9fff4cbf09 69 #endif
okano 41:74b9ff21098f 70 }
okano 32:3700d5df4e18 71 }
okano 30:e0d7524661ca 72
okano 30:e0d7524661ca 73 printf( " data size = %d bytes, it takes %d secotrs in flash area\r\n", data_size, last_sector + 1 );
okano 30:e0d7524661ca 74 printf( " resetting target\r\n" );
okano 30:e0d7524661ca 75
okano 34:eaca33d3e632 76
okano 34:eaca33d3e632 77 #ifdef ENABLE_WRITING
okano 30:e0d7524661ca 78 if ( erase_sectors( last_sector ) )
okano 30:e0d7524661ca 79 return ( ERROR_AT_SECTOR_ERASE );
okano 30:e0d7524661ca 80
okano 30:e0d7524661ca 81 printf( "\r\n ==== flash writing ====\r\n" );
okano 30:e0d7524661ca 82
okano 30:e0d7524661ca 83 if ( err = write_flash( fp, tpp, &transferred_size ) )
okano 30:e0d7524661ca 84 return ( err );
okano 30:e0d7524661ca 85
okano 30:e0d7524661ca 86 printf( " -- %d bytes data are written\r\n", transferred_size );
okano 34:eaca33d3e632 87 leds_off();
okano 34:eaca33d3e632 88 #else
okano 34:eaca33d3e632 89 printf( "\r\n ==== writing is disabled ====\r\n\r\n" );
okano 34:eaca33d3e632 90 #endif
okano 34:eaca33d3e632 91
okano 30:e0d7524661ca 92
okano 33:ce9fff4cbf09 93 #ifdef ENABLE_VERIFYING
okano 30:e0d7524661ca 94 printf( "\r\n ==== flash reading and verifying ====\r\n" );
okano 30:e0d7524661ca 95
okano 30:e0d7524661ca 96 if ( err = verify_flash( fp, tpp, &transferred_size ) )
okano 30:e0d7524661ca 97 return ( err );
okano 30:e0d7524661ca 98
okano 30:e0d7524661ca 99 printf( " -- %d bytes data are read and verified\r\n", transferred_size );
okano 34:eaca33d3e632 100 leds_off();
okano 33:ce9fff4cbf09 101 #else
okano 33:ce9fff4cbf09 102 printf( "\r\n ==== verifying has been skipped ====\r\n\r\n" );
okano 33:ce9fff4cbf09 103 #endif
okano 30:e0d7524661ca 104
okano 34:eaca33d3e632 105
okano 30:e0d7524661ca 106 fclose( fp );
okano 30:e0d7524661ca 107
okano 30:e0d7524661ca 108 post_writing_process( tpp );
okano 30:e0d7524661ca 109
okano 30:e0d7524661ca 110 return ( 0 );
okano 30:e0d7524661ca 111 }
okano 30:e0d7524661ca 112
okano 30:e0d7524661ca 113
okano 30:e0d7524661ca 114 int file_size( FILE *fp )
okano 30:e0d7524661ca 115 {
okano 30:e0d7524661ca 116 int size;
okano 30:e0d7524661ca 117
okano 30:e0d7524661ca 118 fseek( fp, 0, SEEK_END ); // seek to end of file
okano 41:74b9ff21098f 119 size = ftell( fp ); // get current file pointer
okano 30:e0d7524661ca 120 fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
okano 30:e0d7524661ca 121
okano 30:e0d7524661ca 122 return size;
okano 30:e0d7524661ca 123 }
okano 30:e0d7524661ca 124
okano 30:e0d7524661ca 125
okano 32:3700d5df4e18 126 unsigned int crp_check( FILE *fp )
okano 32:3700d5df4e18 127 {
okano 32:3700d5df4e18 128 unsigned int crp;
okano 32:3700d5df4e18 129
okano 33:ce9fff4cbf09 130 switch ( crp = read_crp( fp ) ) {
okano 33:ce9fff4cbf09 131 case NO_ISP :
okano 33:ce9fff4cbf09 132 printf( "\r\n WARNING : CRP code detected 0x%08X (NO_ISP)\r\n", crp );
okano 33:ce9fff4cbf09 133 break;
okano 33:ce9fff4cbf09 134 case CRP1 :
okano 33:ce9fff4cbf09 135 printf( "\r\n WARNING : CRP code detected 0x%08X (CRP1)\r\n", crp );
okano 33:ce9fff4cbf09 136 break;
okano 33:ce9fff4cbf09 137 case CRP2 :
okano 33:ce9fff4cbf09 138 printf( "\r\n WARNING : CRP code detected 0x%08X (CRP2)\r\n", crp );
okano 33:ce9fff4cbf09 139 break;
okano 33:ce9fff4cbf09 140 case CRP3 :
okano 33:ce9fff4cbf09 141 printf( "\r\n WARNING : CRP code detected 0x%08X (CRP3)\r\n", crp );
okano 33:ce9fff4cbf09 142 break;
okano 33:ce9fff4cbf09 143 default :
okano 33:ce9fff4cbf09 144 crp = 0x0; // no CRP code detected
okano 33:ce9fff4cbf09 145 break;
okano 33:ce9fff4cbf09 146 }
okano 41:74b9ff21098f 147
okano 33:ce9fff4cbf09 148 return ( crp );
okano 33:ce9fff4cbf09 149 }
okano 33:ce9fff4cbf09 150
okano 33:ce9fff4cbf09 151
okano 33:ce9fff4cbf09 152 unsigned int read_crp( FILE *fp )
okano 33:ce9fff4cbf09 153 {
okano 33:ce9fff4cbf09 154 unsigned int crp;
okano 33:ce9fff4cbf09 155
okano 41:74b9ff21098f 156 fseek( fp, CRP_WORD_OFFSET, SEEK_SET ); // seek to 0x2FC (764th byte)
okano 32:3700d5df4e18 157
okano 32:3700d5df4e18 158 if ( 1 != fread( &crp, sizeof( crp ), 1, fp ) )
okano 32:3700d5df4e18 159 return ( CRP_CHECK_ERROR );
okano 32:3700d5df4e18 160
okano 32:3700d5df4e18 161 fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
okano 32:3700d5df4e18 162
okano 32:3700d5df4e18 163 return ( crp );
okano 32:3700d5df4e18 164 }
okano 32:3700d5df4e18 165
okano 32:3700d5df4e18 166
okano 30:e0d7524661ca 167 void start_target_in_normal_mode( int baud_rate )
okano 30:e0d7524661ca 168 {
okano 30:e0d7524661ca 169 set_target_baud_rate( baud_rate );
okano 30:e0d7524661ca 170 reset_target( NO_ISP_MODE );
okano 30:e0d7524661ca 171 }
okano 30:e0d7524661ca 172
okano 30:e0d7524661ca 173 void start_success_indicator( void )
okano 30:e0d7524661ca 174 {
okano 30:e0d7524661ca 175 success.attach( &success_indicator, 0.1 );
okano 30:e0d7524661ca 176 }
okano 30:e0d7524661ca 177
okano 30:e0d7524661ca 178 void success_indicator()
okano 30:e0d7524661ca 179 {
okano 30:e0d7524661ca 180 static int i = 0;
okano 30:e0d7524661ca 181
okano 30:e0d7524661ca 182 leds = 0x1 << (i++ & 0x3);
okano 30:e0d7524661ca 183 }
okano 30:e0d7524661ca 184
okano 30:e0d7524661ca 185
okano 30:e0d7524661ca 186 void toggle_led( char v )
okano 30:e0d7524661ca 187 {
okano 30:e0d7524661ca 188 leds = leds ^ (0x1 << v);
okano 30:e0d7524661ca 189 }
okano 30:e0d7524661ca 190
okano 34:eaca33d3e632 191
okano 34:eaca33d3e632 192 void leds_off( void )
okano 34:eaca33d3e632 193 {
okano 34:eaca33d3e632 194 leds = 0x0;
okano 34:eaca33d3e632 195 }