JP2008165729A - Microcomputer - Google Patents

Microcomputer Download PDF

Info

Publication number
JP2008165729A
JP2008165729A JP2007200839A JP2007200839A JP2008165729A JP 2008165729 A JP2008165729 A JP 2008165729A JP 2007200839 A JP2007200839 A JP 2007200839A JP 2007200839 A JP2007200839 A JP 2007200839A JP 2008165729 A JP2008165729 A JP 2008165729A
Authority
JP
Japan
Prior art keywords
rewrite
memory
program
partial
area
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
JP2007200839A
Other languages
Japanese (ja)
Other versions
JP4743182B2 (en
Inventor
Masahiro Kamiya
政裕 神谷
Kiyouichi Suzuki
亨市 鈴木
Naoki Ito
直紀 伊藤
Hideaki Ishihara
秀昭 石原
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Denso Corp
Original Assignee
Denso Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Denso Corp filed Critical Denso Corp
Priority to JP2007200839A priority Critical patent/JP4743182B2/en
Priority to US12/000,001 priority patent/US7934050B2/en
Publication of JP2008165729A publication Critical patent/JP2008165729A/en
Application granted granted Critical
Publication of JP4743182B2 publication Critical patent/JP4743182B2/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

<P>PROBLEM TO BE SOLVED: To provide a microcomputer, capable of restarting a rewrite program without performing mode switching through an external terminal in the event of a rewriting failure of a nonvolatile memory. <P>SOLUTION: When a CPU of the microcomputer executes the rewrite program, the FLASH status 0 of a flash memory is cleared prior to rewriting of all areas of the flash memory, and a rewrite completion code is finally written to the FLASH status 0. When the CPU executes a determination program, the FLASH status 0 of the flash memory is read first (step S1). When the data is not matched with the rewrite completion code (NO), the CPU confirms that reading data of ID statuses 2_1 and 2_2 is matched with an ID code (step S5: YES), and then executes the rewrite program again. <P>COPYRIGHT: (C)2008,JPO&INPIT

Description

本発明は、アプリケーションプログラムが記憶される書換え可能な不揮発性の第1メモリの書換えを、オンボード若しくはオンチップ上で実行可能に構成されるマイクロコンピュータに関する。   The present invention relates to a microcomputer configured to be able to execute rewriting of a rewritable nonvolatile first memory in which an application program is stored on board or on chip.

図12は、車両制御用のECU(Electronic Control Unit)を示すものである。ECU1は、基板2上にマイクロコンピュータ3やその他の図示しない周辺回路が搭載されて構成されている。そのマイコン3の制御プログラムは、フラッシュメモリ4のように書換え可能な不揮発性メモリに格納されている場合がある。そして、CPU5により実行されるフラッシュメモリ4上の制御プログラムは、デバッグやバージョンアップのため必要に応じて書換えを行うようにしている。   FIG. 12 shows an ECU (Electronic Control Unit) for vehicle control. The ECU 1 is configured by mounting a microcomputer 3 and other peripheral circuits (not shown) on a substrate 2. The control program for the microcomputer 3 may be stored in a rewritable nonvolatile memory such as the flash memory 4. The control program on the flash memory 4 executed by the CPU 5 is rewritten as necessary for debugging and version upgrade.

フラッシュメモリ4の書換えを行う場合は、マイコン3を書換え用のモードに設定してリセットすることで、例えばマイコン3上のROM6に格納されている書換え用プログラムを起動し、CPU5が図示しない外部の書換え装置より転送されたデータを書き込む。例えば、特許文献1には、上記のようなフラッシュメモリの書換えに関する技術が開示されている。
特開2000−20178号公報
When the flash memory 4 is rewritten, the microcomputer 3 is set to a rewriting mode and reset to start a rewriting program stored in the ROM 6 on the microcomputer 3, for example, and the CPU 5 is connected to an external device (not shown). Write the data transferred from the rewrite device. For example, Patent Document 1 discloses a technique related to rewriting of the flash memory as described above.
JP 2000-20178 A

ところで、マイコンに対して外部よりリセットをかけることが可能な構成であれば、フラッシュメモリの書換えを行っている途中に電源電圧が低下したり、書換え装置との間の通信線が断線するなどして書換えが失敗しても、マイコンをリセットすることで書換え用プログラムを起動し、同じ手順を繰り返すことで書換えを再試行すれば良い。
しかしながら、フィールドにおいて実際にECUが動作している場合は外部よりリセット制御を行う必要はないことから、リセットを行うための端子を余分に設けるのは冗長であり、コストの増大に繋がる。そこで、ECUについてはパワーオンリセットのみが作用するように構成するのが好ましい。
By the way, if the microcomputer can be reset from the outside, the power supply voltage drops while the flash memory is being rewritten, or the communication line to the rewrite device is disconnected. Even if rewriting fails, it is sufficient to start the rewriting program by resetting the microcomputer and retry the rewriting by repeating the same procedure.
However, when the ECU is actually operating in the field, it is not necessary to perform reset control from the outside. Therefore, providing an extra terminal for resetting is redundant, leading to an increase in cost. Therefore, it is preferable to configure the ECU so that only the power-on reset acts.

そして、ECUは、フィールドでは車両のバッテリからの電源供給を常時受けている状態にあるため、基本的にパワーオンリセットが発生することもない。また、リセットが発生しなければ、マイコンの動作モードを「書換えモード」等に切換える機会もないことから、モード切替え用の端子も不要となるはずである。
ところが、上記のような構成を想定すると、フラッシュメモリの書換えが途中で失敗すると書換えプログラムを起動する手段がなくなるため、フラッシュメモリの書換えを再度行うことができなくなってしまう。
And since ECU is in the state which always receives the power supply from the battery of a vehicle in a field, a power-on reset does not generate | occur | produce fundamentally. Further, if no reset occurs, there is no opportunity to switch the operation mode of the microcomputer to “rewrite mode” or the like, so that a terminal for mode switching should be unnecessary.
However, assuming the configuration as described above, if rewriting of the flash memory fails in the middle, there is no means for starting the rewriting program, so that rewriting of the flash memory cannot be performed again.

例えば、ECUがフラッシュメモリに書き込まれているアプリケーションプログラムを実行している通常動作状態で、外部の書込み装置より書換え指令が与えられたことを認識して書換えプログラムを起動すれば、1回は書換えを行うことができる。しかし、上記の書換えが途中で失敗すれば、それ以降アプリケーションプログラムは正常に実行されなくなるので、ECU上のCPUは書換え指令を認識することもできなくなる。従って、実際にはマイコンの端子数を減らすことが困難であった。   For example, in the normal operation state where the ECU is executing the application program written in the flash memory, if the rewriting program is started upon recognizing that the rewriting command is given from the external writing device, the rewriting is performed once. It can be performed. However, if the above rewriting fails midway, the application program will not be executed normally thereafter, and the CPU on the ECU will not be able to recognize the rewriting command. Therefore, it was actually difficult to reduce the number of terminals of the microcomputer.

本発明は上記事情に鑑みてなされたものであり、その目的は、不揮発性メモリの書換えが失敗した場合に、外部端子を介してモード切替えを行わずとも書換えプログラムを再起動できるマイクロコンピュータを提供することにある。   The present invention has been made in view of the above circumstances, and an object thereof is to provide a microcomputer capable of restarting a rewriting program without switching modes via an external terminal when rewriting of a nonvolatile memory fails. There is to do.

請求項1記載のマイクロコンピュータによれば、CPUにより書換えプログラムが実行されると、最初に第1メモリの書換えチェック領域をクリアしてから当該メモリの全領域の書換えを行ない、最後に書換えチェック領域に書換え完了コードを書込む。そして、CPUにより判定プログラムが実行されると、最初に第1メモリの書換えチェック領域を読出す。
ここで、書換えチェック領域のデータが書換え完了コードに一致する場合は、第1メモリの書換えは正常に完了していることを示すので、CPUはアプリケーションプログラムを実行する。一方、前記データが書換え完了コードに一致しない場合は、第1メモリの書換えが途中で失敗したことを示すので、CPUは書換えプログラムを再度実行する。
According to the microcomputer of claim 1, when the rewrite program is executed by the CPU, the rewrite check area of the first memory is cleared first, then the entire area of the memory is rewritten, and finally the rewrite check area Write the rewrite completion code in. When the determination program is executed by the CPU, first, the rewrite check area of the first memory is read.
Here, if the data in the rewrite check area matches the rewrite completion code, this indicates that the rewrite of the first memory has been completed normally, and the CPU executes the application program. On the other hand, if the data does not match the rewrite completion code, it indicates that the rewriting of the first memory has failed in the middle, so the CPU executes the rewriting program again.

即ち、例えばマイクロコンピュータのパワーオンリセットが解除されると、CPUが最初に判定プログラムを実行するように設定しておけば、書換えチェック領域を参照することで第1メモリのアプリケーションプログラムが正常に書き換えられているか否かを判定でき、書換えが失敗していた場合は再試行することができる。従って、第1メモリの書換えを再試行するために、マイコンの外部端子としてリセット端子やモード設定用の端子を設ける必要がなくなり、マイコンのパッケージを小型化してコストの低下を図ることができる。   That is, for example, when the power-on reset of the microcomputer is released, if the CPU is set to execute the determination program first, the application program in the first memory can be rewritten normally by referring to the rewrite check area. Whether rewriting has failed or not can be retried. Accordingly, it is not necessary to provide a reset terminal or a mode setting terminal as an external terminal of the microcomputer in order to retry the rewriting of the first memory, and the microcomputer package can be downsized to reduce the cost.

請求項2記載のマイクロコンピュータによれば、CPUにより書換えプログラムが実行されると、第1メモリの2つの書換え許可ID領域に同一のIDコードが書込まれる。そして、CPUが判定プログラムを実行した場合に、書換えチェック領域より読み出されたデータが書換え完了コードに一致しなければ第1,第2書換え許可ID領域を夫々読出し、両者のデータが共に前記IDコードに一致すれば書換えプログラムを実行する。即ち、上記のようにIDコードが一致すれば、当該メモリに書き込みを行った主体は第1メモリに対する正当なアクセス権を有していることが確認されるので、不正な書き込みを防止することができる。   According to the microcomputer of the second aspect, when the rewrite program is executed by the CPU, the same ID code is written in the two rewrite permission ID areas of the first memory. Then, when the CPU executes the determination program, if the data read from the rewrite check area does not match the rewrite completion code, the first and second rewrite permission ID areas are read, and both the data are the ID If it matches the code, the rewriting program is executed. That is, if the ID codes match as described above, it is confirmed that the subject who has written to the memory has a legitimate access right to the first memory, so that unauthorized writing can be prevented. it can.

請求項3記載のマイクロコンピュータによれば、CPUにより書換えプログラムが実行されると、第1メモリの2つのブロックに設定される第1,第2書換え許可ID領域に、同一のIDコードを書込み、CPUが判定プログラムを実行した場合に書換えチェック領域より読み出されたデータが書換え完了コードに一致しなければ、2つのブロックについて、第1,第2書換え許可ID領域を夫々読出す。そして、何れか一方のブロックにおける両者の読出しデータが共にIDコードに一致すれば書換えプログラムを実行する。   According to the microcomputer of claim 3, when the rewrite program is executed by the CPU, the same ID code is written in the first and second rewrite permission ID areas set in the two blocks of the first memory, If the data read from the rewrite check area does not match the rewrite completion code when the CPU executes the determination program, the first and second rewrite permission ID areas are read for two blocks, respectively. Then, if both of the read data in one of the blocks match the ID code, the rewrite program is executed.

即ち、第1メモリの2つのブロックについては、同時に消去や書き込みが行われることはない。そして、第1メモリの書換えが途中で失敗すると、そのタイミングによっては一方のブロックが書換えられていない場合が想定されるので、IDコードが確認できなくなる。そこで、書換えプログラムにおいて、2つのブロックに対して同じようにIDコードを書き込むようにして、各ブロック毎にIDコードの一致を判定すれば、何れか一方のブロックで確実に一致を確認することができる。   That is, the two blocks of the first memory are not erased or written at the same time. If rewriting of the first memory fails in the middle, depending on the timing, it is assumed that one block has not been rewritten, and therefore the ID code cannot be confirmed. Therefore, in the rewriting program, if the ID code is written to the two blocks in the same manner and the ID code match is determined for each block, the match can be reliably confirmed in either one of the blocks. it can.

請求項4記載のマイクロコンピュータによれば、CPUにより部分書換えプログラムが実行されると、最初に第1メモリの部分書換えチェック領域をクリアしてから当該メモリの書換えを開始位置から前記終了位置まで行ない、最後に部分書換えチェック領域に部分書換え完了コードを書込む。そして、CPUが判定プログラムを実行し、書換えチェック領域より読み出したデータが書換え完了コードに一致する場合は、続いてフラグ格納領域を参照し、許可が設定されていれば第1メモリの部分書換えチェック領域を読出す。
その読み出しデータが部分書換え完了コードに一致する場合はアプリケーションプログラムを実行し、前記データが部分書換え完了コードに一致しない場合は部分書換えプログラムを実行する。従って、第1メモリの一部だけを書換えている途中でその書換えが失敗した場合についても、請求項1と同様の効果を得ることができる。
According to the microcomputer of claim 4, when the partial rewrite program is executed by the CPU, the partial rewrite check area of the first memory is first cleared, and then the memory is rewritten from the start position to the end position. Finally, a partial rewrite completion code is written in the partial rewrite check area. Then, when the CPU executes the determination program and the data read from the rewrite check area matches the rewrite completion code, the flag storage area is subsequently referred to. If permission is set, the partial memory rewrite check is performed. Read the area.
When the read data matches the partial rewrite completion code, the application program is executed, and when the data does not match the partial rewrite completion code, the partial rewrite program is executed. Therefore, the same effect as in claim 1 can be obtained even when rewriting fails while rewriting only a part of the first memory.

請求項5記載のマイクロコンピュータによれば、CPUが書換えプログラムを実行すると、第1メモリの第1,第2書換え許可ID領域に同一のIDコードを書込むと共に、フラグ格納領域への部分書換えの許可/禁止設定,開始位置及び終了位置の書き込み設定も行う。そして、CPUが判定プログラムを実行し、書換えチェック領域より読み出したデータが書換え完了コードに一致すれば、第1,第2書換え許可ID領域を夫々読出し、両者の読出しデータが共にIDコードに一致すればフラグ格納領域を参照する。従って、第1メモリの部分書き換えを行なう場合についても、IDコードの一致確認を行うことができる。   According to the microcomputer of claim 5, when the CPU executes the rewrite program, the same ID code is written in the first and second rewrite permission ID areas of the first memory, and the partial rewrite to the flag storage area is performed. Enable / disable setting, write setting of start position and end position are also performed. When the CPU executes the determination program and the data read from the rewrite check area matches the rewrite completion code, the first and second rewrite permission ID areas are read out, and both read data match the ID code. Refer to the flag storage area. Therefore, even when partial rewriting of the first memory is performed, ID code matching can be confirmed.

請求項6記載のマイクロコンピュータによれば、請求項1における書換えチェック領域を全書換えチェック領域として、第1メモリには、請求項4における部分書換えの許可/禁止設定を行うフラグの格納領域と、開始位置及び終了位置を書き込む領域とが、前記全書換えチェック領域と共に当該第1メモリについて定められている最小書込み単位内のサイズで設定される。また、第1メモリの全書換え,部分書き換えについては、夫々請求項1,4と同様に実行される。ここで、「最小書込み単位」とは、1回のライトサイクルにおいて第1メモリに書き込まれるデータの最小サイズであり、マイクロコンピュータの設計仕様に応じて定められる。   According to the microcomputer of claim 6, the rewrite check area in claim 1 is set as a full rewrite check area, and the first memory has a flag storage area for performing partial rewrite permission / inhibition setting in claim 4; The area for writing the start position and the end position is set in a size within the minimum write unit defined for the first memory together with the all-rewrite check area. Further, full rewriting and partial rewriting of the first memory are executed in the same manner as in claims 1 and 4 respectively. Here, the “minimum write unit” is the minimum size of data written to the first memory in one write cycle, and is determined according to the design specifications of the microcomputer.

そして、CPUにより判定プログラムが実行されると、最初に第1メモリの全書換えチェック領域を読出し、そのデータが全書換え完了コードに一致しない場合は全書換えプログラムを実行する。また、前記データが全書換え完了コードに一致すれば続いてフラグ格納領域を参照し、許可が設定されていれば部分書換えチェック領域を読出し、そのデータが部分書換え完了コードに一致すればアプリケーションプログラムを実行し、前記データが部分書換え完了コードに一致しない場合は部分書換えプログラムを実行する。
即ち、第1メモリの部分書き換えに関する情報は、少なくとも全書換えが1回完了した後に意味を成すので、部分書き換え情報を、全書換えチェック領域と共に最小書込み単位内のサイズで持たせれば、情報量を低減して有効に利用できる。その結果、判定プログラムの実行をより短時間内に完了することができる。
When the determination program is executed by the CPU, first, the entire rewrite check area of the first memory is read, and if the data does not match the complete rewrite completion code, the complete rewrite program is executed. If the data matches the complete rewrite completion code, the flag storage area is referred to.If permission is set, the partial rewrite check area is read. If the data matches the partial rewrite completion code, the application program is read. If the data does not match the partial rewrite completion code, the partial rewrite program is executed.
That is, the information related to the partial rewrite of the first memory is meaningful at least after the complete rewrite is completed once. Therefore, if the partial rewrite information has the size within the minimum write unit together with the full rewrite check area, the amount of information is reduced. Reduced and can be used effectively. As a result, the execution of the determination program can be completed within a shorter time.

請求項7記載のマイクロコンピュータによれば、部分書換えチェック領域に、その次に部分書き換えを行なう対象とする領域について、部分書換えの許可/禁止設定を行うフラグの格納領域と、開始位置及び終了位置を書き込む領域とを最小書込み単位内のサイズで設定し、その部分書換えチェック領域を1つ以上配置する。従って、部分書換えを、アドレスが不連続となる複数の領域についても行なうことができる。   According to the microcomputer of the seventh aspect, in the partial rewrite check area, for the area to be subjected to partial rewrite next, the storage area of the flag for setting permission / prohibition of partial rewrite, the start position, and the end position Is set to a size within the minimum writing unit, and one or more partial rewrite check areas are arranged. Therefore, partial rewriting can be performed for a plurality of areas where the addresses are discontinuous.

請求項8記載のマイクロコンピュータによれば、CPUは、判定プログラムを、リセット時に実行するので、第1メモリに対する書き込みが正常に行なわれているか否かをリセットが解除された場合にチェックすることで、誤った書込み或いはデータ化けなどが発生している場合にユーザプログラムの実行を停止して、プログラムの暴走を未然に防止することができる。   According to the microcomputer of the eighth aspect, since the CPU executes the determination program at the time of resetting, the CPU checks whether or not the writing to the first memory is normally performed when the reset is released. When an erroneous writing or data corruption occurs, the execution of the user program can be stopped to prevent the program from running out of control.

請求項9記載のマイクロコンピュータによれば、CPUは、判定プログラムを、低消費電力モードが解除された時点(ウエイクアップ時)に実行するので、第1メモリに対する書き込みが正常に行なわれているか否かをウエイクアップ時にチェックすることで、誤った書込み或いはデータ化けなどが発生している場合にユーザプログラムの実行を停止して、プログラムの暴走を未然に防止することができる。   According to the microcomputer of the ninth aspect, since the CPU executes the determination program when the low power consumption mode is canceled (during wake-up), whether or not writing to the first memory is normally performed. By checking this at the time of wakeup, the execution of the user program can be stopped and the program runaway can be prevented beforehand when erroneous writing or data corruption occurs.

(第1実施例)
以下、本発明の第1実施例について図1乃至図5を参照して説明する。図5は、本発明のマイクロコンピュータ11の構成を示すブロック図である。マイコン11は、例えば、マイコン3と同様に車両制御用ECUを構成するもので、CPU12を中心として、ROM(第2メモリ)13,RAM14,フラッシュメモリ(第1メモリ)15,フラッシュコントローラ16,通信回路17などを備えており、これらはアドレスバス18及びデータバス19を介して接続されている。
(First embodiment)
Hereinafter, a first embodiment of the present invention will be described with reference to FIGS. FIG. 5 is a block diagram showing the configuration of the microcomputer 11 of the present invention. For example, the microcomputer 11 constitutes a vehicle control ECU in the same manner as the microcomputer 3. With the CPU 12 as the center, the ROM (second memory) 13, the RAM 14, the flash memory (first memory) 15, the flash controller 16, communication A circuit 17 and the like are provided, and these are connected via an address bus 18 and a data bus 19.

フラッシュメモリ15には、CPU12によって実行されるECUとしての制御プログラムであるユーザプログラム20が記憶されるようになっている。ROM13には、フラッシュメモリ15にユーザプログラム20を書き込むための書換えプログラム21と、ユーザプログラム20,書換えプログラム21の何れを実行するかを決定するため、フラッシュメモリ15のステータスを判定する判定プログラム22が記憶されている。フラッシュコントローラ16は、CPU12がフラッシュメモリ15にアクセスする場合に、フラッシュメモリ15のブロック管理やエラー訂正処理などを行なうものである。   The flash memory 15 stores a user program 20 that is a control program as an ECU executed by the CPU 12. The ROM 13 has a rewrite program 21 for writing the user program 20 to the flash memory 15 and a determination program 22 for determining the status of the flash memory 15 in order to determine which of the user program 20 and the rewrite program 21 is executed. It is remembered. The flash controller 16 performs block management and error correction processing of the flash memory 15 when the CPU 12 accesses the flash memory 15.

通信回路17は、例えば、UARTやその他のシリアル通信、又はCAN等の車内LANなどのプロトコルに対応した通信インターフェイスであり、フラッシュメモリ15のユーザ(アプリケーション)プログラム20を書換える場合には、外部の書換え装置23との間で通信を行うようになっている。そして、書換え装置23より転送された書換えデータ24は、RAM14に書き込まれる。   The communication circuit 17 is a communication interface corresponding to a protocol such as UART, other serial communication, or an in-vehicle LAN such as CAN. When the user (application) program 20 of the flash memory 15 is rewritten, an external interface is used. Communication is performed with the rewriting device 23. Then, the rewrite data 24 transferred from the rewriting device 23 is written in the RAM 14.

次に、本実施例の作用について図1乃至図3も参照して説明する。尚、フラッシュメモリ15に対するユーザプログラム20の最初の書き込みは、ROMライタなどを使用して予め行われていることを前提とする(或いは、後述する図1のステップS6において「NO」と判断された場合に、ユーザプログラム20に分岐することに替えて書換えプログラム21に分岐させることで、フラッシュメモリ15に対する最初の書き込みを行なわせることも可能である)。   Next, the operation of this embodiment will be described with reference to FIGS. Note that the initial writing of the user program 20 to the flash memory 15 is preliminarily performed using a ROM writer or the like (or “NO” is determined in step S6 of FIG. 1 described later). In this case, the first write to the flash memory 15 can be performed by branching to the rewrite program 21 instead of branching to the user program 20).

