JP2010102743A - Microcomputer - Google Patents

Microcomputer Download PDF

Info

Publication number
JP2010102743A
JP2010102743A JP2010026758A JP2010026758A JP2010102743A JP 2010102743 A JP2010102743 A JP 2010102743A JP 2010026758 A JP2010026758 A JP 2010026758A JP 2010026758 A JP2010026758 A JP 2010026758A JP 2010102743 A JP2010102743 A JP 2010102743A
Authority
JP
Japan
Prior art keywords
register
program
data
debug
built
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.)
Pending
Application number
JP2010026758A
Other languages
Japanese (ja)
Inventor
Shunichi Iwata
俊一 岩田
Takashi Nasu
隆 那須
Fumitaka Fukuzawa
史隆 福澤
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.)
Renesas Technology Corp
Original Assignee
Renesas Technology 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 Renesas Technology Corp filed Critical Renesas Technology Corp
Priority to JP2010026758A priority Critical patent/JP2010102743A/en
Publication of JP2010102743A publication Critical patent/JP2010102743A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

<P>PROBLEM TO BE SOLVED: To provide a microcomputer for performing overwrite control of a built-in flash memory 5 directly from a debug tool 2 to improve debug work efficiency. <P>SOLUTION: Built-in flash information stored in the built-in flash memory 5 is read by a CPU 3 from a debug tool 2 via a JTAG interface 11 and overwrite data based on the built-in flash information are input from the debut tool 2 via the JTAG interface 11; moreover, overwrite data are overwritten by the CPU 3 to the built-in flash memory 5 on the basis of an overwrite program stored in the built-in flash memory 5. <P>COPYRIGHT: (C)2010,JPO&INPIT

Description

この発明は、実使用環境下でデバッグを行う場合に有効なマイクロコンピュータに関するものである。   The present invention relates to a microcomputer effective for debugging in an actual use environment.

マイクロコンピュータ応用機器などに設けられたマイクロコンピュータのデバッグを行う場合に、ICE(エミュレータ)などのデバッグツールを使用する。マイクロコンピュータがフラッシュメモリを内蔵している場合には、デバッグ中にフラッシュメモリのデータを書き換える必要が生じる。しかしながら、従来のデバッグツールには、マイクロコンピュータに内蔵されているフラッシュメモリに対する書き換え機能を備えていないため、フラッシュメモリの書き換え専用ツールであるフラッシュライタを使用して書き換えを行うか、または、ユーザがフラッシュメモリの書き換えを行うためのプログラムを用意し、デバッグツールによりそのプログラムを実行することにより、書き換えを行っていた。   When debugging a microcomputer provided in a microcomputer application device or the like, a debugging tool such as an ICE (emulator) is used. When the microcomputer has a built-in flash memory, it is necessary to rewrite the data in the flash memory during debugging. However, since the conventional debugging tool does not have a rewriting function for the flash memory built in the microcomputer, the rewriting is performed using a flash writer which is a dedicated flash memory rewriting tool, or the user can A program for rewriting the flash memory was prepared, and the program was rewritten by executing the program with a debugging tool.

従来のマイクロコンピュータは以上のように構成されているので、フラッシュメモリの書き換えにフラッシュライタを使用する場合には、デバッグツールとは別にフラッシュライタを用意しなくてはならないので、デバッグのためのコストが高くなる。また、フラッシュメモリの構成に応じたフラッシュライタを使用しなくてはならないので、フラッシュメモリの構成が異なる度に異なるフラッシュライタを使用しなくてはならず、デバッグの作業効率が落ちるなどの課題があった。   Since the conventional microcomputer is configured as described above, if a flash writer is used for rewriting the flash memory, a flash writer must be prepared separately from the debugging tool. Becomes higher. In addition, since a flash writer must be used according to the configuration of the flash memory, a different flash writer must be used every time the flash memory configuration is different, resulting in problems such as reduced debugging work efficiency. there were.

さらに、デバッグツールにより書き換え用のプログラムを実行する場合には、ユーザが書き換え用のプログラムを用意しなくてはならず、デバッグの作業効率が落ちるなどの課題があった。   Furthermore, when a rewriting program is executed by a debugging tool, the user has to prepare a rewriting program, which causes problems such as a reduction in debugging work efficiency.

さらに、上記両フラッシュメモリの書き換え手法では、デバッグツールから直接にフラッシュメモリの書き換え制御を行うことができないため、フラッシュメモリの書き換えを伴うようなデバッグ機能を使用することができず、例えば、ソフトウエアブレーク機能を使用することができないなど、デバッグツールの機能が制限される課題があった。   Furthermore, in the above flash memory rewriting methods, the flash memory rewrite control cannot be performed directly from the debug tool, so that it is not possible to use a debugging function that involves rewriting the flash memory. There was a problem that the function of the debug tool was restricted, such as the inability to use the break function.

この発明は上記のような課題を解決するためになされたもので、デバッグツールから直接に内蔵フラッシュメモリの書き換え制御を行うことができ、デバッグの作業効率を高くすることが可能なマイクロコンピュータを得ることを目的とする。   The present invention has been made to solve the above-described problems, and provides a microcomputer capable of performing rewrite control of a built-in flash memory directly from a debug tool and capable of increasing the work efficiency of debugging. For the purpose.

この発明に係るマイクロコンピュータは、第2の格納手段に格納された内蔵フラッシュ情報をインタフェースを介してデバッグツールから読み出し可能にし、デバッグツールから内蔵フラッシュ情報に基づいた書き込みデータをインタフェースを介して入力して、第1の格納手段に格納された書き換えプログラムに基づいて書き込みデータを内蔵フラッシュメモリに書き換えるCPUを備えたものである。   The microcomputer according to the present invention makes it possible to read the internal flash information stored in the second storage means from the debug tool via the interface, and input write data based on the internal flash information from the debug tool via the interface. And a CPU for rewriting write data in the built-in flash memory based on the rewrite program stored in the first storage means.

この発明に係るマイクロコンピュータは、内蔵フラッシュメモリに第1の格納手段を設けたものである。   In the microcomputer according to the present invention, the first storage means is provided in the built-in flash memory.

この発明に係るマイクロコンピュータは、書き換えプログラムに、E/Wモード移行プログラム、消去プログラム、書き込みプログラム、ステータスレディ待ちプログラム、およびE/Wモード終了プログラムを備えたものである。   The microcomputer according to the present invention is provided with an E / W mode transition program, an erase program, a write program, a status ready wait program, and an E / W mode end program in the rewrite program.

この発明に係るマイクロコンピュータは、内蔵フラッシュメモリに第2の格納手段を設けたものである。   In the microcomputer according to the present invention, the second storage means is provided in the built-in flash memory.

この発明に係るマイクロコンピュータは、内蔵フラッシュ情報に、内蔵フラッシュメモリのブロックのサイズおよびアドレスからなるブロック情報と、書き換えプログラムの先頭アドレスからなる書き換えプログラム情報とを備えたものである。   The microcomputer according to the present invention includes the built-in flash information including block information composed of the block size and address of the built-in flash memory and rewrite program information composed of the start address of the rewrite program.

この発明に係るマイクロコンピュータは、内蔵フラッシュ情報に、セキュリティコードの格納場所を示す情報を備えたものである。   In the microcomputer according to the present invention, the internal flash information is provided with information indicating the storage location of the security code.

この発明に係るマイクロコンピュータは、内蔵フラッシュ情報に、内蔵フラッシュメモリの書き換えプログラムを退避したり、書き込みデータをテンポラリに保持するのに使用する領域がどこにあるかを示す情報を備えたものである。   The microcomputer according to the present invention includes, in the built-in flash information, information indicating where an area used for saving a rewrite program of the built-in flash memory and temporarily holding write data is present.

この発明に係るマイクロコンピュータは、内蔵フラッシュ情報に、内蔵フラッシュメモリの書き換え時に書き込みデータを一旦保持するために使用する領域のサイズ情報を備えたものである。   In the microcomputer according to the present invention, the built-in flash information is provided with size information of an area used to temporarily hold write data when the built-in flash memory is rewritten.

この発明に係るマイクロコンピュータは、内蔵フラッシュメモリの書き換えプログラムを格納した第1の格納手段と、内蔵フラッシュメモリに関する内蔵フラッシュ情報を格納した第2の格納手段と、デバッグツールからシリアルインタフェースを介して第1のレジスタに保持されたデバッグプログラムの命令コードに基づいてデバッグを実行すると共に、内蔵フラッシュ情報を第2のレジスタに保持させ、シリアルインタフェースを介してデバッグツールから読み出し可能にし、デバッグツールからシリアルインタフェースを介して第3のレジスタに保持された内蔵フラッシュ情報に基づいた書き込みデータを書き換えプログラムに基づいて内蔵フラッシュメモリに書き換えるCPUとを備えたものである。   The microcomputer according to the present invention includes a first storage means for storing a rewrite program for the internal flash memory, a second storage means for storing internal flash information related to the internal flash memory, and a debug tool via a serial interface via a serial interface. Debugging is executed based on the instruction code of the debug program held in the register 1 and the internal flash information is held in the second register so that it can be read out from the debug tool via the serial interface. And a CPU for rewriting write data based on the built-in flash information held in the third register to the built-in flash memory based on the rewrite program.

この発明に係るマイクロコンピュータは、シリアルインタフェースをJTAGインタフェースとしたものである。   In the microcomputer according to the present invention, the serial interface is a JTAG interface.

この発明に係るマイクロコンピュータは、デバッグモードになると内蔵フラッシュメモリの書き換えを許可するFP端子の入力値にかかわらず強制的にその内蔵フラッシュメモリの書き換えを許可する書き換え許可手段を備えたものである。   The microcomputer according to the present invention includes rewrite permission means for forcibly permit rewriting of the built-in flash memory regardless of the input value of the FP terminal permitting rewrite of the built-in flash memory in the debug mode.

この発明に係るマイクロコンピュータは、デバッグツールからの分岐命令コードに応じてCPUによって内蔵フラッシュメモリの消去および書き込み可能なモードに移行するE/Wモード移行プログラム実行手段と、デバッグツールからの分岐命令コードに応じてCPUによって消去プログラムを実行して、デバッグツールからの内蔵フラッシュメモリのアドレスに応じたブロックのデータを消去する消去プログラム実行手段と、デバッグツールからの分岐命令コードに応じてCPUによって消去実行状況情報をデバッグツールから読み出し可能にするステータスレディ待ちプログラム実行手段と、消去実行状況情報が正常と認められ、内蔵フラッシュメモリの消去すべきブロックに応じて消去プログラム実行手段およびステータスレディ待ちプログラム実行手段を所定回数実行した後に、デバッグツールからの分岐命令コードに応じてCPUによって通常モードに移行するE/Wモード終了プログラム実行手段とを備えたものである。   The microcomputer according to the present invention includes an E / W mode transition program execution means for shifting to a mode in which the internal flash memory can be erased and written by the CPU according to a branch instruction code from the debug tool, and a branch instruction code from the debug tool The erase program is executed by the CPU in accordance with the erase program execution means for erasing the block data in accordance with the address of the internal flash memory from the debug tool, and the CPU executes the erase in accordance with the branch instruction code from the debug tool. Status ready wait program execution means that enables status information to be read from the debug tool, and erase program execution means and status ready wait according to the block to be erased in the internal flash memory where the erase execution status information is recognized as normal Program execution means after a predetermined number of times of execution, in which a E / W mode end program execution means to shift to the normal mode by the CPU in response to the branch instruction code from the debug tool.

この発明に係るマイクロコンピュータは、デバッグツールからの分岐命令コードに応じてCPUによって内蔵フラッシュメモリの消去および書き込み可能なモードに移行するE/Wモード移行プログラム実行手段と、デバッグツールからの分岐命令コードに応じてCPUによって消去プログラムを実行して、デバッグツールからの内蔵フラッシュメモリのアドレスに応じたブロックのデータを消去する消去プログラム実行手段と、デバッグツールからの分岐命令コードに応じてCPUによって書き込みプログラムを実行して、デバッグツールからの内蔵フラッシュメモリのアドレスに、デバッグツールからの書き込みデータを書き込む書き込みプログラム実行手段と、デバッグツールからの分岐命令コードに応じてCPUによって書き込み実行状況情報をデバッグツールから読み出し可能にするステータスレディ待ちプログラム実行手段と、書き込み実行状況情報が正常と認められ、内蔵フラッシュメモリの書き換えすべきブロックに応じて消去プログラム実行手段、書き込みプログラム実行手段およびステータスレディ待ちプログラム実行手段を所定回数実行した後に、デバッグツールからの分岐命令コードに応じてCPUによって通常モードに移行するE/Wモード終了プログラム実行手段とを備えたものである。   The microcomputer according to the present invention includes an E / W mode transition program execution means for shifting to a mode in which the internal flash memory can be erased and written by the CPU according to a branch instruction code from the debug tool, and a branch instruction code from the debug tool The erase program is executed by the CPU in accordance with the program, and erase program execution means for erasing the block data in accordance with the address of the built-in flash memory from the debug tool, and the write program by the CPU in accordance with the branch instruction code from the debug tool And write program execution means for writing the write data from the debug tool to the address of the internal flash memory from the debug tool, and write execution by the CPU according to the branch instruction code from the debug tool. Status ready waiting program execution means that makes it possible to read status information from the debug tool, and erase execution means, write program execution means and status according to the block to be rewritten in the internal flash memory where the write execution status information is recognized as normal After executing the ready waiting program execution means a predetermined number of times, an E / W mode end program execution means for shifting to the normal mode by the CPU in accordance with a branch instruction code from the debug tool is provided.

以上のように、この発明によれば、第2の格納手段に格納された内蔵フラッシュ情報をインタフェースを介してデバッグツールから読み出し可能にし、デバッグツールから内蔵フラッシュ情報に基づいた書き込みデータをインタフェースを介して入力して、第1の格納手段に格納された書き換えプログラムに基づいて書き込みデータを内蔵フラッシュメモリに書き換えるCPUを備えるように構成したので、デバッグ時にデバッグツールからマイクロコンピュータに内蔵される書き換えプログラムを用いて直接に内蔵フラッシュメモリの書き換え制御を行うことができ、デバッグの作業効率を高くすることができる。   As described above, according to the present invention, the internal flash information stored in the second storage means can be read from the debug tool via the interface, and the write data based on the internal flash information can be read from the debug tool via the interface. And a CPU that rewrites the write data into the built-in flash memory based on the rewrite program stored in the first storage means. The built-in flash memory can be directly rewritten and used, and the work efficiency of debugging can be increased.

また、内蔵フラッシュ情報をマイクロコンピュータに内蔵し、デバッグツールがその内蔵フラッシュ情報を読み出すことが可能であるため、デバッグツールはその内蔵フラッシュ情報に応じて書き込みデータを用意することができる。したがって、内蔵フラッシュメモリの容量やブロック構成等が異なるマイクロコンピュータであっても、同じデバッグツールで書き換えが可能となる効果が得られる。   Further, since the built-in flash information is built into the microcomputer and the debug tool can read the built-in flash information, the debug tool can prepare write data according to the built-in flash information. Therefore, even if the microcomputers have different internal flash memory capacities, block configurations, etc., the same debug tool can be used for rewriting.

さらに、内蔵フラッシュメモリの書き換えプログラムをマイクロコンピュータに内蔵し、デバッグツールがその書き換えプログラムを起動することで内蔵フラッシュメモリの書き換えを行うようなインターフェースとなっているので、内蔵フラッシュメモリの書き換え手法が異なるマイクロコンピュータであっても、同じデバッグツールで書き換えが可能となる効果が得られる。   Furthermore, the built-in flash memory rewrite program is built into the microcomputer, and the interface is such that the internal flash memory is rewritten when the debug tool starts the rewrite program. Even with a microcomputer, the same debugging tool can be used for rewriting.

また、この発明によれば、内蔵フラッシュメモリに第1の格納手段を設けるように構成したので、書き換えプログラムは内蔵フラッシュメモリに格納されるので、マイクロコンピュータのチップが製作された後からでも書き換えプログラムを書き込んだり、また、書き換えたりすることができる効果が得られる。   Also, according to the present invention, since the first storage means is provided in the built-in flash memory, the rewrite program is stored in the built-in flash memory, so that the rewrite program can be stored even after the microcomputer chip is manufactured. Can be written or rewritten.

さらに、この発明によれば、書き換えプログラムに、E/Wモード移行プログラム、消去プログラム、書き込みプログラム、ステータスレディ待ちプログラム、およびE/Wモード終了プログラムを備えるように構成したので、書き換えプログラムを細かなプログラムモジュールによって構成することにより、全体の書き換えプログラムを小型化することができる。   Furthermore, according to the present invention, the rewrite program is configured to include the E / W mode transition program, the erase program, the write program, the status ready wait program, and the E / W mode end program. By configuring the program module, the entire rewriting program can be reduced in size.

また、消去プログラム、および書き込みプログラムに分割することにより、内蔵フラッシュメモリの消去のみの処理を行うことができる効果が得られる。   Further, by dividing the program into an erasing program and a writing program, an effect of performing only the erasing of the built-in flash memory can be obtained.

さらに、この発明によれば、内蔵フラッシュメモリに第2の格納手段を設けるように構成したので、内蔵フラッシュ情報は内蔵フラッシュメモリに格納されるので、マイクロコンピュータのチップが製作された後からでも内蔵フラッシュ情報を書き込んだり、また、書き換えたりすることができる効果が得られる。   Further, according to the present invention, since the second storage means is provided in the built-in flash memory, the built-in flash information is stored in the built-in flash memory, so that the built-in flash memory is built in even after the microcomputer chip is manufactured. The effect that the flash information can be written or rewritten can be obtained.

さらに、この発明によれば、内蔵フラッシュ情報に、内蔵フラッシュメモリのブロックのサイズおよびアドレスからなるブロック情報と、書き換えプログラムの先頭アドレスからなる書き換えプログラム情報とを備えるように構成したので、デバッグツールは、ブロック情報に応じて書き換えデータを用意することができる。したがって、内蔵フラッシュメモリの容量やブロック構成、配置アドレスなどが異なるマイクロコンピュータであっても、同じデバッグツールで書き換えが可能となる効果が得られる。   Furthermore, according to the present invention, since the built-in flash information includes the block information including the block size and address of the built-in flash memory and the rewrite program information including the start address of the rewrite program, the debug tool The rewrite data can be prepared according to the block information. Therefore, even if the microcomputers have different internal flash memory capacities, block configurations, arrangement addresses, etc., the same debugging tool can be used for rewriting.

また、内蔵フラッシュメモリの書き換えプログラムの格納場所をデバッグツールが読み出すことができるので、内蔵フラッシュメモリの書き換えプログラムの格納場所が異なるマイクロコンピュータであっても、同じデバッグツールで書き換えが可能となる効果が得られる。   In addition, since the debug tool can read the storage location of the rewrite program in the internal flash memory, the same debug tool can be used for rewriting even if the internal flash memory rewrite program storage location is different. can get.

さらに、この発明によれば、内蔵フラッシュ情報に、セキュリティコードの格納場所を示す情報を備えるように構成したので、デバッグツールに、そのセキュリティコードとユーザによって入力されるセキュリティコードとの比較に応じて、書き換えを許可する機能を持たせることができる効果が得られる。   Further, according to the present invention, the built-in flash information is configured to include information indicating the storage location of the security code, so that the debugging tool can be compared with the security code input by the user according to the comparison. Thus, an effect of providing a function for permitting rewriting is obtained.

さらに、この発明によれば、内蔵フラッシュ情報に、内蔵フラッシュメモリの書き換え時に書き換えプログラムを退避したり、書き込みデータをテンポラリに保持するのに使用する領域がどこにあるかを示す情報を備えるように構成したので、デバッグツールでは、そのテンポラリ領域上のデータを退避させることができ、内蔵フラッシュメモリの書き換え処理によってテンポラリ領域上のデータが消去されてしまうのを未然に防ぐことができる効果が得られる。   Further, according to the present invention, the internal flash information is configured to include information indicating where an area used for saving the rewrite program when rewriting the internal flash memory or temporarily holding the write data is provided. As a result, the debug tool can save the data in the temporary area and can prevent the data in the temporary area from being erased by the rewriting process of the built-in flash memory.

さらに、この発明によれば、内蔵フラッシュ情報に、内蔵フラッシュメモリの書き換え時に書き込みデータを一旦保持するために使用する領域のサイズ情報を備えるように構成したので、デバッグツールでは、そのサイズ情報に応じて書き込みデータを生成することができる効果が得られる。   Furthermore, according to the present invention, the built-in flash information is configured to include the size information of the area used to temporarily hold the write data when rewriting the built-in flash memory. As a result, it is possible to produce the write data.

