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:
Fri Sep 27 14:48:17 2013 +0000
Revision:
38:cb95bfe0546a
Parent:
35:0b434ef4af49
Child:
39:f68f9fa1e88e
ver 0.97: ; can verify non 4*N size binary.; can write full 32768 bytes for LPC1114FN28, can write 4096 bytes for LPC810.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 24:9830b4f1207b 1 #include "mbed.h"
okano 24:9830b4f1207b 2 #include "verification.h"
okano 24:9830b4f1207b 3 #include "command_interface.h"
okano 24:9830b4f1207b 4 #include "uu_coding.h"
okano 24:9830b4f1207b 5 #include "serial_utilities.h"
okano 24:9830b4f1207b 6 #include "writing.h"
okano 30:e0d7524661ca 7 #include "isp.h"
okano 28:689c3880e0e4 8
okano 24:9830b4f1207b 9
okano 29:96e28bc1bd99 10 int verify_binary_data( FILE *fp, int *transferred_size_p );
okano 29:96e28bc1bd99 11 int verify_uucoded_data( FILE *fp, int *transferred_size_p );
okano 24:9830b4f1207b 12 void get_binary_from_uucode_str( char *b, int size );
okano 24:9830b4f1207b 13
okano 24:9830b4f1207b 14
okano 29:96e28bc1bd99 15 int verify_flash( FILE *fp, target_param *tpp, int *transferred_size_p )
okano 24:9830b4f1207b 16 {
okano 24:9830b4f1207b 17 if ( tpp->write_type == BINARY )
okano 29:96e28bc1bd99 18 return ( verify_binary_data( fp, transferred_size_p ) );
okano 24:9830b4f1207b 19 else
okano 29:96e28bc1bd99 20 return ( verify_uucoded_data( fp, transferred_size_p ) );
okano 24:9830b4f1207b 21 }
okano 24:9830b4f1207b 22
okano 24:9830b4f1207b 23
okano 29:96e28bc1bd99 24 int verify_binary_data( FILE *fp, int *read_size_p )
okano 24:9830b4f1207b 25 {
okano 24:9830b4f1207b 26 char command_str[ STR_BUFF_SIZE ];
okano 24:9830b4f1207b 27 int read_size = 0;
okano 24:9830b4f1207b 28 int size;
okano 24:9830b4f1207b 29 int flash_reading_size;
okano 24:9830b4f1207b 30 char *bf;
okano 24:9830b4f1207b 31 char *br;
okano 24:9830b4f1207b 32 int error_flag = 0;
okano 24:9830b4f1207b 33 unsigned long checksum = 0;
okano 24:9830b4f1207b 34 unsigned long checksum_count = 0;
okano 24:9830b4f1207b 35
okano 29:96e28bc1bd99 36
okano 24:9830b4f1207b 37 fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
okano 24:9830b4f1207b 38
okano 24:9830b4f1207b 39 flash_reading_size = 128;
okano 24:9830b4f1207b 40
okano 24:9830b4f1207b 41 if ( NULL == (bf = (char *)malloc( flash_reading_size * sizeof( char ) )) )
okano 28:689c3880e0e4 42 return( ERROR_AT_MALLOC_FOR_VERIFY_FILE_BUFF );
okano 24:9830b4f1207b 43
okano 24:9830b4f1207b 44 if ( NULL == (br = (char *)malloc( flash_reading_size * sizeof( char ) )) )
okano 28:689c3880e0e4 45 return( ERROR_AT_MALLOC_FOR_VERIFY_DATA_BUFF );
okano 24:9830b4f1207b 46
okano 24:9830b4f1207b 47
okano 24:9830b4f1207b 48 while ( size = fread( bf, sizeof( char ), flash_reading_size, fp ) ) {
okano 24:9830b4f1207b 49
okano 24:9830b4f1207b 50 if ( read_size < 0x20 ) {
okano 24:9830b4f1207b 51 for ( int i = 0; i < flash_reading_size; i += 4 ) {
okano 24:9830b4f1207b 52
okano 24:9830b4f1207b 53 if ( checksum_count == 7 ) {
okano 24:9830b4f1207b 54 checksum = 0xFFFFFFFF - checksum + 1;
okano 24:9830b4f1207b 55 *((unsigned int *)(bf + i)) = checksum;
okano 26:a63e73885b21 56 //printf( "\r\n\r\n -- calculated checksum : 0x%08X\r\n", checksum );
okano 24:9830b4f1207b 57 } else {
okano 24:9830b4f1207b 58 checksum += *((unsigned int *)(bf + i));
okano 24:9830b4f1207b 59 }
okano 26:a63e73885b21 60
okano 24:9830b4f1207b 61 checksum_count++;
okano 24:9830b4f1207b 62 }
okano 24:9830b4f1207b 63 }
okano 24:9830b4f1207b 64
okano 24:9830b4f1207b 65
okano 38:cb95bfe0546a 66 sprintf( command_str, "R %ld %ld\r\n", read_size, (size + 3) & ~0x3 ); // reading size must be 4*N
okano 35:0b434ef4af49 67 if ( try_and_check( command_str, "0" ) )
okano 27:2b5c1eb39bb5 68 return ( ERROR_AT_READ_COMMAND );
okano 24:9830b4f1207b 69
okano 24:9830b4f1207b 70 get_binary( br, 1 );
okano 24:9830b4f1207b 71 get_binary( br, size );
okano 24:9830b4f1207b 72
okano 24:9830b4f1207b 73 for ( int i = 0; i < size; i++ ) {
okano 24:9830b4f1207b 74 // printf( " %s 0x%02X --- 0x%02X\r\n", (*(bf + i) != *(br + i)) ? "***" : " ", *(bf + i), *(br + i) );
okano 24:9830b4f1207b 75 if ( (*(bf + i) != *(br + i)) ) {
okano 24:9830b4f1207b 76 // printf( " %s 0x%02X --- 0x%02X\r\n", (*(bf + i) != *(br + i)) ? "***" : " ", *(bf + i), *(br + i) );
okano 24:9830b4f1207b 77 error_flag++;
okano 24:9830b4f1207b 78 }
okano 24:9830b4f1207b 79 }
okano 24:9830b4f1207b 80
okano 24:9830b4f1207b 81 if ( error_flag )
okano 24:9830b4f1207b 82 break;
okano 26:a63e73885b21 83
okano 24:9830b4f1207b 84 read_size += size;
okano 24:9830b4f1207b 85 }
okano 26:a63e73885b21 86
okano 24:9830b4f1207b 87 free( bf );
okano 24:9830b4f1207b 88 free( br );
okano 24:9830b4f1207b 89
okano 29:96e28bc1bd99 90 *read_size_p = read_size;
okano 29:96e28bc1bd99 91
okano 27:2b5c1eb39bb5 92 return ( error_flag ? ERROR_DATA_DOES_NOT_MATCH : NO_ERROR );
okano 24:9830b4f1207b 93 }
okano 24:9830b4f1207b 94
okano 24:9830b4f1207b 95
okano 34:eaca33d3e632 96 #define LINE_BYTES 44
okano 34:eaca33d3e632 97 #define N_OF_LINES 4
okano 34:eaca33d3e632 98 #define READ_SIZE (LINE_BYTES * N_OF_LINES)
okano 34:eaca33d3e632 99
okano 34:eaca33d3e632 100
okano 29:96e28bc1bd99 101 int verify_uucoded_data( FILE *fp, int *read_size_p )
okano 24:9830b4f1207b 102 {
okano 24:9830b4f1207b 103 char command_str[ STR_BUFF_SIZE ];
okano 24:9830b4f1207b 104 int read_size = 0;
okano 24:9830b4f1207b 105 int size;
okano 24:9830b4f1207b 106 int flash_reading_size;
okano 24:9830b4f1207b 107 char *bf;
okano 24:9830b4f1207b 108 char *br;
okano 24:9830b4f1207b 109 int error_flag = 0;
okano 24:9830b4f1207b 110
okano 34:eaca33d3e632 111 flash_reading_size = READ_SIZE;
okano 24:9830b4f1207b 112
okano 24:9830b4f1207b 113 initialize_uud_table();
okano 24:9830b4f1207b 114
okano 24:9830b4f1207b 115 if ( NULL == (bf = (char *)malloc( flash_reading_size * sizeof( char ) )) )
okano 24:9830b4f1207b 116 error( "malloc error happened (in verify process, file data buffer)\r\n" );
okano 24:9830b4f1207b 117
okano 24:9830b4f1207b 118 if ( NULL == (br = (char *)malloc( flash_reading_size * sizeof( char ) )) )
okano 24:9830b4f1207b 119 error( "malloc error happened (in verify process, read data buffer)\r\n" );
okano 24:9830b4f1207b 120
okano 24:9830b4f1207b 121 fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
okano 24:9830b4f1207b 122
okano 24:9830b4f1207b 123 while ( size = fread( bf, sizeof( char ), flash_reading_size, fp ) ) {
okano 24:9830b4f1207b 124
okano 24:9830b4f1207b 125 if ( !read_size ) {
okano 24:9830b4f1207b 126 // overwriting 4 bytes data for address=0x1C
okano 24:9830b4f1207b 127 // there is a slot for checksum that is checked in (target's) boot process
okano 24:9830b4f1207b 128 add_isp_checksum( bf );
okano 24:9830b4f1207b 129 }
okano 24:9830b4f1207b 130
okano 38:cb95bfe0546a 131 sprintf( command_str, "R %ld %ld\r\n", read_size, (size + 3) & ~0x3 ); // reading size must be 4*N
okano 35:0b434ef4af49 132 if ( try_and_check( command_str, "0" ) )
okano 27:2b5c1eb39bb5 133 return ( ERROR_AT_READ_COMMAND );
okano 24:9830b4f1207b 134
okano 24:9830b4f1207b 135 get_binary_from_uucode_str( br, size );
okano 24:9830b4f1207b 136
okano 24:9830b4f1207b 137 for ( int i = 0; i < size; i++ ) {
okano 24:9830b4f1207b 138 // printf( " %s 0x%02X --- 0x%02X\r\n", (*(bf + i) != *(br + i)) ? "***" : " ", *(bf + i), *(br + i) );
okano 24:9830b4f1207b 139 if ( (*(bf + i) != *(br + i)) ) {
okano 38:cb95bfe0546a 140 // printf( " %s 0x%02X --- 0x%02X\r\n", (*(bf + i) != *(br + i)) ? "***" : " ", *(bf + i), *(br + i) );
okano 24:9830b4f1207b 141 error_flag++;
okano 24:9830b4f1207b 142 }
okano 24:9830b4f1207b 143 }
okano 24:9830b4f1207b 144
okano 24:9830b4f1207b 145 if ( error_flag )
okano 24:9830b4f1207b 146 break;
okano 26:a63e73885b21 147
okano 24:9830b4f1207b 148 read_size += size;
okano 24:9830b4f1207b 149 }
okano 24:9830b4f1207b 150
okano 24:9830b4f1207b 151 free( bf );
okano 24:9830b4f1207b 152 free( br );
okano 24:9830b4f1207b 153
okano 29:96e28bc1bd99 154 *read_size_p = read_size;
okano 29:96e28bc1bd99 155
okano 27:2b5c1eb39bb5 156 return ( error_flag ? ERROR_DATA_DOES_NOT_MATCH : NO_ERROR );
okano 24:9830b4f1207b 157 }
okano 24:9830b4f1207b 158
okano 24:9830b4f1207b 159
okano 24:9830b4f1207b 160 void get_binary_from_uucode_str( char *b, int size )
okano 24:9830b4f1207b 161 {
okano 34:eaca33d3e632 162 char s[ N_OF_LINES ][ STR_BUFF_SIZE ];
okano 24:9830b4f1207b 163 char ss[ STR_BUFF_SIZE ];
okano 24:9830b4f1207b 164 long checksum = 0;
okano 24:9830b4f1207b 165 int line_count = 0;
okano 24:9830b4f1207b 166 int read_size = 0;
okano 24:9830b4f1207b 167 int retry_count = 3;
okano 24:9830b4f1207b 168
okano 38:cb95bfe0546a 169 size = (size + 3) & ~0x3;
okano 24:9830b4f1207b 170
okano 24:9830b4f1207b 171 while ( retry_count-- ) {
okano 24:9830b4f1207b 172
okano 34:eaca33d3e632 173 for ( int i = 0; i < ((READ_SIZE < size) ? N_OF_LINES : ((size - 1) / LINE_BYTES) + 1) ; i++ )
okano 24:9830b4f1207b 174 get_string( s[ i ] );
okano 24:9830b4f1207b 175
okano 24:9830b4f1207b 176 get_string( ss );
okano 24:9830b4f1207b 177
okano 24:9830b4f1207b 178
okano 24:9830b4f1207b 179 while ( size ) {
okano 24:9830b4f1207b 180 read_size = uudecode_a_line( b, s[ line_count ] );
okano 24:9830b4f1207b 181
okano 24:9830b4f1207b 182 for ( int i = 0; i < read_size; i++ )
okano 24:9830b4f1207b 183 checksum += *b++;
okano 24:9830b4f1207b 184
okano 24:9830b4f1207b 185 size -= read_size;
okano 24:9830b4f1207b 186 line_count++;
okano 24:9830b4f1207b 187 }
okano 24:9830b4f1207b 188
okano 24:9830b4f1207b 189 // printf( " checksum -- %s (internal = %ld)\r\n", ss, checksum );
okano 24:9830b4f1207b 190
okano 24:9830b4f1207b 191 if ( checksum == atol( ss ) ) {
okano 24:9830b4f1207b 192 put_string( "OK\r\n" );
okano 24:9830b4f1207b 193 return;
okano 24:9830b4f1207b 194 // printf( " checksum OK\r\n" );
okano 24:9830b4f1207b 195 } else {
okano 24:9830b4f1207b 196 printf( " checksum RESEND\r\n" );
okano 24:9830b4f1207b 197 put_string( "RESEND\r\n" );
okano 24:9830b4f1207b 198 }
okano 24:9830b4f1207b 199 }
okano 24:9830b4f1207b 200 }