図2は、フラッシュメモリ15のメモリマップを示すもので、図3は、書換えプログラム21による全書換え処理の手順、及びその書換え処理に伴うフラッシュメモリ15の状態変化を示すものである。図2に示すように、フラッシュメモリ15は、例えば、64Kバイトを単位とするブロック0〜nに分割されており、書換え処理もブロックを単位として行われる。
そして、先頭ブロック0には、「全書換え」の完了を示す「FLASHステータス0(書換えチェック領域)」と「ID領域2」とが配置され、終了ブロックnには「ID領域1」が配置されるようになっている。また、ブロック6は、一例として「部分書換え」が行われる場合の先頭ブロックに設定されており、「部分書換え」の完了を示す「FLASHステータス1(部分書換えチェック領域)」が配置されている。
FIG. 2 shows a memory map of the flash memory 15, and FIG. 3 shows a procedure of the entire rewriting process by the rewriting program 21, and a change in the state of the flash memory 15 accompanying the rewriting process. As shown in FIG. 2, the flash memory 15 is divided into, for example, blocks 0 to n in units of 64 Kbytes, and the rewriting process is also performed in units of blocks.
Then, “FLASH status 0 (rewrite check area)” and “ID area 2” indicating the completion of “rewrite all” are arranged in the first block 0, and “ID area 1” is arranged in the end block n. It has become so. Further, the block 6 is set as a head block when “partial rewriting” is performed as an example, and “FLASH status 1 (partial rewriting check area)” indicating the completion of “partial rewriting” is arranged.