さらに、この発明によれば、内蔵フラッシュメモリの書き換えプログラムを格納した第1の格納手段と、内蔵フラッシュメモリに関する内蔵フラッシュ情報を格納した第2の格納手段と、デバッグツールからシリアルインタフェースを介して第1のレジスタに保持されたデバッグプログラムの命令コードに基づいてデバッグを実行すると共に、内蔵フラッシュ情報を第2のレジスタに保持させ、シリアルインタフェースを介してデバッグツールから読み出し可能にし、デバッグツールからシリアルインタフェースを介して第3のレジスタに保持された内蔵フラッシュ情報に基づいた書き込みデータを書き換えプログラムに基づいて内蔵フラッシュメモリに書き換えるCPUとを備えるように構成したので、デバッグツールからデバッグプログラムの命令コードを第1のレジスタに設定すれば、このマイクロコンピュータのデバッグを行うことができ、さらに、そのデバッグ時にデバッグツールから直接に内蔵フラッシュメモリの書き換え制御を行うことができ、デバッグの作業効率をさらに高くすることができる。   Further, according to the present invention, the first storage means storing the rewrite program of the internal flash memory, the second storage means storing the internal flash information regarding the internal flash memory, and the debug tool via the serial interface via the serial interface. Debugging is executed based on the instruction code of the debug program held in the register 1 and the internal flash information is held in the second register so that it can be read out from the debug tool via the serial interface. And a CPU that rewrites the write data based on the built-in flash information held in the third register to the built-in flash memory based on the rewrite program. This microcomputer can be debugged if the instruction code of the program is set in the first register, and the internal flash memory can be rewritten directly from the debugging tool during debugging. Efficiency can be further increased.

また、内蔵フラッシュ情報をマイクロコンピュータに内蔵し、デバッグツールがその内蔵フラッシュ情報を読み出すことが可能であるため、デバッグツールはその内蔵フラッシュ情報に応じて書き込みデータを用意することができる。したがって、内蔵フラッシュメモリの容量やブロック構成等が異なるマイクロコンピュータであっても、同じデバッグツールで書き換えが可能となる効果が得られる。   Further, since the built-in flash information is built into the microcomputer and the debug tool can read the built-in flash information, the debug tool can prepare write data according to the built-in flash information. Therefore, even if the microcomputers have different internal flash memory capacities, block configurations, etc., the same debug tool can be used for rewriting.

さらに、内蔵フラッシュメモリの書き換えプログラムをマイクロコンピュータに内蔵し、デバッグツールがその書き換えプログラムを起動することで内蔵フラッシュメモリの書き換えを行うようなインターフェースとなっているので、内蔵フラッシュメモリの書き換え手法が異なるマイクロコンピュータであっても、同じデバッグツールで書き換えが可能となる効果が得られる。   Furthermore, the built-in flash memory rewrite program is built into the microcomputer, and the interface is such that the internal flash memory is rewritten when the debug tool starts the rewrite program. Even with a microcomputer, the same debugging tool can be used for rewriting.

さらに、シリアルなインターフェースを使用することによって、デバッグツールとのインターフェース用端子を少なくすることができる効果が得られる。   Further, by using a serial interface, an effect of reducing the number of terminals for interface with the debug tool can be obtained.

さらに、デバッグツールからCPU命令を供給可能な機能は、マイクロプロセッサの通常のデバッグに使用できる機能であることから、この機能は通常のデバッグと内蔵フラッシュメモリの書き換え機能とを共用することができる。従って、内蔵フラッシュメモリ専用のハードウェアを追加することがないという効果が得られる。   Furthermore, since the function that can supply the CPU instruction from the debug tool is a function that can be used for normal debugging of the microprocessor, this function can share the normal debugging and the rewriting function of the built-in flash memory. Therefore, there is an effect that no hardware dedicated to the built-in flash memory is added.

さらに、この発明によれば、シリアルインタフェースをJTAGインタフェースとするように構成したので、バウンダリスキャンテストを行うJTAGインタフェースと共有化することができ、新たなシリアルインタフェースを設ける必要が無く、構成を簡単にすることができる効果が得られる。   Furthermore, according to the present invention, since the serial interface is configured as the JTAG interface, it can be shared with the JTAG interface for performing the boundary scan test, and there is no need to provide a new serial interface, and the configuration is simplified. The effect which can be done is acquired.

さらに、この発明によれば、デバッグモードになると内蔵フラッシュメモリの書き換えを許可するFP端子の入力値にかかわらず強制的にその内蔵フラッシュメモリの書き換えを許可する書き換え許可手段を備えるように構成したので、デバッグモードでは、FP端子の入力値にかかわらずデバッグツールによって内蔵フラッシュメモリの書き換えを行うことができる効果が得られる。   Furthermore, according to the present invention, since it is configured to include the rewrite permission means for forcibly permit rewriting of the built-in flash memory regardless of the input value of the FP terminal permitting rewrite of the built-in flash memory in the debug mode. In the debug mode, there is an effect that the built-in flash memory can be rewritten by the debug tool regardless of the input value of the FP terminal.

さらに、この発明によれば、デバッグツールからの分岐命令コードに応じてCPUによって内蔵フラッシュメモリの消去および書き込み可能なモードに移行するE/Wモード移行プログラム実行手段と、デバッグツールからの分岐命令コードに応じてCPUによって消去プログラムを実行して、デバッグツールからの内蔵フラッシュメモリのアドレスに応じたブロックのデータを消去する消去プログラム実行手段と、デバッグツールからの分岐命令コードに応じてCPUによって消去実行状況情報をデバッグツールから読み出し可能にするステータスレディ待ちプログラム実行手段と、消去実行状況情報が正常と認められ、内蔵フラッシュメモリの消去すべきブロックに応じて消去プログラム実行手段およびステータスレディ待ちプログラム実行手段を所定回数実行した後に、デバッグツールからの分岐命令コードに応じてCPUによって通常モードに移行するE/Wモード終了プログラム実行手段とを備えるように構成したので、デバッグツールからの分岐命令コードに応じて、内蔵フラッシュメモリの所定のブロックのデータを消去する一連の消去処理を実行することができる効果が得られる。   Furthermore, according to the present invention, an E / W mode transition program executing means for shifting to a mode in which the built-in flash memory can be erased and written by the CPU in accordance with a branch instruction code from the debug tool, and a branch instruction code from the debug tool The erase program is executed by the CPU in accordance with the erase program execution means for erasing the block data in accordance with the address of the internal flash memory from the debug tool, and the CPU executes the erase in accordance with the branch instruction code from the debug tool. Status ready wait program execution means that enables status information to be read from the debug tool, and erase program execution means and status ready wait program according to the block to be erased in the internal flash memory where the erase execution status information is recognized as normal Since the E / W mode end program executing means for shifting to the normal mode by the CPU according to the branch instruction code from the debug tool after executing the line means a predetermined number of times, the branch instruction code from the debug tool is provided. Accordingly, an effect of performing a series of erasing processes for erasing data in a predetermined block of the built-in flash memory can be obtained.

さらに、この発明によれば、デバッグツールからの分岐命令コードに応じてCPUによって内蔵フラッシュメモリの消去および書き込み可能なモードに移行するE/Wモード移行プログラム実行手段と、デバッグツールからの分岐命令コードに応じてCPUによって消去プログラムを実行して、デバッグツールからの内蔵フラッシュメモリのアドレスに応じたブロックのデータを消去する消去プログラム実行手段と、デバッグツールからの分岐命令コードに応じてCPUによって書き込みプログラムを実行して、デバッグツールからの内蔵フラッシュメモリのアドレスに、デバッグツールからの書き込みデータを書き込む書き込みプログラム実行手段と、デバッグツールからの分岐命令コードに応じてCPUによって書き込み実行状況情報をデバッグツールから読み出し可能にするステータスレディ待ちプログラム実行手段と、書き込み実行状況情報が正常と認められ、内蔵フラッシュメモリの書き換えすべきブロックに応じて消去プログラム実行手段、書き込みプログラム実行手段およびステータスレディ待ちプログラム実行手段を所定回数実行した後に、デバッグツールからの分岐命令コードに応じてCPUによって通常モードに移行するE/Wモード終了プログラム実行手段とを備えるように構成したので、デバッグツールからの分岐命令コードに応じて、内蔵フラッシュメモリの所定のブロックに書き込みデータを書き換える一連の書き換え処理を実行することができる効果が得られる。   Furthermore, according to the present invention, an E / W mode transition program executing means for shifting to a mode in which the built-in flash memory can be erased and written by the CPU in accordance with a branch instruction code from the debug tool, and a branch instruction code from the debug tool The erase program is executed by the CPU in accordance with the program, and erase program execution means for erasing the block data in accordance with the address of the built-in flash memory from the debug tool, and the write program by the CPU in accordance with the branch instruction code from the debug tool And write program execution means for writing the write data from the debug tool to the address of the built-in flash memory from the debug tool, and write execution status information by the CPU according to the branch instruction code from the debug tool Status ready waiting program execution means that can be read from the bag tool, and erase execution means, writing program execution means, and status ready waiting program according to the block to be rewritten in the internal flash memory where the write execution status information is recognized as normal Since the execution means is executed a predetermined number of times, and the E / W mode end program execution means for shifting to the normal mode by the CPU according to the branch instruction code from the debug tool is provided, the branch instruction code from the debug tool is provided. Accordingly, it is possible to execute a series of rewriting processes for rewriting write data in a predetermined block of the built-in flash memory.

この発明の実施の形態1によるマイクロコンピュータを示す構成図である。It is a block diagram which shows the microcomputer by Embodiment 1 of this invention. マイクロコンピュータのCPUおよびデバッグモジュールの詳細を示す構成図である。It is a block diagram which shows the detail of CPU and a debug module of a microcomputer. デバッグ事象発生時の処理手順を示す説明図である。It is explanatory drawing which shows the process sequence at the time of a debug event generation | occurrence | production. 内蔵領域にマッピングされたデバッグモジュール用領域を示す説明図である。It is explanatory drawing which shows the area | region for debug modules mapped by the built-in area | region. モニタコード供給機能およびJTAG制御部のレジスタ構成を示す構成図である。It is a block diagram which shows the register structure of a monitor code supply function and a JTAG control part. 内蔵フラッシュメモリのメモリ領域を示す説明図である。It is explanatory drawing which shows the memory area of a built-in flash memory. フラッシュレディステータスレジスタを示す説明図である。It is explanatory drawing which shows a flash ready status register. フラッシュメモリ制御レジスタを示す説明図である。It is explanatory drawing which shows a flash memory control register. 内蔵フラッシュ書き換えに関する情報を示す説明図である。It is explanatory drawing which shows the information regarding internal flash rewriting. ツールROM領域の構成を示す説明図である。It is explanatory drawing which shows the structure of a tool ROM area | region. 内蔵フラッシュ情報格納領域の構成を示す説明図である。It is explanatory drawing which shows the structure of a built-in flash information storage area. モニタコード供給機能およびJTAG制御部の動作を示すフローチャートである。It is a flowchart which shows the operation | movement of a monitor code supply function and a JTAG control part. 内蔵フラッシュメモリの書き換え動作の概要を示すフローチャートである。It is a flowchart which shows the outline | summary of the rewriting operation | movement of a built-in flash memory. 内蔵フラッシュメモリの消去動作を示すフローチャートである。It is a flowchart which shows the erase | elimination operation | movement of a built-in flash memory. 内蔵フラッシュメモリの消去動作の詳細を示すフローチャートである。3 is a flowchart showing details of an erasing operation of a built-in flash memory. 内蔵フラッシュメモリの書き込み動作を示すフローチャートである。It is a flowchart which shows the write-in operation | movement of a built-in flash memory. 内蔵フラッシュメモリの書き込み動作の詳細を示すフローチャートである。It is a flowchart which shows the detail of write-in operation | movement of a built-in flash memory.

以下、この発明の実施の一形態を説明する。
実施の形態1.
図1はこの発明の実施の形態1によるマイクロコンピュータを示す構成図であり、図において、1はマイクロコンピュータ応用機器などに設けられた1チップのマイクロコンピュータ、2はマイクロコンピュータ1のデバッグ時に接続される汎用的なデバッグツールである。また、マイクロコンピュータ1において、3は32ビット汎用レジスタを16本(R0〜R15)備えたマイクロプロセッサであるCPU、4はこの実施の形態1の特徴であるデバッグモジュール、5はこの実施の形態1の特徴であるユーザプログラムなどが格納された内蔵フラッシュメモリ、6はこの実施の形態1の特徴である内蔵SRAM、7はDMAコントローラ、割り込みコントローラ、タイマなどの内蔵周辺I/O、8はバス制御回路、9は上記各モジュールを接続する32ビットの内部バスである。
An embodiment of the present invention will be described below.
Embodiment 1 FIG.
FIG. 1 is a block diagram showing a microcomputer according to Embodiment 1 of the present invention. In FIG. 1, reference numeral 1 denotes a one-chip microcomputer provided in a microcomputer application device or the like, and reference numeral 2 denotes a connection when the microcomputer 1 is debugged. It is a general-purpose debugging tool. In the microcomputer 1, 3 is a CPU which is a microprocessor having 16 32-bit general purpose registers (R0 to R15), 4 is a debug module which is a feature of the first embodiment, and 5 is a first embodiment. The built-in flash memory storing the user program, which is a characteristic of the first embodiment, 6 is a built-in SRAM which is the characteristic of the first embodiment, 7 is a built-in peripheral I / O such as a DMA controller, interrupt controller, and timer, and 8 is bus control. A circuit 9 is a 32-bit internal bus connecting the modules.

また、内蔵フラッシュメモリ5の周辺において、5aは“1”の入力値で内蔵フラッシュメモリ5の書き換えの許可、“0”の入力値で書き換えを禁止するフラッシュプロテクト信号を入力するFP端子、5bはそのフラッシュプロテクト信号と、CPU3から出力されるデバッグモードで“1”、通常モードで“0”となるモード信号との論理和をとるOR回路、5cはそのOR回路5bの出力値が“1”で、内蔵フラッシュメモリ5の書き換えを許可し、“0”で、内蔵フラッシュメモリ5の書き換えを禁止するフラッシュ内部制御回路であり、OR回路5bおよびフラッシュ内部制御回路5cにより、FP端子5aの入力値にかかわらずデバッグモードになると内蔵フラッシュメモリ5の書き換えを強制的に許可する書き換え許可手段を構成する。   Further, in the periphery of the built-in flash memory 5, 5a is an FP terminal for inputting a flash protect signal for permitting rewrite of the built-in flash memory 5 with an input value of “1”, and for prohibiting rewrite with an input value of “0”, and 5b. An OR circuit that takes the logical sum of the flash protect signal and a mode signal that is “1” in the debug mode and “0” in the normal mode that is output from the CPU 3. The output value of the OR circuit 5 b is “1”. The internal flash memory 5 is a flash internal control circuit that permits rewriting of the internal flash memory 5 and prohibits rewriting of the internal flash memory 5 when “0”. The input value of the FP terminal 5a is determined by the OR circuit 5b and the flash internal control circuit 5c. Rewrite permission means for forcibly allowing rewriting of the built-in flash memory 5 when the debug mode is entered regardless of To configure.

図2はマイクロコンピュータのCPUおよびデバッグモジュールの詳細を示す構成図であり、図において、11はデバッグモジュール4と外部のデバッグツール2とを接続するIEEE 1149.1で定められた5本のJTAGインタフェース端子(インタフェース,シリアルインタフェース)であり、各端子の機能を以下に説明する。   FIG. 2 is a block diagram showing details of the CPU and debug module of the microcomputer. In FIG. 2, reference numeral 11 denotes five JTAG interfaces defined by IEEE 1149.1 for connecting the debug module 4 and the external debug tool 2. Terminals (interface, serial interface), and the function of each terminal will be described below.

TCK端子:クロック入力端子
TDI端子:テスト命令コードまたはテストデータをシリアルに入力する端子
TDO端子:テスト命令コードまたはテストデータをシリアルに出力する端子
TMS端子:テスト回路の状態遷移を制御するテストモード選択を入力する端子
TRST端子:テスト回路を非同期に初期化するテストリセットを入力する端子
12はチップ外部からCPU3に対してデバッグ割り込みを入力する端子である。
TCK terminal: Clock input terminal TDI terminal: Terminal for inputting test instruction code or test data serially TDO terminal: Terminal for outputting test instruction code or test data serially TMS terminal: Test mode selection for controlling state transition of test circuit TRST terminal: A terminal for inputting a test reset for asynchronously initializing the test circuit 12 is a terminal for inputting a debug interrupt to the CPU 3 from the outside of the chip.

また、CPU3において、13aはデバッグトラップ命令実行機能であり、このデバッグトラップ命令実行機能13aは、デバッグ専用のトラップ命令であり、CPU3がこの命令を実行することによりデバッグ事象が発生し、デバッグモードに移行するものである。13bはプログラムカウンタであり、このプログラムカウンタ13bは、CPU3が実行している命令のアドレスを保持するレジスタである。13cはプログラムカウンタ退避用レジスタであり、このプログラムカウンタ退避用レジスタ13cは、デバッグ事象等が発生した時にプログラムカウンタ13b値の退避先となるレジスタである。13dはPSWレジスタであり、このPSWレジスタ13dは、CPU3の状態を示すレジスタである。13eはPSW退避用レジスタであり、このPSW退避用レジスタ13eは、デバッグ事象等が発生した時にPSWレジスタ13d値の退避先となるレジスタである。CPU3は、上記以外にもロード命令、ストア命令、分岐命令、加算命令等、一般的なCPUが備えている命令実行機能と汎用レジスタ13fを16本備えている。ここではこの実施の形態とは直接関係が無いので詳細は省略する。14は実行後PCブレーク機能であり、この実行後PCブレーク機能14は、ターゲットとなる命令のプログラムカウンタ値を設定すると、その命令の実行直後にデバッグ事象が発生し、デバッグモードに移行するものである。   Further, in the CPU 3, 13a is a debug trap instruction execution function, and this debug trap instruction execution function 13a is a debug dedicated trap instruction. When the CPU 3 executes this instruction, a debug event occurs and the debug mode is entered. It is to be migrated. Reference numeral 13b denotes a program counter. The program counter 13b is a register that holds an address of an instruction executed by the CPU 3. Reference numeral 13c denotes a program counter saving register. The program counter saving register 13c is a register to which the value of the program counter 13b is saved when a debug event or the like occurs. Reference numeral 13d denotes a PSW register, and the PSW register 13d is a register indicating the state of the CPU 3. Reference numeral 13e denotes a PSW saving register, and the PSW saving register 13e is a register to which the value of the PSW register 13d is saved when a debug event or the like occurs. In addition to the above, the CPU 3 has 16 instruction execution functions and general-purpose registers 13f provided in a general CPU such as a load instruction, a store instruction, a branch instruction, and an addition instruction. Here, since it is not directly related to this embodiment, the details are omitted. Reference numeral 14 denotes a post-execution PC break function. The post-execution PC break function 14 sets a program counter value of a target instruction, a debug event occurs immediately after the execution of the instruction, and shifts to a debug mode. is there.

