Home

Example of Rewriting the User ROM Area Using EW1 Mode

image

Contents

1. Returned value Type Value Meaning unsigned char REV_ERASE Erase command received REV_PROGRAM Program command received REV_ERROR Error occurred Function Determine the received character string and return the appropriate command REJ05B1424 0100 Rev 1 00 Nov 15 2010 ztENESAS Page 10 of 26 M32C 84 85 87 88 Groups Declaration unsigned short rev_size void Example of Rewriting the User ROM Area Using EW1 Mode Outline Size receive function Argument None Variable global None Returned value Type Meaning unsigned short Received data size Function Declaration Return the size sent from the master device unsigned char rev_data void Outline Program data receive function Argument None Variable global Variable name Content REV_BUFF rb Array for storing receive data Size data Store the SUM value Returned value Type Value Meaning f COMPLETE unsigned char Successfully received ERROR Failed to receive Declaration Receive 256 byte data and the SUM value Compare the SUM value for the received one packet data and the received SUM value When the received data is 256 bytes or less write FFh in the remaining space void snd_msg unsigned char msg Outline Message send function Argument Argument name Meaning unsi
2. Declaration unsigned char block_erase_command unsigned short far addr Outline Block erase function Argument name Meaning unsigned short far addr Address of block to be erased Variable global None Type Value Meaning COMPLETE Successfully completed Returned value unsigned char ERR_CMD_SEQ Command sequence error ERR_ERASE Erase error ERR_PROGRAM Program write error After executing the block erase command to the specified block execute a full status check Argument REJ05B1424 0100 Rev 1 00 2tENESAS Page 12 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode Declaration unsigned char program_command unsigned short far addr unsigned short buff Outline Program function Argument name Meaning Argument unsigned short far addr Starting address of write destination unsigned short buff 2 byte write data Variable global None Type Value Meaning COMPLETE Successfully completed Returned value urieigned Ghat ERR_CMD_SEQ Command sequence error ERR_ERASE Erase error ERR_PROGRAM Program write error After executing the program command to the specified address execute a full status check Declaration unsigned char full_status_check void Outline Full status check function Argument None Variable global None Type Value Meaning COMPLETE Successfully completed Returned value ERR_CMD_SEQ Command sequen
3. Function Set timer AO to 10 ms and UART3 transmission reception REJ05B1424 0100 Rev 1 00 Nov 15 2010 2tENESAS Page 9 of 26 M32C 84 85 87 88 Groups Declaration void cpu_slow void Example of Rewriting the User ROM Area Using EW1 Mode Outline CPU slow down processing function Argument None Variable global None Returned value None Function Declaration Select the CPU clock as main clock void cpu_fast void Outline CPU speed up processing function Argument None Variable global None Returned value None Function Declaration Select the CPU clock as the PLL clock unsigned char rev_byte unsigned char rev_data Outline 1 byte command receive function Argument Argument name Meaning unsigned char rev_data Address of the array for storing a received command Variable global None Returned value Type Value Meaning unsigned char COMPLETE Successfully completed ERR_URT_TMO Timeout ERR_URT_RCV Error occurred Function Declaration Store the received 1 byte data in the array unsigned char rev_cmd_check unsigned char cmd_buff Outline Command check function Argument Argument name Meaning unsigned char cmd_buff Starting address of the array for storing a received command Variable global None
4. The latest versions can be downloaded from the Renesas Electronics website Technical Update Technical News The latest information can be downloaded from the Renesas Electronics website C Compiler Manual M32C 100 Series C Compiler Package V 5 42 Release 00 C Compiler User s Manual Rev 2 00 The latest version can be downloaded from the Renesas Electronics website Website and Support Renesas Electronics website http www renesas com Inquiries http www renesas com inquiry REJ05B1424 0100 Rev 1 00 2tENESAS Page 26 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Ons Example of Rewriting the User ROM Area Using EW1 Mode Description Rev Date Nov 15 2010 First edition issued All trademarks and registered trademarks are the property of their respective owners A 1 General Precautions in the Handling of MPU MCU Products The following usage notes are applicable to all MPU MCU products from Renesas For detailed usage notes on the products covered by this manual refer to the relevant sections of the manual If the descriptions under General Precautions in the Handling of MPU MCU Products and in the body of the manual differ from each other the description in the body of the manual takes precedence 1 Handling of Unused Pins Handle unused pins in accord with the directions given under Handling of Unused Pins in the manual The input pins of CMOS products are generally in the high impedance state
5. This document may not be reproduced or duplicated in any form in whole or in part without prior written consent of Renesas Electronics 12 Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or Renesas Electronics products or if you have any other inquiries Note 1 Renesas Electronics as used in this document means Renesas Electronics Corporation and also includes its majority owned subsidiaries Note 2 Renesas Electronics product s means any product developed or manufactured by or for Renesas Electronics 2 CENESAS SALES OFFICES Renesas Electronics Corporation http www renesas com Refer to http www renesas com for the latest and detailed information Renesas Electronics America Inc 2880 Scott Boulevard Santa Clara CA 95050 2554 U S A Tel 1 408 588 6000 Fax 1 408 588 6130 Renesas Electronics Canada Limited 1101 Nicholson Road Newmarket Ontario LY 9C3 Canada Tel 1 905 898 5441 Fax 1 905 898 3220 Renesas Electronics Europe Limited Dukes Meadow Millboard Road Bourne End Buckinghamshire SL8 5FH U K Tel 44 1628 585 100 Fax 44 1628 585 900 Renesas Electronics Europe GmbH Arcadiastrasse 10 40472 D sseldorf Germany Tel 49 211 65030 Fax 49 211 6503 1327 Renesas Electronics China Co Ltd 7th Floor Quantum Plaza No 27 ZhiChunLu Haidian District Beijing 100083 P R China Tel 86 10 823
6. 84 85 87 88 Groups 5 Declaration Structure typedef struct buff unsigned char command CMD_SIZE unsigned short size unsigned short rev_sum REV_BUFF unsigned char prg_data RECORD_ SIZE Example of Rewriting the User ROM Area Using EW1 Mode unsigned char command CMD_SIZE Receive command unsigned short size Receive size unsigned char prg_data RECORD_SIZE RECORD_ SIZE 256 byte data storage array unsigned short rev_sum SUM value storage variable 6 Declaration Function Tables void main void Store the received sample program 256 bytes and the SUM value Outline Main function Argument None Variable global Variable name Content Array for storing received data REV_BUFF rb Size data Store the SUM value Returned value None Function Declaration Initialize CPU operating mode and the peripheral functions Receive data from the master device and execute the command Transmit the execution result to the master device void mcu_init void Outline CPU initial setting function Argument None Variable global None Returned value None Function Select the PLL clock as the CPU clock Declaration void peripheral_init void Outline Initial setting of peripheral functions Argument None Variable global None Returned value None
7. In operation with an unused pin in the open circuit state extra electromagnetic noise is induced in the vicinity of LSI an associated shoot through current flows internally and malfunctions occur due to the false recognition of the pin state as an input signal become possible Unused pins should be handled as described under Handling of Unused Pins in the manual 2 Processing at Power on The state of the product is undefined at the moment when power is supplied The states of internal circuits in the LSI are indeterminate and the states of register settings and pins are undefined at the moment when power is supplied In a finished product where the reset signal is applied to the external reset pin the states of pins are not guaranteed from the moment when power is supplied until the reset process is completed In a similar way the states of pins in a product that is reset by an on chip power on reset function are not guaranteed from the moment when power is supplied until the power reaches the level at which resetting has been specified 3 Prohibition of Access to Reserved Addresses Access to reserved addresses is prohibited The reserved addresses are provided for the possible future expansion of functions Do not access these addresses the correct operation of LSI is not guaranteed if they are accessed 4 Clock Signals After applying a reset only release the reset line after the operating clock signal has become stable Whe
8. Mode 3 3 9 Low Power Consumption Mode and On Chip Oscillator Low Power Consumption Mode When the CMO05 bit in the CMO register is set to 1 main clock stopped do not execute the following commands e Program command e Block erase command e Lock bit program command Read lock bit status command REJ05B1424 0100 Rev 1 00 ztENESAS Page 5 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 4 Description of the Application Example This application note describes an example of a monitor program where the sample program is received from the master device and the sample program execute and program ROM area rewrite commands are executed Figure 4 1 shows the System Structure Diagram Clock asynchronous serial I O mode 38400 bps Sample program transmission Master device Monitor program Command transmission and reception PC etc Figure 4 1 System Structure Diagram Clocks used in this application note are listed in the following table Table 4 1 Clock Conditions Frequency Main clock 10 MHz PLL frequency 30 MHz multiply by 6 then divide by 2 Control commands used in this application note are listed in the following table Table 4 2 Control Commands Control Command Command 1st to 3rd 4th to 5th After 6th Byte Name Explanation Bytes Bytes Data max SUM value 2 256 bytes bytes The data SUM value transmission and received results are repeated
9. ret Figure 7 8 Size Receive Function REJ05B1424 0100 Rev 1 00 ztENESAS Page 19 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 7 9 Program Data Receive Function rev_data void ret FAIL Initialize received result Initialize SUM value Stored amount of data equal to the received size Yes 1 byte received No ri_u0c1 0 Yes ri_u0c1 1 rb prg_data i lt UORB amp FFh Store received data sum lt sum rb prg_data i Add SUM value Decrement the received size 1 byte received No ri_u0c1 0 Yes ri_u0c1 1 buff gt rev_sum UORB amp FFh Receive lower SUM value data No ri_u0c1 0 1 byte received Yes ri_u0c1 1 rb rev_sum amp Combine the received upper SUM value data and rb rev_sum UORB amp FFh lt lt 8 the lower SUM value data Stored amount of data No i lt RECORD_SIZE equal to the received size prg_datali Yes i RECORD_SIZE When the received data is 256 buff gt prg_data i lt _ FFh bytes or less write FFh in the remaining space No SUM value is equal Yes sum rb rev_sum ret COMPLETE return ret Figure 7 9 Program Data Receive Function REJ05B1424 0100 Rev 1 00 ztENESAS Page 20 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 7 10 Message Transmit Function Argument send_mess
10. up to the program size Results 1 Program write Execute to write command the received data Erases the Erase command program ROM Results 1 area Note 1 When the program and erase operations are successfully completed 6FH o is returned If an error occurs 65H e is returned UARTO clock asynchronous serial I O mode is used in communication with the master device The UARTO settings are as follows e Mode Clock asynchronous serial I O mode Communication bit rate 38400 bps e CTS RTS Not used e Stop bit 1 stop bit e Parity None e Data bit length 8 bits REJ05B1424 0100 Rev 1 00 2tENESAS Page 6 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode Figure 4 2 shows a Monitor Program Operation Example Reset start Send erase command ers Erase processing Send erase complete code Send program write command prg Send sample program size 2 bytes Receive size 2 bytes Send sample program 256 bytes Receive sample program 256 bytes Send SUM value 2 bytes Receive SUM value 2 bytes Compare SUM value Program processing Send program write complete code Receive program write complete code Figure 4 2 Monitor Program Operation Example REJ05B1424 0100 Rev 1 00 2tENESAS Page 7 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriti
11. 5 1155 Fax 86 10 8235 7679 Renesas Electronics Shanghai Co Ltd Unit 204 205 AZIA Center No 1233 Lujiazui Ring Rd Pudong District Shanghai 200120 China Tel 86 21 5877 1818 Fax 86 21 6887 7858 7898 Renesas Electronics Hong Kong Limited Unit 1601 1613 16 F Tower 2 Grand Century Place 193 Prince Edward Road West Mongkok Kowloon Hong Kong Tel 852 2886 9318 Fax 852 2886 9022 9044 Renesas Electronics Taiwan Co Ltd 7F No 363 Fu Shing North Road Taipei Taiwan Tel 886 2 8175 9600 Fax 886 2 8175 9670 Renesas Electronics Singapore Pte Ltd 1 harbourFront Avenue 06 10 keppel Bay Tower Singapore 098632 Tel 65 6213 0200 Fax 65 6278 8001 Renesas Electronics Malaysia Sdn Bhd Unit 906 Block B Menara Amcorp Amcorp Trade Centre No 18 Jin Persiaran Barat 46050 Petaling Jaya Selangor Darul Ehsan Malaysia Tel 60 3 7955 9390 Fax 60 3 7955 9510 Renesas Electronics Korea Co Ltd 11F Samik Lavied or Bldg 720 2 Yeoksam Dong Kangnam Ku Seoul 135 080 Korea Tel 82 2 558 3737 Fax 82 2 558 5141 2010 Renesas Electronics Corporation All rights reserved Colophon 1 0
12. FORM bit lt 0 U3BRG register lt UART_BRG U3C1 register TE bit lt 0 TI bit lt 1 RE bit 0 RI bit 0 U3IRS bit lt 0 U3RRM bit lt 0 U3LCH bit lt 0 U3CO0 register S3TIC register Bits ILVL2 to ILVLO lt 000b IR bit lt 0 Bits ILVL2 to ILVLO lt 000b IR bit lt 0 S3RIC register Pin settings in the Function Select Registers Timer AO setting TAOMR register Bits TMOD1 and TMODO lt 10b MR1 bit lt 0 MR2 bit lt 0 MR3 bit lt 0 Bits TCK1 and TCKO lt 01b TAO register TIM10MS TAOIC register Bits ILVL2 to ILVLO lt 000b IR bit lt 0 return Peripheral Function Initial Setting Function UART mode 8 bit data length Internal clock 1 stop bit Parity disabled not inverted U3BRG count source f1 Disable CTS function LSB first Set the baud rate to 38400 bps Disable transmit operations Disable receive operations f Transmit interrupt source select bit Transmit interrupt priority level select bits Interrupt not requested Receive interrupt priority level select bits Interrupt not requested One shot timer mode Enable one shot start bit Count source f8 Set 10 ms timer Disable timer AO interrupt Peripheral Function Initial Setting Function REJ05B1424 0100 Rev 1 00 Nov 15 2010 ztENESAS Page 16 of 26 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 7 4 CPU Slow Down Processing Functi
13. RENESAS APPLICATION NOTE M32C 84 85 87 88 Groups A Example of Rewriting the User ROM Area Using EW1 Mode Rev 1 00 Nov 15 2010 1 Abstract This document describes an example of using EW1 mode in flash memory version 2 Introduction The application example described in this document applies to the following microcomputers MCUs MCUs M32C 84 Group M32C 85 Group M32C 87 Group and M32C 88 Group This application note can be used with other M32C 80 Series MCUs which have the same special function registers SFRs as the above groups Check the manuals for any modifications to functions Careful evaluation is recommended before using the program described in this application note REJ05B1424 0100 Rev 1 00 ztENESAS Page 1 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 3 CPU Rewrite Modes The CPU rewrite mode consists of EWO mode and EW1 mode 3 1 EW1 Mode Features EW1 mode allows the user to rewrite a different block from that of the CPU rewrite program by allocating the CPU rewrite program to any block in the user ROM area and issuing program and erase commands During programming or erasing peripheral function interrupts DMA requests and DMACII requests are not accepted 3 2 EW1 Mode Settings After setting the FMRO1 bit in the FMRO register to 1 CPU rewrite mode enabled the CPU enters EW1 mode by setting the FMR11 bit in the FMRI register Re
14. TMO Received 1 byte Yes result COMPLETE rev_buff lt UORB Store data in buffers temporarily Successfully received Yes rev_buff amp F000h 00h rev_data lt rev_ buff amp FFh Store the received ret ERR_URT_RCV data in the array return ret Note 1 Timeout processing is performed when a command is received in this function while it is not performed in other functions Timeout processing can be added to other functions when necessary Figure 7 6 1 byte Command Receive Function REJ05B1424 0100 Rev 1 00 ztENESAS Page 18 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 7 7 Command Check Function Argument unsigned char cmd_buff Starting address of the array for storing a received command rev_cmd_check unsigned char cmd_buff ret REV_ERROR Initialize the received result Receive command is ers ret lt 1 REV_ERASE Erase command Receive command is prg ret REV_PROGRAM Program command return ret Figure 7 7 Command Check Function 7 8 Size Receive Function rev_size void ia No ri_u0c1 0 1 byte received Yes ri_u0c1 1 ret UORB amp FFh Store size upper data Shift stored data 8 bits to the left No ri_u0c1 0 1 byte received Yes ri_u0c1 1 ret lt ret UORB amp FFh Store size lower data and match to upper data return
15. ad the FMRO register to determine the status of program and erase operations when completed In EW1 mode the status register cannot be read Figure 3 1 shows the Setting Procedure for EW1 Mode Set the CPU clock frequency to 10 MHz MCD register or lower in CPU rewrite mode PM1 register PM12 bit 1 Internal memory wait state inserted J j CPU rewrite mode enabled FMRO register FMRO1 bit 0 To set the FMRO01 bit to 1 write 1 to the FMRO1 bit immediately after writing 0 Write the value to the FMRO register in 8 bit units Do not generate an interrupt or a DMA or DMACII transfer FMRO register FMR01 bit 1 between these two setting _ Set it while the NMI pin level is held H Pr Enter EW1 mode EME gisele MU Dp O To set the FMR11 bit to 1 write 1 to the FMR11 bit immediately after writing 0 to the bit while the FMR01 bit is set to 1 Do not generate an interrupt or a DMA or DMACII transfer between these two setting FMR1 register FMR11 bit 1 Set it while H is applied to the NMI pin CPU rewrite mode disabled f Execute the software commands ii To change the FMR01 bit from 1 to 0 enter read array mode FMRO register FMRO01 bit 0 and then write to address 0057h in 16 bit units Set the 8 high order bits to 00h Note 1 Do not use EW1 mode in memory expansion mode or boot mode Figure 3 1 Setting Procedure for EW1 Mode REJ05B1424 0100 Rev 1 00 2tENESAS Pag
16. age const unsigned char mess Starting address of the array for the const unsigned char mess transmit message No mess 0 Transmit data exits Yes mess 0 Data ee Wait until there is no data in the UOTB register transmit buffer Yes ti_u0c1 0 UOTB register lt mess Send 1 byte data Figure 7 10 Message Transmit Function REJ05B1424 0100 Rev 1 00 2tENESAS Page 21 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 7 11 Flash Memory Erase Function erase void Disable maskable interrupts CPU slow down processing cpu_slow PRC1 bit in the PRCR register lt 1 Protection disabled PM12 bit in the PM1 register lt 1 Number of internal memory waits 1 PRCO bit in the PRCR register lt 0 Protection enabled FMR01 bit in the FMRO register lt 0 FMR01 bit in the FMRO register 1 FMR11 bit in the FMR1 register lt 0 EW1 mode Enable CPU rewrite mode FMR11 bit in the FMR1 register lt 1 full_status_check i Full status check Successfully completed Yes ret COMPLETE i Block erase function i block_erase_command addr addr lt CLR_STS_CMD Successfully completed Yes ret COMPLETE addr CLR_STS_CMD FMR01 bit in the FMRO register lt 0 Disable CPU rewrite mode CPU Speed Up processing Initialize CPU setting cpu_fast Peripheral fu
17. ce error unsigned char ERR_ERASE Erase error ERR_PROGRAM Program write error Execute a full status check and return the result REJ05B1424 0100 Rev 1 00 2tENESAS Page 13 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 7 Flowcharts 7 1 Main Function main void Disable maskable interrupts CPU initial setting mcu_init Peripheral function initialization peripheral int peripheral int Enable maskable interrupts U3C1 register lt 05h TABSR register lt 01h Reception size initialization 3 bytes received CPU initial setting Peripheral function initial setting Enable UARTS3 transmission reception Start timer AO count i 1 byte command reception i i Check receive command i rev_cmd_check amp rev_command 0 rev_byte amp rev_command i uccessfully completed 7 Yes Increment receive size Receive size initialization Receive command command REV_ERASE i Flash memory erase a i Flash memory write i erase Successfully completed command REV_PROGRAM Receive error default receive_program Yes Transmit successfully completed send_message o send_message e Transmit completed in error Note 1 In this application note an error message is only sent when an error occurs Error p
18. ction Renesas Electronics products and technology may not be used for or incorporated into any products or systems whose manufacture use or sale is prohibited under any applicable domestic or foreign laws or regulations 6 Renesas Electronics has used reasonable care in preparing the information included in this document but Renesas Electronics does not warrant that such information is error free Renesas Electronics assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein 7 Renesas Electronics products are classified according to the following three quality grades Standard High Quality and Specific The recommended applications for each Renesas Electronics product depends on the product s quality grade as indicated below You must check the quality grade of each Renesas Electronics product before using it in a particular application You may not use any Renesas Electronics product for any application categorized as Specific without the prior written consent of Renesas Electronics Further you may not use any Renesas Electronics product for any application for which it is not intended without the prior written consent of Renesas Electronics Renesas Electronics shall not be in any way liable for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for an application categorized as Specific or for which the
19. e 2 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 3 2 1 Memory Map Figure 3 2 shows the Flash Memory Map for the M32C 87 Group M32C 87 M32C 87A and M32C 87B Refer to the respective hardware user s manuals for details of other MCUs The user ROM area has an area to store programs and another 4 Kbyte area as the block A for data storage The user ROM area is divided into blocks each of which can be protected locked from erasing or programming The user ROM area can be rewritten in CPU rewrite mode standard serial I O mode or parallel I O mode 000F000h n O00FFFFh Block A 4 KB 0F00000h OFOFFFFh 0F10000h OF1FFFFh 0F20000h OF2FFFFh F h ican Block 17 64 KB OF3FFFFh F4 h aan Block 16 64 KB OF4FFFFh F h OF50000 Block 15 64 KB OF5FFFFh OF60000h OF6FFFFh lock 20 64 KB lock 19 64 KB lock 18 64 KB Block 14 64 KB OF70000h palais Block 13 64 KB LOFF0000h User ROM F h 1 MB Merges Block 12 64 KB OF8FFFFh OF90000h Block 11 64 KB Block 5 32 KB OF9FFFFh User ROM FA0000h 768 KB EFAON00 Block 10 64 KB aaa OFF7FFFh Block 9 64 KB OFF8000h OFBFFFFh ock 4 8 KB User ROM OFC0000h SAKE Block 8 64 KB OFF9FFFh User ROM OFCFFFFh OFFA000h 384 KB OFD0000h ock 3 8 KB Block 7 64 KB OFFBFFFh OFDFFFFh OFFC000h OFE0000h Block 6 64 KB ock 2 8 KB OFEFFFFh OFFDFFFh OFF0000
20. egister is set to 1 When setting the FMR11 bit write to the FMR1 register in 8 bit units Do not generate an interrupt or a DMA or DMACII transfer between these two settings Set the FMR11 bit while the NMI pin level is held H When setting the FMRO01 bit to 0 the FMR11 bit becomes 0 REJ05B1424 0100 Rev 1 00 Nov 15 2010 Figure 7 12 Flash Memory Write Function Full status check full_status_check Successfully completed Yes ret COMPLETE Program function addr CLR_STS_CMD program command addr amp buf_data Successfully completed Yes ret COMPLETE To the next w ritten address addr lt CLR_STS_CMD_ ztENESAS ee S Page 23 of 26 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 7 13 Block Erase Function block_erase_command Argument unsigned short far addr cmd lt 0020h cmd lt 00DOh No FMRO0 0 Successfully erased Yes FMROO 1 Full status check full_status_check Successfully completed unsigned short far addr block address to be erased Write 0020h to the highest order even address Write 00DOh to the highest order even address Yes ret COMPLETE return ret Figure 7 13 Block Erase Function 7 14 Program Function Argument program_command unsigned short far addr unsigned short buff cmd
21. gned char msg Starting address of the array for the transmit message Variable global None Returned value None Function Send a message to the master device Declaration unsigned char erase void Outline Flash memory erase function Argument None Variable global None Returned value Type Value Meaning COMPLETE Successfully completed ERR_CMD_SEQ unsigned char Command sequence error ERR_ERASE Erase error ERR_PROGRAM Program write error REJ05B1424 0100 Rev 1 00 Nov 15 2010 Erase the specified block in EW1 mode and execute a full status check ztENESAS Page 11 of 26 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode Declaration unsigned char receive_program void Outline Flash memory write function Argument None Variable name Content Array for storing receive data REV_BUFF rb Size data Store the SUM value Type Value Meaning COMPLETE Successfully completed ERROR Write data error unsigned char ERR_ERASE Erase error ERR_PROGRAM Program write error ERR_CMD_SEQ Command sequence error Receive the size data and SUM value sent from the master device Write 256 bytes of data from the specified address in EW1 mode If an error occurred during the write operation execute the clear status command Variable global Returned value
22. h Block 0 to Block 5 OFFE000h ock 1 4 KB 32 84 8 8 4 44 OFFEFFFh OFFF000h KB OFFFFFFh Block 0 4 KB User ROM area OFFFFFFh Figure 3 2 Flash Memory Map REJ05B1424 0100 Rev 1 00 2tENESAS Page 3 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 3 3 Notes on EW1 Mode 3 3 1 Operating Speed Prior to entering EW1 mode set the CPU clock frequency to 10 MHz or lower using bits MCD4 to MCDO in the MCD register and also set the PM12 bit in the PM1 register to 1 1 wait state 3 3 2 Interrupts e When an interrupt request is generated by the peripheral function or watchdog timer when the PM22 bit in the PM2 register is set to 0 during the erase or program operation the interrupt is acknowledged after the erase or program operation is completed e When an interrupt request is generated by the NMI watchdog timer when the PM22 bit is set to 1 Vdet4 detection function or oscillation stop detection function registers FMRO and FMR1 are forcibly initialized and the erase or program operation in progress is aborted Now that the flash memory can be accessed the interrupt routine will be executed 3 3 3 How to Access To set the FMROI or FMRO2 bit in the FMRO register or the FMR11 bit in the FMRI register to 1 write 1 immediately after writing 0 to the bit Write to the FMRO or FMRI register in 8 bit units Do not generate an interrupt or a DMA or DMACTII
23. h our website 2 Renesas Electronics does not assume any liability for infringement of patents copyrights or other intellectual property rights of third parties by or arising from the use of Renesas Electronics products or technical information described in this document No license express implied or otherwise is granted hereby under any patents copyrights or other intellectual property rights of Renesas Electronics or others 3 You should not alter modify copy or otherwise misappropriate any Renesas Electronics product whether in whole or in part 4 Descriptions of circuits software and other related information in this document are provided only to illustrate the operation of semiconductor products and application examples You are fully responsible for the incorporation of these circuits software and information in the design of your equipment Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use of these circuits software or information 5 When exporting the products or technology described in this document you should comply with the applicable export control laws and regulations and follow the procedures required by such laws and regulations You should not use Renesas Electronics products or the technology described in this document for any purpose relating to military applications or use by the military including but not limited to the development of weapons of mass destru
24. lt 0040h cmd lt buff Write data addr CLR_STS_CMD unsigned short far addr Starting address to be written unsigned short buff 2 byte write data Write 0040h to the highest order even address No FMROO 0 Successfully programmed Yes FMROO 1 Full status check full_status_check Successfully completed Yes ret COMPLETE return ret Figure 7 14 Program Function addr lt CLR_STS_CMD REJ05B1424 0100 Rev 1 00 ztENESAS Nov 15 2010 Page 24 of 26 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 7 15 Full Status Check Function C full_status_check void FMRO07 bit 1 and Command sequence error FMRO6 bit 1 FMR07 bit 1 Erase error FMRO6 bit 1 Program error Successfully completed Figure 7 15 Full Status Check Function REJ05B1424 0100 Rev 1 00 2tENESAS Page 25 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 8 Sample Program A sample program can be downloaded from the Renesas Electronics website 9 Reference Documents User s Manuals R32C 84 Group M32C 84 M32C 84T User s Manual Hardware Rev 1 01 R32C 85 Group M32C 85 M32C 85T User s Manual Hardware Rev 1 03 R32C 87 Group M32C 87 M32C 87A M32C 87B User s Manual Hardware Rev 1 51 R32C 88 Group M32C 88T User s Manual Hardware Rev 1 10
25. n switching the clock signal during program execution wait until the target clock signal has stabilized When the clock signal is generated with an external resonator or from an external oscillator during a reset ensure that the reset line is only released after full stabilization of the clock signal Moreover when switching to a clock signal produced with an external resonator or by an external oscillator while program execution is in progress wait until the target clock signal is stable 5 Differences between Products Before changing from one product to another i e to one with a different part number confirm that the change will not lead to problems The characteristics of MPU MCU in the same group but having different part numbers may differ because of the differences in internal memory capacity and layout pattern When changing to products of different part numbers implement a system evaluation test for each of the products Notice 1 All information included in this document is current as of the date this document is issued Such information however is subject to change without any prior notice Before purchasing or using any Renesas Electronics products listed herein please confirm the latest product information with a Renesas Electronics sales office Also please pay regular and careful attention to additional and different information to be disclosed by Renesas Electronics such as that disclosed throug
26. nction initialization processing 0 Peripheral function initialization setting peripheral_init Enable maskable interrupts U3C1 register 05h Enable UARTS3 transmission reception TABSR register lt 01h Start timer AO count return ret Notes 1 To set the FMRO1 bit to 1 write 1 to the FMRO1 bit in the FMRO register immediately after writing 0 to the bit When setting the FMR01 bit write to the FMRO register in 8 bit units Do not generate an interrupt or a DMA or DMACII transfer between these two settings To set the FMR11 bit in the FMR1 register to 1 write 1 to the FMR11 bit immediately after writing 0 to the bit while the FMR01 bit in the FMRO register is set to 1 When setting the FMR11 bit write to the FMR1 register in 8 bit units Do not generate an interrupt or a DMA or DMACII transfer between these two settings Set the FMR11 bit while the NMI pin level is held H When setting the FMR01 bit to 0 the FMR11 bit becomes 0 Figure 7 11 Flash Memory Erase Function REJ05B1424 0100 Rev 1 00 ztENESAS Page 22 of 26 Nov 15 2010 M32C 84 85 87 88 Groups receive_program void Size receive function rev_size No Received size gt 0 Yes Example of Rewriting the User ROM Area Using EW1 Mode 7 12 Flash Memory Write Function Program data receive function rev_data No Successfully received Yes ret COMPLETE Disable maskable interru
27. ng the User ROM Area Using EW1 Mode The monitor program in this application note is explained below Block 12 in the user ROM area is used e When the MCU starts up the monitor program waits to receive the control command When the received command is prg 1 Receive the sample size 2 byte data 2 Receive one packet maximum 256 bytes of program data 3 Receive the data SUM value 2 byte data 4 Calculate the SUM value for the received one packet data and compare with the received SUM value 2 byte data 5 If there is no match error code is sent to master device 6 If the values match set the CPU clock to 10 MHz or lower so that one packet of data is written to the user ROM area before returning the CPU clock to its original setting e When the data has been successfully written the write complete code is sent to the master device e If a write error occurs an error code is sent to the master device and data reception is stopped 7 If an error does not occur steps 2 through 6 are repeated until receipt of the data is completed When the received command is ers 1 Set the CPU clock to 10 MHz or lower and erase the program ROM area before returning the CPU clock to its original setting 2 When successfully erased the erase complete code is sent to the master device 3 If an erase error occurs an error code is sent to the master device REJ05B1424 0100 Rev 1 00 ztENESAS Page 8 of 26 Nov 15 2010 M32C
28. of Renesas Electronics products beyond such specified ranges 9 Although Renesas Electronics endeavors to improve the quality and reliability of its products semiconductor products have specific characteristics such as the occurrence of failure at a certain rate and malfunctions under certain use conditions Further Renesas Electronics products are not subject to radiation resistance design Please be sure to implement safety measures to guard them against the possibility of physical injury and injury or damage caused by fire in the event of the failure of a Renesas Electronics product such as safety design for hardware and software including but not limited to redundancy fire control and malfunction prevention appropriate treatment for aging degradation or any other appropriate measures Because the evaluation of microcomputer software alone is very difficult please evaluate the safety of the final products or system manufactured by you 10 Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each Renesas Electronics product Please use Renesas Electronics products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances including without limitation the EU RoHS Directive Renesas Electronics assumes no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations 11
29. on cpu_slow void D PRCO bit in the PRCR register lt 1 Protection disabled CM17 bit in the CM1 register 0 CPU clock Main clock PRCO bit in the PRCR register lt 0 Protection enabled return Note 1 Set the CPU clock to 10 MHz or less Figure 7 4 CPU Slow Down Processing Function 7 5 CPU Speed Up Processing Function cpu_fast void PRCO bit in the PRCR register lt 1 Protection disabled Bits MCD4 to MCDO in the MCD register 10010b Main clock No division CM17 bit in the CM1 register lt 1 CPU clock PLL clock PRCO bit in the PRCR register lt 0 Protection enabled return Figure 7 5 CPU Speed Up Processing Function REJ05B1424 0100 Rev 1 00 2tENESAS Page 17 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 7 6 1 byte Command Receive Function Argument rev_byte unsigned char rev_data vnsigned char rev_data Address of the array for storing the received ret COMPLETE Initialize the received result TAOIC register Bits ILVL2 to ILVLO lt 000b IR bit lt 0 Clear timer AO interrupt request I TAOOS bit in the ONSF register lt 1 Start timer A0 one shot No ri 1 Received 1 byte o ri _u0c1 0 No ir_ta0ic 0 10 ms elapsed Yes ir_ta0ic 1 ret lt ERR_URT_TMO TAOOS bit in the ONSF register lt 0 Stop timer A0 one shot No result ERR_URT_
30. product is not intended where you have failed to obtain the prior written consent of Renesas Electronics The quality grade of each Renesas Electronics product is Standard unless otherwise expressly specified in a Renesas Electronics data sheets or data books etc Standard Computers office equipment communications equipment test and measurement equipment audio and visual equipment home electronic appliances machine tools personal electronic equipment and industrial robots High Quality Transportation equipment automobiles trains ships etc traffic control systems anti disaster systems anti crime systems safety equipment and medical equipment not specifically designed for life support Specific Aircraft aerospace equipment submersible repeaters nuclear reactor control systems medical equipment or systems for life support e g artificial life support devices or systems surgical implantations or healthcare intervention e g excision etc and any other applications or purposes that pose a direct threat to human life 8 You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics especially with respect to the maximum rating operating supply voltage range movement power voltage range heat radiation characteristics installation and other product characteristics Renesas Electronics shall have no liability for malfunctions or damages arising out of the use
31. pts CPU slow down process cpu_slow PRC1 bit in the PRCR register lt 1 PM12 bit in the PM1 register lt 1 PRC1 bit in the PRCR register lt 0 FMR01 bit in the FMRO register 0 FMRO01 bit in the FMRO register lt 1 FMR11 bit in the FMR1 register 0 FMR11 bit in the FMR1 register lt 1 lt Protection disabled Number of internal memory waits 1 Protection enabled CPU rewrite mode enabled i EW1 mode Successfully completed or wrote an amount of data equal to the received size Yes FMR01 bit in the FMRO register 0 CPU speed up processing cpu_fast Peripheral function initialization processing peripheral_init Enable maskable interrupts U3C1 register 05h TABSR register lt 01h return ret Notes 1 To set the FMR01 bit to 1 write 1 to the FMR01 bit in the FMRO register immediately after writing 0 to the bit When setting the FMR01 bit write to the FMRO register in 8 bit units Do not generate an interrupt or a DMA or DMACII CPU rewrite mode disabled CPU initial setting Peripheral function initialization setting Enable UART3 transmit receive Start timer AO count transfer between these two settings To set the FMR11 bit in the FMR1 register to 1 write 1 to the FMR11 bit immediately after writing 0 to the bit while the FMR01 bit in the FMRO r
32. rocessing can be added as needed Figure 7 1 Main Function REJ05B1424 0100 Rev 1 00 Nov 15 2010 ztENESAS Page 14 of 26 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 7 2 CPU Initial Setting Function mcu_init void PRCO bit in the PRCR register lt 1 Protection disabled Bits MCD4 to MCDO in the MCD register 10010b Main clock divide by 1 no division mode Set registers PLCO and PLC1 Select the multiplication factor to 3 for the PLL clock PLCO register lt 0101 0011b PLC1 register lt 0000 0010b PLCO7 bit in the PLCO register lt 1 PLL runs Wait for tsu PLL Wait for the PLL frequency synthesizer to stabilize CM17 bit in the CM1 register 1 Select the PLL clock as the CPU clock Note 1 Simultaneously set registers PLCO and PLC1 in 16 bit units Figure 7 2 CPU Initial Setting Function REJ05B1424 0100 Rev 1 00 2tENESAS Page 15 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1 Mode 7 3 Figure 7 3 peripheral_init void UARTS setting U3MR register Bits SMD2 and SMDO lt 101b CKDIR bit lt 0 STPS bit lt 0 PRY bit lt 0 PRYE bit lt 1 IOPOL bit lt 0 U3SMR register lt 00h U3SMR2 register lt 00h U3SMR3 register lt 00h U3SMR4 register lt 00h Bits CLK1 and CLKO lt 00b CRS bit lt 1 TXEPT bit lt 0 CRD bit 1 NCH bit 0 CKPOL bit lt 0 U
33. transfer between these two settings Also set these bits while a high level signal is applied to the NMI pin To change the FMRO1 bit from 1 to 0 enter read array mode first and then write into address 0057h in 16 bit units Set the 8 high order bits to 00h 3 3 4 Rewriting User ROM Area Do not rewrite a block where the rewrite control program is stored 3 3 5 Writing Command and Data Write command codes and data to even addresses in the user ROM area 3 3 6 Block Erase If an erase operation in progress is aborted due to such as the NMI interrupt hardware reset or supply voltage drop the lock bit of the block which has been erased may become 0 locked To erase the same block again set the FMRO2 bit in the FMRO register to 1 lock bit disabled and then execute the block erase command 3 3 7 Wait Mode To enter wait mode set the FMRO1 bit in the FMRO register to 0 CPU rewrite mode disabled and then execute the WAIT instruction 3 3 8 Stop Mode To enter stop mode use the following procedure e Set the FMRO1 bit to 0 CPU rewrite mode disabled before setting the CM10 bit to 1 stop mode e Execute the JMP B instruction right after the instruction to set the CM10 bit in the CM1 register to 1 stop mode Example BSET 0 CM1 Stop mode JMP B L1 L1 Program after exiting stop mode REJ05B1424 0100 Rev 1 00 2tENESAS Page 4 of 26 Nov 15 2010 M32C 84 85 87 88 Groups Example of Rewriting the User ROM Area Using EW1

Download Pdf Manuals

image

Related Search

Related Contents

Oracle FLEXCUBE Core Banking  Procedimiento Reclamaciones  Lunchbox LBG2 Owner`s Manual (English)  マルチン式人体測定器(B)  Manual de Usuario / User Manual / Notice d`utilisation  Siig 2-Port Serial 950-Value  

Copyright © All rights reserved.
Failed to retrieve file