「FLASHステータス0」には、全書換え処理が完了した段階で、所定のデータ、例えば55AA…55AAHが書き込まれる。「FLASHステータス1」も同様に、部分書換え処理が完了した段階で、例えば「55AA…55AA(以下、データ値はHEXで示す)」が書き込まれる。「ID領域2」と「ID領域1」には同じデータが書き込まれるようになっており、後述する照合確認のために使用される。
これらの「ID領域」には、フラッシュメモリ15の書換えを許可するIDやパスワードなどが格納され、当該領域の先頭と末尾には、同一のIDステータス(IDコード)1,2が書き込まれる。また、部分書換えの許可/禁止を設定するためのフラグ格納領域と、部分書換えの開始ブロック番号,終了ブロック番号を格納する領域や、その他プログラムIDやパスワードなどが格納される。
In the “FLASH status 0”, predetermined data, for example, 55AA... 55AAH is written at the stage when the entire rewriting process is completed. Similarly, for “FLASH status 1”, for example, “55AA... 55AA (hereinafter, the data value is indicated by HEX)” is written when the partial rewriting process is completed. The same data is written in “ID area 2” and “ID area 1”, and is used for collation confirmation described later.
In these “ID areas”, IDs and passwords that permit rewriting of the flash memory 15 are stored, and the same ID statuses (ID codes) 1 and 2 are written at the beginning and end of the areas. In addition, a flag storage area for setting permission / prohibition of partial rewriting, an area for storing the start block number and end block number for partial rewrite, and other program IDs and passwords are stored.

<全書換え処理>
図3に示す全書換え処理において、CPU12は、最初にブロック0の「FLASHステータス0」にデータ「0000…0000」を書き込んでクリアしてから、各ブロック0,…,6,…,n毎に、「消去」、「書込み」、「ベリファイ」を順次行ってゆく。そして、最後に「FLASHステータス0」にデータ「55AA…55AA」を書き込んで処理を終了する。
尚、ID領域2,1の「部分書換え」に関するデータは、後に「部分書換え」を行なうケースがあるか否かに応じて、この段階で許可/禁止の設定や、開始,終了ブロック番号の設定を書き込んでおくようにする。
<All rewrite processing>
In the all-rewrite process shown in FIG. 3, the CPU 12 first writes and clears data “0000... 0000” in “FLASH status 0” of block 0, and then blocks each block 0,. , “Erase”, “Write”, and “Verify” are sequentially performed. Finally, the data “55AA... 55AA” is written in “FLASH status 0”, and the process ends.
It should be noted that the data related to “partial rewrite” in the ID areas 2 and 1 is set at this stage to allow / prohibit and to set start and end block numbers depending on whether or not “partial rewrite” is performed later. Is written.

また、図3には、全書換え処理の進行に伴い、「FLASHステータス0,1」,ID領域2,1の「IDステータス1,2」の書き込みデータが変化する状態を示している。フラッシュメモリ15に既に書き込みが行われていると、「FLASHステータス0」のデータは「55AA…55AA」になっている。そして、最初にデータ「0000…0000」が書き込まれるが、次のブロック0の消去で「FFFF…FFFF」に変化し、次の「書込み」では「FLASHステータス0」の書き込みは行わないようにして、上記データ値を維持する。そして、最後の書込み処理で「55AA…55AA」に戻る。従って、全書換え処理中の「FLASHステータス0」は、「55AA…55AA」以外の値になっている。   Further, FIG. 3 shows a state in which the write data of “FLASH status 0, 1” and “ID status 1, 2” in the ID area 2, 1 change as the entire rewrite process proceeds. If the flash memory 15 has already been written, the data of “FLASH status 0” is “55AA ... 55AA”. The data “0000... 0000” is written first, but changes to “FFFF... FFFF” when the next block 0 is erased, and “FLASH status 0” is not written at the next “write”. The above data value is maintained. And it returns to "55AA ... 55AA" by the last writing process. Therefore, “FLASH status 0” during the entire rewriting process is a value other than “55AA... 55AA”.

また、「FLASHステータス1」も、既に書き込みが行われている状態では初期値が「55AA…55AA」になっているが、ブロック6の消去で「FFFF…FFFF」に変化し、次の「書込み」で「55AA…55AA」に書き戻される。ID領域2の「IDステータス2_1,2_2」も、初期値は「55AA…55AA」、ブロック0の消去で「FFFF…FFFF」、次の「書込み」で「55AA…55AA」に書き戻される。ID領域1の「IDステータス1_1,1_2」も、同様に初期値は「55AA…55AA」、ブロックnの消去で「FFFF…FFFF」、次の「書込み」で「55AA…55AA」に書き戻される。   In addition, “FLASH status 1” has an initial value of “55AA... 55AA” in a state where writing has already been performed, but changes to “FFFF... FFFF” by erasing block 6, and the next “writing "Is written back to" 55AA ... 55AA ". The initial values of “ID status 2_1, 2_2” in the ID area 2 are also written back to “55AA... 55AA”, “FFFF... FFFF” when erasing block 0, and “55AA. Similarly, the initial values of “ID status 1_1, 1_2” in the ID area 1 are also written back to “55AA... 55AA”, “FFFF... FFFF” when erasing block n, and “55AA. .

尚、全書換え処理中の「ベリファイ」において書込みエラーが検出されると、CPU12はその時点で内部リセットを発生させてリセットベクタから実行を開始し、判定プログラム22、即ち、図1に示すフラッシュステータス判定処理を実行するようになっている。また、例えば、全書換え処理を開始してから終了するまでの時間をタイマによりカウントし、所定時間内に処理が終了しない場合(タイムアウト)に内部リセットを発生させても良い。図1において、CPU12は、フラッシュメモリ15の「FLASHステータス0」を読み出して、そのデータ値が書換え完了コード「55AA…55AA」に一致するかどうかを判定する(ステップS1)。   When a write error is detected in “verify” during the entire rewrite process, the CPU 12 generates an internal reset at that time and starts execution from the reset vector, and the determination program 22, that is, the flash status shown in FIG. Judgment processing is executed. In addition, for example, the time from the start to the end of all rewrite processing may be counted by a timer, and an internal reset may be generated when the processing does not end within a predetermined time (timeout). In FIG. 1, the CPU 12 reads “FLASH status 0” from the flash memory 15 and determines whether or not the data value matches the rewrite completion code “55AA... 55AA” (step S1).

「FLASHステータス0」のデータ値が書換え完了コードに一致しなければ(「NO」)、CPU12は、ID領域2の「IDステータス2_1,2_2」が何れも正常コード「55AA…55AA」であるか否かを判断する(ステップS5)。そして、何れも正常コードであれば(「YES」)、ID領域2に書き込まれているIDやパスワードは有効であると判定し、書換えプログラム21の実行を開始する。この場合、書換えプログラム21は、ID領域2に書き込まれているIDやパスワードについて認証を行い、その認証結果が「OK」であれば図3のフローチャートの処理を開始する。   If the data value of “FLASH status 0” does not match the rewrite completion code (“NO”), the CPU 12 determines whether both of “ID status 2_1, 2_2” in the ID area 2 are normal codes “55AA... 55AA”. It is determined whether or not (step S5). If both are normal codes (“YES”), it is determined that the ID and password written in the ID area 2 are valid, and execution of the rewriting program 21 is started. In this case, the rewriting program 21 authenticates the ID and password written in the ID area 2 and starts the processing of the flowchart of FIG. 3 if the authentication result is “OK”.