さらに、デバッグモジュール4において、15はJTAG制御部であり、このJTAG制御部15は、JTAGインタフェース端子11を通じてデバッグツール2と通信を行い、デバッグ機能の制御を行うものであり、JTAGインタフェース端子11でアクセス可能なデバッグ関連の制御レジスタやJTAGインタフェース端子11でのアクセスを制御するTAPコントローラなどで構成されている。16はこの実施の形態1の特徴であるJTAGインタフェース端子11を通じてCPU命令を実行するモニタコード供給機能、17はアクセスブレーク機能であり、このアクセスブレーク機能17は、ターゲットとなるデータアクセスの条件を設定すると、設定された条件を満たすデータアクセスを検出する。条件が成立するとCPU3に対してデバッグ割り込み要求を出力するものである。18は実行前PC(プログラムカウンタ)ブレーク機能であり、この実行前PCブレーク機能18は、ターゲットとなる命令のプログラムカウンタ値を設定すると、その命令がフェッチされたことを検出してCPU3に実行前PCブレーク要求を出力する。CPU3が実行前PCブレーク要求を受け取ると、その命令の実行直前にデバッグ事象が発生し、デバッグモードに移行するものである。19はデバッグ割り込み要求であり、このデバッグ割り込み要求19は、デバッグ専用の割り込みであり、DBI端子12、JTAG制御部15、アクセスブレーク機能17の3個所から発生するデバッグ割り込み要求を論理和して1本化してからCPU3に対して出力するものである。CPU3にデバッグ要求が入力されるとデバッグ事象が発生し、デバッグモードに移行する。   In the debug module 4, reference numeral 15 denotes a JTAG control unit. The JTAG control unit 15 communicates with the debug tool 2 through the JTAG interface terminal 11 to control the debugging function. It includes an accessible debug-related control register, a TAP controller that controls access at the JTAG interface terminal 11, and the like. Reference numeral 16 denotes a monitor code supply function for executing a CPU instruction through the JTAG interface terminal 11 which is a feature of the first embodiment. Reference numeral 17 denotes an access break function. The access break function 17 sets a target data access condition. Then, data access satisfying the set condition is detected. When the condition is satisfied, a debug interrupt request is output to the CPU 3. Reference numeral 18 denotes a pre-execution PC (program counter) break function. When the pre-execution PC break function 18 sets a program counter value of a target instruction, the pre-execution PC break function 18 detects that the instruction has been fetched and A PC break request is output. When the CPU 3 receives a pre-execution PC break request, a debug event occurs immediately before the execution of the instruction, and a transition is made to the debug mode. Reference numeral 19 denotes a debug interrupt request. This debug interrupt request 19 is a debug-dedicated interrupt, and is obtained by logically ORing debug interrupt requests generated from three locations of the DBI terminal 12, the JTAG control unit 15, and the access break function 17. The data is output to the CPU 3 after the realization. When a debug request is input to the CPU 3, a debug event occurs and shifts to the debug mode.

以上のように、マイクロコンピュータ1には、デバッグ機能が内蔵されており、主にデバッグモジュール4がデバッグ機能の制御を行っている。   As described above, the microcomputer 1 has a built-in debug function, and the debug module 4 mainly controls the debug function.