また、ステップS5において「NO」と判断すると、CPU12はステップS6に移行し、ID領域1の「IDステータス1_1,1_2」が何れも正常コード「55AA…55AA」であるか否かを判断する。そして、何れも正常コードであれば(「YES」)、ID領域1に書き込まれているIDやパスワードは有効であると判定し、書換えプログラム21の実行を開始する。
即ち、図3に示すように、ID領域2,1の何れか一方について、正しく書き込みが行われない状態で全書換え処理が終了すると、そのIDステータスは「FFFF…FFFFF」となっており、正常なデータが書き込まれていない。しかし、他方のID領域には必ず正常なデータが書き込まれているので、何れか有効な方を選択するようにしている。
If “NO” is determined in the step S5, the CPU 12 proceeds to a step S6 so as to determine whether or not the “ID statuses 1_1 and 1_2” in the ID area 1 are all normal codes “55AA... 55AA”. If both are normal codes (“YES”), it is determined that the ID and password written in the ID area 1 are valid, and the execution of the rewrite program 21 is started.
That is, as shown in FIG. 3, when the entire rewriting process is completed in a state where writing is not correctly performed for either one of the ID areas 2 and 1, the ID status is “FFFF... FFFFF”, which is normal. Is not written. However, since normal data is always written in the other ID area, one of the valid ones is selected.

また、ID領域2,1の何れも正常なデータでない場合(ステップS6,「NO」)、CPU12はユーザプログラム20を実行する。この場合は、何らかの理由により、ユーザプログラム20に対する一番最初の書き込みが正常に行われていなかったか、或いはフラッシュメモリ15の一部やバス18,19に故障が発生した、といったような異常状態と推定される。
従って、このまま書換えを実行すると、フラッシュメモリ15に異常なデータが書き込まれるおそれがあることから、ユーザプログラム20に分岐する。そして、当該プログラム20に用意されているメモリチェックルーチンが正常であれば、そのチェックルーチンによりフラッシュメモリ15のチェックサムを計算する。その結果、異常が判定されればエラー処理を行う。この場合、フラッシュメモリ15に正常な書き込みを行うことは不能であるから、必要に応じて部品交換などの処置を行うようにする。
If neither of the ID areas 2 and 1 is normal data (step S6, “NO”), the CPU 12 executes the user program 20. In this case, there is an abnormal state in which, for some reason, the first writing to the user program 20 has not been normally performed, or a failure has occurred in a part of the flash memory 15 or the buses 18 and 19. Presumed.
Therefore, if rewriting is executed as it is, abnormal data may be written to the flash memory 15, so that the process branches to the user program 20. If the memory check routine prepared in the program 20 is normal, the checksum of the flash memory 15 is calculated by the check routine. As a result, if an abnormality is determined, error processing is performed. In this case, since it is impossible to perform normal writing in the flash memory 15, measures such as component replacement are performed as necessary.

<部分書換え処理>
また、図4は、フラッシュメモリ15の部分書換え処理を示す。部分書換え処理については、前述したように、フィールドにおいてECU−マイコン11に電源が投入された状態のまま、ユーザプログラム20の一部を書換えてバージョンアップを行う場合を想定している。従って、マイコン11がユーザプログラム20を実行している状態で、書換え装置23を接続し、その書換え装置23が部分書換え指令を発行すると、ユーザプログラム20中においてその部分書換え指令を認識し、図4の部分書換え処理を実行する。また、フラッシュメモリ15のブロック0は、部分書換えの対象としないように予め決定されている。
<Partial rewrite processing>
FIG. 4 shows a partial rewriting process of the flash memory 15. As described above, the partial rewriting process is assumed to be performed by updating a part of the user program 20 while the ECU-microcomputer 11 is powered on in the field. Accordingly, when the microcomputer 11 is executing the user program 20, the rewriting device 23 is connected, and when the rewriting device 23 issues a partial rewrite command, the user program 20 recognizes the partial rewrite command, and FIG. The partial rewriting process is executed. The block 0 of the flash memory 15 is determined in advance so as not to be partially rewritten.

図4は、ブロック6の部分書換えを行なう場合であり、ID領域の開始ブロック番号,終了ブロック番号は何れも「6」に設定されている。尚、部分書換えプログラムは、書換えプログラム21の一部となっている。CPU12は、最初にブロック6の「FLASHステータス1」にデータ「0000…0000」を書き込んでクリアしてから、ブロック6の「消去」、「書込み」、「ベリファイ」を順次行う。そして、最後に「FLASHステータス1」にデータ「55AA…55AA」を書き込んで処理を終了する。   FIG. 4 shows a case where partial rewriting of the block 6 is performed, and the start block number and end block number of the ID area are both set to “6”. Note that the partial rewriting program is a part of the rewriting program 21. The CPU 12 first writes and clears data “0000... 0000” in the “FLASH status 1” of the block 6 and then sequentially performs “erasing”, “writing”, and “verifying” of the block 6. Finally, the data “55AA... 55AA” is written in “FLASH status 1”, and the process ends.

また、図4には、部分書換え処理の進行に伴い、「FLASHステータス1」の書き込みデータが変化する状態を示している。尚、ブロック6のみしか書換えを行なわないため、「FLASHステータス0」,ID領域2,1の「IDステータス1,2」のデータは「55AA…55AA」のままである。   FIG. 4 shows a state in which the write data of “FLASH status 1” changes with the progress of the partial rewriting process. Since only the block 6 is rewritten, the data of “FLASH status 0” and “ID statuses 1 and 2” in the ID areas 2 and 1 remain “55AA... 55AA”.

この場合、フラッシュメモリ15に既に書き込みが行われているので、「FLASHステータス1」のデータは「55AA…55AA」になっている。そして、最初にデータ「0000…0000」が書き込まれるが、次のブロック6の消去で「FFFF…FFFF」に変化し、次の「書込み」では「FLASHステータス1」の書き込みは行わず、上記データ値を維持する。そして、最後の書込み処理で「55AA…55AA」に戻る。従って、部分書換え処理中の「FLASHステータス0」は、「55AA…55AA」以外の値になっている。   In this case, since the flash memory 15 has already been written, the data of “FLASH status 1” is “55AA... 55AA”. The data “0000... 0000” is written first, but changes to “FFFF... FFFF” by erasing the next block 6, and “FLASH status 1” is not written in the next “write”, and the above data Keep the value. And it returns to "55AA ... 55AA" by the last writing process. Accordingly, “FLASH status 0” during the partial rewriting process is a value other than “55AA... 55AA”.

また、部分書換えにおけるブロック6の「ベリファイ」において書込みエラーが検出された場合も、CPU12は同様にその時点で内部リセットを発生させてリセットベクタから実行を開始し、図1に示すフラッシュステータス判定処理を実行する。この場合、「FLASHステータス0」のデータ値は書換え完了コードに一致するので、CPU12はステップS1で「YES」と判定し、ステップS5と同様にID領域2の「IDステータス2_1,2_2」が何れも正常コードであるか否かを判断する(ステップS2)。   Further, when a write error is detected in the “verify” of the block 6 in the partial rewrite, the CPU 12 similarly generates an internal reset at that time and starts execution from the reset vector, and performs the flash status determination process shown in FIG. Execute. In this case, since the data value of “FLASH status 0” matches the rewrite completion code, the CPU 12 determines “YES” in step S1, and the “ID status 2_1, 2_2” in the ID area 2 is the same as in step S5. Is also a normal code (step S2).

ID領域2のステータスが正常コードであれば(「YES」)、CPU12は同領域において部分書換えが「許可」に設定されているか否かを判断する(ステップS3)。そして、「許可」に設定されていれば(「YES」)、ブロック6の「FLASHステータス1」を読出し、データ値が書換え完了コード「55AA…55AA」に一致するか否かを判断する(ステップS4)。書換え完了コードに一致しなければ(「NO」)書換えプログラム21に分岐し、図4の部分書換え処理を再試行する。   If the status of the ID area 2 is a normal code (“YES”), the CPU 12 determines whether or not partial rewriting is set to “permitted” in the area (step S3). If it is set to “permitted” (“YES”), the “FLASH status 1” in the block 6 is read, and it is determined whether or not the data value matches the rewrite completion code “55AA. S4). If it does not match the rewrite completion code (“NO”), the process branches to the rewrite program 21 and the partial rewrite process in FIG. 4 is retried.

尚、部分書換え処理の場合、ブロック0は書換え対象より外されているので、基本的にステップS2では「YES」と判断されるはずであり、「NO」と判断されるのは、ステップS6で「NO」と判断される場合と同様に異常な状態である。従って、同様にユーザプログラム20に分岐し、メモリチェックルーチンを実行する。また、ステップS5,S6のように、ブロックnのID領域1の確認を重ねて行う必要はない。   In the case of the partial rewriting process, since block 0 is excluded from the rewriting target, basically “YES” should be determined in step S2, and “NO” is determined in step S6. Similar to the case where “NO” is determined, the state is abnormal. Therefore, similarly, the program branches to the user program 20, and the memory check routine is executed. Further, it is not necessary to repeatedly check the ID area 1 of the block n as in steps S5 and S6.

また、CPU12における内部リセットの発生は、その他、ウォッチドックタイマなどにより暴走を検知した場合やバスエラーなどによっても発生するので、その場合も図1の判定処理は実行される。この時、フラッシュメモリ15の書換えが正常に行われていれば、判定処理ではステップS1〜S4において何れも「YES」と判定されるので、CPU12は判定処理を抜けてユーザプログラム20へ分岐し、当該プログラム20を実行する。また、ステップS3において、部分書換え処理が「禁止」に設定されている場合も(「NO」)、ユーザプログラム20に分岐する。   In addition, the occurrence of an internal reset in the CPU 12 also occurs when a runaway is detected by a watchdog timer or the like, or due to a bus error or the like. In this case, the determination process of FIG. 1 is executed. At this time, if the rewriting of the flash memory 15 is normally performed, the determination process determines “YES” in steps S1 to S4. Therefore, the CPU 12 exits the determination process and branches to the user program 20. The program 20 is executed. Further, when the partial rewrite process is set to “prohibited” in step S3 (“NO”), the process branches to the user program 20.

以上のように本実施例によれば、マイコン11のCPU12により書換えプログラム21が実行されると、最初にフラッシュメモリ15のFLASHステータス0をクリアしてから当該メモリ15の全領域の書換えを行ない、最後にFLASHステータス0に書換え完了コード「55AA…55AA」を書込む。そして、CPU12が判定プログラム22を実行すると、最初にフラッシュメモリ15のFLASHステータス0を読出し、そのデータが書換え完了コードに一致しない場合、CPU12は書換えプログラム21を再度実行する。   As described above, according to this embodiment, when the rewrite program 21 is executed by the CPU 12 of the microcomputer 11, the FLASH status 0 of the flash memory 15 is first cleared and then the entire area of the memory 15 is rewritten. Finally, the rewrite completion code “55AA... 55AA” is written in the FLASH status 0. When the CPU 12 executes the determination program 22, first, the FLASH status 0 of the flash memory 15 is read. If the data does not match the rewrite completion code, the CPU 12 executes the rewrite program 21 again.

即ち、CPU12が判定プログラム22を実行してFLASHステータス0を参照すれば、フラッシュメモリ15のユーザプログラム20が正常に書き換えられているか否かを判定でき、書換えが失敗していた場合は再試行できる。従って、フラッシュメモリ15の書換えを再試行するために、マイコン11の外部端子としてリセット端子やモード設定用の端子を設ける必要がなくなり、マイコン11のパッケージを小型化してコストの低下を図ることができる。   That is, if the CPU 12 executes the determination program 22 and refers to the FLASH status 0, it can be determined whether or not the user program 20 of the flash memory 15 has been normally rewritten, and can be retried if rewriting has failed. . Accordingly, it is not necessary to provide a reset terminal or a mode setting terminal as an external terminal of the microcomputer 11 in order to retry the rewriting of the flash memory 15, and the package of the microcomputer 11 can be downsized to reduce the cost. .

また、CPU12が書換えプログラム21を実行すると、フラッシュメモリ15の2つのIDステータス2_1,2_2に同一のIDコードを書込み、判定プログラム22を実行した場合に、FLASHステータス0のデータが書換え完了コードに一致しなければIDステータス2_1,2_2を夫々読出し、両者のデータが共に前記IDコードに一致すれば書換えプログラム21を実行するので、メモリ15に書き込みを行った主体が正当なアクセス権を有していることを確認して、不正な書き込みを防止できる。   Further, when the CPU 12 executes the rewrite program 21, the same ID code is written to the two ID statuses 2_1 and 2_2 of the flash memory 15, and when the determination program 22 is executed, the data of the FLASH status 0 matches the rewrite completion code. Otherwise, the ID statuses 2_1 and 2_2 are read out, and if both data match the ID code, the rewrite program 21 is executed, so that the subject who has written in the memory 15 has a legitimate access right. This can be confirmed to prevent unauthorized writing.

更に、フラッシュメモリ15の2つのブロック0,nに設定されるIDステータス2,1に同一のIDコードを書込み、CPU12が判定プログラム22を実行し、FLASHステータス0のデータが書換え完了コードに一致しなければ、2つのブロック0,nについてIDステータス2,1を夫々読出し、何れか一方のブロックで両者の読出しデータが共にIDコードに一致すれば書換えプログラム21を実行する。従って、フラッシュメモリ15の書換えが途中で失敗した場合でも、何れか一方のブロックで確実にIDコードの一致を確認できる。   Further, the same ID code is written to the ID statuses 2 and 1 set in the two blocks 0 and n of the flash memory 15, the CPU 12 executes the determination program 22, and the data of the FLASH status 0 matches the rewrite completion code. If not, the ID statuses 2 and 1 are read for the two blocks 0 and n, respectively, and if both read data match the ID code in either block, the rewrite program 21 is executed. Therefore, even if rewriting of the flash memory 15 fails in the middle, it is possible to reliably confirm the coincidence of the ID code in any one of the blocks.

また、CPU12により書換えプログラム21の一部である部分書換えプログラムが実行されると、最初にフラッシュメモリ15のFLASHステータス1をクリアし、当該メモリの書換えを開始位置から終了位置まで行ない、最後に部分FLASHステータス1に部分書換え完了コード「55AA…55AA」を書込む。
そして、CPU12が判定プログラム22を実行し、FLASHステータス1のデータが書換え完了コードに一致する場合は、続いてフラグ格納領域を参照し、許可が設定されていればFLASHステータス1を読出す。その読み出しデータが部分書換え完了コードに一致しない場合は部分書換えプログラムを実行するので、フラッシュメモリ15の一部だけを書換えている途中でその書換えが失敗した場合について、全領域書換えの場合と同様の効果を得ることができる。例えば、フィールドにおいてユーザプログラム20の一部を書換えてバージョンアップを図る場合などに有効である。
When the partial rewrite program which is a part of the rewrite program 21 is executed by the CPU 12, the flash status 1 of the flash memory 15 is cleared first, the memory is rewritten from the start position to the end position, and finally the partial rewrite program 21 is executed. A partial rewrite completion code “55AA... 55AA” is written in FLASH status 1.
Then, when the CPU 12 executes the determination program 22 and the data of the FLASH status 1 matches the rewrite completion code, the flag storage area is subsequently referred to, and if the permission is set, the FLASH status 1 is read. When the read data does not match the partial rewrite completion code, the partial rewrite program is executed. Therefore, when rewriting fails while rewriting only a part of the flash memory 15, the same as in the case of all area rewriting is performed. An effect can be obtained. For example, this is effective when a part of the user program 20 is rewritten in the field to upgrade the version.

加えて、CPU12が書換えプログラム21を実行すると、フラッシュメモリ15のIDステータス2_1,2_2に同一のIDコードを書込むと共にフラグ格納領域への部分書換えの許可/禁止設定,開始位置及び終了位置の書き込み設定も行う。そして、CPU12が判定プログラム22を実行し、FLASHステータス0より読み出したデータが書換え完了コードに一致すれば、IDステータス2_1,2_2を夫々読出し、両者の読出しデータが共にIDコードに一致すればFLASHステータ1を参照するので、フラッシュメモリ15の部分書き換えを行なう場合についても、IDコードの一致確認を行うことができる。   In addition, when the CPU 12 executes the rewrite program 21, the same ID code is written in the ID statuses 2_1 and 2_2 of the flash memory 15, and the partial rewrite permission / prohibition setting, the start position and the end position are written in the flag storage area. Also set. Then, the CPU 12 executes the determination program 22, and if the data read from the FLASH status 0 matches the rewrite completion code, the ID status 2_1 and 2_2 are read respectively. If both read data match the ID code, the FLASH status is read. Since ID 1 is referred to, ID code matching can be confirmed even when partial rewriting of the flash memory 15 is performed.

更にまた、CPU12は、判定プログラム22を、リセット時に実行するので、フラッシュメモリ15に対する書き込みが正常に行なわれているか否かをリセットが解除された場合にチェックすることで、誤った書込み或いはデータ化けなどが発生している場合にユーザプログラム20の実行を停止して、プログラム20の暴走を未然に防止することができる。   Furthermore, since the CPU 12 executes the determination program 22 at the time of resetting, by checking whether or not writing to the flash memory 15 is normally performed when the reset is released, erroneous writing or garbled data is obtained. In such a case, the execution of the user program 20 can be stopped to prevent the program 20 from running out of control.

(第2実施例)
図6乃至図9は本発明の第2実施例を示すものであり、第1実施例と同一部分には同一符号を付して説明を省略し、以下異なる部分について説明する。図6は、第1実施例の図2相当図である。第2実施例では、先頭ブロック0の冒頭16バイトに、「FLASHステータス0」と共に、部分書換えの許可/禁止を設定するためのフラグ格納領域と、部分書換えの開始ブロック番号,終了ブロック番号を格納する領域とが配置されている。そして、「ID領域2」,「ID領域1」は削除されている。また、終了ブロックnについては、第1実施例と異なり、格別な領域設定は行われていない。ブロック6は、第1実施例と同様に「部分書換え」が行われる場合の先頭ブロックに設定され、「FLASHステータス1」が配置されている。
(Second embodiment)
6 to 9 show a second embodiment of the present invention. The same parts as those in the first embodiment are denoted by the same reference numerals and the description thereof will be omitted. Hereinafter, different parts will be described. FIG. 6 is a diagram corresponding to FIG. 2 of the first embodiment. In the second embodiment, in the first 16 bytes of the first block 0, together with “FLASH status 0”, a flag storage area for setting permission / prohibition of partial rewrite, and the start block number and end block number of partial rewrite are stored. Area to be placed. “ID area 2” and “ID area 1” are deleted. Further, unlike the first embodiment, no special area setting is performed for the end block n. As in the first embodiment, the block 6 is set as the head block when “partial rewriting” is performed, and “FLASH status 1” is arranged.

尚、16バイトは、フラッシュコントローラ16がフラッシュメモリ15に対してデータの書込みを行う場合の最小書込み単位として設定されているサイズである。即ち、CPU12がフラッシュメモリ15に1バイトのデータを書き込む場合でも、フラッシュコントローラ16はエラーチェックを行なうため、上記1バイトデータのアドレスを含む連続した16バイトのデータを単位として、書込み(リード・モディファイ・ライト)を行なうようになっている。   The 16 bytes is a size set as a minimum writing unit when the flash controller 16 writes data to the flash memory 15. That is, even when the CPU 12 writes 1-byte data to the flash memory 15, the flash controller 16 performs error checking. Therefore, the write (read / modify) is performed in units of continuous 16-byte data including the address of the 1-byte data.・ Light).

次に、第2実施例の作用について説明する。
<全書換え処理>
図7に示す全書換え処理において、部分書換え許可禁止フラグは「許可」=「01H」,部分書換え開始ブロック/終了ブロックは「0006H」に設定されている。CPU12は、最初にブロック0の「FLASHステータス0」にデータ「0000…0000」を書き込んでクリアすると共に、部分書換え許可禁止フラグ,部分書換え開始ブロック/終了ブロックの格納領域もゼロクリアする。そして、第1実施例と同様に、各ブロック0,…,6,…,n毎に、「消去」、「書込み」、「ベリファイ」を順次行ってゆく。そして、最後に「FLASHステータス0」にデータ「55AA…55AA」を書き込むと共に、部分書換え許可禁止フラグを「01H」に、部分書換え開始ブロック/終了ブロックに「0006H」を書き込んで処理を終了する。すなわち、「FLASHステータス0,1」に関しては、データ値の変化は第1実施例と全く同様である。
Next, the operation of the second embodiment will be described.
<All rewrite processing>
In the full rewrite process shown in FIG. 7, the partial rewrite permission prohibition flag is set to “permitted” = “01H”, and the partial rewrite start block / end block is set to “0006H”. The CPU 12 first writes and clears the data “0000... 0000” in the “FLASH status 0” of the block 0, and clears the partial rewrite permission prohibition flag and the partial rewrite start block / end block storage area to zero. As in the first embodiment, “erase”, “write”, and “verify” are sequentially performed for each block 0,..., 6,. Finally, the data “55AA... 55AA” is written in “FLASH status 0”, the partial rewrite permission prohibition flag is written in “01H”, and “0006H” is written in the partial rewrite start block / end block. That is, regarding the “FLASH status 0, 1”, the change in the data value is exactly the same as in the first embodiment.