ここで、JTAGについて補足説明する。
今日のマイクロコンピュータ応用機器では、高密度実装化、デバイスの高集積、大規模、狭ピッチ化により、ボードレベルのテストが困難となってきている。このようなボードレベルのテストの課題を解決する目的で欧米の半導体、電子機器メーカ、テスタメーカなどが中心となってJTAG(Joint Test Action Group)が結成された。このJTAGより提案されたボードレベルのテスト方式がバウンダリスキャン方式といわれるものであり、現在はIEEE1149.1テストポートアクセス規格(IEEE Standard Test Access Port and Boundary Scan Architecture (IEEE Std.1149.1a−1993)として標準化されている。
Here, supplementary explanation of JTAG will be given.
In today's microcomputer-applied equipment, board-level testing has become difficult due to high-density mounting, high device integration, large scale, and narrow pitch. A JTAG (Joint Test Action Group) was formed mainly by European and American semiconductors, electronic equipment manufacturers, tester manufacturers, etc. for the purpose of solving such board-level test problems. The board-level test method proposed by JTAG is called the boundary scan method, and is currently referred to as the IEEE 1149.1 Test Port Access Standard (IEEE Standard Test Access Port and Boundary Scan Architecture (IEEE Std. 1143. 1149.1)). As standardized.

バウンダリスキャン方式では、ボード上に搭載されている各デバイスの入出力ピンと内部回路間にスキャンレジスタ回路(バウンダリスキャン)を挿入し、さらにコントロール回路と専用ピンを設ける。ボード上では、各デバイスのバウンダリスキャンを接続して、専用ポートを使用してシリアルにデータの入出力を行うことにより、全てのスキャンレジスタのアクセスとコントロールを可能にしている。シリアルに命令やデータを入力し、シリアルに出力されるデータを観測することによって、ボード上にテスト用のプローブを接触させることなく、ボード上のデバイス間の接続テストやデバイス内部のテストを行うことができる。   In the boundary scan method, a scan register circuit (boundary scan) is inserted between input / output pins of each device mounted on the board and an internal circuit, and a control circuit and a dedicated pin are further provided. On the board, the boundary scan of each device is connected, and data is input and output serially using a dedicated port, thereby enabling access and control of all the scan registers. By inputting instructions and data serially and observing serially output data, the connection test between devices on the board and the internal test can be performed without contacting the test probe on the board. Can do.

バウンダリスキャンは、以下のコンポーネントで構成される。
TAP(Test Access Port) バウンダリスキャンへのデータの入出力およびコントロールを行うためのポートであり、図2におけるJTAGインタフェース端子11に相当する。
The boundary scan is composed of the following components.
TAP (Test Access Port) A port for performing input / output and control of data to / from the boundary scan, and corresponds to the JTAG interface terminal 11 in FIG.

TAPコントローラ TCK端子およびTMS端子からの入力に応じて状態遷移を行い、テスト回路の制御を行う。   TAP controller A state transition is performed in accordance with inputs from the TCK terminal and the TMS terminal, and the test circuit is controlled.

命令レジスタ テスト命令コードを保持するレジスタで、この値をデコードしてテスト回路の制御信号を生成する。テスト命令コードとして、SAMPLE/PRELOAD命令、EXTEST命令、BYPASS命令などがある。また、上記命令とは別にデバイス独自のプライベート命令を追加することも許されている。この実施の形態1のマイクロコンピュータにおいても内蔵デバッグ機能用にいくつかのプライベート命令を備えている。   Instruction register This register holds the test instruction code and decodes this value to generate a control signal for the test circuit. Test instruction codes include a SAMPLE / PRELOAD instruction, an EXTEST instruction, and a BYPASS instruction. In addition to the above commands, it is also allowed to add device-specific private commands. The microcomputer according to the first embodiment also has some private instructions for the built-in debugging function.

データレジスタ
・バイパスレジスタ TDI端子とTDO端子との間に設けられた1ビットのレジスタで、テスト回路をバイパスするために使用する。
Data register • Bypass register This is a 1-bit register provided between the TDI terminal and the TDO terminal, and is used to bypass the test circuit.

・バウンダリスキャンレジスタ デバイスの内部回路と各ピンとの間に設けられたシフトレジスタをシリアルに接続した一連のレジスタ。   -Boundary scan register A series of registers in which a shift register provided between the internal circuit of the device and each pin is connected in series.

・上記以外にもデバイス独自のデータレジスタを追加することも許されている。この実施の形態1のマイクロコンピュータにおいても内蔵デバッグ機能用にいくつかのデータレジスタを備えている。   • In addition to the above, it is allowed to add device-specific data registers. The microcomputer according to the first embodiment also has several data registers for the built-in debug function.

図3はデバッグ事象発生時の処理手順を示す説明図である。
マイクロコンピュータ1には、ユーザモードとデバッグモードの2つの実行モードがあり、ユーザプログラムを実行しているモードがユーザモードであり、ユーザプログラムの実行中にデバッグ事象が発生するとユーザモードからデバッグモードに遷移する。デバッグモードではデバッグツール2から供給されるモニタプログラムを実行する。
FIG. 3 is an explanatory diagram showing a processing procedure when a debug event occurs.
The microcomputer 1 has two execution modes, a user mode and a debug mode. The mode in which the user program is executed is the user mode. When a debug event occurs during the execution of the user program, the user mode is changed to the debug mode. Transition. In the debug mode, the monitor program supplied from the debug tool 2 is executed.

デバッグ事象の種類には、デバッグトラップ命令の実行、デバッグ割り込み要求、実行前/実行後プログラムカウンタブレーク要求がある。   Types of debug events include execution of a debug trap instruction, a debug interrupt request, and a pre-execution / post-execution program counter break request.

デバッグ事象が発生すると、以下の処理をCPU3およびデバッグモジュール4が自動的に行った後、デバッグモードに遷移する。   When a debug event occurs, the CPU 3 and the debug module 4 automatically perform the following processing, and then transition to the debug mode.

・プログラムカウンタ13bの値をプログラムカウンタ退避用レジスタ13cに退避
・PSWレジスタ13dの値をPSW退避用レジスタ13eに退避した後、PSWレジスタ13dの値を更新
・発生したデバッグ事象を示すデバッグ事象発生要因フラグをJTAG制御部15にあるJTAGレジスタにセット
・デバッグ事象のベクタアドレス(H’FFFF9000番地)に分岐
デバッグ事象のベクタアドレスに分岐したら、デバッグツール2は、モニタコード供給機能16を使用して命令コードをCPU3に供給することによって、モニタプログラムを実行する。
The value of the program counter 13b is saved in the program counter saving register 13c. The value of the PSW register 13d is updated after saving the value of the PSW register 13d in the PSW saving register 13e. Set the flag in the JTAG register in the JTAG control unit 15 • Branch to the debug event vector address (address H'FFFF9000) After branching to the debug event vector address, the debug tool 2 uses the monitor code supply function 16 to The monitor program is executed by supplying the code to the CPU 3.

ユーザモードへの復帰命令(RTE命令)を実行することにより、デバッグモードからユーザモードに遷移する。ユーザモードに遷移する際には、以下の処理をCPU3およびデバッグモジュール4が自動的に行う。   By executing a return instruction to the user mode (RTE instruction), a transition is made from the debug mode to the user mode. When transitioning to the user mode, the CPU 3 and the debug module 4 automatically perform the following processing.

・デバッグ事象発生要因フラグをクリア
・PSW退避用レジスタ13eに退避されていた値をPSWレジスタ13dに復帰
・プログラムカウンタ退避用レジスタ13cに退避されていた値をプログラムカウンタ13bに復帰すると共に、その値の番地に分岐する
図4は内蔵領域にマッピングされたデバッグモジュール用領域を示す説明図であり、図において、21はデバッグモジュール用内蔵I/O領域(H’FFFF8000〜H’FFFF9FFF)、22はデバッグモジュール用制御レジスタ領域(H’FFFF8000〜H’FFFF8FFF)であり、実行前PCブレーク機能用のレジスタ群、アクセスブレーク機能用のレジスタ群、モニタコード供給機能用のレジスタ群がこの領域に配置されている。23はモニタコード供給領域(H’FFFF9000〜H’FFFF9FFF)であり、モニタコード供給機能にアクセスできる領域である。この領域内での命令フェッチは、全てモニタコード供給機能を使用したJTAGインタフェース端子11経由の命令コードをフェッチすることになる。デバッグ事象ベクタエントリ(H’FFFF9000〜H’FFFF9003)は、デバッグ事象が発生するとこの領域に分岐するものである。
Clear the debug event occurrence factor flag Restore the value saved in the PSW save register 13e to the PSW register 13d Restore the value saved in the program counter save register 13c to the program counter 13b and its value FIG. 4 is an explanatory diagram showing a debug module area mapped to the built-in area. In FIG. 4, reference numeral 21 denotes a debug module built-in I / O area (H'FFFF8000 to H'FFFF9FFF), and 22 denotes a debug module area. This is the debug module control register area (H'FFFF8000 to H'FFFF8FFF). The pre-execution PC break function register group, the access break function register group, and the monitor code supply function register group are arranged in this area. ing. Reference numeral 23 denotes a monitor code supply area (H'FFFF9000 to H'FFFF9FFF), which is an area where the monitor code supply function can be accessed. Instruction fetches in this area all fetch instruction codes via the JTAG interface terminal 11 using the monitor code supply function. The debug event vector entry (H'FFFF9000 to H'FFFF9003) branches to this area when a debug event occurs.

また、24はツールROM領域であり(H’FF003FE0〜H’FF003FFF)、セキュリティコードや内蔵フラッシュ情報が置かれているアドレスを格納する領域である。25はセキュリティコード格納領域であり、この領域のアドレスとバイト数はツールROM領域24内で指定される。26は内蔵フラッシュ情報格納領域であり、内蔵フラッシュ書き換え用プログラム(以下、書き換えプログラムと言う)の一つであるE/Wモード移行プログラムのエントリアドレスと内蔵フラッシュメモリ5のブロック構成の情報を格納する領域であり、この領域のアドレスとバイト数はツールROM領域24内で指定される。   Reference numeral 24 denotes a tool ROM area (H'FF003FE0 to H'FF003FFF), which is an area for storing an address where a security code and built-in flash information are placed. Reference numeral 25 denotes a security code storage area. The address and the number of bytes of this area are specified in the tool ROM area 24. An internal flash information storage area 26 stores an entry address of an E / W mode transition program which is one of internal flash rewrite programs (hereinafter referred to as a rewrite program) and block configuration information of the internal flash memory 5. This is an area, and the address and the number of bytes of this area are specified in the tool ROM area 24.

図5はモニタコード供給機能およびJTAG制御部のレジスタ構成を示す構成図であり、ここで、モニタコード供給機能16は、JTAGインタフェース端子11を使用して外部からCPU3に対して命令コードを供給する機能である。CPU3は、デバッグ事象が発生すると、図4に示したモニタコード供給領域23の先頭であるH’FFFF9000番地へ分岐し、このモニタコード供給機能16から供給される命令コードを実行するものである。   FIG. 5 is a block diagram showing the register configuration of the monitor code supply function and the JTAG control unit. Here, the monitor code supply function 16 supplies an instruction code to the CPU 3 from the outside using the JTAG interface terminal 11. It is a function. When a debug event occurs, the CPU 3 branches to the address H'FFFF9000 which is the head of the monitor code supply area 23 shown in FIG. 4 and executes the instruction code supplied from the monitor code supply function 16.

JTAG制御部15において、31はJTAGインタフェース端子11でのアクセスを制御するTAPコントローラ、32はいずれのレジスタを用いてどのようなテストを行うか選択する命令レジスタである。   In the JTAG control unit 15, 31 is a TAP controller that controls access at the JTAG interface terminal 11, and 32 is an instruction register that selects which test is performed using which register.

33はMON_CODEレジスタ(第1のレジスタ)であり、このMON_CODEレジスタ33は、デバッグモード時にJTAGインタフェース端子11経由でモニタプログラムを実行する場合に、デバッグツール2から供給される命令コードの設定に使用する32ビットのレジスタである。MON_CODEレジスタ33に設定された値は、モニタコード供給機能16の命令コードバッファ37に転送される。この時、命令コードバッファ37の入力ポインタも自動的にインクリメントされるものである。   Reference numeral 33 denotes a MON_CODE register (first register). The MON_CODE register 33 is used to set an instruction code supplied from the debug tool 2 when the monitor program is executed via the JTAG interface terminal 11 in the debug mode. It is a 32-bit register. The value set in the MON_CODE register 33 is transferred to the instruction code buffer 37 of the monitor code supply function 16. At this time, the input pointer of the instruction code buffer 37 is also automatically incremented.

34はMON_DATAレジスタ(第2のレジスタ)であり、このMON_DATAレジスタ34は、デバッグモード時にJTAGインタフェース端子11経由でモニタプログラムを実行する場合に、その実行結果をデバッグツール2に出力したり、内蔵フラッシュ情報をデバッグツール2に出力するインタフェースとなる32ビットのレジスタである。モニタプログラム上でストア命令を使用してモニタコード供給機能16のFrontMON_DATAレジスタ38に書き込みを行うと、その値がMON_DATAレジスタ34に転送され、JTAGインタフェース端子11経由でデバッグツール2から読み出すことができる。   Reference numeral 34 denotes a MON_DATA register (second register). This MON_DATA register 34 outputs the execution result to the debug tool 2 when the monitor program is executed via the JTAG interface terminal 11 in the debug mode, or the built-in flash. This is a 32-bit register serving as an interface for outputting information to the debug tool 2. When writing to the FrontMON_DATA register 38 of the monitor code supply function 16 using a store instruction on the monitor program, the value is transferred to the MON_DATA register 34 and can be read from the debug tool 2 via the JTAG interface terminal 11.

35はMON_PARAMレジスタ(第3のレジスタ)であり、このMON_PARAMレジスタ35は、デバッグモード時にJTAGインタフェース端子11経由でモニタプログラムを実行する場合に、デバッグツール2から書き換えデータなどのパラメータを渡すためのインタフェースとなる32ビットのレジスタである。デバッグツール2からJTAGインタフェース端子11経由でMON_PARAMレジスタ35に書き込みを行うと、モニタコード供給機能16のFrontMON_PARAMレジスタ39に転送され、モニタプログラム上でロード命令を使用してその値を読み出すことができる。   Reference numeral 35 denotes a MON_PARAM register (third register). The MON_PARAM register 35 is an interface for passing parameters such as rewrite data from the debug tool 2 when the monitor program is executed via the JTAG interface terminal 11 in the debug mode. This is a 32-bit register. When writing to the MON_PARAM register 35 from the debug tool 2 via the JTAG interface terminal 11, it is transferred to the FrontMON_PARAM register 39 of the monitor code supply function 16, and the value can be read using a load instruction on the monitor program.

36はMON_ACCESSレジスタであり、このMON_ACCESSレジスタ36は、デバッグモード時にJTAGインタフェース端子11経由でモニタプログラムを実行する場合に、アクセス制御情報を設定/格納する4ビットのレジスタである。   Reference numeral 36 denotes a MON_ACCESS register. The MON_ACCESS register 36 is a 4-bit register that sets / stores access control information when the monitor program is executed via the JTAG interface terminal 11 in the debug mode.

bit0 MNSTART モニタコード供給開始ビット(読み出し/書き込み可)
1:命令コード設定済み
0:命令コード未設定
“1”を設定することにより、命令コードバッファ37に有効な値が設定されたことを示す。すなわち、モニタコード供給機能16における命令フェッチ要求を受け付けるようになる。
bit0 MNSTART Monitor code supply start bit (read / write available)
1: Instruction code set 0: Instruction code not set Setting "1" indicates that a valid value has been set in the instruction code buffer 37. That is, an instruction fetch request in the monitor code supply function 16 is accepted.

bit1 MNDTVLD FrontMON_DATA有効ビット(読み出し専用)
1:FrontMON_DATA有効(FrontMON_DATAレジスタ38への書き込みがあり、かつ、MON_DATAレジスタ34は未参照)
0:FrontMON_DATA無効(FrontMON_DATAレジスタ38への書き込みがない、またはMON_DATAレジスタ34を参照した後)
このビットは、FrontMON_DATAレジスタ38への書き込みがあった時、“1”にセットされる。このビットは、以下の条件でゼロクリアされる。
bit1 MNDTVLD FrontMON_DATA valid bit (read only)
1: FrontMON_DATA valid (There is a write to the FrontMON_DATA register 38 and the MON_DATA register 34 is not referenced)
0: FrontMON_DATA invalid (no writing to FrontMON_DATA register 38 or after referring to MON_DATA register 34)
This bit is set to “1” when there is a write to the FrontMON_DATA register 38. This bit is cleared to zero under the following conditions.

・MON_DATAレジスタ34をアクセスした時
・デバッグモードでのRTE命令実行時
・デバッグ制御部のリセット時(デバッグモジュールのリセット)
bit2 MNPRMVLD FrontMON_PARAM有効ビット(読み出し専用)
1:FrontMON_PARAM有効(MON_PARAMレジスタ35は設定済みであるが、FrontMON_PARAMレジスタ39が未だ読み出されていない)
0:FrontMON_PARAM無効(MON_PARAMレジスタ35が設定されていないか、FrontMON_PARAMレジスタ39が読み出された後)
このビットは、FrontMON_PARAMレジスタ39への設定が行われた時に“1”がセットされる。このビットは、以下の条件でゼロクリアされる。
-When the MON_DATA register 34 is accessed-When an RTE instruction is executed in debug mode-When the debug control unit is reset (debug module reset)
bit2 MNPRMVLD FrontMON_PARAM valid bit (read only)
1: FrontMON_PARAM valid (MON_PARAM register 35 has been set, but FrontMON_PARAM register 39 has not been read yet)
0: FrontMON_PARAM invalid (after the MON_PARAM register 35 is not set or the FrontMON_PARAM register 39 is read)
This bit is set to “1” when the setting in the FrontMON_PARAM register 39 is performed. This bit is cleared to zero under the following conditions.

・FrontMON_PARAMレジスタ39に対して読み出しがあった時
・デバッグモードでのRTE命令実行時
・デバッグ制御部のリセット時(デバッグモジュールのリセット)
bit3 MNCDBUSY MON_CODEビジービット(読み出し専用)
1:MON_CODEへの設定不可
0:MON_CODEへの設定可
このビットは、次の命令コードをMON_CODEレジスタ33に設定してもよいかどうかを示すビットである。このビットは、以下のような2つの意味がある。
-When reading to the FrontMON_PARAM register 39-When executing an RTE instruction in debug mode-When resetting the debug controller (resetting the debug module)
bit3 MNCDBUSY MON_CODE busy bit (read only)
1: Cannot be set to MON_CODE 0: Can be set to MON_CODE This bit indicates whether or not the next instruction code may be set in the MON_CODE register 33. This bit has two meanings as follows.

・MON_CODEレジスタ33から命令コードバッファ37への転送中=“1”、転送完了=“0”、命令コードバッファ37にフェッチされていない命令コードがある=“1”、ない=“0”
このビットは、以下の条件で“1”にセットされる。
Transfer from the MON_CODE register 33 to the instruction code buffer 37 = “1”, transfer completion = “0”, instruction code not fetched in the instruction code buffer 37 = “1”, not = “0”
This bit is set to “1” under the following conditions.

・MON_CODEレジスタ33をアクセスした時
・MNSTARTビットに“1”をセットした時
このビットは、以下の条件でゼロクリアされる。
• When the MON_CODE register 33 is accessed • When the MNSTART bit is set to “1” This bit is cleared to zero under the following conditions.

・MON_CODEレジスタ33に書き込んだ値が命令コードバッファ37に転送された時
・命令コードバッファ37に格納されている命令が全てCPU3によってフェッチされた時(注1)
・デバッグモードでのRTE命令実行時
・デバッグ制御部のリセット時(デバッグモジュールのリセット)
(注1)命令コードバッファ37のフェッチ完了の判断
命令コードバッファ37の先頭のワードに対して、2回目の命令フェッチ要求が発生した時を「命令コードバッファ37の全ての命令コードをフェッチした」と判断する。例えば、命令コードバッファ37の2ワード目に分岐命令があった場合には、3ワード目、4ワード目に命令コードが設定されていても、2ワード目の分岐命令による分岐先の命令フェッチ要求が、命令コードバッファ37に対して発生した時点で「全ての命令コードがフェッチされた」ことになる。なお、モニターコード供給機能16で分岐を行う場合には「必ず分岐先を命令コードバッファ37の先頭アドレスにしなければならない」という制限がデバッグツール2に対して要求されているものとする。すなわち、デバッグツール2がMON_CODEレジスタ33に設定する分岐命令の分岐先アドレスは、常に4ワード境界上のアドレス(アドレスの下位4ビット[28:31]を“0000”)にする必要がある。この制限によって、モニターコード供給機能16内で分岐した場合には、必ず命令コードバッファ37の1ワード目に対する命令フェッチ要求になることが保証される。
When the value written to the MON_CODE register 33 is transferred to the instruction code buffer 37 When all the instructions stored in the instruction code buffer 37 are fetched by the CPU 3 (Note 1)
・ When executing RTE instruction in debug mode ・ When resetting the debug control unit (resetting the debug module)
(Note 1) Determination of instruction code buffer 37 fetch completion When a second instruction fetch request is issued for the first word of the instruction code buffer 37, “all instruction codes in the instruction code buffer 37 have been fetched” Judge. For example, when there is a branch instruction in the second word of the instruction code buffer 37, even if an instruction code is set in the third word and the fourth word, a branch destination instruction fetch request by the second word branch instruction However, when this occurs in the instruction code buffer 37, “all instruction codes have been fetched”. In the case of branching by the monitor code supply function 16, it is assumed that the debug tool 2 is required to be restricted so that the branch destination must be the start address of the instruction code buffer 37. That is, the branch destination address of the branch instruction set in the MON_CODE register 33 by the debug tool 2 must always be an address on a 4-word boundary (the lower 4 bits [28:31] of the address are “0000”). This restriction ensures that an instruction fetch request for the first word of the instruction code buffer 37 is always made when branching in the monitor code supply function 16.

また、モニタコード供給機能16において、37は命令コードバッファであり、この命令コードバッファ37は、4ワードで構成され、JTAG制御部15のMON_CODEレジスタ33の内容が転送される。命令コードバッファ37は、(H’FFFF9000〜H’FFFF9FFF)にマッピングされており、どのワードが選択されるかは、アドレスの下位2ビットで決定される。   In the monitor code supply function 16, reference numeral 37 denotes an instruction code buffer. The instruction code buffer 37 is composed of 4 words, and the contents of the MON_CODE register 33 of the JTAG control unit 15 are transferred. The instruction code buffer 37 is mapped to (H′FFFF9000 to H′FFFF9FFF), and which word is selected is determined by the lower two bits of the address.

38はFrontMON_DATAレジスタであり、このFrontMON_DATAレジスタ38は、実行結果や内蔵フラッシュ情報などをデバッグツール2に受け渡しするための32ビットのレジスタである。このFrontMON_DATAレジスタ38の内容がJTAG制御部15のMON_DATAレジスタ34に転送される。   Reference numeral 38 denotes a FrontMON_DATA register, and the FrontMON_DATA register 38 is a 32-bit register for passing execution results, built-in flash information, and the like to the debug tool 2. The contents of the FrontMON_DATA register 38 are transferred to the MON_DATA register 34 of the JTAG control unit 15.

39はFrontMON_PARAMレジスタであり、このFrontMON_PARAMレジスタ39は、デバッグツール2からモニタプログラムへの書き換えデータなどのパラメータを受け渡しするための32ビットのレジスタである。JTAG制御部15のMON_PARAMレジスタ35の内容がこのFrontMON_PARAMレジスタ39に転送される。   Reference numeral 39 denotes a FrontMON_PARAM register, and the FrontMON_PARAM register 39 is a 32-bit register for passing parameters such as rewrite data from the debug tool 2 to the monitor program. The contents of the MON_PARAM register 35 of the JTAG control unit 15 are transferred to the FrontMON_PARAM register 39.

9aはアドレスバス、9bはデータバスである。
図6は内蔵フラッシュメモリのメモリ領域を示す説明図であり、図において、41はユーザ領域、42はブートROM領域である。
9a is an address bus and 9b is a data bus.
FIG. 6 is an explanatory diagram showing a memory area of the built-in flash memory, in which 41 is a user area and 42 is a boot ROM area.

内蔵フラッシュメモリ5のユーザ領域41は、512Kバイトのフラッシュメモリが(H’00000000〜H’0007FFFF)番地に割り当てられ、11ブロックに分割されたユーザが使用できる領域である。内蔵フラッシュメモリ5の消去は、一括で全領域消去を行う方法とブロック単位で消去する方法があり、また、内蔵フラッシュメモリ5への書き込みは、ページ単位(1ページ=256バイト)で行うものである。内蔵フラッシュメモリ5の消去および書き込みは、後述するフラッシュE/Wイネーブルモードへ移行することにより可能となるものである。   The user area 41 of the built-in flash memory 5 is an area that can be used by a user divided into 11 blocks, with 512 Kbytes of flash memory allocated to addresses (H'00000000 to H'0007FFFF). The built-in flash memory 5 can be erased all at once or in blocks, and the built-in flash memory 5 can be written on a page basis (1 page = 256 bytes). is there. The internal flash memory 5 can be erased and written by shifting to a flash E / W enable mode described later.

内部フラッシュメモリ5のブートROM領域42は、16Kバイトのフラッシュメモリが(H’FF000000〜H’FF003FFF)番地に割り当てられ、内臓フラッシュメモリ5に対する書き換えプログラムを格納する領域である。   The boot ROM area 42 of the internal flash memory 5 is an area in which a 16 Kbyte flash memory is allocated to addresses (H′FF000000 to H′FF003FFF) and stores a rewrite program for the built-in flash memory 5.

図7はフラッシュレディステータスレジスタを示す説明図であり、図において、51はフラッシュレディステータスレジスタであり、内蔵フラッシュメモリ5に設けられた32ビットのレジスタである。52はそのフラッシュレディステータスレジスタ51に設けられたFSTAT(レディステータス)ビットであり、内蔵フラッシュメモリ5に対する消去および書き込みの動作状態を示すものである。   FIG. 7 is an explanatory diagram showing a flash ready status register. In the figure, 51 is a flash ready status register, which is a 32-bit register provided in the built-in flash memory 5. Reference numeral 52 denotes an FSTAT (ready status) bit provided in the flash ready status register 51, which indicates an operation state of erasing and writing to the built-in flash memory 5.

0:消去または書き込み実行中
1:レディ状態
このFSTATビット52は、図1に示したフラッシュ内部制御回路5cによって制御されるものである。
0: Erasing or writing is being executed 1: Ready state This FSTAT bit 52 is controlled by the flash internal control circuit 5c shown in FIG.

図8はフラッシュメモリ制御レジスタを示す説明図であり、図において、61はフラッシュメモリ制御レジスタであり、内蔵フラッシュメモリ5に設けられた32ビットのレジスタである。62はそのフラッシュメモリ制御レジスタ61に設けられたFENTRY(フラッシュモードエントリ)ビットであり、フラッシュE/Wイネーブルモードへの移行を制御するためのビットである。このビットを“1”セットすることにより、フラッシュE/Wイネーブルに移行し、このビットを“0”セットすることにより、通常動作モードに復帰するものである。   FIG. 8 is an explanatory diagram showing the flash memory control register. In the figure, reference numeral 61 denotes a flash memory control register, which is a 32-bit register provided in the built-in flash memory 5. 62 is a FENTRY (flash mode entry) bit provided in the flash memory control register 61, and is a bit for controlling the transition to the flash E / W enable mode. Setting this bit to “1” shifts to flash E / W enable, and setting this bit to “0” returns to the normal operation mode.

このFENTRYビット62は、図1に示したフラッシュ内部制御回路5cによって制御されるものである。   The FENTRY bit 62 is controlled by the flash internal control circuit 5c shown in FIG.

図9は内蔵フラッシュ書き換えに関する情報を示す説明図であり、図において、ツールROM領域24は、セキュリティコードや内蔵フラッシュ情報が置かれているアドレスを格納する領域であり、図4に示したように内蔵空間に配置されている。   FIG. 9 is an explanatory diagram showing information related to the internal flash rewrite. In the figure, a tool ROM area 24 is an area for storing an address where a security code or internal flash information is placed, as shown in FIG. Located in the built-in space.

図10はツールROM領域の構成を示す説明図であり、図に示すように、ツールROM領域24の場所は、(H’FF003FE0〜H’FF003FFF)番地であり、このツールROM領域24に各情報が設定済みであることを示すために、(H’FF003FFC−F)番地に固定値(H’DF534449)のコードが埋め込まれている。デバッグツール2は、このコードの値を確認してからツールROM領域24の各情報を使用する。   FIG. 10 is an explanatory diagram showing the configuration of the tool ROM area. As shown in the figure, the location of the tool ROM area 24 is address (H'FF003FE0 to H'FF003FFF), and each information is stored in the tool ROM area 24. Is already set, a code of a fixed value (H′DF534449) is embedded at the address (H′FF003FFC-F). The debug tool 2 uses each information in the tool ROM area 24 after confirming the value of this code.

また、図9および図10に示すように、セキュリティコード格納領域25とセキュリティレベルの情報が置かれており、セキュリティコードが設定されている場合、デバッグツール2側でセキュリティコードの比較を行い、一致しない場合にはセキュリティレベルに応じてツールの動作を制限する。   Further, as shown in FIGS. 9 and 10, when the security code storage area 25 and the security level information are placed and the security code is set, the security code is compared on the debug tool 2 side to match the security code. If not, restrict the operation of the tool according to the security level.

H’FF003FF0−1番地 セキュリティコードのバイト数
H’FF003FF2−3番地 セキュリティレベル
H’0000 レベル0
デバッグツールのリセット以外の動作を許可しない。
H'FF003FF0-1 address Security code byte count H'FF003FF2-3 address Security level H'0000 Level 0
Do not allow any operation other than resetting the debug tool.

H’0001 レベル1
内蔵フラッシュの全領域消去を実行しない限り、デバッグツールの動作を
許可しない。
H'0001 Level 1
Debug tool operation is not permitted unless the entire area of the internal flash is erased.

H’FF003FF4−7番地 セキュリティコード格納領域の先頭アドレス
セキュリティコードがない場合には(H’FFFFFFFF)となる。
Address H'FF003FF4-7 Start address of security code storage area If there is no security code, it becomes (H'FFFFFFFF).

さらに、図9および図10に示すように、内蔵フラッシュ情報格納領域26の先頭アドレスが置かれている。   Furthermore, as shown in FIGS. 9 and 10, the head address of the built-in flash information storage area 26 is placed.

H’FF003FE8−EB番地 内蔵フラッシュ情報格納領域の先頭アドレス
内蔵フラッシュ情報格納領域がない場合にはH’FFFFFFFFとなる。
H'FF003FE8-EB address Start address of the built-in flash information storage area If there is no built-in flash information storage area, the address becomes H'FFFFFFFF.

図11は内蔵フラッシュ情報格納領域の構成を示す説明図であり、図に示すように、内蔵フラッシュ情報格納領域26の先頭アドレスは、ツールROM領域24のH’FF003FE8−EB番地に置かれている。そして、内蔵フラッシュ情報格納領域26には、以下の情報が置かれている。   FIG. 11 is an explanatory diagram showing the configuration of the internal flash information storage area. As shown in the figure, the head address of the internal flash information storage area 26 is located at address H'FF003FE8-EB in the tool ROM area 24. . The internal flash information storage area 26 stores the following information.

E/Wモード移行プログラムのエントリアドレス(書き換えプログラム情報)
先頭アドレス+ H’00〜H’03番地:E/Wモード移行プログラムのエントリアドレス
内蔵フラッシュのブロック数
先頭アドレス+ H’04〜H’07番地:内蔵フラッシュのブロック数
各ブロック情報
先頭アドレス+ H’08〜H’0B番地:ブロック0の先頭アドレス
H’0C〜H’0F番地:ブロック0のバイト数
H’10〜H’13番地:ブロック1の先頭アドレス
H’14〜H’17番地:ブロック1のバイト数
・・・・・ ・・・・・
8n+H’08〜H’0B番地:ブロックnの先頭アドレス
8n+H’0C〜H’0F番地:ブロックnのバイト数
(注)ブロック数=(n+1)個
内蔵フラッシュ書き換え時に使用するテンポラリ領域の情報
内蔵フラッシュメモリ5の書き換え時には、フラッシュ書き換え用プログラムの格納や書き込みデータのバッファ用として内蔵SRAM6の一部を使用する。このような内蔵フラッシュメモリ5の書き換え時にテンポラリに使用する領域の先頭アドレスとバイト数を格納する。
E / W mode transition program entry address (rewrite program information)
Start address + H'00 to H'03: E / W mode transition program entry address Number of internal flash blocks Start address + H'04 to H'07: Number of internal flash blocks Each block information start address + H '08 -H '0B address: Start address of block 0
H'0C to H'0F addresses: Number of bytes in block 0
H'10 to H'13: Start address of block 1
H'14 to H'17: Number of bytes in block 1
...
8n + H'08 to H'0B addresses: start address of block n
8n + H'0C to H'0F addresses: Number of bytes in block n (Note) Number of blocks = (n + 1) pieces Information on temporary area used when rewriting internal flash memory When rewriting internal flash memory 5, storing or writing flash rewriting program A part of the built-in SRAM 6 is used as a data buffer. The start address and the number of bytes of an area used temporarily when rewriting the built-in flash memory 5 are stored.

デバッグ中に内蔵フラッシュメモリ5の書き換えを行うような場合には、デバッグツール2側でこの領域のデータを内蔵SRAM6から退避できるように、この情報を格納している。   When the internal flash memory 5 is rewritten during debugging, this information is stored so that the data in this area can be saved from the internal SRAM 6 on the debug tool 2 side.

8n+H’10〜H’13番地:フラッシュの書き換え用テンポラリ領域の先頭アドレス
8n+H’14〜H’17番地:フラッシュの書き換え用テンポラリ領域のバイト数
(注)ブロック数=(n+1)個
フラッシュ書き込み用バッファのサイズ(=ページサイズ)情報
フラッシュ書き込み用バッファのバイト数(=ページサイズ)を格納する。
8n + H'10 to H'13: start address of flash rewriting temporary area
8n + H'14 to H'17: Number of bytes in flash rewriting temporary area (Note) Number of blocks = (n + 1) pieces Size of flash write buffer (= page size) Information Number of bytes in flash write buffer (= page Size).

8n+H’18〜H’1B番地:フラッシュの書き込み用バッファのバイト数(=ページサイズ)
(注)ブロック数=(n+1)個
次に内蔵フラッシュ書き換え用プログラム(書き換えプログラム)の構成について説明する。書き換えプログラムは、図6に示したブートROM42内に格納され、E/Wモード移行プログラム、ブロック消去プログラム(消去プログラム)、ページ書き込みプログラム(書き込みプログラム)、ステータスレディ待ちプログラム、およびE/W終了プログラムからなるものである。以下に、各プログラムの構成について説明する。
8n + H'18 to H'1B addresses: number of bytes of flash write buffer (= page size)
(Note) Number of blocks = (n + 1) blocks Next, the configuration of the built-in flash rewrite program (rewrite program) will be described. The rewrite program is stored in the boot ROM 42 shown in FIG. 6, and is an E / W mode transition program, a block erase program (erase program), a page write program (write program), a status ready wait program, and an E / W end program. It consists of The configuration of each program will be described below.

E/Wモード移行プログラム
E/Wモード移行プログラムは、内蔵フラッシュメモリ5の書き換えの最初に実行しなければならないプログラムであり、書き換えに必要な各種パラメータをCPUレジスタに設定した後、フラッシュE/Wイネーブルモードに移行するものである。
E / W mode transition program The E / W mode transition program is a program that must be executed at the beginning of rewriting of the built-in flash memory 5. After setting various parameters necessary for rewriting in the CPU register, the flash E / W mode Transition to enable mode.

実行方法
モニタコード供給機能16を使用して、内蔵フラッシュ情報格納領域26の先頭1ワードに格納されているアドレスに分岐させる。この時、MON_PARAMレジスタ35への設定は必要ない。
Execution method The monitor code supply function 16 is used to branch to the address stored in the first word of the internal flash information storage area 26. At this time, setting to the MON_PARAM register 35 is not necessary.

処理内容
(1)CPUレジスタに各パラメータを設定
R0 :パラメータの設定は無し、デバッグツール2が使用可能
R1 :パラメータの設定は無し、デバッグツール2が使用可能
R2 :パラメータの設定は無し、デバッグツール2が使用可能
R3 :パラメータの設定は無し、デバッグツール2が使用可能
R4 :H’FFFF8400(MON_DATAレジスタ34のアドレス)
R5 :フラッシュ書き込み用バッファの先頭アドレス−4
R6 :パラメータの設定は無し、デバッグツール2が使用可能
R7 :フラッシュ書き込み用バッファのバイト数(=ページサイズ)
R8 :ブロック消去プログラムのエントリアドレス
R9 :ページ書き込みプログラムのエントリアドレス
R10:ステータスレディ待ちのプログラムのエントリアドレス
R11:E/W終了プログラムのエントリアドレス
R12:パラメータの設定は無し、デバッグツール2が使用可能
R13:パラメータの設定は無し、デバッグツール2が使用可能
R14:パラメータの設定は無し、デバッグツール2が使用可能
R15:パラメータの設定は無し、デバッグツール2が使用可能
(2)内蔵フラッシュメモリ5上のフラッシュ書き換えプログラムを内蔵SRAM6上に転送
(3)フラッシュE/Wイネーブルモードに移行
(4)MON_DATAレジスタ34にプログラム正常/エラー終了情報を書き込む
実行終了の確認方法
デバッグツール2は、MON_DATAレジスタ34を読み出し、MSBビット(bit0)の値を確認することによって、E/Wモード移行プログラムが正常終了したか否かを確認できる。
Processing contents (1) Set each parameter in the CPU register R0: No parameter setting, debug tool 2 can be used R1: No parameter setting, debug tool 2 can be used R2: No parameter setting, debug tool 2 can be used. R3: No parameter is set, and debug tool 2 can be used. R4: H'FFFF8400 (MON_DATA register 34 address)
R5: Start address of flash write buffer −4
R6: No parameter is set and the debug tool 2 can be used. R7: Number of bytes of buffer for flash writing (= page size)
R8: Entry address of block erase program R9: Entry address of page write program R10: Entry address of program waiting for status ready R11: Entry address of E / W end program R12: No parameter setting, debug tool 2 can be used R13: No parameter setting, debug tool 2 can be used R14: No parameter setting, debug tool 2 can be used R15: No parameter setting, debug tool 2 can be used (2) On internal flash memory 5 (3) Transfer to flash E / W enable mode (4) Write program normal / error end information to MON_DATA register 34 Execution end confirmation method Gutsuru 2 reads the MON_DATA register 34, by checking the value of the MSB bit (bit0), it can be confirmed whether the E / W mode transition program was successful.

ブロック消去プログラム
ブロック消去プログラムは、MON_PARAMレジスタ35で指定された内蔵フラッシュメモリ5上のブロックに対して消去プログラムを発行するプログラムである。フラッシュE/Wイネーブルモードで使用する。
Block Erase Program The block erase program is a program that issues an erase program to a block on the built-in flash memory 5 designated by the MON_PARAM register 35. Used in flash E / W enable mode.

実行方法
モニタコード供給機能16を使用して、上記R8が示すアドレスに分岐させる。この際、消去したいメモリブロックの先頭アドレスをMON_PARAMレジスタ35に設定する。内蔵フラッシュメモリ5のブロック構成の情報は、内蔵フラッシュ情報格納領域26にある。
Execution method The monitor code supply function 16 is used to branch to the address indicated by R8. At this time, the start address of the memory block to be erased is set in the MON_PARAM register 35. The block configuration information of the built-in flash memory 5 is in the built-in flash information storage area 26.

処理内容
(1)MON_PARAMレジスタ35で指定されたメモリブロックに対して消去コマンドを発行
(2)プログラムの最後に、MON_DATAレジスタ34への書き込みを行う。
Processing Contents (1) Issue an erase command to the memory block specified by the MON_PARAM register 35. (2) Write to the MON_DATA register 34 at the end of the program.

実行終了の確認方法
MON_DATAレジスタ34の書き込みはツール(デバッグツール2)側とデバイス(マイクロコンピュータ1)側とのハンドシェイク用である。MON_DATAレジスタ34への書き込みがこのプログラムの終了を表す。従って、MON_DATAレジスタ34の内容には意味がないが、デバッグツール2は、MON_DATAレジスタ34を一旦空読みしてから次の処理を実行する。
Execution completion confirmation method The MON_DATA register 34 is written for handshaking between the tool (debug tool 2) side and the device (microcomputer 1) side. Writing to the MON_DATA register 34 indicates the end of this program. Accordingly, the contents of the MON_DATA register 34 are meaningless, but the debug tool 2 reads the MON_DATA register 34 once and then executes the next process.

このプログラムの終了は、消去が完了していることを示すものではない。消去の完了を確認するには「ステータスレディ待ちプログラム」を実行する必要がある。   The end of the program does not indicate that the erase is complete. In order to confirm the completion of erasure, it is necessary to execute a “status ready program”.

ページ書き込みプログラム
ページ書き込みプログラムは、MON_PARAMレジスタ35で指定されたページに対してページ書き込みコマンドを発行するプログラムである。フラッシュE/Wイネーブルモードで使用する。
Page Write Program The page write program is a program that issues a page write command to the page specified by the MON_PARAM register 35. Used in flash E / W enable mode.

実行方法
モニタコード供給機能16を使用して、上記R9が示すアドレスに分岐させる。この際、書き込みしたいページの先頭アドレスをMON_PARAMレジスタ35に設定する。書き込みデータは、予め内蔵SRAM6上のフラッシュ書き込み用バッファ領域に転送しておく。バッファの先頭アドレスは(R5値+4)、バッファサイズ(=ページサイズ)はR7値で示される。この処理は、以下のような命令をモニタコード供給機能16を使用して実行することによって実現できる。
Execution method The monitor code supply function 16 is used to branch to the address indicated by R9. At this time, the top address of the page to be written is set in the MON_PARAM register 35. The write data is transferred to the flash write buffer area on the built-in SRAM 6 in advance. The head address of the buffer is indicated by (R5 value + 4), and the buffer size (= page size) is indicated by R7 value. This process can be realized by executing the following instruction using the monitor code supply function 16.

FFFF9000 LD R0,@(4,R4)
:(R4の値+4)=H’FFFF8004番地を読み出し、読み出してきたデータをR0に格納する。すなわち、FrontMON_PARAM値(=書き込みデータ)を読み出してきてR0にセットする。
FFFF9000 LD R0, @ (4, R4)
: (R4 value + 4) = H′FFFF8004 is read, and the read data is stored in R0. That is, the FrontMON_PARAM value (= write data) is read and set to R0.

FFFF9004 ST R0,@+R5
:R5の値を+4してからR5値が示す番地にR0の値をストアする。すなわち、上記命令で読み出してきた書き込みデータをフラッシュ書き込み用バッファに転送する。
FFFF9004 ST R0, @ + R5
: After the value of R5 is +4, the value of R0 is stored at the address indicated by the R5 value. That is, the write data read by the above instruction is transferred to the flash write buffer.

FFFF9006 ADDI R7,#−4
:R7の値を−4する。すなわち、書き込み用バッファのサイズを1ワード分デクリメントする。
FFFF9006 ADDI R7, # -4
: Decrease the value of R7 by -4. That is, the size of the write buffer is decremented by one word.

FFFF9008 BNEZ R7,LFFFF9000
:R7の値がゼロでない時には、H’FFFF9000番地に分岐し、ゼロになるとH’FFFF900C番地に移る。すなわち、バッファサイズ分の転送が終了するまでループする。
FFFF9008 BNEZ R7, LFFFF9000
: When the value of R7 is not zero, branch to address H'FFFF9000, and when it becomes zero, move to address H'FFFF900C. That is, it loops until the transfer for the buffer size is completed.

FFFF900C JMP R8
:R8の値が示す番地にジャンプする。すなわち、転送が終了するとステータスレディ待ちプログラムにジャンプする。
FFFF900C JMP R8
: Jump to the address indicated by the value of R8. That is, when the transfer is completed, the program jumps to the status ready waiting program.

FFFF900E NOP
処理内容
(1)フラッシュ書き込み用バッファのデータをMON_PARAMレジスタ35で指定されたページに対して書き込みコマンドを発行
(2)CPUレジスタR5,R7の値を以下の値に設定する。(次のバッファへの転送処理の時にR5,R7の値をそのまま使用できる。)
R5:フラッシュ書き込み用バッファの先頭アドレス−4
R7:フラッシュ書き込み用バッファのバイト数(=ページサイズ)
(3)プログラムの最後に、MON_DATAレジスタ34への書き込みを行う。
FFFF900E NOP
Processing Contents (1) Issue a write command to the page specified by the MON_PARAM register 35 for the data in the flash write buffer. (2) Set the values of the CPU registers R5 and R7 to the following values. (The values of R5 and R7 can be used as they are at the time of transfer processing to the next buffer.)
R5: Start address of flash write buffer -4
R7: Number of bytes in the flash write buffer (= page size)
(3) Write to the MON_DATA register 34 at the end of the program.

実行終了の確認方法
MON_DATAレジスタ34の書き込みは、ツール側とデバイス側とのハンドシェイク用である。MON_DATAレジスタ34への書き込みがこのプログラムの終了を表す。従って、MON_DATAレジスタ34の内容には意味がないが、デバッグツール2は、MON_DATAレジスタ34を一旦空読みしてから次の処理を実行する。
Execution end confirmation method The MON_DATA register 34 is written for handshaking between the tool side and the device side. Writing to the MON_DATA register 34 indicates the end of this program. Accordingly, the contents of the MON_DATA register 34 are meaningless, but the debug tool 2 reads the MON_DATA register 34 once and then executes the next process.

このプログラムの終了は、書き込みが完了していることを示すものではない。書き込みの完了を確認するには「ステータスレディ待ちプログラム」を実行する必要がある。このプログラムの終了後は、フラッシュ書き込み用バッファに次の書き込みデータを書くことができる。   The termination of this program does not indicate that writing has been completed. To confirm the completion of writing, it is necessary to execute a “status ready waiting program”. After this program is finished, the next write data can be written in the flash write buffer.

ステータスレディ待ちプログラム
ステータスレディ待ちプログラムは、ブロック消去プログラムやページ書き込みプログラムを実行した後、消去や書き込みが終了するまで待つためのプログラムである。消去や書き込みが正常終了したかどうかはMON_DATAレジスタ34に反映する。フラッシュE/Wイネーブルモードで使用する。
Status Ready Waiting Program The status ready waiting program is a program for waiting until erase or writing is completed after executing a block erase program or page write program. Whether the erasure or writing has been normally completed is reflected in the MON_DATA register 34. Used in flash E / W enable mode.

実行方法
モニタコード供給機能16を使用して、上記R10が示すアドレスに分岐させる。MON_PARAMレジスタ35への設定は必要ない。
Execution Method The monitor code supply function 16 is used to branch to the address indicated by R10. It is not necessary to set the MON_PARAM register 35.

処理内容
(1)フラッシュの消去もしくは書き込み動作が終了するまで待つ
(2)MON_DATAレジスタ34にプログラム正常/エラー終了情報を書き込む。
Processing Contents (1) Wait until the flash erase or write operation is completed. (2) Write program normal / error end information to the MON_DATA register 34.

実行終了の確認方法
デバッグツール2は、MON_DATAレジスタ34を読み出し、MSBビット(bit0)の値を確認することによって、消去や書き込みが正常に行われたかどうかを確認できる。
Execution Completion Confirmation Method The debug tool 2 can confirm whether erasure or writing has been normally performed by reading the MON_DATA register 34 and confirming the value of the MSB bit (bit 0).

E/Wモード終了プログラム
E/Wモード終了プログラムは、フラッシュE/Wモードイネーブルモードから通常モードに戻るためのプログラムである。内蔵フラッシュ書き換え処理の最後に実行する。
E / W mode end program The E / W mode end program is a program for returning from the flash E / W mode enable mode to the normal mode. Execute at the end of the internal flash rewrite process.

実行方法
モニタコード供給機能16を使用して、上記R11が示すアドレスに分岐させる。MON_PARAMレジスタ35への設定は必要ない。
Execution method The monitor code supply function 16 is used to branch to the address indicated by R11. It is not necessary to set the MON_PARAM register 35.

処理内容
(1)通常モードに移行
(2)プログラムの最後に、MON_DATAレジスタ34への書き込みを行う。
Processing contents (1) Transition to the normal mode (2) Write to the MON_DATA register 34 at the end of the program.

実行終了の確認方法
MON_DATAレジスタ34の書き込みは、ツール側とデバイス側とのハンドシェイク用である。MON_DATAレジスタ34への書き込みがこのプログラムの終了を表す。従って、MON_DATAレジスタ34の内容には意味がないが、デバッグツール2は、MON_DATAレジスタ34を一旦空読みしてから次の処理を実行する。
Execution end confirmation method The MON_DATA register 34 is written for handshaking between the tool side and the device side. Writing to the MON_DATA register 34 indicates the end of this program. Accordingly, the contents of the MON_DATA register 34 are meaningless, but the debug tool 2 reads the MON_DATA register 34 once and then executes the next process.

次に動作について説明する。
1.モニタコード供給機能およびJTAG制御部の動作
図12はモニタコード供給機能およびJTAG制御部の動作を示すフローチャートであり、まず、上記図5の構成図とこの図12のフローチャートを参照しながらモニタコード供給機能およびJTAG制御部の動作を説明する。
Next, the operation will be described.
1. Monitor Code Supply Function and Operation of JTAG Control Unit FIG. 12 is a flowchart showing the operation of the monitor code supply function and the JTAG control unit. First, monitor code supply with reference to the configuration diagram of FIG. 5 and the flowchart of FIG. Functions and operations of the JTAG control unit will be described.

(1)モニタコードの設定
デバッグツール2は、JTAGインタフェース端子11を通じてMON_CODEレジスタ33に命令コードを設定する。MON_CODEレジスタ33に設定された命令コードは、命令コードバッファ37に転送されると同時にMON_ACCESSレジスタ36のMNCDBUSYビットに“1”がセットされ、転送完了により“0”がセットされる。1ワード分の命令コードが命令コードバッファ37のどの段に格納されるかは入力ポインタによって内部制御される。先に設定した順にバッファ#0〜#3に格納される。入力ポインタの値は、デバッグモジュールのリセットを行うか、MNSTARTビットに“1”を設定することによりゼロクリアされる(ST1)。
(1) Setting Monitor Code The debug tool 2 sets an instruction code in the MON_CODE register 33 through the JTAG interface terminal 11. The instruction code set in the MON_CODE register 33 is transferred to the instruction code buffer 37. At the same time, the MNCDBUSY bit of the MON_ACCESS register 36 is set to “1”, and “0” is set when the transfer is completed. The stage in which the instruction code for one word is stored in the instruction code buffer 37 is internally controlled by the input pointer. They are stored in buffers # 0 to # 3 in the order set previously. The value of the input pointer is cleared to zero by resetting the debug module or setting the MNSTART bit to “1” (ST1).

(2)命令コードバッファに転送されたことの確認
デバッグツール2は、MON_ACCESSレジスタ36を読み出して、MNCDBUSYビットに“0”がセットされていることを確認する。MNCDBUSYビットに“0”がセットされていれば、MON_CODEレジスタ33に設定された命令コードが命令コードバッファ37に転送されたことを示している。次のMON_CODEレジスタ33への命令コードの設定は、MNCDBUSYビットに“0”がセットされていることを確認してから行う(ST2)。
(2) Confirmation of Transfer to Instruction Code Buffer The debug tool 2 reads the MON_ACCESS register 36 and confirms that the MNCDBUSY bit is set to “0”. If the MNCDBUSY bit is set to “0”, this indicates that the instruction code set in the MON_CODE register 33 has been transferred to the instruction code buffer 37. The next instruction code is set in the MON_CODE register 33 after confirming that the MNCDBUSY bit is set to “0” (ST2).

上記(ST1)と(ST2)の処理を最大4回まで任意の回数繰り返す。
なお、命令コードバッファ37の命令コードは、MON_CODEレジスタ33をアクセスしない限り保持される。従って、命令コードバッファ37に設定した命令コードを再度使用する場合には新規に設定し直す必要がない。MNSTARTビットに“1”を設定すれば、命令コードバッファ37に保持されている命令コードが再びCPU3によって実行される。
The processes (ST1) and (ST2) are repeated any number of times up to four times.
The instruction code in the instruction code buffer 37 is held unless the MON_CODE register 33 is accessed. Therefore, when the instruction code set in the instruction code buffer 37 is used again, there is no need to newly set it again. If “1” is set in the MNSTART bit, the instruction code held in the instruction code buffer 37 is executed again by the CPU 3.

(3)パラメータの設定
モニタプログラムがパラメータを必要としない場合にはこの処理は必要ない。
(3) Parameter setting This process is not necessary if the monitor program does not require parameters.

デバッグツール2は、JTAGインタフェース端子11を通じてMON_PARAMレジスタ35にパラメータを設定する。MON_PARAMレジスタ35に設定されたパラメータは、FrontMON_PARAMレジスタ39に転送されると同時にMON_ACCESSレジスタ36のMNPRMVLDビットに“1”がセットされる。CPU3がFrontMON_PARAMレジスタ39を読み出すとMNPRMVLDビットに“0”がセットされる。FrontMON_PARAMレジスタ39の内容は、MON_PARAMレジスタ35の設定を行わない限り保持され、同じパラメータを何度も使用する場合は、新規に設定し直す必要はない(ST3)。   The debug tool 2 sets a parameter in the MON_PARAM register 35 through the JTAG interface terminal 11. The parameter set in the MON_PARAM register 35 is transferred to the FrontMON_PARAM register 39, and at the same time, the MNPRMVLD bit of the MON_ACCESS register 36 is set to “1”. When the CPU 3 reads the FrontMON_PARAM register 39, “0” is set to the MNPRMVLD bit. The contents of the FrontMON_PARAM register 39 are retained unless the MON_PARAM register 35 is set. If the same parameter is used many times, it is not necessary to newly set it (ST3).

(4)モニターコード供給のスタート
デバッグツール2は、JTAGインタフェース端子11を通じてMON_ACCESSレジスタ36のMNSTARTビットに“1”をセットする。MNSTARTビットに“1”がセットされることにより、CPU3は命令コードバッファ37の内容をフェッチできるようになる(ST4)。
(4) Start of supply of monitor code The debug tool 2 sets “1” to the MNSTART bit of the MON_ACCESS register 36 through the JTAG interface terminal 11. By setting “1” to the MNSTART bit, the CPU 3 can fetch the contents of the instruction code buffer 37 (ST4).

(5)スタート要求の解除
デバッグツール2は、MON_ACCESSレジスタ36のMNSTARTビットに“0”をセットする。
(5) Release of start request The debug tool 2 sets “0” to the MNSTART bit of the MON_ACCESS register 36.

(6)モニタコードがフェッチされたことの確認
デバッグツール2は、MON_ACCESSレジスタ36を読み出して、MNCDBUSYビットに“0”がセットされていることを確認する。MNCDBUSYビットに“0”がセットされていれば、命令コードバッファ37へ設定した全ての命令のフェッチが完了したことを示す。
(6) Confirmation that monitor code has been fetched The debug tool 2 reads the MON_ACCESS register 36 and confirms that the MNCDBUSY bit is set to “0”. If “0” is set in the MNCDBUSY bit, it indicates that all the instructions set in the instruction code buffer 37 have been fetched.

(7)MON_PARAMが使用されたことを確認
この処理は、パラメータ設定を行った場合のみ必要である。
(7) Confirm that MON_PARAM has been used This process is necessary only when parameters are set.

デバッグツール2は、MON_ACCESSレジスタ36を読み出して、MNPRMVLDビットに“0”がセットされていることを確認する。MNPRMVLDビットに“0”がセットされていれば、CPU3がFrontMON_PARAMレジスタ39を読み出したことを示している。   The debug tool 2 reads the MON_ACCESS register 36 and confirms that the MNPRMVLD bit is set to “0”. If the MNPRMVLD bit is set to “0”, it indicates that the CPU 3 has read the FrontMON_PARAM register 39.

(8)FrontMON_DATAに書き込みがあったことの確認
この処理は、FrontMON_DATAレジスタ38への書き込みをモニタプログラムが行う場合にのみ必要である。
(8) Confirmation that FrontMON_DATA has been written This process is necessary only when the monitor program writes to the FrontMON_DATA register 38.

デバッグツール2は、MON_ACCESSレジスタ36を読み出して、MNDTVLDビットに“1”がセットされていることを確認する。MNDTVLDビットに“1”がセットされていれば、CPU3がFrontMON_DATAレジスタ38に書き込みを行ったことを示している。   The debug tool 2 reads the MON_ACCESS register 36 and confirms that the MNDTVLD bit is set to “1”. If the MNDTVLD bit is set to “1”, it indicates that the CPU 3 has written to the FrontMON_DATA register 38.

(9)FrontMON_DATAの読み出し
この処理は、FrontMON_DATA38への書き込みをモニタプログラムが行う場合にのみ必要である。
(9) Reading FrontMON_DATA This process is necessary only when the monitor program performs writing to the FrontMON_DATA38.

デバッグツール2がJTAGインタフェース端子11を通じてMON_DATAレジスタ34を読み出すと、MNDTVLDビットは自動的にクリアされる。FrontMON_DATAレジスタ38の内容は、FrontMON_DATAレジスタ38への書き込みを行わない限り保持されている(ST9)。   When the debug tool 2 reads the MON_DATA register 34 through the JTAG interface terminal 11, the MNDTVLD bit is automatically cleared. The contents of the FrontMON_DATA register 38 are retained unless data is written to the FrontMON_DATA register 38 (ST9).

2.内蔵フラッシュメモリの書き換え動作
図13は内蔵フラッシュメモリの書き換え動作の概要を示すフローチャートであり、次に、この図13のフローチャートを参照しながら内蔵フラッシュメモリ5の書き換え動作の概要を説明する。
2. Internal Flash Memory Rewriting Operation FIG. 13 is a flowchart showing an outline of the internal flash memory rewriting operation. Next, an outline of the internal flash memory 5 rewriting operation will be described with reference to the flowchart of FIG.

内蔵フラッシュメモリ5の書き換えは、図5に示したJTAG制御部15およびモニタコード供給機能16を使用して、図6に示した内蔵フラッシュメモリ5内のブートROM領域42に格納された書き換えプログラムを呼び出すことによって行う。デバッグツール2からの書き込みデータの転送もJTAG制御部15のMON_PARAMレジスタ35を使用して転送するものである。   The internal flash memory 5 is rewritten by using the JTAG control unit 15 and the monitor code supply function 16 shown in FIG. 5 to rewrite the rewrite program stored in the boot ROM area 42 in the internal flash memory 5 shown in FIG. Do by calling. Transfer of write data from the debug tool 2 is also performed using the MON_PARAM register 35 of the JTAG control unit 15.

前処理(ST11)
デバッグツール2は、フラッシュ書き換え処理の前に、予め処理を行っておくことが必要になる。
Pre-processing (ST11)
The debug tool 2 needs to perform processing in advance before the flash rewrite processing.

・セキュリティレベルのチェック
・内蔵フラッシュのブロック構成の情報を読み出しておく
・E/Wモード移行プログラムのエントリアドレスを読み出しておく
保持すべきデータの読み出し(ST12)
内蔵フラッシュメモリ5への書き込みではブロック単位の消去を伴う。書き込みを行うブロックの中で保持しなければならないデータがある場合では、この段階でフラッシュE/Wイネーブルモードになる前に読み出しておく必要がある。
-Checking the security level-Reading the block configuration information of the built-in flash-Reading the entry address of the E / W mode transition program Reading data to be held (ST12)
Writing to the built-in flash memory 5 involves erasing in units of blocks. If there is data that must be held in the block to be written, it must be read before entering the flash E / W enable mode at this stage.

フラッシュE/Wイネーブルモード移行(ST13)
E/Wモード移行プログラムを実行することにより、通常モードからフラッシュE/Wイネーブルモードに移行する。
Transition to flash E / W enable mode (ST13)
By executing the E / W mode transition program, the normal mode is shifted to the flash E / W enable mode.

フラッシュ書き換え(ST14)
消去のみを行うか、書き込みを行うかで処理が異なる。それぞれの処理の中で必要なプログラムを実行する。
Flash rewrite (ST14)
Processing differs depending on whether only erasing or writing is performed. A necessary program is executed in each process.

「ブロック消去プログラム」
「ページ書き込みプログラム」
「ステータスレディプログラム」
通常モード復帰(ST15)
「E/Wモード終了プログラム」を実行することにより、フラッシュE/Wイネーブルモードから通常モードに復帰する。
"Block erase program"
"Page writing program"
"Status Ready Program"
Return to normal mode (ST15)
By executing the “E / W mode end program”, the flash E / W enable mode returns to the normal mode.

次に図13に示した前処理(ST11)、および保持すべきデータの読み出し(ST12)について詳細に説明する。   Next, the preprocessing (ST11) and reading of data to be held (ST12) shown in FIG. 13 will be described in detail.

デバッグツール2は、起動されるとマイクロコンピュータ1に内蔵されている各種情報をJTAG制御部15およびモニタコード供給機能16を使用して読み出し、セキュリティコードのチェックを行う。   When the debug tool 2 is activated, it reads various information built in the microcomputer 1 using the JTAG control unit 15 and the monitor code supply function 16 and checks the security code.

(1)ツールROM設定済み確認コードの読み出し
(i)デバッグツール2から図5に示すJTAGインタフェース端子11を介してMON_CODEレジスタ33に命令コードがセットされる。
(1) Reading tool ROM setting confirmation code
(i) An instruction code is set in the MON_CODE register 33 from the debug tool 2 via the JTAG interface terminal 11 shown in FIG.

(ii)MON_CODEレジスタ33にセットされた命令コードを、JTAG制御部15およびモニタコード供給機能16の機能により、命令コードバッファ37に転送する。   (ii) The instruction code set in the MON_CODE register 33 is transferred to the instruction code buffer 37 by the functions of the JTAG control unit 15 and the monitor code supply function 16.

ツールROM設定済み確認コードを読み出して、FrontMON_DATAレジスタ38に書き込みを行うプログラムを、上記(i),(ii)の処理を4回行って命令コードバッファ37にセットする。   A program for reading the confirmation code in which the tool ROM has been set and writing it in the FrontMON_DATA register 38 is set in the instruction code buffer 37 by performing the processes (i) and (ii) four times.

(iii)デバッグツール2から図5に示すJTAGインタフェース端子11を介してMON_ACCESSレジスタ36のMNSTARTビットに“1”がセットされる。   (iii) “1” is set to the MNSTART bit of the MON_ACCESS register 36 from the debug tool 2 via the JTAG interface terminal 11 shown in FIG.

(iv)図5に示したCPU3は、命令コードバッファ37に転送されたツールROM設定済み確認コードの読み出しプログラムを実行し、以下の処理を行う。   (iv) The CPU 3 shown in FIG. 5 executes a program for reading the confirmation code with the tool ROM set transferred to the instruction code buffer 37 and performs the following processing.

・図10に示したツールROM領域のH’FF003FFC番地のデータを読み出す。
・読み出したデータをFrontMON_DATAレジスタ38(H’FFFF8000番地)に書き込む。
Read the data at address H'FF003FFC in the tool ROM area shown in FIG.
Write the read data to the FrontMON_DATA register 38 (address H'FFFF8000).

・H’FFFF9000番地に分岐し、次のデバッグツール2から供給される命令コードを待つ。   Branch to address H'FFFF9000 and wait for the next instruction code supplied from the debug tool 2.

(v)FrontMON_DATAレジスタ38に書き込まれたデータを、JTAG制御部15およびモニタコード供給機能16の機能により、MON_DATAレジスタ34に転送する。   (v) The data written in the FrontMON_DATA register 38 is transferred to the MON_DATA register 34 by the functions of the JTAG control unit 15 and the monitor code supply function 16.

(vi)デバッグツール2から図5に示すJTAGインタフェース端子11を介してMON_DATAレジスタ34のデータが読み出される。   (vi) Data in the MON_DATA register 34 is read from the debug tool 2 via the JTAG interface terminal 11 shown in FIG.

(vii)デバッグツール2では、MON_DATAレジスタ34のデータによって、次のように処理が分けられる。   (vii) In the debug tool 2, processing is divided as follows according to the data in the MON_DATA register 34.

・データがH’DF534449であれば、次の(2)の処理に進む。
・データがH’DF534449以外であれば、ツールROMの読み出し処理を終了する。
If the data is H'DF534449, the processing proceeds to the next (2).
If the data is other than H'DF534449, the reading process of the tool ROM ends.

(2)セキュリティコードの読み出し
(i)セキュリティコード格納領域の先頭アドレスの読み出し
読み出し番地をツールROM領域のH’FF003FF4番地に変更して、上記(1)の(i)〜(vi)と同様な処理を行うことによって、図10に示した「セキュリティコード格納領域の先頭アドレス」を読み出す。
(2) Security code reading
(i) Reading of the start address of the security code storage area The read address is changed to the address H'FF003FF4 in the tool ROM area, and the same processing as (i) to (vi) in (1) above is performed. The “start address of the security code storage area” shown in FIG.

(ii)セキュリティコードのバイト数、セキュリティのレベルの読み出し
読み出し番地をツールROM領域のH’FF003FF0番地に変更して、上記(1)の(i)〜(vi)と同様な処理を行うことによって、図10に示した「セキュリティコードのバイト数、セキュリティのレベル」を読み出す。
(ii) Reading of security code byte count and security level By changing the read address to H'FF003FF0 in the tool ROM area and performing the same processing as (i) to (vi) in (1) above , “Number of bytes of security code, security level” shown in FIG. 10 is read.

(iii)セキュリティコードの読み出し
読み出し番地を上記(i)で得られたセキュリティコード格納領域の先頭アドレスに変更して、上記(1)の(i)〜(vi)と同様な処理を行うことによって、「セキュリティコード」を読み出す。
(iii) Reading of security code By changing the read address to the start address of the security code storage area obtained in (i) above, and performing the same processing as (i) to (vi) in (1) above , “Security Code” is read.

なお、セキュリティコードのバイト数が4バイトを越える場合は、上記(1)の(i)〜(vi)と同様な処理を繰り返すことによって全てのセキュリティコードを得る。   When the number of bytes of the security code exceeds 4 bytes, all the security codes are obtained by repeating the same processing as (i) to (vi) in (1) above.

(iv)セキュリティコードのチェック
デバッグツール2は、デバッグツール2を使用しているユーザに対してセキュリティコードをキー入力してもらう。
(iv) Security code check The debug tool 2 asks the user who is using the debug tool 2 to key in the security code.

デバッグツール2は、キー入力された値と(iii)で得られた値とを比較し、(ii)で得られたセキュリティのレベルとの組合せで次のように処理が分けられる。   The debug tool 2 compares the value input in key with the value obtained in (iii), and the processing is divided as follows according to the combination with the security level obtained in (ii).

・キー入力された値と(iii)で得られた値とが一致した場合:次の(3)の処理に進む。   When the value input by key coincides with the value obtained in (iii): The process proceeds to the next (3).

・キー入力された値と(iii)で得られた値とが不一致、かつ、セキュリティレベル=“0”の場合:デバッグツール2は、デバッグツール2のリセット以外の動作を許可しない。   When the value input by key does not match the value obtained in (iii) and the security level = “0”: The debug tool 2 does not permit any operation other than reset of the debug tool 2.

・キー入力された値と(iii)で得られた値とが不一致、かつ、セキュリティレベル=“1”の場合:ユーザが内蔵フラッシュメモリ5の全領域の消去を実行しない限り、デバッグツール2の動作を許可しない。   If the value entered in (iii) does not match and the security level is “1”: Unless the user erases the entire area of the internal flash memory 5, the debug tool 2 Do not allow operation.

このように、セキュリティチェックを行うことによって、内蔵フラッシュメモリ5上のプログラムやデータを安易に他人に読み出されたり書き換えされたりできないようにすることができる。   As described above, by performing the security check, it is possible to prevent a program or data on the built-in flash memory 5 from being easily read or rewritten by another person.

(3)内蔵フラッシュ情報の読み出し
(i)内蔵フラッシュ情報格納領域の先頭アドレスの読み出し
読み出し番地をツールROM領域のH’FF003FE8番地に変更して、上記(1)の(i)〜(vi)と同様な処理を行うことによって、図10に示した「内蔵フラッシュ情報格納領域の先頭アドレス」を読み出す。
(3) Reading internal flash information
(i) Reading the start address of the built-in flash information storage area By changing the read address to address H'FF003FE8 in the tool ROM area and performing the same processing as (i) to (vi) in (1) above, The “start address of the built-in flash information storage area” shown in FIG. 10 is read.

(ii)E/Wモード移行プログラムのエントリアドレスの読み出し
読み出し番地を上記(i)で得られた内蔵フラッシュ情報格納領域の先頭アドレスに変更して、上記(1)の(i)〜(vi)と同様な処理を行うことによって、図11に示した「E/Wモード移行プログラムのエントリアドレス」を読み出す。
(ii) Reading the entry address of the E / W mode transition program The read address is changed to the start address of the internal flash information storage area obtained in (i) above, and (i) to (vi) in (1) above. By performing the same processing as the above, the “entry address of the E / W mode transition program” shown in FIG. 11 is read.

(iii)ブロック数の読み出し
読み出し番地を上記(i)で得られた内蔵フラッシュ情報格納領域の先頭アドレス+4に変更して、上記(1)の(i)〜(vi)と同様な処理を行うことによって、図11に示した「ブロック数」を読み出す。
(iii) Reading the number of blocks The read address is changed to the start address +4 of the internal flash information storage area obtained in (i) above, and the same processing as (i) to (vi) in (1) above is performed. Thus, the “number of blocks” shown in FIG. 11 is read.

(iv)各ブロックの先頭アドレスとバイト数の読み出し
読み出し番地を上記(i)で得られた内蔵フラッシュ情報格納領域の先頭アドレス+8に変更して、上記(1)の(i)〜(vi)と同様な処理を行うことによって、図11に示した「ブロック0の先頭アドレス」を読み出す。
(iv) Reading the start address and number of bytes of each block The read address is changed to the start address +8 of the internal flash information storage area obtained in (i) above, and (i) to (vi) in (1) above. By performing the same processing as the above, the “first address of block 0” shown in FIG. 11 is read.

そして、読み出し番地を4ずつ増加させながら上記(1)の(i)〜(vi)と同様な処理を行うことによって、図11に示した「各ブロックの先頭アドレスおよびバイト数」を読み出す。   Then, the same processing as (i) to (vi) in (1) above is performed while incrementing the read address by 4, thereby reading the “start address and number of bytes of each block” shown in FIG.

読み出す領域は、(iii)で得られたブロック数から次のように計算することができる。
「(i)で得られた先頭アドレス+8」〜「(i)で得られた先頭アドレス+(8×n+H’0C)」、ただし、n=((iii)で得られたブロック数−1)
(v)フラッシュ書き換え用テンポラリ領域の読み出し
読み出し番地を上記(i)で得られた内蔵フラッシュ情報格納領域の先頭アドレス+(8×n+H’10)に変更して、上記(1)の(i)〜(vi)と同様な処理を行うことによって、図11に示した「フラッシュ書き換え用テンポラリ領域の先頭アドレス」を読み出す。
The area to be read can be calculated as follows from the number of blocks obtained in (iii).
“Start address obtained in (i) +8” to “Start address obtained in (i) + (8 × n + H′0C)”, where n = (number of blocks obtained in (iii) −1)
(v) Reading the flash rewrite temporary area The read address is changed to the start address of the internal flash information storage area obtained in (i) above + (8 × n + H′10), and the above (1) (i) By performing the same processing as in (vi), the “first address of the flash rewriting temporary area” shown in FIG. 11 is read.

そして、読み出し番地を上記(i)で得られた内蔵フラッシュ情報格納領域の先頭アドレス+(8×n+H’14)に変更して、上記(1)の(i)〜(vi)と同様な処理を行うことによって、図11に示した「フラッシュ書き換え用テンポラリ領域のバイト数」を読み出す。   Then, the read address is changed to the head address of the built-in flash information storage area obtained in (i) above + (8 × n + H′14), and the same processing as in (i) to (vi) in (1) above. To read the “number of bytes in the flash rewriting temporary area” shown in FIG.

内蔵フラッシュメモリ5の消去および書き込みを行う場合には、フラッシュ書き換えプログラムの格納や書き込みデータのバッファ用として、内蔵SRAM6の一部を使用する。これをフラッシュ書き換え用テンポラリ領域と言う。この領域は、デバッグを行うユーザが使用する領域であるため、デバッグツール2は内蔵フラッシュメモリ5の消去および書き込みを行う前に、ユーザが使用している内蔵SRAM6上のデータを退避する必要がある。デバッグツール2は(v)で得られたフラッシュ書き換え用テンポラリ領域のデータを使用して退避処理を行い、内蔵フラッシュメモリ5の消去および書き込み処理を行った後に復帰処理を行う。   When the built-in flash memory 5 is erased and written, a part of the built-in SRAM 6 is used for storing a flash rewrite program and for buffering write data. This is called a flash rewrite temporary area. Since this area is used by the user who performs debugging, the debug tool 2 needs to save the data on the internal SRAM 6 used by the user before erasing and writing the internal flash memory 5. . The debug tool 2 performs a saving process using the data in the flash rewriting temporary area obtained in (v), and performs a restoration process after erasing and writing the internal flash memory 5.

(vi)フラッシュ書き込み用バッファのバイト数の読み出し
読み出し番地を上記(i)で得られた内蔵フラッシュ情報格納領域の先頭アドレス+(8×n+H’18)に変更して、上記(1)の(i)〜(vi)と同様な処理を行うことによって、図11に示した「フラッシュ書き込み用バッファのバイト数」を読み出す。
(vi) Reading the number of bytes in the flash write buffer The read address is changed to the start address of the internal flash information storage area obtained in (i) + (8 × n + H′18), and the ( By performing the same processing as i) to (vi), the “number of bytes of the flash write buffer” shown in FIG. 11 is read.

フラッシュ書き込み用バッファとは、フラッシュ書き換え用テンポラリ領域のうちの書き込みデータが格納されるバッファ領域である。内蔵フラッシュメモリ5の書き込みを行う場合には、デバッグツール2はページサイズ単位で書き込み処理をループさせるような制御が必要になる。マイクロコンピュータによって異なるページサイズとなる可能性があるため、(vi)で得られたページサイズ情報を使用して、書き込みデータを生成する。   The flash write buffer is a buffer area for storing write data in the flash rewrite temporary area. When writing to the built-in flash memory 5, the debug tool 2 needs to be controlled to loop the writing process in units of page size. Since there is a possibility of different page sizes depending on the microcomputer, write data is generated using the page size information obtained in (vi).

図14は内蔵フラッシュメモリの消去動作を示すフローチャートであり、次に、この図14のフローチャートを参照しながら内蔵フラッシュメモリ5の消去動作を説明する。なお、この図14に示すフローチャートは、図13のフラッシュE/Wイネーブルモード移行(ST13)、フラッシュ書き換え(ST14)、および通常モード復帰(ST15)において、内蔵フラッシュメモリ5の消去動作のみ行った場合の詳細に相当するものである。   FIG. 14 is a flowchart showing the erase operation of the built-in flash memory. Next, the erase operation of the built-in flash memory 5 will be described with reference to the flowchart of FIG. In the flowchart shown in FIG. 14, only the erase operation of the built-in flash memory 5 is performed in the flash E / W enable mode transition (ST13), flash rewrite (ST14), and normal mode return (ST15) in FIG. This corresponds to the details.

(4)E/Wモード移行プログラムの実行(E/Wモード移行プログラム実行手段)
(i)デバッグツール2から図5に示すJTAGインタフェース端子11を介してMON_CODEレジスタ33にE/Wモード移行プログラムに分岐する命令コードがセットされる(ST21)。
(4) Execution of E / W mode transition program (E / W mode transition program execution means)
(i) The instruction code for branching to the E / W mode transition program is set from the debug tool 2 to the MON_CODE register 33 via the JTAG interface terminal 11 shown in FIG. 5 (ST21).

(ii)MON_CODEレジスタ33にセットされた命令コードを、JTAG制御部15およびモニタコード供給機能16の機能により、命令コードバッファ37に転送する(ST22)。   (ii) The instruction code set in the MON_CODE register 33 is transferred to the instruction code buffer 37 by the functions of the JTAG control unit 15 and the monitor code supply function 16 (ST22).

(iii)デバッグツール2から図5に示すJTAGインタフェース端子11を介してMON_ACCESSレジスタ36のMNSTARTビットに“1”がセットされる(ST21)。   (iii) “1” is set from the debug tool 2 to the MNSTART bit of the MON_ACCESS register 36 via the JTAG interface terminal 11 shown in FIG. 5 (ST21).

(iv)図5に示したCPU3は、命令コードバッファ37に転送されたE/Wモード移行プログラムに分岐する命令コードを実行し、図6に示したブートROM領域42上にあるE/Wモード移行プログラムに分岐する(ST21)。   (iv) The CPU 3 shown in FIG. 5 executes the instruction code branching to the E / W mode transition program transferred to the instruction code buffer 37, and the E / W mode on the boot ROM area 42 shown in FIG. Branch to the migration program (ST21).

(v)CPU3は、E/Wモード移行プログラムを実行し、以下の処理を行う(ST22)。   (v) The CPU 3 executes the E / W mode transition program and performs the following processing (ST22).

・CPU3の各レジスタに各パラメータをセットする(構成で説明したE/Wモード移行プログラムの処理内容:R0〜R15を参照)。   Each parameter is set in each register of the CPU 3 (refer to processing contents of the E / W mode transition program described in the configuration: R0 to R15).

・図6に示したブートROM42上にある書き換えプログラム(E/Wモード移行プログラム、ブロック消去プログラム、ページ書き込みプログラム、ステータスレディ待ちプログラム、およびE/W終了プログラム)を図1に示した内蔵SRAM6上に転送する。この書き換えプログラムの内蔵フラッシュメモリ5内のブートROM領域42上から内蔵SRAM6上への転送は、フラッシュE/Wモードに移行すると、内蔵フラッシュメモリ5からの読み出し動作を行うことができなくなるため、内蔵フラッシュメモリ5上にあるフラッシュ書き換えプログラムを内蔵SRAM6上に退避するためである。   The rewrite programs (E / W mode transition program, block erase program, page write program, status ready wait program, and E / W end program) on the boot ROM 42 shown in FIG. 6 are stored on the built-in SRAM 6 shown in FIG. Forward to. The transfer of the rewrite program from the boot ROM area 42 in the built-in flash memory 5 to the built-in SRAM 6 cannot be performed from the built-in flash memory 5 when the flash E / W mode is entered. This is because the flash rewriting program on the flash memory 5 is saved on the built-in SRAM 6.

・内蔵SRAM6に分岐して、さらに以下の処理を引き続いて実行する。
・図8に示したフラッシュメモリ制御レジスタ61のFENTRYビット62に“1”をセットし、内蔵フラッシュメモリ5をフラッシュE/Wイネーブルモードに移行させる。
Branches to the built-in SRAM 6 and further executes the following processing.
• “1” is set to the FENTRY bit 62 of the flash memory control register 61 shown in FIG. 8, and the built-in flash memory 5 is shifted to the flash E / W enable mode.

・図5に示したFrontMON_DATAレジスタ38(H’FFFF8000番地)にH’00000000を書き込む。   Write H'00000000 to the FrontMON_DATA register 38 (address H'FFFF8000) shown in FIG.

・H’FFFF9000番地に分岐し、次のデバッグツール2から供給される命令コードを待つ。   Branch to address H'FFFF9000 and wait for the next instruction code supplied from the debug tool 2.

(vi)FrontMON_DATAレジスタ38に書き込まれたデータを、JTAG制御部15およびモニタコード供給機能16の機能により、MON_DATAレジスタ34に転送すると共に、MON_ACCESSレジスタ36のMNDTVLDビットを“1”にセットする(ST22)。   (vi) The data written in the FrontMON_DATA register 38 is transferred to the MON_DATA register 34 by the functions of the JTAG control unit 15 and the monitor code supply function 16, and the MNDTVLD bit of the MON_ACCESS register 36 is set to “1” (ST22). ).

(vii)デバッグツール2は、JTAGインタフェース端子11を介してMON_ACCESSレジスタ36を読み出して、MNDTVLDビットをチェックし、“1”になったらJTAGインタフェース端子11を介してMON_DATAレジスタ34の値を読み出す。読み出したデータのbit0値が“0”ならば、次の(2)ブロック消去プログラムの実行に移り、bit0値が“1”ならば、エラー処理(ST24)を行う(ST23)。   (vii) The debug tool 2 reads the MON_ACCESS register 36 via the JTAG interface terminal 11 and checks the MNDTVLD bit. When the debug tool 2 becomes “1”, the value of the MON_DATA register 34 is read via the JTAG interface terminal 11. If the bit0 value of the read data is “0”, the next (2) block erase program is executed. If the bit0 value is “1”, error processing (ST24) is performed (ST23).

(5)ブロック消去プログラムの実行(消去プログラム実行手段)
(i)デバッグツール2からJTAGインタフェース端子11を介してMON_PARAMレジスタ35に消去したい内蔵フラッシュメモリ5のブロックに対応するアドレスがセットされる(ST25)。
(5) Execution of block erase program (erase program execution means)
(i) The address corresponding to the block of the built-in flash memory 5 to be erased is set from the debug tool 2 to the MON_PARAM register 35 via the JTAG interface terminal 11 (ST25).