<部分書換え処理>
また、図8は、フラッシュメモリ15の部分書換え処理を示す。部分書換え処理についても、「FLASHステータス1」に関するデータ値の変化は第1実施例と全く同様である。そして、「FLASHステータス0」,部分書換え許可禁止フラグの状態、並びに部分書換え開始ブロック/終了ブロックの値は初期値のまま変化しない。
図9は、図1相当のフラッシュステータス判定処理であり、ステップS1,S3,S4のみとなっている。すなわち、第2実施例ではIDステータスが正常コードであるか否かをチェックしないため、判定処理が簡単になっている。
<Partial rewrite processing>
FIG. 8 shows a partial rewriting process of the flash memory 15. Also in the partial rewriting process, the change in the data value related to “FLASH status 1” is exactly the same as in the first embodiment. Then, the “FLASH status 0”, the state of the partial rewrite permission prohibition flag, and the values of the partial rewrite start block / end block remain the initial values.
FIG. 9 shows the flash status determination process corresponding to FIG. 1 and includes only steps S1, S3 and S4. That is, in the second embodiment, since it is not checked whether the ID status is a normal code, the determination process is simplified.

以上のように第2実施例によれば、部分書換えの許可/禁止設定を行うフラグの格納領域と、開始位置及び終了位置を書き込む領域とを、全書換えチェック領域と共にフラッシュメモリ15の最小書込み単位のサイズで設定した。即ち、フラッシュメモリ15の部分書き換えに関する情報は、少なくとも全書換えが1回完了した後に意味を成すので、部分書き換え情報を、全書換えチェック領域と共に最小書込み単位のサイズで持たせれば、情報量を低減した上で有効に利用することができる。   As described above, according to the second embodiment, the storage area of the flag for setting the permission / prohibition of partial rewriting, the area for writing the start position and the end position, and the minimum rewrite unit of the flash memory 15 together with the entire rewrite check area. The size was set. That is, the information related to the partial rewrite of the flash memory 15 is meaningful at least after the complete rewrite is completed once, so that the amount of information can be reduced by providing the partial rewrite information together with the full rewrite check area in the size of the minimum write unit. And can be used effectively.

また、本発明に関連する従来技術の1つに、国際公開第WO2004/031966号パンフレットに開示されているものがある。この従来技術では、複数のブロック(最小消去単位)からなるメモリについて、どのブロックが消去済みであるかを判断するため、各ブロックにフラグを設けてそのフラグの状態を判定することで、消去済みであるか否かを決定するようにしている。しかしながら、マイコンの起動時に各ブロック毎に設けられているフラグの状態を判定すると、判定に時間を要するためプログラムの起動が遅れることになり、その起動遅れは、メモリのブロック数が増加するのに伴って大きくなってしまう。   Further, one of the prior arts related to the present invention is disclosed in International Publication No. WO 2004/031966. In this prior art, in order to determine which block has been erased in a memory composed of a plurality of blocks (minimum erase unit), each block is provided with a flag, and the state of the flag is determined. It is determined whether or not. However, when the state of the flag provided for each block is determined when the microcomputer is activated, the activation of the program is delayed because the determination takes time, and this activation delay increases the number of memory blocks. Along with it.

データメモリとしての用途では、起動時にはそのメモリを使用するホストマイコン自体が初期化を行なうため、その間にメモリの判定を行うことも可能である。ところが、プログラムメモリとしての用途では、メモリの処理により起動が遅れることは、プログラム,即ち、マイコン自体の起動が遅れることに繋がってしまう。
これに対して、第2実施例によれば、フラッシュメモリ15について第1実施例のようにIDコードをチェックしないので、判定プログラムの実行をより短時間内に完了することができる。
In use as a data memory, since the host microcomputer itself using the memory initializes at the time of startup, it is possible to determine the memory during that time. However, in use as a program memory, a delay in activation due to processing of the memory leads to a delay in activation of the program, that is, the microcomputer itself.
On the other hand, according to the second embodiment, since the ID code is not checked for the flash memory 15 as in the first embodiment, the execution of the determination program can be completed in a shorter time.

(第3実施例)
図10及び図11は本発明の第3実施例を示すものであり、第2実施例と異なる部分のみ説明する。第3実施例は、部分書換えを行うブロックが複数ある場合に対応した処理を示す。図10に示すように、部分書換えを行うブロックが「6,11」の2ブロックであるとする。この場合、ブロック0のFLASHステータス0には、第2実施例と同様にブロック6の部分書換え(1)を行うための情報が配置され、ブロック6のFLASHステータス1には、ブロック11の部分書換え(2)を行うための情報,すなわち、部分書換え(2)の許可/禁止を設定するためのフラグ格納領域と、部分書換えの開始ブロック番号,終了ブロック番号を格納する領域とが計16バイトで配置されている。
(Third embodiment)
10 and 11 show a third embodiment of the present invention, and only the parts different from the second embodiment will be described. The third embodiment shows processing corresponding to a case where there are a plurality of blocks to be partially rewritten. As shown in FIG. 10, it is assumed that the blocks to be partially rewritten are two blocks “6, 11”. In this case, in the FLASH status 0 of the block 0, information for performing the partial rewrite (1) of the block 6 is arranged as in the second embodiment, and the partial rewrite of the block 11 is included in the FLASH status 1 of the block 6 Information for performing (2), that is, a flag storage area for setting permission / prohibition of partial rewrite (2) and an area for storing the start block number and end block number of partial rewrite are 16 bytes in total. Has been placed.

そして、ブロック11には、部分書換えチェック領域としてFLASHステータス2が配置されており、そのFLASHステータス2と共に、更に続けて部分書換えを行う場合に対応して、部分書換え(3)を行うための情報が計16バイトで配置されている。部分書換え(3)を行わない場合、許可/禁止設定フラグは「禁止」に設定される。
図11は、図9相当図であり、図9におけるステップS3,S4が、部分書換え(1)に対応するステップS3’,S4’となっている。続いて、部分書換え(2)に対応する判断ステップが、ステップS11,S12として配置されている。
In block 11, FLASH status 2 is arranged as a partial rewrite check area, and information for performing partial rewrite (3) is performed together with the FLASH status 2 in response to subsequent partial rewrite. Are arranged in a total of 16 bytes. When partial rewriting (3) is not performed, the permission / prohibition setting flag is set to “prohibited”.
FIG. 11 is a diagram corresponding to FIG. 9, and steps S3 and S4 in FIG. 9 are steps S3 ′ and S4 ′ corresponding to partial rewriting (1). Subsequently, determination steps corresponding to partial rewriting (2) are arranged as steps S11 and S12.

尚、部分書換えが最大2ブロックまでと規定されている場合は図11に示す判定処理で対応すれば良く、部分書換えが最大3ブロックまで行われる場合は、ステップS12に続いて、部分書換え(3)に対応する判断ステップを、ステップS13,S14として配置すれば良い。その場合、第3実施例のケースでは、部分書換え(3)の許可/禁止設定フラグが「禁止」に設定されるため、ステップS13で(NO)と判断してユーザプログラムに移行することになる。   If the partial rewriting is defined as a maximum of 2 blocks, the determination process shown in FIG. 11 may be used. If the partial rewriting is performed up to a maximum of 3 blocks, the partial rewriting (3 The determination step corresponding to) may be arranged as steps S13 and S14. In this case, in the case of the third embodiment, since the permission / prohibition setting flag for partial rewriting (3) is set to “prohibited”, it is determined (NO) in step S13 and the process proceeds to the user program. .

以上のように第3実施例によれば、ブロック6の部分書換えチェック領域に、その次に部分書き換えを行なう対象とする領域について、部分書換えの許可/禁止設定を行うフラグの格納領域と、開始位置及び終了位置を書き込む領域とを最小書込み単位のサイズで設定し、その部分書換えチェック領域を1つ以上配置するので、部分書換えを、アドレスが不連続となる複数のブロックについても行なうことができる。   As described above, according to the third embodiment, in the partial rewrite check area of the block 6, the storage area for the flag for setting permission / prohibition of partial rewrite for the area to be subjected to partial rewrite next, and the start The area for writing the position and end position is set in the size of the minimum writing unit, and one or more partial rewriting check areas are arranged, so that partial rewriting can be performed for a plurality of blocks whose addresses are discontinuous. .

本発明は上記し又は図面に記載した実施例にのみ限定されるものではなく、以下のような変形が可能である。
ブロックnに、ブロック0と同じID領域を設け、ステップS5,S6で二重にチェックする処理は、必要に応じて行えば良い。また、ブロック0におけるIDコードのチェックも、必要に応じて行えば良い。
FLASHステータス0,1やID領域2,1をフラッシュメモリ15のどこに配置するかは、適宜変更して実施しても良い。
書換え完了コードやIDコードのデータ値についても、適宜変更して実施可能である。
ブロック0を、部分書き換えの対象としても良い。
フラッシュメモリ15のブロック容量は、64Kバイトに限らない。
第1メモリは、ブロック単位で書換えを行うものに限ることはない。また、書き換えを行なう際に、「ベリファイ」処理はメモリの仕様に応じて実施すれば良い。
更に、ステップS2におけるチェックも必要に応じて行えば良い。
部分書換え処理についても、仕様上必要とされる場合に実施すれば良い。
書換えデータ24は、RAM14に一括転送される場合に限らず、書換え装置23より順次送信されるデータを受信しながら書換えを行っても良い。
The present invention is not limited to the embodiments described above or shown in the drawings, and the following modifications are possible.
The same ID area as that of block 0 is provided in block n, and the process of double checking in steps S5 and S6 may be performed as necessary. The ID code check in block 0 may be performed as necessary.
Where the FLASH statuses 0 and 1 and the ID areas 2 and 1 are arranged in the flash memory 15 may be changed as appropriate.
The data value of the rewrite completion code and ID code can be changed as appropriate.
Block 0 may be a target of partial rewriting.
The block capacity of the flash memory 15 is not limited to 64 Kbytes.
The first memory is not limited to one that is rewritten in units of blocks. Further, when performing the rewriting, the “verify” process may be performed according to the specifications of the memory.
Furthermore, the check in step S2 may be performed as necessary.
The partial rewriting process may also be performed when required by the specifications.
The rewrite data 24 is not limited to the batch transfer to the RAM 14 and may be rewritten while receiving data sequentially transmitted from the rewrite device 23.