(ii)MON_PARAMレジスタ35にセットされたアドレスを、JTAG制御部15およびモニタコード供給機能16の機能により、FrontMON_PARAMレジスタ39に転送する(ST26)。   (ii) The address set in the MON_PARAM register 35 is transferred to the FrontMON_PARAM register 39 by the functions of the JTAG control unit 15 and the monitor code supply function 16 (ST26).

(iii)デバッグツール2からJTAGインタフェース端子11を介してMON_CODEレジスタ33にブロック消去プログラムに分岐する命令コードがセットされる(ST25)。   (iii) The instruction code for branching to the block erase program is set from the debug tool 2 to the MON_CODE register 33 via the JTAG interface terminal 11 (ST25).

(iv)デバッグツール2からJTAGインタフェース端子11を介してMON_ACCESSレジスタ36のMNSTARTビットに“1”がセットされる(ST25)。   (iv) “1” is set from the debug tool 2 to the MNSTART bit of the MON_ACCESS register 36 via the JTAG interface terminal 11 (ST25).

(v)CPU3は、命令コードバッファ37に転送されたブロック消去プログラムに分岐する命令コードを実行し、内蔵SRAM6上に退避されたブロック消去プログラムに分岐する(ST26)。   (v) The CPU 3 executes the instruction code branched to the block erase program transferred to the instruction code buffer 37, and branches to the block erase program saved on the built-in SRAM 6 (ST26).

(vi)CPU3は、ブロック消去プログラムを実行し、以下の処理を行う(ST26)。
・FrontMON_PARAMレジスタ39(H’FFFF8004番地)を読み出す。
(vi) The CPU 3 executes the block erase program and performs the following processing (ST26).
Reads the FrontMON_PARAM register 39 (address H'FFFF8004).

・内蔵フラッシュメモリ5に対して消去コマンドを発行する。
図15は内蔵フラッシュメモリの消去動作の詳細を示すフローチャートであり、このフローチャートを参照しながら、上記消去コマンドに応じた動作を説明する。
Issue an erase command to the built-in flash memory 5.
FIG. 15 is a flowchart showing details of the erase operation of the built-in flash memory. The operation according to the erase command will be described with reference to this flowchart.

まず、内蔵フラッシュメモリ5の任意のアドレスにブロックイレーズコマンドデータ(H’2020)を書き込み(ST41)、上記FrontMON_PARAMレジスタ39から読み出した消去したいブロックに対応するアドレスに応じて、消去対象であるブロックの最終偶数アドレスに確認コマンドデータ(H’D0D0)を書き込む(ST42)。そして、図1に示したフラッシュ内部制御回路5cによって消去対象であるブロックの消去が開始される(ST43)。   First, the block erase command data (H′2020) is written to an arbitrary address of the built-in flash memory 5 (ST41), and the block to be erased is read according to the address corresponding to the block to be erased read from the FrontMON_PARAM register 39. The confirmation command data (H′D0D0) is written to the final even address (ST42). Then, the flash internal control circuit 5c shown in FIG. 1 starts erasing the block to be erased (ST43).

・FrontMON_DATAレジスタ38(H’FFFF8000番地)にH’00000000を書き込む。   Write H'00000000 to the FrontMON_DATA register 38 (address H'FFFF8000).

・H’FFFF9000番地に分岐し、次のデバッグツール2から供給される命令コードを待つ。   Branch to address H'FFFF9000 and wait for the next instruction code supplied from the debug tool 2.

(vii)FrontMON_DATAレジスタ38に書き込まれたデータを、JTAG制御部15およびモニタコード供給機能16の機能により、MON_DATAレジスタ34に転送すると共に、MON_ACCESSレジスタ36のMNDTVLDビットを“1”にセットする(ST26)。   (vii) The data written in the FrontMON_DATA register 38 is transferred to the MON_DATA register 34 by the functions of the JTAG control unit 15 and the monitor code supply function 16, and the MNDTVLD bit of the MON_ACCESS register 36 is set to “1” (ST26). ).

(viii)デバッグツール2は、JTAGインタフェース端子11を介してMON_ACCESSレジスタ36を読み出して、MNDTVLDビットをチェックし“1”になったらJTAGインタフェース端子11を介してMON_DATAレジスタ34のデータを読み出す(ST27)。   (viii) The debug tool 2 reads the MON_ACCESS register 36 through the JTAG interface terminal 11, checks the MNDTVLD bit, and when it becomes “1”, reads the data in the MON_DATA register 34 through the JTAG interface terminal 11 (ST27). .

(6)ステータスレディ待ちプログラムの実行(ステータスレディ待ちプログラム実行手段)
(i)デバッグツール2からJTAGインタフェース端子11を介してMON_CODEレジスタ33にステータスレディ待ちプログラムに分岐する命令コードがセットされる(ST28)。
(6) Status ready waiting program execution (status ready waiting program execution means)
(i) The instruction code for branching to the status ready waiting program is set from the debug tool 2 to the MON_CODE register 33 via the JTAG interface terminal 11 (ST28).

(ii)MON_CODEレジスタ33にセットされた命令コードを、JTAG制御部15およびモニタコード供給機能16の機能により、命令コードバッファ37に転送する(ST29)。   (ii) The instruction code set in the MON_CODE register 33 is transferred to the instruction code buffer 37 by the functions of the JTAG control unit 15 and the monitor code supply function 16 (ST29).

(iii)デバッグツール2からJTAGインタフェース端子11を介してMON_ACCESSレジスタ36のMNSTARTビットに“1”がセットされる(ST28)。   (iii) “1” is set from the debug tool 2 to the MNSTART bit of the MON_ACCESS register 36 via the JTAG interface terminal 11 (ST28).

(iv)CPU3は、命令コードバッファ37に転送されたステータスレディ待ちプログラムに分岐する命令コードを実行し、内蔵SRAM6上に退避されたステータスレディ待ちプログラムに分岐する(ST29)。   (iv) The CPU 3 executes the instruction code branching to the status ready waiting program transferred to the instruction code buffer 37, and branches to the status ready waiting program saved in the built-in SRAM 6 (ST29).

(v)CPU3は、ステータスレディ待ちプログラムを実行し、以下の処理を行う(ST29)。   (v) The CPU 3 executes the status ready waiting program and performs the following processing (ST29).

・図7に示したフラッシュレディステータスレジスタ51を読み出し、FSTATビットが“1”になったら、FrontMON_DATAレジスタ38(H’FFFF8000番地)にH’00000000を書き込み、FSTATビットが所定の一定期間に“1”にならなければ、FrontMON_DATAレジスタ38(H’FFFF8000番地)にH’80000000を書き込む。   When the flash ready status register 51 shown in FIG. 7 is read and the FSTAT bit becomes “1”, H′00000000 is written to the FrontMON_DATA register 38 (address H′FFFF8000), and the FSTAT bit is set to “1” for a predetermined fixed period. If not, “H′80000000” is written to the FrontMON_DATA register 38 (address H′FFFF8000).

(vi)FrontMON_DATAレジスタ38に書き込まれたデータを、JTAG制御部15およびモニタコード供給機能16の機能により、MON_DATAレジスタ34に転送すると共に、MON_ACCESSレジスタ36のMNDTVLDビットを“1”にセットする(ST29)。   (vi) The data written in the FrontMON_DATA register 38 is transferred to the MON_DATA register 34 by the functions of the JTAG control unit 15 and the monitor code supply function 16, and the MNDTVLD bit of the MON_ACCESS register 36 is set to “1” (ST29). ).

(vii)デバッグツール2は、JTAGインタフェース端子11を介してMON_ACCESSレジスタ36を読み出して、MNDTVLDビットをチェックし“1”になったらJTAGインタフェース端子11を介してMON_DATAレジスタ34のデータを読み出す。読み出したデータのbit0値が“0”ならば、次の(viii)の実行に移り、bit0値が“1”ならば、エラー処理(ST31)を行う(ST30)。   (vii) The debug tool 2 reads the MON_ACCESS register 36 through the JTAG interface terminal 11, checks the MNDTVLD bit, and reads the data in the MON_DATA register 34 through the JTAG interface terminal 11 when it becomes “1”. If the bit0 value of the read data is “0”, the process proceeds to the next execution of (viii). If the bit0 value is “1”, error processing (ST31) is performed (ST30).

(viii)デバッグツール2によって、消去したいブロック数分だけ、上記ST25からST30の処理を繰り返す(ST32)。   (viii) The process from ST25 to ST30 is repeated by the debug tool 2 for the number of blocks to be erased (ST32).

(7)E/Wモード終了プログラムの実行(E/Wモード終了プログラム実行手段)
(i)デバッグツール2からJTAGインタフェース端子11を介してMON_CODEレジスタ33にE/Wモード終了プログラムに分岐する命令コードがセットされる(ST33)。
(7) Execution of E / W mode end program (E / W mode end program execution means)
(i) The instruction code for branching to the E / W mode end program is set in the MON_CODE register 33 from the debug tool 2 through the JTAG interface terminal 11 (ST33).

(ii)MON_CODEレジスタ33にセットされた命令コードを、JTAG制御部15およびモニタコード供給機能16の機能により、命令コードバッファ37に転送する(ST34)。   (ii) The instruction code set in the MON_CODE register 33 is transferred to the instruction code buffer 37 by the functions of the JTAG control unit 15 and the monitor code supply function 16 (ST34).

(iii)デバッグツール2からJTAGインタフェース端子11を介してMON_ACCESSレジスタ36のMNSTARTビットに“1”がセットされる(ST33)。   (iii) “1” is set from the debug tool 2 to the MNSTART bit of the MON_ACCESS register 36 via the JTAG interface terminal 11 (ST33).

(iv)CPU3は、命令コードバッファ37に転送されたE/Wモード終了プログラムに分岐する命令コードを実行し、内蔵SRAM6上に退避されたE/Wモード終了プログラムに分岐する(ST34)。   (iv) The CPU 3 executes the instruction code branching to the E / W mode end program transferred to the instruction code buffer 37, and branches to the E / W mode end program saved in the built-in SRAM 6 (ST34).

(v)CPU3は、E/Wモード終了プログラムを実行し、以下の処理を行う(ST34)。   (v) The CPU 3 executes the E / W mode end program and performs the following processing (ST34).

・図8に示したフラッシュメモリ制御レジスタ61のFENTRYビット62に“0”を書き込み、内蔵フラッシュメモリ5を通常モードに移行させる。   Write “0” to the FENTRY bit 62 of the flash memory control register 61 shown in FIG. 8 to shift the built-in flash memory 5 to the normal mode.

・FrontMON_DATAレジスタ38(H’FFFF8000番地)にH’00000000を書き込む。   Write H'00000000 to the FrontMON_DATA register 38 (address H'FFFF8000).

(vi)FrontMON_DATAレジスタ38に書き込まれたデータを、JTAG制御部15およびモニタコード供給機能16の機能により、MON_DATAレジスタ34に転送すると共に、MON_ACCESSレジスタ36のMNDTVLDビットを“1”にセットする(ST34)。   (vi) The data written in the FrontMON_DATA register 38 is transferred to the MON_DATA register 34 by the functions of the JTAG control unit 15 and the monitor code supply function 16, and the MNDTVLD bit of the MON_ACCESS register 36 is set to “1” (ST34). ).

(vii)デバッグツール2は、JTAGインタフェース端子11を介してMON_ACCESSレジスタ36を読み出して、MNDTVLDビットをチェックし、“1”になったらJTAGインタフェース端子11を介してMON_DATAレジスタ34のデータを読み出す(ST35)。   (vii) The debug tool 2 reads the MON_ACCESS register 36 via the JTAG interface terminal 11, checks the MNDTVLD bit, and when it becomes “1”, reads the data in the MON_DATA register 34 via the JTAG interface terminal 11 (ST35). ).

図16は内蔵フラッシュメモリの書き込み動作を示すフローチャートであり、次に、この図16のフローチャートを参照しながら内蔵フラッシュメモリ5の書き込み動作を説明する。なお、この図16に示すフローチャートは、図13のフラッシュE/Wイネーブルモード移行(ST13)、フラッシュ書き換え(ST14)、および通常モード復帰(ST15)において、内蔵フラッシュメモリ5の消去および書き込み動作を行った場合の詳細に相当するものである。   FIG. 16 is a flowchart showing the write operation of the built-in flash memory. Next, the write operation of the built-in flash memory 5 will be described with reference to the flowchart of FIG. The flowchart shown in FIG. 16 performs the erase and write operations of the built-in flash memory 5 in the flash E / W enable mode transition (ST13), flash rewrite (ST14), and normal mode return (ST15) shown in FIG. This corresponds to the details of the case.

(4)E/Wモード移行プログラムの実行(E/Wモード移行プログラム実行手段)
この動作は、図14に示した内蔵フラッシュメモリ5の消去動作の(ST21)〜(ST24)と同一である。
(4) Execution of E / W mode transition program (E / W mode transition program execution means)
This operation is the same as (ST21) to (ST24) in the erase operation of the built-in flash memory 5 shown in FIG.

(5)ブロック消去プログラムの実行(消去プログラム実行手段)
この動作は、図14に示した内蔵フラッシュメモリ5の消去動作の(ST25)〜(ST27)と同一である。
(5) Execution of block erase program (erase program execution means)
This operation is the same as (ST25) to (ST27) in the erase operation of the built-in flash memory 5 shown in FIG.

(6)内蔵フラッシュメモリへの書き込みデータの転送
本来ならば、(ST27)の後は、消去が終了したかどうかをステータスレディ待ちプログラムを実行して検証すべきであるが、消去に要する時間を利用して、内蔵フラッシュメモリ5への書き込みデータを内蔵SRAM6上のフラッシュ書き込み用バッファに転送する。以下にその動作を説明する。
(6) Transfer of write data to built-in flash memory Normally, after (ST27), it should be verified by executing a status ready wait program to determine whether or not the erase has been completed. Using this, write data to the built-in flash memory 5 is transferred to a flash write buffer on the built-in SRAM 6. The operation will be described below.

(i)デバッグツール2からJTAGインタフェース端子11を介してMON_CODEレジスタ33に書き込みデータ転送プログラムの命令コードがセットされる(ST51)。   (i) The instruction code of the write data transfer program is set from the debug tool 2 to the MON_CODE register 33 via the JTAG interface terminal 11 (ST51).

(ii)MON_CODEレジスタ33にセットされた命令コードを、JTAG制御部15およびモニタコード供給機能16の機能により、命令コードバッファ37に転送する(ST52)。   (ii) The instruction code set in the MON_CODE register 33 is transferred to the instruction code buffer 37 by the functions of the JTAG control unit 15 and the monitor code supply function 16 (ST52).

上記(i)(ii)の処理を4回行って、書き込みデータ転送プログラムを命令コードバッファ37にセットする。書き込みデータ転送プログラムとは、内蔵フラッシュメモリに書き込みたいデータをデバッグツール2から内蔵SRAM6上のフラッシュ書き込み用バッファに転送するためのプログラムである(構成のページ書き込みプログラムの実行方法を参照)。   The processes (i) and (ii) are performed four times to set the write data transfer program in the instruction code buffer 37. The write data transfer program is a program for transferring data to be written to the built-in flash memory from the debug tool 2 to the flash write buffer on the built-in SRAM 6 (see the execution method of the page write program having the configuration).

(iii)デバッグツール2からJTAGインタフェース端子11を介してMON_PARAMレジスタ35に書き込みデータが32ビット分セットされる(ST51)。   (iii) Write data for 32 bits is set from the debug tool 2 to the MON_PARAM register 35 via the JTAG interface terminal 11 (ST51).

(iv)MON_PARAMレジスタ35にセットされた書き込みデータを、JTAG制御部15およびモニタコード供給機能16の機能により、FrontMON_PARAMレジスタ39に転送する(ST52)。   (iv) The write data set in the MON_PARAM register 35 is transferred to the FrontMON_PARAM register 39 by the functions of the JTAG control unit 15 and the monitor code supply function 16 (ST52).

(v)デバッグツール2からJTAGインタフェース端子11を介してMON_ACCESSレジスタ36のMNSTARTビットに“1”がセットされる(ST51)。   (v) “1” is set from the debug tool 2 to the MNSTART bit of the MON_ACCESS register 36 via the JTAG interface terminal 11 (ST51).

(vi)CPU3は、命令コードバッファ37にセットされた書き込みデータ転送プログラムを実行し、以下の処理を行う(ST52)。   (vi) The CPU 3 executes the write data transfer program set in the instruction code buffer 37 and performs the following processing (ST52).