マイコン11が、動作用クロックの供給を停止した状態で待機する低消費電力モード(スリープ,ストップモード)を実行可能に構成されている場合、CPU12は、判定プログラム22を、低消費電力モードの解除(ウエイクアップ)時に実行するようにしても良い。斯様に構成すれば、フラッシュメモリ15に対する書き込みが正常に行なわれているか否かをウエイクアップ時にもチェックすることで、誤った書込み或いはデータ化けなどが発生している場合にユーザプログラム20の実行を停止して、プログラム20の暴走を未然に防止することができる。
最小書き込み単位は、16バイトに限ることはなく、マイクロコンピュータの個別の仕様に応じて適宜変更すれば良い。
フラッシュコントローラ16も、必要に応じて設ければ良く、CPU12が直接フラッシュメモリ15に書き込みを行っても良い。
第2,第3実施例における「FLASHステータス0,1」等と、部分書換えに関する情報との合計サイズは、最小書き込み単位より小さくても良い。
車両制御用のECUを構成するマイクロコンピュータに限ることなく、書換え可能な不揮発性メモリを備えているマイクロコンピュータであれば適用可能である。
When the microcomputer 11 is configured to be able to execute a low power consumption mode (sleep, stop mode) that waits in a state where the supply of the operation clock is stopped, the CPU 12 cancels the determination program 22 in the low power consumption mode. It may be executed during (wake-up). With this configuration, the user program 20 can be executed when erroneous writing or garbled data occurs by checking whether or not the writing to the flash memory 15 is normally performed at the time of wakeup. To prevent the program 20 from going out of control.
The minimum writing unit is not limited to 16 bytes, and may be appropriately changed according to the individual specifications of the microcomputer.
The flash controller 16 may be provided as necessary, and the CPU 12 may directly write to the flash memory 15.
The total size of “FLASH status 0, 1” and the like and information related to partial rewriting in the second and third embodiments may be smaller than the minimum writing unit.
The present invention is not limited to the microcomputer constituting the vehicle control ECU, and any microcomputer having a rewritable nonvolatile memory can be applied.

本発明の第1実施例であり、フラッシュステータス判定処理の内容を示すフローチャートThe flowchart which shows the content of the flash status determination process which is 1st Example of this invention. フラッシュメモリのメモリマップMemory map of flash memory 書換えプログラムによる全書換え処理の手順、及びその書換え処理に伴うフラッシュメモリの状態変化を示す図The figure which shows the procedure of all the rewriting processes by a rewriting program, and the state change of the flash memory accompanying the rewriting process 部分書換え処理に対応する図3相当図3 equivalent diagram corresponding to partial rewrite processing マイクロコンピュータの構成を示すブロック図Block diagram showing the configuration of the microcomputer 本発明の第2実施例を示す図2相当図FIG. 2 equivalent diagram showing a second embodiment of the present invention. 図3相当図3 equivalent figure 図4相当図4 equivalent diagram 図1相当図1 equivalent diagram 本発明の第3実施例を示す図6相当図FIG. 6 equivalent view showing a third embodiment of the present invention. 図9相当図Fig. 9 equivalent 従来のECUにおけるフラッシュメモリの書換え状態を示す図The figure which shows the rewriting state of the flash memory in the conventional ECU

符号の説明Explanation of symbols

図面中、11はマイクロコンピュータ、12はCPU、13はROM(第2メモリ)、15はフラッシュメモリ(第1メモリ)、20はユーザプログラム(アプリケーションプログラム)、21は書換えプログラム(部分書換えプログラム)を示す。   In the drawing, 11 is a microcomputer, 12 is a CPU, 13 is a ROM (second memory), 15 is a flash memory (first memory), 20 is a user program (application program), and 21 is a rewrite program (partial rewrite program). Show.

Claims (9)

アプリケーションプログラムが記憶されている書換え可能な不揮発性の第1メモリと、この第1メモリの書換えを行なうための書換えプログラム,及び前記第1メモリの書換え判定を行うための判定プログラムが記憶されている第2メモリと、前記各プログラムを読み出して実行するCPUとを備えてなるマイクロコンピュータにおいて、
前記CPUにより前記書換えプログラムが実行されると、最初に前記第1メモリの書換えチェック領域をクリアしてから当該メモリの全領域の書換えを行ない、最後に前記書換えチェック領域に書換え完了コードを書込み、
前記CPUにより前記判定プログラムが実行されると、最初に前記第1メモリの書換えチェック領域を読出し、読み出されたデータが前記書換え完了コードに一致する場合は前記アプリケーションプログラムを実行し、前記データが前記書換え完了コードに一致しない場合は前記書換えプログラムを実行することを特徴とするマイクロコンピュータ。
A rewritable non-volatile first memory in which an application program is stored, a rewriting program for rewriting the first memory, and a determination program for performing rewriting determination of the first memory are stored. In a microcomputer comprising a second memory and a CPU that reads and executes each program,
When the rewrite program is executed by the CPU, the rewrite check area of the first memory is first cleared and then the entire area of the memory is rewritten, and finally the rewrite completion code is written in the rewrite check area.
When the determination program is executed by the CPU, the rewrite check area of the first memory is read first, and when the read data matches the rewrite completion code, the application program is executed, and the data is A microcomputer that executes the rewriting program when it does not match the rewriting completion code.
前記CPUにより前記書換えプログラムが実行されると、前記第1メモリの第1,第2書換え許可ID領域に、同一のIDコードを書込み、
前記CPUにより前記判定プログラムが実行され、前記第1メモリの書換えチェック領域より読み出されたデータが前記書換え完了コードに一致しない場合は、前記第1,第2書換え許可ID領域を夫々読出し、両者の読出しデータが共に前記IDコードに一致する場合は、前記書換えプログラムを実行することを特徴とする請求項1記載のマイクロコンピュータ。
When the rewrite program is executed by the CPU, the same ID code is written in the first and second rewrite permission ID areas of the first memory,
When the determination program is executed by the CPU and the data read from the rewrite check area of the first memory does not match the rewrite completion code, the first and second rewrite permission ID areas are read respectively. 2. The microcomputer according to claim 1, wherein said rewriting program is executed when both of the read data coincide with said ID code.
前記第1メモリの書換えが、所定容量のブロックを単位として行われる場合、
前記CPUにより前記書換えプログラムが実行されると、前記第1メモリの2つのブロックに設定される第1,第2書換え許可ID領域に、同一のIDコードを書込み、
前記CPUにより前記判定プログラムが実行され、前記第1メモリの書換えチェック領域より読み出されたデータが前記書換え完了コードに一致しない場合は、前記2つのブロックについて、前記第1,第2書換え許可ID領域を夫々読出し、何れか一方のブロックにおける両者の読出しデータが共に前記IDコードに一致する場合は、前記書換えプログラムを実行することを特徴とする請求項2記載のマイクロコンピュータ。
When the first memory is rewritten in units of a predetermined capacity block,
When the rewrite program is executed by the CPU, the same ID code is written in the first and second rewrite permission ID areas set in the two blocks of the first memory,
When the CPU executes the determination program and the data read from the rewrite check area of the first memory does not match the rewrite completion code, the first and second rewrite permission IDs for the two blocks 3. The microcomputer according to claim 2, wherein each of the areas is read, and when both read data in any one of the blocks match the ID code, the rewriting program is executed.
前記第2メモリには、前記第1メモリの部分書換えを行なうための部分書換えプログラムも記憶されており、
前記第1メモリには、前記部分書換えの許可/禁止設定を行うフラグの格納領域と、開始位置及び終了位置を書き込む領域とが設定され、
前記CPUにより前記部分書換えプログラムが実行されると、最初に前記第1メモリの部分書換えチェック領域をクリアしてから当該メモリの書換えを前記開始位置から前記終了位置まで行ない、最後に前記部分書換えチェック領域に部分書換え完了コードを書込み、
前記CPUにより前記判定プログラムが実行され、前記第1メモリの書換えチェック領域より読み出されたデータが前記書換え完了コードに一致する場合は、続いて前記フラグ格納領域を参照し、前記許可が設定されていれば前記部分書換えチェック領域を読出し、読み出されたデータが前記部分書換え完了コードに一致する場合は前記アプリケーションプログラムを実行し、前記データが前記部分書換え完了コードに一致しない場合は前記部分書換えプログラムを実行することを特徴とする請求項1乃至3の何れかに記載のマイクロコンピュータ。
The second memory also stores a partial rewriting program for performing partial rewriting of the first memory,
In the first memory, a flag storage area for performing the partial rewrite permission / prohibition setting and an area for writing a start position and an end position are set.
When the partial rewrite program is executed by the CPU, the partial rewrite check area of the first memory is first cleared, then the memory is rewritten from the start position to the end position, and finally the partial rewrite check is performed. Write the partial rewrite completion code in the area,
When the CPU executes the determination program and the data read from the rewrite check area of the first memory matches the rewrite completion code, the permission is set by referring to the flag storage area. If so, the partial rewrite check area is read. If the read data matches the partial rewrite completion code, the application program is executed. If the data does not match the partial rewrite completion code, the partial rewrite check area is executed. The microcomputer according to any one of claims 1 to 3, wherein the program is executed.
前記CPUにより前記書換えプログラムが実行されると、前記第1メモリの第1,第2書換え許可ID領域に同一のIDコードを書込むと共に、前記フラグ格納領域への部分書換えの許可/禁止設定,前記開始位置及び終了位置の書き込み設定も行い、
前記CPUにより前記判定プログラムが実行され、前記書換えチェック領域より読み出されたデータが前記書換え完了コードに一致する場合は、前記第1,第2書換え許可ID領域を夫々読出し、両者の読出しデータが共に前記IDコードに一致すると、前記フラグ格納領域を参照することを特徴とする請求項4記載のマイクロコンピュータ。
When the rewrite program is executed by the CPU, the same ID code is written in the first and second rewrite permission ID areas of the first memory, and the partial rewrite permission / prohibition setting in the flag storage area; Write setting of the start position and end position,
When the determination program is executed by the CPU and the data read from the rewrite check area matches the rewrite completion code, the first and second rewrite permission ID areas are read respectively, and both read data are 5. The microcomputer according to claim 4, wherein when both coincide with the ID code, the flag storage area is referred to.
アプリケーションプログラムが記憶されている書換え可能な不揮発性の第1メモリと、この第1メモリの全書換えを行なうための全書換えプログラム,及び前記第1メモリの書換え判定を行うための判定プログラムが記憶されている第2メモリと、前記各プログラムを読み出して実行するCPUとを備えてなるマイクロコンピュータにおいて、
前記CPUにより前記全書換えプログラムが実行されると、最初に前記第1メモリの全書換えチェック領域をクリアしてから当該メモリの全領域の書換えを行ない、最後に前記書換えチェック領域に全書換え完了コードを書込み、
前記第2メモリには、前記第1メモリの部分書換えを行なうための部分書換えプログラムも記憶されており、
前記第1メモリには、前記部分書換えの許可/禁止設定を行うフラグの格納領域と、開始位置及び終了位置を書き込む領域とが、前記全書換えチェック領域と共に当該第1メモリについて定められている最小書込み単位内のサイズで設定され、
前記CPUにより前記部分書換えプログラムが実行されると、最初に前記第1メモリの部分書換えチェック領域をクリアしてから当該メモリの書換えを前記開始位置から前記終了位置まで行ない、最後に前記部分書換えチェック領域に部分書換え完了コードを書込み、
前記CPUにより前記判定プログラムが実行されると、最初に前記第1メモリの全書換えチェック領域を読出し、読み出されたデータが前記全書換え完了コードに一致しない場合は前記全書換えプログラムを実行し、前記データが前記全書換え完了コードに一致する場合は、続いて前記フラグ格納領域を参照し、前記許可が設定されていれば前記部分書換えチェック領域を読出し、読み出されたデータが前記部分書換え完了コードに一致する場合は前記アプリケーションプログラムを実行し、前記データが前記部分書換え完了コードに一致しない場合は前記部分書換えプログラムを実行することを特徴とするマイクロコンピュータ。
A rewritable nonvolatile first memory in which an application program is stored, a total rewrite program for performing a complete rewrite of the first memory, and a determination program for performing a rewrite determination of the first memory are stored. A microcomputer comprising: a second memory; and a CPU that reads and executes each of the programs,
When the all-rewrite program is executed by the CPU, first the all-rewrite check area of the first memory is cleared and then all the areas of the memory are rewritten, and finally the all-rewrite completion code is stored in the rewrite check area. Write
The second memory also stores a partial rewriting program for performing partial rewriting of the first memory,
In the first memory, a storage area for a flag for setting the permission / prohibition of partial rewriting and an area for writing a start position and an end position are defined for the first memory together with the all-rewrite check area. It is set by the size within the writing unit,
When the partial rewrite program is executed by the CPU, the partial rewrite check area of the first memory is first cleared, then the memory is rewritten from the start position to the end position, and finally the partial rewrite check is performed. Write the partial rewrite completion code in the area,
When the determination program is executed by the CPU, first, the entire rewrite check area of the first memory is read, and when the read data does not match the complete rewrite completion code, the complete rewrite program is executed, If the data matches the complete rewrite completion code, the flag storage area is subsequently referred to, and if the permission is set, the partial rewrite check area is read, and the read data is the partial rewrite complete. The microcomputer executes the application program when the code matches the code, and executes the partial rewrite program when the data does not match the partial rewrite completion code.
前記部分書換えチェック領域には、その次に部分書き換えを行なう対象とする領域について、前記部分書換えの許可/禁止設定を行うフラグの格納領域と、開始位置及び終了位置を書き込む領域とが前記最小書込み単位内のサイズで設定されており、
前記部分書換えチェック領域を1つ以上備えることを特徴とする請求項6記載のマイクロコンピュータ。
In the partial rewrite check area, a storage area for a flag for setting permission / prohibition of partial rewrite and an area for writing a start position and an end position for the area to be subjected to partial rewrite next, and a minimum write area It is set with the size within the unit,
7. The microcomputer according to claim 6, further comprising one or more partial rewrite check areas.
前記CPUは、前記判定プログラムを、リセット時に実行することを特徴とする請求項1乃至7の何れかに記載のマイクロコンピュータ。   The microcomputer according to claim 1, wherein the CPU executes the determination program at the time of resetting. 前記CPUは、前記判定プログラムを、低消費電力モードが解除された時点に実行することを特徴とする請求項1乃至8の何れかに記載のマイクロコンピュータ。   The microcomputer according to claim 1, wherein the CPU executes the determination program when the low power consumption mode is canceled.
JP2007200839A 2006-12-07 2007-08-01 Microcomputer Expired - Fee Related JP4743182B2 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
JP2007200839A JP4743182B2 (en) 2006-12-07 2007-08-01 Microcomputer
US12/000,001 US7934050B2 (en) 2006-12-07 2007-12-06 Microcomputer for flash memory rewriting