・FrontMON_PARAMレジスタ39(H’FFFF8004番地)を読み出す。   Read the FrontMON_PARAM register 39 (address H'FFFF8004).

・読み出した書き込みデータを内蔵SRAM6上のフラッシュ書き込み用バッファに書き込む。   Write the read write data to the flash write buffer on the built-in SRAM 6.

・書き込み先のアドレスを+4する。
・H’FFFF9000番地に分岐し、新たな命令コードが供給されるのを待つ。
• Add +4 to the write destination address.
Branch to address H'FFFF9000 and wait for a new instruction code to be supplied.

(iii)〜(vi)の処理を繰り返すことによって、1ページ(=256バイト)分の書き込みデータを内蔵SRAM6上のフラッシュ書き込み用バッファに転送する。最終ループの(vi)の処理で、最後にステータスレディ待ちプログラムに分岐する。   By repeating the processes (iii) to (vi), write data for one page (= 256 bytes) is transferred to the flash write buffer on the built-in SRAM 6. In the final loop (vi), the program branches to the status ready program.

(7)ステータスレディ待ちプログラムの実行(ステータスレディ待ちプログラム実行手段)
この動作は、図14に示した内蔵フラッシュメモリ5の消去動作の(ST28)〜(ST31)と同一である。
(7) Status ready waiting program execution (status ready waiting program execution means)
This operation is the same as (ST28) to (ST31) in the erase operation of the built-in flash memory 5 shown in FIG.

(8)ページ書き込みプログラムの実行(書き込みプログラム実行手段)
(i)デバッグツール2からJTAGインタフェース端子11を介してMON_PARAMレジスタ35に書き込み先のアドレスがセットされる(ST53)。
(8) Execution of page writing program (writing program execution means)
(i) A write destination address is set from the debug tool 2 to the MON_PARAM register 35 via the JTAG interface terminal 11 (ST53).

(ii)MON_PARAMレジスタ35にセットされたアドレスを、JTAG制御部15およびモニタコード供給機能16の機能により、FrontMON_PARAMレジスタ39に転送する(ST54)。   (ii) The address set in the MON_PARAM register 35 is transferred to the FrontMON_PARAM register 39 by the functions of the JTAG control unit 15 and the monitor code supply function 16 (ST54).

(iii)デバッグツール2からJTAGインタフェース端子11を介してMON_CODEレジスタ33にページ書き込みプログラムに分岐する命令コードがセットされる(ST53)。   (iii) The instruction code for branching to the page writing program is set from the debug tool 2 to the MON_CODE register 33 via the JTAG interface terminal 11 (ST53).

(iv)デバッグツール2からJTAGインタフェース端子11を介してMON_ACCESSレジスタ36のMNSTARTビットに“1”がセットされる(ST53)。   (iv) “1” is set from the debug tool 2 to the MNSTART bit of the MON_ACCESS register 36 via the JTAG interface terminal 11 (ST53).

(v)CPU3は、命令コードバッファ37に転送されたページ書き込みプログラムに分岐する命令コードを実行し、内蔵SRAM6上に退避されたページ書き込みプログラムに分岐する(ST54)。   (v) The CPU 3 executes the instruction code branching to the page writing program transferred to the instruction code buffer 37, and branches to the page writing program saved on the built-in SRAM 6 (ST54).

(vi)CPU3は、ページ書き込みプログラムを実行し、以下の処理を行う(ST54)。   (vi) The CPU 3 executes the page writing program and performs the following processing (ST54).

・FrontMON_PARAMレジスタ39(H’FFFF8004番地)を読み出す。   Read the FrontMON_PARAM register 39 (address H'FFFF8004).

・内蔵フラッシュメモリ5に対してページ書き込みコマンドを発行する。
図17は内蔵フラッシュメモリの書き込み動作の詳細を示すフローチャートであり、このフローチャートを参照しながら、上記ページ書き込みコマンドに応じた動作を説明する。
Issue a page write command to the built-in flash memory 5.
FIG. 17 is a flowchart showing details of the write operation of the built-in flash memory. The operation according to the page write command will be described with reference to this flowchart.

まず、内蔵フラッシュメモリ5の任意のアドレスにページプログラムコマンドデータ(H’4141)を書き込む(ST81)。フラッシュ書き込み用バッファの先頭16ビット分のデータを読み出し、FrontMON_PARAMレジスタ39から読み出した値を書き込み先アドレスとして書き込みを行う(ST82)。フラッシュ書き込み用バッファから読み出し先のアドレスとフラッシュへの書き込み先アドレスを順次+2ずつ増加しながら(ST83)、1ページ分(=256バイト)の書き込みを行う(ST82〜ST84)。1ページ分の書き込みが終了すると、図1に示したフラッシュ内部制御回路5cによって1ページ分のデータの内蔵フラッシュメモリ5への書き込みが開始される(ST85)。   First, page program command data (H′4141) is written to an arbitrary address in the built-in flash memory 5 (ST81). Data for the first 16 bits of the flash write buffer is read, and writing is performed using the value read from the FrontMON_PARAM register 39 as a write destination address (ST82). While increasing the read destination address from the flash write buffer and the write destination address to the flash by +2 sequentially (ST83), writing for one page (= 256 bytes) is performed (ST82 to ST84). When the writing for one page is completed, the flash internal control circuit 5c shown in FIG. 1 starts writing data for one page to the built-in flash memory 5 (ST85).

・FrontMON_DATAレジスタ38(H’FFFF8000番地)にH’00000000を書き込む。   Write H'00000000 to the FrontMON_DATA register 38 (address H'FFFF8000).

・H’FFFF9000番地に分岐し、次のデバッグツール2から供給される命令コードを待つ。   Branch to address H'FFFF9000 and wait for the next instruction code supplied from the debug tool 2.

(vii)FrontMON_DATAレジスタ38に書き込まれたデータを、JTAG制御部15およびモニタコード供給機能16の機能により、MON_DATAレジスタ34に転送すると共に、MON_ACCESSレジスタ36のMNDTVLDビットを“1”にセットする(ST54)。   (vii) The data written in the FrontMON_DATA register 38 is transferred to the MON_DATA register 34 by the functions of the JTAG control unit 15 and the monitor code supply function 16, and the MNDTVLD bit of the MON_ACCESS register 36 is set to “1” (ST54). ).

(viii)デバッグツール2は、JTAGインタフェース端子11を介してMON_ACCESSレジスタ36を読み出して、MNDTVLDビットをチェックし、“1”になったらJTAGインタフェース端子11を介してMON_DATAレジスタ34の値を読み出す(ST55)。   (viii) The debug tool 2 reads the MON_ACCESS register 36 via the JTAG interface terminal 11, checks the MNDTVLD bit, and when it becomes “1”, reads the value of the MON_DATA register 34 via the JTAG interface terminal 11 (ST55). ).

(9)内蔵フラッシュメモリへの書き込みデータの転送
この動作は、(6)内蔵フラッシュメモリへの書き込みデータの転送と同一である(ST56)。
(9) Transfer of write data to built-in flash memory This operation is the same as (6) Transfer of write data to built-in flash memory (ST56).

(10)ステータスレディ待ちプログラムの実行(ステータスレディ待ちプログラム実行手段)
この動作は、(7)ステータスレディ待ちプログラムの実行と同一である(ST56)〜(ST59)。
(10) Executing status ready waiting program (status ready waiting program execution means)
This operation is the same as (7) execution of the status ready waiting program (ST56) to (ST59).

そして、必要なページ数分だけST53〜ST58の処理を繰り返し(ST60)、必要なブロック数分だけST25〜ST60の処理を繰り返す(ST32)。   Then, the processing of ST53 to ST58 is repeated for the required number of pages (ST60), and the processing of ST25 to ST60 is repeated for the required number of blocks (ST32).

(11)E/Wモード終了プログラムの実行(E/Wモード終了プログラム実行手段)
この動作は、図14に示した内蔵フラッシュメモリ5の消去動作の(ST33)〜(ST35)と同一である。
(11) Execution of E / W mode end program (E / W mode end program execution means)
This operation is the same as (ST33) to (ST35) in the erase operation of the built-in flash memory 5 shown in FIG.

なお、上記実施の形態1では、図9に示したように、ツールROM領域24、および書き換えプログラムを内蔵フラッシュメモリ5内のブートROM領域42に設け、セキュリティコード格納領域25および内蔵フラッシュ情報格納領域26を任意の空間に設けた。しかし、これらの領域は、CPU3からアクセスできる空間であればどの領域に置いても良く、ただし、これらの領域を内蔵フラッシュメモリ5に設けると、マイクロコンピュータ1のチップの製作後に、情報を書き込んだり、書き換えたりすることが可能となる利点がある。   In the first embodiment, as shown in FIG. 9, the tool ROM area 24 and the rewrite program are provided in the boot ROM area 42 in the built-in flash memory 5, and the security code storage area 25 and the built-in flash information storage area. 26 was provided in an arbitrary space. However, these areas may be placed in any area accessible from the CPU 3. However, if these areas are provided in the built-in flash memory 5, information can be written after the manufacture of the microcomputer 1 chip. There is an advantage that it can be rewritten.

書き換えプログラムについては、格納場所を内蔵フラッシュメモリ5ではなく、マスクROMに格納してもよく、この場合には、内蔵フラッシュメモリ5の書き換えの際に内蔵SRAM6上に退避する必要がなく、処理が簡単になるという効果がある。   As for the rewrite program, the storage location may be stored not in the built-in flash memory 5 but in the mask ROM. In this case, when the built-in flash memory 5 is rewritten, it is not necessary to save it in the built-in SRAM 6, and the processing is performed. There is an effect that it becomes easy.

なお、上記実施の形態1では、ツールROM領域24内の情報、セキュリティコード格納領域25内の情報、および内蔵フラッシュ情報格納領域26内の情報を区別したが、これら3つの情報をまとめて内蔵フラッシュ情報としても良い。   In the first embodiment, the information in the tool ROM area 24, the information in the security code storage area 25, and the information in the built-in flash information storage area 26 are distinguished from each other. It may be information.

以上のように、この実施の形態1によれば、デバッグツール2から直接に内蔵フラッシュメモリ5の書き換え制御を行うことができ、デバッグの作業効率を高くすることができるマイクロコンピュータが得られる効果がある。   As described above, according to the first embodiment, the rewrite control of the built-in flash memory 5 can be performed directly from the debug tool 2, and there is an effect that a microcomputer that can increase the work efficiency of debugging is obtained. is there.

1 マイクロコンピュータ、2 デバッグツール、3 CPU、4 デバッグモジュール、5 内蔵フラッシュメモリ、5a FP端子、5b OR回路(書き換え許可手段)、5c フラッシュ内部制御回路(書き換え許可手段)、6 内蔵SRAM、7 内蔵周辺I/O、8 バス制御回路、9 内部バス、9a アドレスバス、9b データバス、11 JTAGインタフェース端子(インタフェース,シリアルインタフェース)、12 端子、13a デバッグトラップ命令実行機能、13b プログラムカウンタ、13c プログラムカウンタ退避用レジスタ、13d PSWレジスタ、13e PSW退避用レジスタ、13f 汎用レジスタ、14 実行後PCブレーク機能、15 JTAG制御部、16 モニタコード供給機能、17 アクセスブレーク機能、18 実行前PCブレーク機能、19 デバッグ割り込み要求、21 デバッグモジュール用内蔵I/O領域、22 デバッグモジュール用制御レジスタ領域、23 モニタコード供給領域、24 ツールROM領域、26 内蔵フラッシュ情報格納領域、31 TAPコントローラ、32 命令レジスタ、33 MON_CODEレジスタ(第1のレジスタ)、34 MON_DATAレジスタ(第2のレジスタ)、35 MON_PARAMレジスタ(第3のレジスタ)、36 MON_ACCESSレジスタ、37 命令コードバッファ、38 FrontMON_DATAレジスタ、39 FrontMON_PARAMレジスタ、41 ユーザ領域、42 ブートROM領域、51 フラッシュレディステータスレジスタ、52 FSTATビット、61 フラッシュメモリ制御レジスタ、62 FENTRYビット。   1 Microcomputer, 2 Debug Tool, 3 CPU, 4 Debug Module, 5 Built-in Flash Memory, 5a FP Terminal, 5b OR Circuit (Rewrite Permission Unit), 5c Flash Internal Control Circuit (Rewrite Permission Unit), 6 Built-in SRAM, 7 Built-in Peripheral I / O, 8 bus control circuit, 9 internal bus, 9a address bus, 9b data bus, 11 JTAG interface terminal (interface, serial interface), 12 terminal, 13a debug trap instruction execution function, 13b program counter, 13c program counter Save register, 13d PSW register, 13e PSW save register, 13f General-purpose register, 14 Post-execution PC break function, 15 JTAG control unit, 16 Monitor code supply function, 17 Access Break function, 18 PC break function before execution, 19 Debug interrupt request, 21 Internal I / O area for debug module, 22 Control register area for debug module, 23 Monitor code supply area, 24 Tool ROM area, 26 Internal flash information storage area , 31 TAP controller, 32 instruction register, 33 MON_CODE register (first register), 34 MON_DATA register (second register), 35 MON_PARAM register (third register), 36 MON_ACCESS register, 37 instruction code buffer, 38 FrontMON_DATA Register, 39 FrontMON_PARAM register, 41 User area, 42 Boot ROM area, 51 Flash ready status register, 52 FSTAT bit, 61 Flash memory control register, 62 FENTRY bit.

Claims (5)

中央処理装置と、不揮発性メモリと、外部にデバッグツールが接続されるデバッグインタフェースとを半導体基板上に有し、
前記中央処理装置は、前記不揮発性メモリから命令のフェッチを行い当該命令を実行し、また前記デバッグツールからの指示に応じて動作制御され、
前記不揮発性メモリは、前記デバッグツールからの指示に応答してデータの書込みまたは消去が可能に構成され、データの書込みまたは消去が正常に完了したか否かの情報を第1レジスタに格納し、
前記デバッグツールから前記第1レジスタを参照可能に構成される半導体処理装置。
A central processing unit, a nonvolatile memory, and a debug interface to which a debug tool is connected to the outside are provided on a semiconductor substrate,
The central processing unit fetches an instruction from the nonvolatile memory and executes the instruction, and is controlled in accordance with an instruction from the debug tool.
The nonvolatile memory is configured to be able to write or erase data in response to an instruction from the debug tool, and stores information on whether or not data writing or erasure has been normally completed in the first register,
A semiconductor processing apparatus configured to be able to refer to the first register from the debug tool.
前記半導体処理装置はさらに揮発性メモリを前記半導体基板上に有し、
前記不揮発性メモリへデータの書込みまたは消去を行うためのプログラムが、前記不揮発性メモリの所定のアドレス空間に格納され、
前記データの書込みまたは消去に先立って、前記プログラムは前記揮発性メモリに転送され、
前記デバッグツールからの指示により、前記プログラムの格納領域の先頭アドレスへ分岐する制御が行われる、請求項1に記載の半導体処理装置。
The semiconductor processing apparatus further includes a volatile memory on the semiconductor substrate,
A program for writing or erasing data in the nonvolatile memory is stored in a predetermined address space of the nonvolatile memory,
Prior to writing or erasing the data, the program is transferred to the volatile memory,
The semiconductor processing apparatus according to claim 1, wherein control is performed to branch to a start address of the storage area of the program in accordance with an instruction from the debug tool.
前記デバッグツールから参照可能とされる第2レジスタを有し、
前記デバッグツールは前記第2レジスタに前記不揮発性メモリへ書込むデータを設定して前記揮発性メモリへ格納させ、
前記不揮発性メモリへデータの書込みを行うためのプログラムは、前記揮発性メモリから書込みデータを読み出して前記不揮発性メモリへデータの書込みを行う、請求項2に記載の半導体処理装置。
A second register that can be referred to by the debug tool;
The debug tool sets data to be written to the nonvolatile memory in the second register and stores the data in the volatile memory,
The semiconductor processing apparatus according to claim 2, wherein the program for writing data to the nonvolatile memory reads write data from the volatile memory and writes the data to the nonvolatile memory.
中央処理装置と、不揮発性メモリと、外部にデバッグツールが接続されるデバッグインタフェースとを半導体基板上に有し、
前記中央処理装置は、前記不揮発性メモリから命令のフェッチを行い当該命令を実行し、また前記デバッグツールからの指示に応じて動作制御され、
前記不揮発性メモリは、前記デバッグツールからの指示に応答してデータの書込み、消去、または読み出しが可能に構成され、所定の領域にアクセス制限情報を格納し、
前記不揮発性メモリに前記アクセス制限情報が格納されている場合において、前記デバッグツールから入力された認証情報と前記アクセス制限情報とが合致しない場合に、前記デバッグツールからの指示に応じての前記不揮発性メモリへのデータの書込み、読み出しが制限される半導体処理装置。
A central processing unit, a nonvolatile memory, and a debug interface to which a debug tool is connected to the outside are provided on a semiconductor substrate,
The central processing unit fetches an instruction from the nonvolatile memory and executes the instruction, and is controlled in accordance with an instruction from the debug tool.
The nonvolatile memory is configured to be able to write, erase, or read data in response to an instruction from the debug tool, and stores access restriction information in a predetermined area,
When the access restriction information is stored in the nonvolatile memory and the authentication information input from the debug tool does not match the access restriction information, the nonvolatile memory according to an instruction from the debug tool Processing apparatus in which writing and reading of data to and from the memory are restricted.
前記不揮発性メモリに格納されているアクセス制限情報と前記デバッグツールから入力された認証情報とが合致しない場合、前記デバッグツールからの指示に応答して前記不揮発性メモリに格納されるデータの消去は可能とされ、
前記不揮発性メモリに格納されるデータの消去完了後に前記デバッグツールからの指示に応じての前記不揮発性メモリへのデータの書込み、読み出しの制限が解除される請求項4に記載の半導体処理装置。
When the access restriction information stored in the nonvolatile memory and the authentication information input from the debug tool do not match, the data stored in the nonvolatile memory is erased in response to an instruction from the debug tool. Is possible,
The semiconductor processing apparatus according to claim 4, wherein restrictions on writing and reading of data to and from the nonvolatile memory are released according to an instruction from the debug tool after completion of erasure of data stored in the nonvolatile memory.
JP2010026758A 2010-02-09 2010-02-09 Microcomputer Pending JP2010102743A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2010026758A JP2010102743A (en) 2010-02-09 2010-02-09 Microcomputer

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2010026758A JP2010102743A (en) 2010-02-09 2010-02-09 Microcomputer

Related Parent Applications (1)

Application Number Title Priority Date Filing Date
JP32435699A Division JP4475709B2 (en) 1999-11-15 1999-11-15 Microcomputer

Related Child Applications (1)

Application Number Title Priority Date Filing Date
JP2011099513A Division JP2011187073A (en) 2011-04-27 2011-04-27 Semiconductor processor

Publications (1)

Publication Number Publication Date
JP2010102743A true JP2010102743A (en) 2010-05-06

Family

ID=42293268

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2010026758A Pending JP2010102743A (en) 2010-02-09 2010-02-09 Microcomputer

Country Status (1)

Country Link
JP (1) JP2010102743A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH08241225A (en) * 1995-03-02 1996-09-17 Fujitsu Ltd Evaluating device
JPH09319727A (en) * 1996-05-31 1997-12-12 Hitachi Ltd Data processor and data processing system
JPH10222362A (en) * 1997-02-05 1998-08-21 Nec Corp Microcomputer incorporating flash eeprom
JPH11203146A (en) * 1998-01-09 1999-07-30 Mitsubishi Electric Corp Microcomputer
JPH11282715A (en) * 1998-03-31 1999-10-15 Seiko Epson Corp Microcomputer, electronic equipment and debug system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH08241225A (en) * 1995-03-02 1996-09-17 Fujitsu Ltd Evaluating device
JPH09319727A (en) * 1996-05-31 1997-12-12 Hitachi Ltd Data processor and data processing system
JPH10222362A (en) * 1997-02-05 1998-08-21 Nec Corp Microcomputer incorporating flash eeprom
JPH11203146A (en) * 1998-01-09 1999-07-30 Mitsubishi Electric Corp Microcomputer
JPH11282715A (en) * 1998-03-31 1999-10-15 Seiko Epson Corp Microcomputer, electronic equipment and debug system

Similar Documents

Publication Publication Date Title
JP4475709B2 (en) Microcomputer
JP4190114B2 (en) Microcomputer
US8443423B2 (en) Secure information processing
KR101461378B1 (en) Synchronizing simd vectors
US5327531A (en) Data processing system including corrupt flash ROM recovery
US7506205B2 (en) Debugging system and method for use with software breakpoint
KR101016711B1 (en) Diagnostic circuit for an integrated circuit
US7610517B2 (en) Microprocessor with trace functionality
US20030014736A1 (en) Debugger breakpoint management in a multicore DSP device having shared program memory
US20080089161A1 (en) Method for testing flash memory power loss recovery
US8316200B2 (en) Microcomputer, electronic instrument, and flash memory protection method
US5784611A (en) Device and process for in-system programming electrically erasable and programmable non-volatile memory
US20060174163A1 (en) Software breakpoints for use with memory devices
US6798713B1 (en) Implementing software breakpoints
US20080148343A1 (en) Debugging security mechanism for soc asic
JP2000065899A (en) Semiconductor device, and its data rewriting method
TWI334082B (en) Apparatus, processor, system and method for control registers accessed via private operations,and computer-readable media
KR100825786B1 (en) Memory card and debugging method for the same
US6510501B1 (en) Non-volatile memory read/write security protection feature selection through non-volatile memory bits
JP2010102743A (en) Microcomputer
JP2011187073A (en) Semiconductor processor
KR100543152B1 (en) Microprocessor and processing method of microprocessor
US20050086454A1 (en) System and methods for providing a debug function built-in type microcomputer
JP4122824B2 (en) Data transfer control circuit for nonvolatile storage device, rewrite circuit for nonvolatile storage device, and communication control device
JP2004038464A (en) Microcomputer with built-in debugging function

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20100209

A711 Notification of change in applicant

Free format text: JAPANESE INTERMEDIATE CODE: A712

Effective date: 20100609

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20110315

A521 Written amendment

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20110427

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20111025

A02 Decision of refusal

Free format text: JAPANESE INTERMEDIATE CODE: A02

Effective date: 20120306