Applications Claiming Priority (3)

Application Number Priority Date Filing Date Title
JP2006330799 2006-12-07
JP2006330799 2006-12-07
JP2007200839A JP4743182B2 (en) 2006-12-07 2007-08-01 Microcomputer

Publications (2)

Publication Number Publication Date
JP2008165729A true JP2008165729A (en) 2008-07-17
JP4743182B2 JP4743182B2 (en) 2011-08-10

Family

ID=39695088

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2007200839A Expired - Fee Related JP4743182B2 (en) 2006-12-07 2007-08-01 Microcomputer

Country Status (1)

Country Link
JP (1) JP4743182B2 (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2013021423A1 (en) * 2011-08-10 2013-02-14 トヨタ自動車株式会社 Reprogramming system and reprogramming method
JP2014164596A (en) * 2013-02-26 2014-09-08 Denso Corp Control system
EP3057101A1 (en) 2015-02-10 2016-08-17 Toyota Jidosha Kabushiki Kaisha Microcomputer apparatus, program rewriting system and rewriting program
DE102017202282A1 (en) 2016-02-17 2017-08-17 Denso Corporation VEHICLE CONTROL DEVICE AND VEHICLE NETWORK WITH VEHICLE CONTROL DEVICE
WO2023127516A1 (en) * 2021-12-27 2023-07-06 ソニーグループ株式会社 Replacement device, information processing method, and information processing device
CN112395122B (en) * 2019-08-16 2023-08-29 慧荣科技股份有限公司 Flash memory controller and method thereof

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2000105694A (en) * 1998-09-28 2000-04-11 Nec Ic Microcomput Syst Ltd Flash memory, microcomputer equipped with flash memory, and method for storing program in flash memory
JP2003015929A (en) * 2001-06-28 2003-01-17 Matsushita Electric Ind Co Ltd Control method for nonvolatile memory
JP2004102893A (en) * 2002-09-12 2004-04-02 Matsushita Electric Ind Co Ltd Remote downloader and remote download method
JP2005321843A (en) * 2004-05-06 2005-11-17 Hitachi Ltd Rewriting method for firmware
JP2006268176A (en) * 2005-03-22 2006-10-05 Denso Corp Data validity/invalidity deciding method for flash eeprom

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2000105694A (en) * 1998-09-28 2000-04-11 Nec Ic Microcomput Syst Ltd Flash memory, microcomputer equipped with flash memory, and method for storing program in flash memory
JP2003015929A (en) * 2001-06-28 2003-01-17 Matsushita Electric Ind Co Ltd Control method for nonvolatile memory
JP2004102893A (en) * 2002-09-12 2004-04-02 Matsushita Electric Ind Co Ltd Remote downloader and remote download method
JP2005321843A (en) * 2004-05-06 2005-11-17 Hitachi Ltd Rewriting method for firmware
JP2006268176A (en) * 2005-03-22 2006-10-05 Denso Corp Data validity/invalidity deciding method for flash eeprom

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2013021423A1 (en) * 2011-08-10 2013-02-14 トヨタ自動車株式会社 Reprogramming system and reprogramming method
JP2014164596A (en) * 2013-02-26 2014-09-08 Denso Corp Control system
EP3057101A1 (en) 2015-02-10 2016-08-17 Toyota Jidosha Kabushiki Kaisha Microcomputer apparatus, program rewriting system and rewriting program
JP2016148930A (en) * 2015-02-10 2016-08-18 トヨタ自動車株式会社 Microcomputer device
US9798658B2 (en) 2015-02-10 2017-10-24 Toyota Jidosha Kabushiki Kaisha Microcomputer apparatus, program rewriting system and non-transitory computer-readable information recording medium
DE102017202282A1 (en) 2016-02-17 2017-08-17 Denso Corporation VEHICLE CONTROL DEVICE AND VEHICLE NETWORK WITH VEHICLE CONTROL DEVICE
DE102017202282B4 (en) 2016-02-17 2023-12-07 Denso Corporation ON-VEHICLE CONTROL DEVICE AND ON-VEHICLE NETWORK WITH THE ON-VEHICLE CONTROL DEVICE
CN112395122B (en) * 2019-08-16 2023-08-29 慧荣科技股份有限公司 Flash memory controller and method thereof
WO2023127516A1 (en) * 2021-12-27 2023-07-06 ソニーグループ株式会社 Replacement device, information processing method, and information processing device

Also Published As

Publication number Publication date
JP4743182B2 (en) 2011-08-10

Similar Documents

Publication Publication Date Title
US10509568B2 (en) Efficient secure boot carried out in information processing apparatus
US7197613B2 (en) Nonvolatile memory
JP7022809B2 (en) Computer systems, their safety management methods, and computer software products
JP4743182B2 (en) Microcomputer
JP4227149B2 (en) Information storage method for electronic control unit
US6587916B2 (en) Microcomputer with built-in programmable nonvolatile memory
JP2990181B1 (en) Flash memory, microcomputer having flash memory, and method of storing program in flash memory
JP5576557B2 (en) Processor system and control method thereof
CN107015878B (en) System repair method and system for computer
US7934050B2 (en) Microcomputer for flash memory rewriting
JP7091486B2 (en) Electronic control device, security verification method for electronic control device
US20100185927A1 (en) Microprocessor System for Controlling at Least Partly Safety-Critical Processes
JP6622360B2 (en) Information processing device
JP6708596B2 (en) Electronic control device and control program verification method
JPH11265283A (en) Correction method for firmware in storage device, and storage device
US20040210751A1 (en) Method for booting computer system with basic input-output system memory and structure thereof
CN115454517B (en) Method, system, storage medium, device and chip for multi-medium secure boot
TWI726436B (en) Method for repairing basic input/output system bios and a computer system using the same
TWI446351B (en) Data writing method and computer system
JP2001331382A (en) Method and device for managing nonvolatile memory
TW202136995A (en) Memory apparatus and memory management method for safe power-up
CN113495808A (en) Memory device and memory management method for safe startup
JP2024044708A (en) Semiconductor storage device and memory system
CN117348910A (en) BootLoader upgrading method and system of intelligent cabin MCU
JP5720206B2 (en) Microprocessor

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20090707

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20100125

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20100330

A521 Request for written amendment filed

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20100510

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20110201

A521 Request for written amendment filed

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20110322

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20110412

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20110425

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20140520

Year of fee payment: 3

R151 Written notification of patent or utility model registration

Ref document number: 4743182

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R151

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20140520

Year of fee payment: 3

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250

LAPS Cancellation because of no payment of annual fees