Home
78K0/Kx2 8-Bit Single-Chip Microcontrollers Flash Memory
Contents
1. Entry RAM outside short direct addressing Entry RAM inside short direct addressing Library Name range range from FE20H Min Max Min Max block blank check library 18 fx 192 28 6x 698 18 fx 55 28 fx 462 block erase library 18 6x 186 28 6x 745 18 fx 49 28 fx 509 word write library 22 fx 189 28 fx 693 22 fx 52 28 fx 457 block verify library 18 fx 192 28 fx 709 18 fx 55 28 fx 473 set information library 16 fx 190 28 fx 454 16 fx 53 28 fx 218 EEPROM write library 22 fx 191 28 fx 783 22 fx 54 28 fx 547 Note fx Operating frequency of external system clock Remark An interrupt is not acknowledged until all of the processing of the above self programming sample libraries has been completed because these libraries execute their processing with interrupts disabled 28 User s Manual U17516EJ1VOUM CHAPTER 3 INTERRUPT SERVICING DURING SELF PROGRAMMING 3 3 Description Example This section shows an example of writing a user program that resumes erase processing that was stopped by the occurrence of an interrupt during execution of a self programming sample library block erase library User s Manual U17516EJ1VOUM 29 CHAPTER 3 INTERRUPT SERVICING DURING SELF PROGRAMMING ERS_RTRY Main processing OV A 0 i OV B 10 i DI i CALL FlashBlockErase EI i CMP A 1FH
2. Flash information data Note Details on flash information data Flash Information Data Contents Bit 0 Swaps boot areas Does not swap boot areas Bit 1 Disables chip erasure Enables chip erasure Bit 2 Disables block erasure Enables block erasure Bit 3 Disables writing Enables writing Bit 5 0 Disables writing boot area 1 Enables writing boot area Other than above Always 1 72 User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Return value Status Explanation Normal completion Parameter error Bit 0 of the information flag value was cleared to 0 for a product that does not support boot swapping Protect error Attempt was made to enable a flag that has already been disabled Attempt was made to change the boot area swap flag while rewriting of the boot area was disabled Erase error An erase error occurred while processing of this library was under execution Verify internal verify error A verify error occurred while processing of this library was under execution Write error Awrite error occurred while processing of this library was under execution Processing is stopped by the occurrence of an interrupt An interrupt occurred while processing of this library was under execution Remark The status is the UCHAR type in C and is stored in the A register in an assembly language Fun
3. lt Assembly language gt CALL FlashBlockErase Argument lt C language gt Argument Explanation UCHAR EraseBANK Bank number of block to be erased UCHAR EraseBlock Block number of block to be erased lt Assembly language gt Argument Explanation Bank number of block to be erased Block number of block to be erased Remark Set the bank number to 0 when a product with which no bank number has to be set is used Return value Status Explanation Normal completion Parameter error Specified bank number or block number is outside the settable range Protect error Specified block is included in the boot area and rewriting the boot area is disabled Erase error An error occurred during processing of this library Processing is stopped by the occurrence of an interrupt An interrupt occurred while processing of this library was under execution Remark The status is the UCHAR type in C and is stored in the A register in an assembly language User s Manual U17516EJ1VOUM 51 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Function This library erases a specified block 1 KB Remark Because only one block is erased at a time call this library as many times as required to erase two or more blocks Caution The operation is not guaranteed if this library is called with interrupts enabled Before calling this library execute the DI instructio
4. HAR FlashGetInfo Call struct stGetInfo ptrl USHORT DataBufferAddress struct GetInfoData ptr2 HAR FlashGetInfo Call5 struct stGetInfo ptrl USHORT DataBufferAddress struct GetInfoData ptr2 HAR FlashSetInfo Call3 UCHAR SetInfoData struct stGetInfo ptr USHORT C n C C u C u OGNA Or E EN EE Oe NG I C User s Manual U17516EJ1VOUM 91 APPENDIX A SAMPLE PROGRAM DataBufferAddress UCHAR FlashSetInfo Call4 UCHAR SetInfoData struct stGetInfo ptr USHORT DataBufferAddress UCHAR CheckFLMD Call void FlashEnv sreg UCHAR EntryRAM 100 Roos EEE EEE EEE Ee eee eee ee ee eee ee ee z Sample program Kees ES es Se SE a SSE eS eee ee SSR SSE ee ee eee void main void USHORT i UCHAR Status FlashBlockErase UCHAR EraseBank UCHAR EraseBlock FlashBlockVerify UCHAR VerifyBank UCHAR VerifyBlock FlashBlockBlankCheck UCHAR BlankCheckBank UCHAR BlankCheckBlock FlashWordWrite struct stWordAddress WordAddr UCHAR DataBuffer 256 struct stWordWriteData WordWriteData DI IMS OxCC IXS 0x00 PCC 0x00 Clock select division ratio gt IN 5MHZ OUT 5MHZ MSTOP 0 MOC bit7 X1 oscillator operation OSTS 0x05 Oscillation stabilization time while OSTC 0 0 MCMO 0 XSEL 0 while MCS 92 User s Manual U1751
5. Get information Block Option value Data buffer number start address Set information Data buffer start address Mode check EEPROM write Start address Start address Start address Number of Data buffer lower bits higher bits MSB words start address Remark Do not modify the content of any single description User s Manual U17516EJ1VOUM 87 CHAPTER 6 DETAILS OF SELF PROGRAMMING CONTROL 3 Data buffer The data buffer is used to pass data and setting related information written to flash memory its specific contents depend on the self programming function being used The data buffer can be placed at any address in internal high speed RAM and its start address is specified in the entry RAM The data buffer s size also depends on the function but it must be in range from 1 to 256 bytes Table 6 3 Data Buffer Parameter List Function Data Buffer Contents Data Buffer 00H Size Bytes Initialize Not used Block erase Not used Word write 4 to 256 Write data Write data Block verify Not used Block blank check Not used Get information Flash Flash information refer to Table 6 4 for details information Set information Information Bit 0 Execute boot swap 0 Not used flag Do not execute 1 Bit 1 Prohibit chip erase 0 Enable 1 Bit 2 Prohibit block erase 0 Enable 1 Bit 3 Prohibit write 0 Ena
6. Output Destroyed register Summary A Status A BC Blank check of specified block 1Kbyte _FlashBlockBlankCheck CALL Calculate Blank check block number from block number and bank ExchangeBlockNum Block number is calculated from block number and bank Return A Blank check block number after BZ Fl FBBC PErr it calculates It is error if the bank number is outside the range Block blank check processing PUSH PUSH OV CALL POP PSW Save register bank in STACK AX RB3 Sets to register bank 3 AX HL 3 A Sets entry RAM 3 to Blank check block number after it calculates C FLASH BLOCK BLANKCHECK Sets function number to C register 8100H Calls flash firmware PSW Restores register bank from STACK Get flash firmware error information MOV BR A OFEB3H Sets flash firmware error information to return value OFEE3H B register of Bank 3 FlashBlockBlankCheck00 Parameter error FBBC PErr MOV A FLASHFIRM PARAMETER ERROR Sets parameter error to return FlashBlockBlankCheckO00 value Function name Input Output Destroyed register Summary _FlashGetInfo AX Address of flash information acquisition structure Member of structure Option number Bank Block number BC The first address in buffer where get data is st
7. MOV A OFEE3H Sets flash firmware error information to return value OFEE3H B register of Bank 3 BR FlashBlockErase00 Parameter error FBE PErr MOV A FLASHFIRM PARAMETER ERROR Sets parameter error to return value FlashBlockErase00 MOV Cp MOV B 00H POP HL User s Manual U17516EJ1VOUM 105 APPENDIX A SAMPLE PROGRAM Function name FlashWordWrite Input AX Address of writing beginning address structure Member of structure Writing starting address Bank of writing starting addres H STACK1 Number of writing data STACK2 Address in writing data buffer Output BC Status Destroyed register AX BC DE Summary Data on RAM is written in the flash memory 256 bytes or less Every 4 bytes are written at a time _FlashWordWrite PUSH HL Calculate Writing address from writing address and bank OVW DE AX OVW AX SP OVW HL AX OV A HL 4 Read STACK data Number of writing data OV B A OV A HL 6 Read STACK data Address in writing data buffer XCH A X OV A HL 7 OVW HL AX OVW AX DE BX Jace Address of writing beginning address G structure address GAB cot aud Number of writing data As ads Address in writing data buffer CALL ExchangeAddress Writing address is calculated from structure member s writing address and bank Return AX Writing add
8. 1 FlashGetinfo Ne library EE Arguments No structure member option AR number Br Yes Save to PSW stack Calculate block number from Set to register bank 3 argument structure member s bank and block number y Save to PSW stack Set to register bank 3 y Set block number to entry RAM 0 14 AA Set argument s structure member option number to entry RAM 3 Set argument s data buffer start address to entry RAM 4 and 5 y Set 09H to C register AA CALL 8100H y Register bank recovery through PSW recovered from stack EE No Option number 5 Yes e Write to the data buffer the bank and address value that was calculated from the address value stored in the data buffer Set B register in register bank 3 to C register normal mode or A register static mode in register bank e End e By User s Manual U17516EJ1VOUM 71 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY set information library Outline Changes setting of flash information Format lt C language gt UCHAR FlashSetInfo UCHAR SetInfoData lt Assembly language gt CALL FlashSetInfo Argument lt C language gt Argument Explanation UCHAR SetlnfoData Flash information data lt Assembly language gt Argument Explanation Note
9. Argument lt C language gt Argument Explanation Note 1 struct stWordAddress ptr First address of write start address structure stWordAddress This structure must be 3 bytes in size and at a 4 byte boundary and must be secured by the user UCHAR WordNumber Number of data to be written 1 to 64 USHORT DataBufferAddress First address of write data buffer lt Assembly language gt Argument Explanation Note 1 First address of data having the same structure as the write start address structure in C Refer to APPENDIX A SAMPLE PROGRAM Number of data to be written 1 to 64 Note 2 First address of write data buffer Notes 1 Write start address structure Struct stWordAddress USHORT WriteAddress Write start address UCHAR WriteBANK Bank number of write start address e Remarks 1 Set the write start address as a multiple of 4 bytes 2 Set the bank number to 0 when a product with which no bank number has to be set is used Caution Seta value to each member of this structure before calling this library 2 Set write data to the write data buffer first address indicated by DataBufferAddress before calling this library Caution Set the write start address and the number of data to be written so that they do not straddle over the boundary of each block 76 User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Return val
10. FWEDIS Function Enable write erase Disable write erase FWEPR This flag is used to control flash memory access write erase etc enable disable through hardware It directly reflects the voltage of the FLMDO pin FLMDO Pin Voltage FWEPR Low level Vss Disable write erase High level Von Enable write erase Note The FWEPR bit is a read only bit Its value cannot be changed by software However when using ICE the value can be changed even by overwriting Flash memory access can be enabled through the combination of FWEDIS and FWEPR FWEDIS FWEPR Flash Memory Write Erase Enable 0 1 Enable write erase Other than above Disable write erase Cautions 1 When executing flash memory write erase be sure to set FWEDIS to 0 2 In the normal mode be sure to set FWEDIS to 1 User s Manual U17516EJ1VOUM 81 CHAPTER 6 DETAILS OF SELF PROGRAMMING CONTROL FLSPMO and FLSPM1 These control flags are used to select the self programming operation mode FLSPM1 FLSPMO Mode Selection Normal mode e Access instruction fetch data read to the entire address range of flash memory is possible Self programming mode e Self programming by CALL 8100H is possible e Access instruction fetch data read to flash memory in products with 32 KB or more of ROM 0000H to 7FFFH is possible Caution Setting FLSPM1 FLSPMO 1 0 or 1 1 is prohibited Figure 6 1 shows the self programming
11. FlashEnv Argument lt C language gt Argument Explanation USHORT EntryRAM First address of entry RAM lt Assembly language gt Argument Explanation First address of entry RAM Note For details on entry RAM refer to 2 2 1 Entry RAM Return value None Function This self programming sample library secures and initializes the entry RAM used for self programming As initialize processing this library secures 100 bytes from an address specified by the parameter as a work area where the flash memory writing firmware operates and sets the initial value to the first address 06H to 16H The other areas are cleared to 0 Remark Call this library after calling the self programming start library Also call this library to resume processing of a library executing self programming that was stopped by the occurrence of an interrupt Register status after calling No register is cleared Stack size 30 bytes ROM capacity 11 bytes User s Manual U17516EJ1VOUM 43 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Call example lt C language gt USHORT EntryRAM Declares variable FlashEnv Ei EntryRAM 0 Calls initialize library lt Assembly language gt SELF RAM DSEG AT OFDBCH EntryRAM DS 100 SELF PROG CSEG MOVW AX EntryRAM Sets first address of entry RAM CALL FlashEnv Calls initialize librar
12. are written at a time EEPROMWrite PUSH D ti Calculate Writing address from writing address and bank CALL ExchangeAddress Writing address is calculated from structure member s writing address and bank Return AX Writing address BZ SEW PErr It is error if the bank number is outside the range I EEPROM write processing User s Manual U17516EJ1VOUM 127 APPENDIX A SAMPLE PROGRAM PUSH buffer OV OV buffer POP OV OV OV POP OV OV OV OV CALL POP PSW Save register bank in STACK AX BC HL RB3 Sets to register bank 3 AX HL 5 A Sets entry RAM 5 to higher address in writing data A X HL 4 A Sets entry RAM 4 to lower address in writing data AX HL 3 A Sets entry RAM 3 to Number of writing data A X HL 0 A Sets entry RAM 0 to Writing address lower bytes AX HL 2 A Sets entry RAM 2 to Writing address most higher bytes A X HL 1 A Sets entry RAM 1 to Writing address higher bytes C FLASH EEPROM WRITE Sets function number to C register 8100H Calls flash firmware PSW Restores register bank from STACK Get flash firmware error information MOV value BR A OFEE3H Sets flash firmware error information to return I Parameter error EW PErr MOV I OFEE3H B register o
13. 4 ES MOV A FLASHFIRM PARAMET ER ERROR The parameter error is returned except when option NO is 3 4 and 5 124 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM BR FlashGetInfo50 Get info processing When Option number 3 4 FlashGetInfo30 PUSH PSW Save register bank in STACK PUSH DE PUSH AX SEL RB3 Sets to register bank 3 POP AX FlashGetInfo40 OV HL 3 A Sets entry RAM 3 to Option number POP AX OV HL 5 A 7S ets entry RAM 5 to Storage buffer higher address OV A X OV HL 4 A Sets entry RAM 4 to Storage buffer lower address OV C FLASH_GET_INF Sets function number to C register CALL 8100H Calls flash firmware POP PSW Restores register bank from STACK r r r Calculate Address from Storage buffer and bank Nothing to do when Option number 30r4 or Bank 0 or Block number Previous lt 32 or Block number Previous gt 48 A Option number B Bank C Block number Previous DE Storage buffer first address of get data CMP A 05H Option number 5 BNZ ReturnAddress end 7 NO MOV A B CMP A 0 Bank 0 BZ ReturnAddress end 7 YES XCH A C CMP A 32 Block number Previous lt 32 BC ReturnAddress end 7 YES CMP A 48 Block number Previous gt 48 BNC ReturnAddress end 7 YES MOV A C Calculation of address 40H Bank is pul
14. BC Status AX BC Internal verify of specified block 1Kbyte _FlashBlockVerify PUSH HL Calculate Verify block number from block number and bank OVW BC AX OVW AX SP OVW HL AX OV A HL 4 Read STACK data Verify block number OV B A OV Apg A Verify bank B Verify block number CALL ExchangeBlockNum Block number is calculated from block number and bank Return A Verify block number after it calculates BZ FBV PErr It is error if the bank number is outside the range User s Manual U17516EJ1VOUM 107 APPENDIX A SAMPLE PROGRAM Block verify processing PUSH PSW Save register bank in STACK PUSH AX SEL RB3 Sets to register bank 3 POP AX OV HL 3 A Sets entry RAM 3 to Verify block number after it calculates OV C FLASH_BLOCK_VERIFY Sets function number to C register CALL 8100H Calls flash firmware POP PSW Restores register bank from STACK Get flash firmware error information MOV A OFEE3H Sets flash firmware error information to return value OFEE3H B register of Bank 3 BR FlashBlockVerify00 Parameter error FBV PErr MOV A FLASHFIRM PARAMETER ERROR Sets parameter error to return value FlashBlockVerify00 MOV C A MOV B 00H POP HL RET Function name _FlashBlockBlankCheck Input AX Blank check bank A STACK Blank check block numbe
15. Previous lt 32 Previous gt 48 Bank C Block number Previous DE Storage buffer first address of get data A 05H CMP BNZ CMP BNC MOV Calculation of address ReturnAddress end A B A 0 ReturnAddress end A C A 32 ReturnAddress end A 48 ReturnAddress end A C Lower address is the state as it is r r Option number 5 NO Bank 0 YES Block number Previous lt 32 YES Block number Previous gt 48 YES 40H Bank is pulled from address in two high rank bytes XCHW AX DE MOVW HL AX MOV A HL 1 MOV X A MOV A HL 2 A Most higher address X Higher address XCHW AX DE A Bank D Most higher address User s Manual U17516EJ1VOUM 111 APPENDIX A SAMPLE PROGRAM MOV HL 2 A MOV X 0 ROL A ROL A ROL A ROL A ROL A ROLC A XCH A X ROLC A XCHW AX DE XCH A X SUB A E XCH A X SUBC A D MOV A X MOV HL 1 A ReturnAddress end E Higher address Sets Storage buffer 2 to Bank AX 40H Bank Sets Storage buffer l to Calculated address higher Get flash firmware error information MOV A 0 FlashGetInfo50 MOV C A FE E3H MOV B 00H Sets flash firmware error information to return value OFEE3H B register of Bank 3 Function name Input Ou
16. YES while 1 DI Block blank check library call Status FlashBlockBlankCheck EraseBank EraseBlock EI State of abort NO if Status STATE OF ABORT break Normal completion YES if Status FLASHFIRM NORMAL END Initialization library call FlashEnv USHORT amp EntryRAM break selse break return Status Return value Status EE Function name FlashWordWrite CALL User s Manual U17516EJ1VOUM 95 APPENDIX A SAMPLE PROGRAM 96 Input ptrl Address of writing beginning address structure 8 DataBufferAddress Address in writing data buffer ptr2 Address of writing beginning address structure Member of structure Number of writing data Writing starting address Bank of writing starting address Output Status Return value from firm Summary WordWrite library call processing EE NE Me ME ee ME Wi UCHAR FlashWordWrite Call struct stWordAddress ptrl USHORT DataBufferAddress struct stWordWriteData ptr2 UCHAR Status USHORT i UCHAR p p UCHAR DataBufferAddress Writing data setting to data buffer for i 0 i lt ptr2 gt WordNumber 4 1 itt p ptr2 gt WriteDataBuffer il ptt Writing address and the bank are set to writing beginning address structure 4 ptrl gt WriteAddress ptr2 gt WriteAddressData ptrl gt WriteBank ptr2 gt W
17. the user UCHAR WordNumber Number of data to be written 1 to 64 USHORT DataBufferAddress First address of write data buffer lt Assembly language gt Argument Explanation Note 1 First address of data having structure same as that of write start address structure in C Refer to APPENDIX A SAMPLE PROGRAM Number of data to be written 1 to 64 Note 2 First address of write data buffer Notes 1 Write start address structure struct stWordAddress USHORT WriteAddress Write start address UCHAR WriteBank Bank number of write start address D Remarks 1 Specify the write start address as a multiple of 4 bytes 2 Set the bank number to 0 when a product with which no bank number has to be set is used Caution Before calling this library set a value to each member of this structure 2 Before calling this library set write data to the write data buffer whose first address is indicated by DataBufferAddress Caution Set the write start address and the number of data to be written so that they do not straddle over the boundary of each block User s Manual U17516EJ1VOUM 55 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Return value Status Explanation Normal completion Parameter error Start address not is a multiple of 1 word 4 bytes The number of data to be written is 0 The number of data to be written exceeds 64 words Write end address Sta
18. APPENDIX A SAMPLE PROGRAM POP HL CMPW AX BANK ADDR ERROR Bank error RET END User s Manual U17516EJ1VOUM 131 APPENDIX A SAMPLE PROGRAM A 4 Boot Swap lt boot asm gt PEEL EFF E FEEL FE FEET EE H H EH EE EE EE EE EE E EE EE DEER System Sample program that uses self programming library Bootswap File name boot asm Target CPU 78K0 Kx2 Last updated 2005 04 04 DEE EE EE EE EE EE EE EE EE EE EE EE DEER EXTRN FlashStart EXTRN FlashEnd EXTRN FlashEnv EXTRN FlashBlockErase EXTRN FlashWordWrite EXTRN _FlashGetInfo EXTRN FlashSetInfo EXTRN CheckFLMD EQU settings STATE OF ABORT EQU 1FH State of abort FLASHFIRM NORMAL END EQU OOH Normal completion TRUE EQU OOH Normal FALSE EQU OFFH Abnormal PARAMETER ERROR EQU 05H Parameter error BANKNUMBER EQU 0 Bank number BLOCK EQU 32 Block number i Stores stack DSTACK DSEG AT OFBOOH DS 80H STACK AREA STACKINI Sets interrupt vector table VCTTBL CSEG AT 0000H addr DW MAIN OOH S_RAM1 DSEG AT OFE20H 132 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM FlashEnv ntryRAM DS 100 S RAM2 DSEG AT OFCOOH FlashWordWrite FlashGetInfo DataBuffer DS 128 S RAM3 DSEG FlashWordWrite WordAddr WriteAddress DS 2 WriteBank DS FlashGetInfo GetInfo OptionNu
19. BZ SBLN RTRY CMP A 00H BNZ SERS FALSE END G BR I RS TRUE END BLN RTRY Resume processing MOV A 0 H MOV B 10 i DI i CALL FlashBlockBlankCheck EI H CMP A 1FH i BZ BLN RTRY CMP A 00H G BNZ U ERS_RTRY Clears the internal status MOVW AX EntryRAM p CALL FlashEnv 7 ERS_TRUE_END Normal completion ERS FALSE END Abnormal termination Sets 0 as the bank number of the block to be erased Sets 10 as the block number of the block to be erased Disables interrupts Calls the block erase library Enables interrupts Checks whether a stop status is set If the stop status is set jumps to resume processing BLN RTRY Checks whether execution has been correctly completed Jumps to abnormal termination ERS FALSE END if execution has not been correctly completed Sets 0 as the bank number of the block to be blank checked Sets 10 as the block number of the block to be blank checked Disables interrupts Calls the block blank check library Enables interrupts Checks whether a stop status is set If the stop status is set retries the resume processing Checks whether execution has been correctly completed Retries the main processing if execution has not been correctly completed of the stop processing Sets the first address of
20. Calculate Erase block number from block number and bank CALL ExchangeBlockNum Block number is calculated from block BZ SFBE PErr Block erase processing number and bank Return A Erase block number after it calculates It is error if the bank number is outside the range PUSH PSW Save register bank in STACK PUSH AX SEL RB3 Sets to register bank 3 POP AX OV HL 3 A Sets entry RAM 3 to Erase block number after it calculates OV C FLASH BLOCK ERASE Sets function number to C register CALL 8100H Calls flash firmware POP PSW Restores register bank from STACK Get flash firmware error information MOV A OFEE3H Sets flash firmware error information to return value OFEE3H B register of Bank 3 BR FlashBlockErase00 Parameter error FBE PErr MOV A FLASHFIRM PARAMETER ERROR Sets parameter error to return value FlashBlockErase00 r Function name Input Output Destroyed register Summary _FlashWordWrite AX Address of writing beginning address structure Member of structure Writing starting address Bank of writing starting address B Number of writing data HL Address in writing data buffer A Status AX C Data on RAM is written in the flash memory 256 bytes or less Every 4 bytes are written at a time 120 User s Manual U17516EJ1
21. Save to PSW stack Set to register bank 3 AA Set block number to entry RAM 3 v Set 06H to C register AA CALL 8100H v Register bank recovery through PSW recovered from stack v Set B register in register bank 3 to C register normal mode or A register static mode in register bank e a End 3 Ne User s Manual U17516EJ1VOUM 63 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY self programming end library Outline Declares the end of self programming Format lt C language gt void FlashEnd void lt Assembly language gt CALL FlashEnd Argument None Return value None Function This library declares the end of self programming It completes writing to the flash memory and restores the normal operation mode Remarks 1 Call this library at the end of the self programming operation 2 After execution of this library is completed the level of the FLMDO pin is returned to low Caution The operation is not guaranteed if this library is called with interrupts enabled Before calling this library execute the DI instruction and execute the EI instruction after execution of this library is completed so that acknowledgment of an interrupt is disabled while this library is executed Register status after calling No register is cleared Stack size 0 bytes ROM capacity 12 bytes 64 User s Manual
22. Version 2 00 Target CPU 78K0 Kx2 Last updated 2005 07 08 B W B ASH BLOCK BLANKCHECK G S E HECK FLMD un r ET Jet BV JE EN GER Ji Ea dei BANK BIC BANK ADDR ERROR ELF PROG ASH EEPROM WRIT Fl gt HHT UBLIC FlashStart UBLIC FlashEnd UBLIC FlashEnv UBLIC FlashBlockErase UBLIC FlashWordWrite UBLIC FlashBlockVerify UBLIC FlashBlockBlankCheck UBLIC FlashGetInfo UBLIC FlashSetInfo UBLIC CheckFLMD UBLIC EEPROMWrite PARAMETER ERROR ERROR CSEG Function name Input Output EQU OOH Initialization EQU 03H Block erace EQU 04H Word write EQU 06H Block verify EQU 08H Block blank check EQU 09H Flash memory information read EQU OAH Flash memory information setting EQU OEH Mode check EQU 17H EEPROM write EQU 05H Parameter error EQU OFFH Bank number error BLOCK EQU OFFFFH Bank number error ADDRESS _FlashStart None None 118 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM r Destroyed register Summary N one Self programming start processing FlashStart MOV MOV MOV MOV PFCMD f0A5H FLPMC 0 FLPMC 0 01H FLPMC f0FEH 01H PFCMD register control Function name Input Output Destroyed re
23. When the first store instruction operation after lt 2 gt above writes a value other than the inverted value of the value to be set to the FLPMC register When the first store instruction operation after lt 3 gt above is for a peripheral register other than the FLPMC register When the first store instruction operation after lt 3 gt above writes a value other than the value write value in lt 2 gt to be set to the FLPMC register Remark The numbers shown in angle brackets above correspond to the numbers shown in angle brackets in section 6 1 2 above lt Reset conditions gt 84 When 0 is written to bit 0 FRPRERR in the PFS register When a system reset is performed User s Manual U17516EJ1VOUM CHAPTER 6 DETAILS OF SELF PROGRAMMING CONTROL 6 1 4 Self programming control parameters The self programming operation includes setting the FLMDO pin to 1 setting the required values to the FLPMC register and setting up entry RAM after which the function number refer to Table 6 1 is set to register bank 3 s C register and CALL8100H processing is performed The parameters involved in this operation are described below 1 Register bank 3 s parameters In the self programming sample library register bank 3 s C register is used to select functions to control self programming while its B register is used to store execution results and the HL register is used to specify the start address of entry RAM Since settings to r
24. area entry RAM can be allocated to addresses in the internal high speed RAM within the short direct addressing area only when the start address is FE20H 86 User s Manual U17516EJ1V0UM CHAPTER 6 DETAILS OF SELF PROGRAMMING CONTROL 2 Entry RAM Entry RAM is a 100 byte RAM area that is used for self programming Parameters that control self programming are set six bytes from the start address of the entry RAM area Once these parameters have been set the self programming sample library is called to begin controlling self programming operations The placement of the parameters for various functions relative to the start of the entry RAM area is listed in Table 6 2 below Allocate the Entry RAM to any address in the high speed RAM area except in the short direct addressing area it is possible to allocate the entry RAM to addresses in internal high speed RAM within the short direct addressing area only when the start address is FE20H Entry RAM is used as a work area for self programming Consequently nothing in the entry RAM area except for parameters should be changed during self programming operations Table 6 2 Entry RAM Parameter List Offset Value 04H 05H Function Name Initialize Block erase Block number Word write Start address Start address Start address Number of Data buffer lower bits higher bits MSB words start address Block verify Block number Block blank check Block number
25. data of 1 to 64 words to specified addresses Call the word write library FlashWordWrite to write data of 1 to 64 words to specified addresses Verifying specified block 1 KB internal verification Call the block verify library FlashBlockVerify to verify a specified block 1 KB internal verification lt 10 gt Post processing declaring end of self programming As post processing call the self programming end library FlashEnd to declare the end of self programming lt 11 gt Post processing setting of hardware environment As post processing return the level of the FLMDO pin to the low level User s Manual U17516EJ1VOUM 13 CHAPTER 1 GENERAL 1 3 Bank Number and Block Number Products in the 78K0 Kx2 Series having flash memory of up to 60 KB have their flash memory divided into 1 KB blocks Erasing blank checking and verification internal verification for self programming are performed in these block units To call the self programming sample library a block number is specified Addresses 0000H to OFFFH and 1000H to 1FFFH of the 78K0 Kx2 are allocated for boot clusters A boot cluster is an area that is used to prevent the vector table data and basic functions of the program from being destroyed and to prevent the user program from being unable to start due to a power failure or because the device was reset while an area including a vector area was being rewritten For details on the boot cluster refer to CHAPTER A BOOT SW
26. erased Remark Because only one block is checked at a time call this library as many times as required to check two or more blocks Caution The operation is not guaranteed if this library is called with interrupts enabled Before calling this library execute the DI instruction and execute the EI instruction after execution of this library is completed so that acknowledgment of an interrupt is disabled while this library is executed Register status after calling Memory Model Register Status Normal model Registers cleared AX BC Registers held DE HL Static model Registers cleared A BC Registers held X DE HL Stack size Memory Model Stack Size Normal model 37 bytes Static model 35 bytes ROM capacity Memory Model ROM Capacity Normal model 67 bytes of which 30 bytes are common routine Static model 54 bytes of which 30 bytes are common routine 48 User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Call example lt C language gt UCHAR di Status ei BlankCheckBANK BlankCheckBlock Status UCHAR BlankCheckBANK UCHAR BlankCheckBlock 0 Declares variable Declares variable Declares variable Sets bank number of block to be blank checked to 0 Sets block number of block to be blank checked to 10 Calls block blank check library and stores status informati
27. of the flash memory can be rewritten and consequently the period for software development can be substantially shortened Cautions 1 Because the self programming sample library rewrites the contents of the flash memory by using the CPU registers and RAM of the 78K0 Kx2 a user program cannot be executed while processing of the self programming sample library is being executed 2 The self programming sample library uses the CPU register bank 3 and a work area 100 bytes of entry RAM Therefore the user must save the data necessary for the user program in that area immediately before calling the self programming sample library 1 2 Calling Self Programming Sample Library The self programming sample library can be called by a user program in C or an assembly language If the SM option that uses an object as a static model is specified when a file written in C is complied use link the library for static models If the SM option is not specified link the library for normal models If the file is written in an assembly language use link the library for static models User s Manual U17516EJ1VOUM 11 CHAPTER 1 GENERAL The following flowchart illustrates how to rewrite the contents of the flash memory by using the self programming sample library Figure 1 1 Flow of Self Programming rewriting contents of flash memory Starting self programming lt 1 gt FLMDO pin Low High a T eer ET mem s Tome Normal N
28. operation mode and memory map Figure 6 1 Self Programming Operation Mode and Memory Map uPD78F0545 FFFFH FFOOH FEFFH FFFFH FFOOH FEFFH Internal expansion Internal expansion RAM Access prohibited Flash memory user area Flash memory user area Normal mode Self programming mode Caution Place the program that controls the self programming in the address range of 0000H to 7FFFH 82 User s Manual U17516EJ1VOUM CHAPTER 6 DETAILS OF SELF PROGRAMMING CONTROL 6 1 2 Flash protect command register PFCMD To prevent erroneous flash memory write or erase caused by an inadvertent program loop etc protection is implemented by this register for flash programming mode control register FLPMC write The FLPMC register is a special register that is valid for write operations only when the write operations are performed via following special sequence lt 1 gt Write a specified value A5H to the PFCMD register lt 2 gt Write the value to be set to the FLPMC register writing is invalid at this step lt 3 gt Write the inverted value of the value to be set to the FLPMC register writing is invalid at this step lt 4 gt Write the value to be set to the FLPMC register writing is valid at this step Caution The above sequence must be executed every time the value of the FLPMC register is changed After reset Undefined WwW Symbol 7 6 5 4 3 2 1 0 lt Coding example of
29. self programming Note The boot swap function is to replace boot program area boot cluster 0 Note cluster 1 Before rewrite processing is started a new boot program is written to boot cluster 1 This boot cluster 1 and boot With the boot swap target area boot cluster 0 are swapped and boot cluster 1 is used as a boot program area As a result even if a power failure occurs while the boot program area is rewritten the program is executed correctly because the next reset start program is booted from boot cluster 1 After that boot cluster 0 can be erased or written as necessary Note Boot cluster 0 0000H to OFFFH Original boot program area Boot cluster 1 1000H to 1FFFH Boot swap target area 32 User s Manual U17516EJ1VOUM CHAPTER 4 BOOT SWAP FUNCTION Figure 4 1 shows the flow of boot swapping by using the self programming sample library Figure 4 1 Flow of Boot Swapping Boot swapping starts lt 1 gt Preprocessing lt 2 gt lt 9 gt FlashBlockErase Normal No completion Yes lt 3 gt lt 10 gt FlashWordWrite Normal No completion Yes lt 4 gt lt 11 gt E FlashBlockVerify B Normal No completion Yes lt 5 gt lt 12 gt FlashGetInfo E Normal No completion Yes lt 6 gt lt 13 gt E FlashSetinfo Normal No completion Yes Cluster 1 No lt 8 gt lt 15 gt completed Yes lt 16 gt Post processing Boot swapping ends User s Manual U17516EJ1VOUM 33 CHAPTER A
30. set information library pts 652400 LC 79157 6875 67 fx 652400 67 fx 79157 6875 pts 78884 5625 75 6 527566 875 EC 78884 5625 67 fx 527566 875 Acknowledged EEPROM write library Note 318 321 fx hie 799 875 EE Me 1647 375 fx Operating frequency of external system clock 262 265 fx 799 875 262 265 fx 1647 375 318 321 fx 538 75 318 321 fx 1386 25 262 265 fx 538 75 Remark Values in parentheses are when the write start address structure is placed outside of internal high speed RAM 262 265 fx 1386 25 Acknowledged TWHANAS YALdVHO CHAPTER 2 PROGRAMMING ENVIRONMENT This chapter explains the hardware environment and software environment necessary for the user to rewrite flash memory by using the self programming sample library 2 1 Hardware Environment To execute self programming a circuit that controls the voltage on the FLMDO pin of the 78K0 Kx2 is necessary The voltage on the FLMDO pin must be low while an ordinary user program is being executed in normal operation mode and high while self programming is being executed in flash rewriting mode While the FLMDO pin is low the firmware and software for rewriting run but the circuit for rewriting flash memory does not operate Therefore the flash memory is not actually rewritten A self programming sample library that makes
31. the FLMDO pin high is not provided Therefore to rewrite the flash memory the voltage level of the FLMDO pin must be made high by manipulating a port through user program before calling the self programming start library Here is an example of the circuit that changes the voltage on the FLMDO pin by manipulating a port Figure 2 1 FLMDO Voltage Generator FLMDO 78K0 Kx2 10 kQ recommended Output port Ar 20 User s Manual U17516EJ1VOUM CHAPTER 2 PROGRAMMING ENVIRONMENT 2 2 Software Environment The self programming sample library allocates its program to a user area and consumes about 500 bytes of the program area The self programming sample library itself uses the CPU register bank 3 work area entry RAM stack and data buffer The following table lists the necessary software resources Table 2 1 Software Resources Description Restriction CPU Register bank 3 Work area Entry RAM 100 bytes Internal high speed RAM outside short addressing range or internal high speed RAM in short direct addressing range with first address as FE20H Refer to 2 2 1 Entry RAM 39 bytes max Internal high speed RAM other than FE20H to FE83H Refer to Remark Use the same stack as for the 2 2 2 Stack and data buffer user program Data buffer 1 to 256 bytes Internal high speed RAM other than FE20H to FE83H Refer to Remark The size of this buffer varies 2 2 2 Stack and data buffer depending on the writing unit sp
32. 0 Enables 1 writing Bit 5 Disables 0 Enables 1 boot area rewriting lt 14 gt Occurrence of event Boot cluster 0 is used as a boot program area when an external reset or overflow of the watchdog timer is generated lt 15 gt End of swap processing boot cluster 0 Operations lt 9 gt to lt 14 gt complete the swap processing of boot cluster 0 lt 16 gt Post processing As post processing of boot swapping the following is performed Declaring end of self programming Setting of hardware environment 38 User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY This chapter explains details on the self programming sample library For the source program of each library refer to APPENDIX A SAMPLE PROGRAM 5 1 Type of Self Programming Sample Library The self programming sample library consists of the following libraries Library Name Table 5 1 Call Example C language Self programming sample library List Call Example assembly language Outline self programming start library FlashStart CALL FlashStart Declares start of self programming initialize library FlashEnv CALL amp EntryRAM O FlashEnv Initializes entry RAM mode check library Status CALL CheckF LMD CheckFLMD Checks voltage level block blank check library Status CALL FlashBlockBlankCheck BlankCheckBANK BlankCheckBlock FlashBloc
33. 000H BNC SEA_end Calculation of address Bank 40H is added to address in two high rank bytes Lower address is the state as it is OV D A XCH A X OV C A OV X 0 OV A HL 2 Read data from writing beginning address structure Bank of writing starting address CMP A 6 BNC SEA error end ROL A ROL A ROL A ROL A ROL A ROLC A 116 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM XCH ROLC XCH ADD XCH ADDC BR Bank error EA error end MOVW BR EA end XCH MOV MOV POP CMPW s s s PP PP PP AX A A EA normal end HL AX EA _ EA E r r X UO X FX 0 i i i normal end AX 40H Bank Addition of Higher address Addition of Most higher address A Most higher address after it calculates X higher address after it calculates C Lower address BANK ADDR ERROR normal end X 0 A Most higher address after it calculates eX higher address after it calculates We Lower address BANK ADDR ERROR Bank error User s Manual U17516EJ1VOUM 117 APPENDIX A SAMPLE PROGRAM A 3 Self Programming Library Static Model lt SelfLibrary static asm gt r r r r r DEE EE EE H H EH EE EE EE EE PEEP PEATE EAP EEE TE System Self programming library Static model File name SelfLibrary static asm
34. 4 bytes Vector table 64 bytes 0800H 07FFH 0081H 0080H 007FH 003FH 0000H Blocks 4 to 7 are verified by calling the block verify library FlashBlockVerify Remark The block verify library verifies each block one by one The set status of boot swapping can be read by calling the get information library FlashGetlnfo User s Manual U17516EJ1VOUM 35 CHAPTER A BOOT SWAP FUNCTION lt 6 gt Setting of boot swap bit Set the boot swap bit to execute boot swapping 0 by calling the set information library FlashSetlnfo Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Bit 0 Executes 0 Does not execute 1 boot swapping Bit 1 Disables 0 Enables 1 chip erasure Bit 2 Disables 0 Enables 1 block erasure Bit 3 Disables 0 Enables 1 writing Bit 5 Disables 0 1 R lt 7 gt Occurrence of event Boot cluster 1 is used as a boot program area when an external reset or overflow of the watchdog timer is generated lt 8 gt End of swap processing boot cluster 1 Operations lt 2 gt to lt 7 gt complete the swap processing of boot cluster 1 lt 9 gt Erasing boot cluster 0 Blocks 0 to 3 are erased by calling the block erase library FlashBlockErase Remark The block erase library erases each block one by one 1FFFH CALLF entry 2048 bytes TEED Program area 1081H 1919 bytes Boot program area 1080H Option byte wee CALLT table 64 bytes 1000H Vector table 64 bytes OFFFH B
35. 516EJ1VOUM 121 APPENDIX A SAMPLE PROGRAM POP DE RET Function name _FlashBlockVerify Input A Verify bank B Verify block number Output A Status Destroyed register A BC Summary Internal verify of specified block 1Kbyte FlashBlockVerify Calculate Verify block number from block number and bank CALL ExchangeBlockNum Block number is calculated from block number and bank Return A Verify block number after it calculates BZ FBV PErr It is error if the bank number is outside the range Block verify processing PUSH PSW Save register bank in STACK PUSH AX SEL RB3 Sets to register bank 3 POP AX OV HL 3 A Sets entry RAM 3 to Verify block number after it calculates OV C FLASH BLOCK VERIFY Sets function number to C register CALL 8100H Calls flash firmware POP PSW Restores register bank from STACK Get flash firmware error information MOV A OFEE3H Sets flash firmware error information to return value OFEE3H B register of Bank 3 BR FlashBlockVerify00 Parameter error FBV_PErr MOV A FLASHFIRM PARAMETER ERROR Sets parameter error to return value FlashBlockVerify00 RET Function name S _FlashBlockBlankCheck Input A Blank check bank B Blank check block number 122 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM
36. 6EJ1VOUM APPENDIX A SAMPLE PROGRAM RSTOP 1 LVIM LVIS 0x00 0x00 Prohibits low voltage detection EI FlashStart Self programming start library call processing FlashStart FlashEnv Initialization library call processing FlashEnv USHORT amp EntryRAM CheckFLMD Mode check library call processing Status CheckFLMD Call if Status TRUE while 1 FlashBlockBlankCheck call processing BlankCheckBank BANKNUM BlankCheckBlock BLOCK Block blank check library Status FlashBlockBlankCheck Call BlankCheckBank BlankCheckBlock if Status TRUE break else if Status PARAMETER ERROR break Abnormal end selse FlashBlockErase call processing EraseBank BANKNUM EraseBlock BLOCK Block erase library Status FlashBlockErase Call EraseBank EraseBlock if Status TRUE break Abnormal end if Status TRUE FlashWordWrite call processing for i 0 i lt 255 i 1 User s Manual U17516EJ1VOUM 93 APPENDIX A SAMPLE PROGRAM 94 WordWriteData WriteDataBuffer i UCHAR i WordWriteData WordNumber 64 WordWriteData WriteAddressData ADDR WordWriteData WriteBankData BANKNUM Status FlashWordWrite Call amp WordAddr USHORT amp DataBuffer amp WordWriteData Wor
37. AA Set argument s data buffer start address to entry RAM 4 and 5 AA Set 04H to C register AA CALL 8100H y Register bank recovery through PSW recovered from stack v Set B register in register bank 3 to C register normal mode or A register static mode in register bank y a User s Manual U17516EJ1VOUM 59 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY block verify library Outline Verifies internal verification a specified block 1 KB Caution Verification internal verification is a function to check if data written to the flash memory is written at a sufficient level and is different from verification that compares data Format lt C language gt UCHAR FlashBlockVerify UCHAR VerifyBANK UCHAR VerifyBlock lt Assembly language gt CALL FlashBlockVerify Argument lt C language gt Argument Explanation UCHAR VerifyBANK Bank number of block to be verified UCHAR VerifyBlock Block number to be verified lt Assembly language gt Argument Explanation Bank number of block to be verified Block number to be verified Remark Set the bank number to 0 when a product with which no bank number has to be set is used Return value Status Explanation Normal completion Parameter error Specified bank number or block number is outside the settable range Verify interna
38. AP FUNCTION Figure 1 2 shows the block numbers and boot clusters of a flash memory of up to 60 KB 78K0 Kx2 products having flash memory of more than 96 KB have banks in an area that is larger than 32 KB For these products not only a block number but also a bank number must be specified to call the self programming sample library when performing erasing blank checking or verification internal verification in the area that is larger than 32 KB during self programming Figure 1 3 shows the block numbers and boot clusters of a flash memory of more than 96 KB 14 User s Manual U17516EJ1VOUM CHAPTER 1 GENERAL Figure 1 2 Block Numbers and Boot Clusters flash memory of up to 60 KB F800H Internal expansion RAM FOOOH 8000H Block 52 DOOOH Block 31 7C00H Block 51 CCO0H Block 30 7800H Block 50 C800H Block 29 7400H Block 49 C400H Block 28 7000H Block 48 CO00H Block 27 6C00H Block 47 BCOOH Block 26 6800H Block 46 B800H Block 25 6400H Block 45 B400H Block 24 6000H Block 44 BOOOH Block 23 5C00H Block 43 ACO0H Block 22 5800H Block 42 A800H Block 21 5400H Block 41 A400H Block 20 5000H Block 40 A000H Block 19 4C00H Block 39 9C00H Block 18 4800H Block 38 9800H Block 17 4400H Block 37 9400H Block 16 4000H Block 36 9000H Block 15 3C00H Block 35 8C00H Block 14 3800H 8800H Block 34 Block 13 CALLF entry 3400H Block 33 Block 12 8400H 2048 bytes 3000H Bokn eee Block 11 P
39. BOOT SWAP FUNCTION lt 1 gt lt 2 gt 34 Preprocessing The following preprocessing of boot swapping is performed Setting of hardware environment Declaring start of self programming Setting of software environment Initializing entry RAM Checking voltage leve Erasing boot cluster 1 Blocks 4 to 7 are erased by calling the block erase library FlashBlockErase Remark The block erase library erases each block one by one Boot cluster 1 Boot cluster 0 1FFFH 1000H OFFFH 0800H 07FFH 0081H 0080H 007FH 003FH 0000H Normal operation mode Program area CALLF entry 2048 bytes Program area 1919 bytes Option byte CALLT table 64 bytes Vector table 64 bytes User s Manual 1FFFH 1C00H 1800H 1400H 1000H OFFFH 0800H 07FFH 0081H 0080H 007FH 003FH 0000H U17516EJ1VOUM CALLF entry 2048 bytes Program area 1919 bytes Option byte CALLT table 64 bytes Vector table 64 bytes CHAPTER 4 BOOT SWAP FUNCTION lt 3 gt lt 4 gt lt 5 gt Reading set status of boot swapping Copying boot cluster 0 The contents of 0000H to OFFFH are written to 1000F to 1FFFH by calling the word write library FlashWordWrite Remark The word write library writes data in word units 256 bytes max Verifying boot cluster 1 1FFFH Copies contents of 0000H to OFFFH 1000H OFFFH CALLF entry 2048 bytes 1919 bytes Option byte CALLT table 6
40. EQU 08H FLASH GET INF EQU 098 FLASH SET INF EQU OAH FLASH CHECK FLMD EQU OEH FLASH EEPROM WRITE EQU 17H FLASHFIRM PARAMETER ERROR EQU O5H BANK BLC ERROR EQU OFFH BANK ADDR ERROR EQU OFFFFH SELF PROG CSEG Function name _FlashStart Input None Output None User s Manual U17516EJ1VOUM 103 APPENDIX A SAMPLE PROGRAM Summary MOV MOV MOV MOV Function Input Output Destroyed register FlashStart PFCMD f0A5H Summary MOV MOV MOV Input Output Destroyed register FLPMC 001H FLPMC 0FEH FLPMC 001H PFCMD 0A5H FLPMC 00 FLPMC 00 Function name Summary _FlashEnv PUSH PUSH SEL POP OV CALL OV OV OV POP Input Destroyed register PSW AX RB3 HL C FLASH I 8100H A 09H HL 13H HL 14H PSW Function name OH FLPMC 0FFH OH A A bi Z lt None Self programming start processing PFCMD register control FLPMC register control set value FLPMC register control inverted set valu FLPMC register control set value FlashEnd None None None PFCMD register control FLPMC register control set value FLPMC register control inverted set valu FLPMC register control set value AX Entry RAM address None None Initialization processing of self programming Initialization p
41. FH data to Block4 Block7 OVW OVW OV OV OVW MAIN 04 OV OVW MAIN 05 OV OV INCW INCW DBNZ PUSH DI OV OV OVW OVW CALL Fl H CMP BNZ POP MOVW ADDW MOVW CMPW BC AX 1000H IWriteAddress AX A 0 WriteBank A HL 0000H B 32 4 DE DataBuffer A HL DE A SMAIN_05 mw Oo mo Gl A 32 B A AX WordAddr HL DataBuffer FlashWordWrite A TRUE SMAIN 09 HL AX WriteAddress AX 128 IWriteAddress AX AX 2000H SMAIN 04 Word write library call Normal completion NO User s Manual U17516EJ1VOUM 135 APPENDIX A SAMPLE PROGRAM MOV OptionNumber A MOVW AX GetInfo MOVW BC DataBuffer CALL FlashGetInfo A CMP A TRUE G BNZ SMAIN 09 MOVW HL DataBuffer MOV A HL MOV FlashGetInfoData A MAIN 07 DI MOV A 0FEH CALL FlashSetInfo EI CMP A TRUE p BNZ MAIN 09 MAIN 08 CALL FlashEnd i Normal end BR MAIN LOOP MAIN 09 CALL FlashEnd i Abnormal end MAIN LOOP NOP NOP BR MAIN LOOP AX Address of flash information acquisition structure BC The first address in buffer where get data is stored Get information library call Normal completion NO Get boot flag information Set information library call Normal completion NO FlashEnd Self programming end library call processing FlashEnd Self progra
42. ICING DURING SELF PROGRAMMING The following figure illustrates the flow of processing if an interrupt is generated while processing of the self programming sample library is being executed Figure 3 1 Flow of Processing in Case of Interrupt Self programming starts FLMDO pin Low gt High FlashStart Interrupt occurs Setting of operating environment S n pong ooo 1 Servicing starts Servicing starts W Calling library a Processing is stopped Servicing ends N pe FlashEnd FLMDO pin High gt Low End of self programming User s Manual U17516EJ1VOUM 25 CHAPTER 3 INTERRUPT SERVICING DURING SELF PROGRAMMING The following table shows how the processing of the self programming sample libraries that acknowledge interrupts is resumed after the processing has been stopped by the occurrence of an interrupt Table 3 1 Resume Processing Stopped by Interrupt Library Name Resuming Method block blank check library Call the block blank check library FlashBlockBlankCheck to resume processing to check block erasure that has been stopped by the occurrence of an interrupt block erase library To resume processing to erase blocks that was stopped by the occurrence of an interrupt call the block blank check library FlashBlockBlankCheck and check whether blocks that should be erased have been erased Then call the block erase library FlashBlockErase wor
43. J1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY block blank check library Outline Checks erasing of a specified block 1 KB Format lt C language gt UCHAR FlashBlockBlankCheck UCHAR BlankCheckBANK UCHAR BlankCheckBlock lt Assembly language gt CALL FlashBlockBlankCheck Argument lt C language gt Argument Explanation UCHAR BlankCheckBANK Bank number of block to be blank checked UCHAR BlankCheckBlock Block number of block to be blank checked lt Assembly language gt Argument Explanation Bank number of block to be blank checked Block number of block to be blank checked Remark Set the bank number to 0 when a product with which no bank number has to be set is used Return value Status Explanation Normal completion Specified block is blank erase processing has been completed Parameter error Specified bank number or block number is outside the settable range Blank check error Specified block is not blank erase processing has not been completed Processing is stopped because an interrupt occurs An interrupt occurs while processing of this library is under execution Remark The status is the UCHAR type in C and is stored in the A register in an assembly language User s Manual U17516EJ1VOUM 47 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Function This library checks if a specified block 1 KB has been
44. NEC User s Manual 78K0 Kx2 8 Bit Single Chip Microcontrollers Flash Memory Self Programming uPD78F0500 uPD78F0521 uPD78F0544 uPD78F0501 uPD78F0522 uPD78F0545 uPD78F0502 uPD78F0523 uPD78F0546 uPD78F0503 uPD78F0524 uPD78F0547 uPD78F0503D uPD78F0525 uPD78F0547D uPD78F0511 uPD78F0526 uPD78F0512 uPD78F0527 uPD78F0513 uPD78F0527D uPD78F0513D uPD78F0531 uPD78F0514 uPD78F0532 uPD78F0515 uPD78F0533 uPD78F0515D uPD78F0534 uPD78F0535 uPD78F0536 uPD78F0537 uPD78F0537D Document No U17516EJ1V0UM00 1st edition Date Published August 2005 N CP K NEC Electronics Corporation 2005 Printed in Japan MEMO 2 User s Manual U17516EJ1VOUM NOTES FOR CMOS DEVICES VOLTAGE APPLICATION WAVEFORM AT INPUT PIN Waveform distortion due to input noise or a reflected wave may cause malfunction If the input of the CMOS device stays in the area between Vu MAX and Vik MIN due to noise etc the device may malfunction Take care to prevent chattering noise from entering the device when the input level is fixed and also in the transition period when the input level passes through the area between Vi MAX and Vin MIN HANDLING OF UNUSED INPUT PINS Unconnected CMOS device inputs can be cause of malfunction If an input pin is unconnected it is possible that an internal input level may be generated due to noise etc causing malfunction CMOS devices behave differently than Bipolar or NMOS devices Input levels of CMOS devices mus
45. Normal model Registers cleared AX BC DE Registers held HL Static model Registers cleared AX C Registers held B DE HL Stack size 39 bytes ROM capacity Memory Model ROM Capacity Normal model 117 bytes of which 57 bytes are common routine Static model 100 bytes of which 57 bytes are common routine 56 User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Call example lt C language gt struct stWordAddress WordAddr UCHAR DataBuffer 4 UCHAR WordNumber UCHAR Status DataBuffer 0 0x11 DataBuffer 1 0x22 DataBuffer 2 0x33 DataBuffer 3 0x44 WordNumber 1 WordAddr WriteAddress 0xA000 WordAddr WriteBANK 0 di ei Status FlashWordWrite amp WordAddr Declares variable Declares variable Declares variable Declares variable Sets data to be written Sets data to be written Sets data to be written Sets data to be written Sets number of data to be written Sets OxA000H as write start address Sets bank number of write start address to 0 Disables interrupts Calls word write library and stores status information WordNumber amp DataBuffer Enables interrupts User s Manual U17516EJ1VOUM 57 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY 58 lt Assembly
46. RET Function name _FlashGetInfo Input AX Address of flash information acquisition structure Member of structure Option number Bank i Block number 7 STACK The first address in buffer where get data is stored p OUTPUT BC Status Destroyed register AX BC DE Summary The set up information of the flash memory is read _FlashGetInfo PUSH HL Check of Option number MOVW BC AX MOVW AX SP MOVW HL AX User s Manual U17516EJ1VOUM 109 APPENDIX A SAMPLE PROGRAM MOV XCH MOV XCHW MOVW MOVW MOVW MOV CMP BNZ A HL 4 A HL 5 AX BC HL 0 A 05H SFlashGetInfol0 r Read STACK data The first address in buffer where get data is stored AX Address of flash information acquisition structure BC The first address in buffer where get data is stored Read data from flash information acquisition structure Option number Option number 5 NO Calculate Block number from block number and bank OV OV OV OV CALL BZ XCH X A A HL 2 B A A HL 1 ExchangeBlockNum SFlashGetInfo20 A X Get info processing When Option PUSH PUSH PUSH SEL PSW DE AX RB3 AX A X HL 0 A A X FlashGetInfo40 Check of Option number error FlashGetInfol0 CMP A 03H BZ FlashGetInfo30 CMP A 04H BZ FlashGetInfo30 r Read data from flash information acquisition structure Blo
47. Status DS 1 SELF PROG CSEG OV A 11111101B DI CALL FlashSetInfo OV Status A EI Sets flash information data to disable chip erase Disables interrupts Calls set information library Stores status information Enables interrupts User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Flow Figure 5 10 shows the flow of the set information library Figure 5 10 Flow of Set Information Library E FlashSetInfo A Ke library ww y Store argument s flash information data setting to stack y Save to PSW stack Set to register bank 3 v Set the address of flash information data saved to the stack to entry RAM 4 and 5 with this address as the data buffer s start address AA Set OAH to C register y CALL 8100H v Register bank recovery through PSW recovered from stack v Set B register in register bank 3 to C register normal mode or A register static mode in register bank i End A S User s Manual U17516EJ1VOUM 75 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY EEPROM write library Outline Writes 1 to 64 word data to a specified address during EEPROM emulation Format lt C language gt UCHAR EEPROMWrite struct stWordAddress ptr UCHAR WordNumber USHORT DataBufferAddress lt Assembly language gt CALL EEPROMWrite
48. U17516EJ1V0UM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Call example lt C language gt di Disables interrupts FlashEnd Calls self programming end library eit Enables interrupts lt Assembly language gt DI Disables interrupts CALL FlashEnd Calls self programming end library EI Enables interrupts Flow Figure 5 8 shows the flow of the self programming end library Figure 5 8 Flow of Self Programming End Library FlashEnd library Switch to normal mode e WC User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY get information library Outline Reads flash information Format lt C language gt UCHAR FlashGetInfo struct stGetInfo ptr USHORT DataBufferAddress lt Assembly language gt CALL FlashGetInfo Argument lt C language gt Argument Explanation struct stGetlnfo ptr First address of flash information acquisition structure stGetlnfo Note This structure is 3 bytes in size and must be secured by the user USHORT DataBufferAddress First address of acquired data storage buffer lt Assembly language gt Argument Explanation First address of data having the same structure as flash information acquisition structure in C Refer to APPENDIX A SAMPLE PROGRAM First address of acquired data storage buffe
49. VOUM APPENDIX A SAMPLE PROGRAM _FlashWordWrite PUSH DE Calculate Writing address from writing address and bank CALL ExchangeAddress Writing address is calculated from structure member s writing address and bank Return AX Writing address BZ SEWN PErr It is error if the bank number is outside the range Word write processing PUSH PSW Save register bank in STACK PUSH AX PUSH BC PUSH HL SEL RB3 Sets to register bank 3 POP AX OV HL 5 A Sets entry RAM 5 to higher address in writing data buffer OV A X OV HL 4 A Sets entry RAM 4 to lower address in writing data buffer POP AX OV HL 3 A Sets entry RAM 3 to Number of writing data OV A X OV HL 0 A Sets entry RAM 0 to Writing address lower bytes POP AX OV HL 2 A Sets entry RAM 2 to Writing address most higher bytes OV A X OV HL 1 A Sets entry RAM 1 to Writing address higher bytes OV C FLASH WORD WRITE Sets function number to C register CALL 8100H Calls flash firmware POP PSW Restores register bank from STACK Get flash firmware error information MOV A OFEE3H Sets flash firmware error information to return value OFEE3H B register of Bank 3 BR FlashWordWrite00 Parameter error FNW PErr MOV A FLASHFIRM PARAMETER ERROR Sets parameter error to return value FlashWordWrite00 User s Manual U17
50. Write Address struct stWordAddressf 90 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM USHORT WriteAddress UCHAR WriteBank e struct stWordWriteData UCHAR WordNumber UCHAR WriteDataBuffer 256 USHORT WriteAddressData UCHAR WriteBankData Hi struct stGetInfo UCHAR OptionNumber UCHAR GetInfoBank UCHAR GetInfoBlock Hi struct stGetInfoDataf UCHAR OptionNumberData UCHAR GetInfoBankData UCHAR GetInfoBlockData extern void lashStart void lashEnd void lashEnv USHORT EntryRAM extern UCHAR lashBlockErase UCHAR EraseBank UCHAR EraseBlock extern UCHAR FlashWordWrite struct stWordAddress ptr UCHAR WordNumber USHORT DataBufferAddress HAR FlashBlockVerify UCHAR VerifyBank UCHAR VerifyBlock HAR FlashBlockBlankCheck UCHAR BlankCheckBank UCHAR BlankCheckBlock AR FlashGetInfo struct stGetInfo ptr USHORT DataBufferAddress HAR FlashSetInfo UCHAR SetInfoData HAR CheckFLMD void extern void extern void extern U extern Y extern LU extern LU CH CIE EI CH I extern Y C HAR FlashBlockErase Call UCHAR EraseBank UCHAR EraseBlock HAR FlashWordWrite Call struct stWordAddress ptrl USHORT DataBufferAddress ruct stWordWriteData ptr2 HAR FlashBlockVerify Call UCHAR VerifyBank UCHAR VerifyBlock AR FlashBlockBlankCheck Call UCHAR BlankCheckBank UCHAR BlankCheckBlock
51. a secured for stack OV C FLASH_SET_INF Sets function number to C register CALL 8100H Calls flash firmware POP PSW Restores register bank from STACK POP AX 126 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM Get flash firmware error information MOV A OFEE3H Sets flash firmware error information to return value OFEE3H B register of Bank 3 RET Function name _CheckFLMD v Input None Output A Status Destroyed register A Summary Checks voltage level of FLMD pin _CheckFLMD Set infomation processing PUSH PSW Save register bank in STACK SEL RB3 Sets to register bank 3 MOV C FLASH CHECK FLMD Sets function number to C register CALL 8100H Calls flash firmware POP PSW Restores register bank from STACK Get flash firmware error information MOV A OFEE3H Sets flash firmware error information to return value OF I E3H B register of Bank 3 I Function name EPROMWrite Input AX Address of writing beginning address structure Member of structure Writing starting address e Bank of writing starting address B Number of writing data HL Address in writing data buffer Output A Status Destroyed register AX C Summary Data on RAM is written in the flash memory d 256 bytes or less Every 4 bytes
52. as for the stack pointer Note that data to be written to the flash memory must be appropriately set and processed before the word write library is called The following figure shows the range in which the stack pointer and data buffer can be allocated Figure 2 3 Allocatable Range for Stack Pointer and Data Buffer FFFFH A Special function registers SFRs 256 bytes FF20H FFOOH FEFFH General purpose registers 32 bytes FE83H hibi PERN Use prohibited Internal high speed RAM Range where stack and data buffer can be 1024 bytes allocated except FE20H to FE83H Short direct addressing FBOOH PASON Use prohibited Buffer RAM 32 bytes FAOOH FOFFH Use prohibited F800H F7FFH Internal expansion high speed RAM 1024 bytes Caution The size of the internal expansion high speed RAM varies depending on the product For the size of the internal expansion high speed RAM refer to the user s manual of each product User s Manual U17516EJ1VOUM 23 CHAPTER 3 INTERRUPT SERVICING DURING SELF PROGRAMMING 3 1 Overview An interrupt can be generated even while self programming is executed in some self programming sample libraries of the 78K0 Kx2 However unlike the case for an ordinary interrupt the user must decide whether the processing that has been interrupted should be resumed by checking the return value from the self programming sample library 24 User s Manual U17516EJ1VOUM CHAPTER 3 INTERRUPT SERV
53. ble 1 Bit 5 Prohibit boot area overwrite 0 Enable 1 Mode check Not used EEPROM write 4 to 256 Write data Write data Remark If a function is used with an area marked as not used the area cannot be used as a data buffer 88 User s Manual U17516EJ1VOUM CHAPTER 6 DETAILS OF SELF PROGRAMMING CONTROL Table 6 4 Detailed Flash Information for Get Information Function Flash Information Option Data Buffer s Offset Value Type Value pp 01H 02H 03H 04H vn 06H 07H Security flag 03H Security Boot area s Not used flag final block information number lt Security flag information Details gt Bit 1 Chip erase enable flag 0 Prohibit 1 Enable Bit 2 Block erase enable flag 0 Prohibit 1 Enable Bit 3 Write enable flag 0 Prohibit 1 Enable Bit 4 Boot area overwrite prohibit flag 0 Prohibit 1 Enable Bits 3 5 6 and 7 are always 1 lt Boot area s final block number gt 03H fixed Boot flag 04H Boot flag Not used information lt Boot flag information details gt OOH Boot area is not being switched 01H Boot area is being switched Last address of 05H Block s end address Not used specified block Lower bits Higher bits MSB Remark If a function is used with an area marked as not used the area cannot be used as a data buffer User s Manual U17516EJ1VOUM 89 APPENDIX A SAMPLE PROGRAM T
54. c78K0 exe yC NECTools32 DEV USER MAIN Imf Static model compile method and options for assembler ra78K0 exe cF054780 yC YNECTools32YDEV USER MAIN asm ra78K0 exe cF054780 yC NECTools32 DEV EEPROM asm ra78K0 exe cF054780 yC NECTools32 DEV SelfLibrary static asm Ik78K0 exe yC NECTools32 DEV USER MAIN rel EEPROM rel SelfLibrary static rel 0C78K0 exe yYC YNECTools32YDEV USER MAIN Imf User s Manual U17516EJ1VOUM 137 138 APPENDIX B B Bank number srerrrrrrrrsvnvvnnnnnnnnnsvnvnnnnnnnnnnsvnvnnnenn 14 Block blank check library uunnununuuunuuununuuunuunnuunnnnnnunnn 47 Block erase library t ttre terete eee teen eeeenees 51 Block number ssrrrrrrtrrnnnnvnnnnnnnnnnnnvnnnnnnnnnnnvnvnnnnn 14 Block verify library nunnunuuununununuuununnnuunuunnnuunnunnnunnnnnn n 60 Boot swap function nnnunnnunnnnnunnnnunnnuunnnnunnnuuunnnuunnnuunnn 32 D Data buffer sss00000nrsnennnnnnnnnnnnennnnnnnnnnnnnensnnnnnenne 23 E EEPROM write library seess 76 Entry DAN unenee 22 G Get information library uunuuuunuuunuuunununuuuuunuunnnunnnunnnnn 66 H Hardware environment uunnnnnunnnnnunnnnunnnnnunnnuunnnuunnnnuur 20 l Initialize library strtrtrteteete tees tee tet eee te ete teeter teen tees 43 Interrupt acknowledment TTT 17 Interrupt response time TUTE 27 Interrupt servicing rtrtrtrtrtrterrrrtresesrsenenennsennnenen 24 INDEX M Mode check library vannnnnunnnunnnnnnnnnnnnnnunnnnnnnnnnnnnnnnnnnen 45 O Overvie
55. ck number Read data from flash information acquisition structure Bank A Bank B Block number Block number is calculated from block number and bank Return A Block number after it calculates It is error if the bank number is outside the range A Option number X Block number number 5 Save register bank in STACK Sets to register bank 3 Sets entry RAM 0 to Block number A Option number Option number 3 YES Option number 4 YES 110 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM FlashGetInfo20 MOV A FLASHFIRM PARAMETER ERROR The parameter error is returned except when option NO is 3 4 and 5 BR FlashGetInfo50 Get info processing When Option number 3 4 FlashGetInfo30 PUSH PSW Save register bank in STACK PUSH DE PUSH AX SEL RB3 Sets to register bank 3 POP AX FlashGetInfo40 OV HL 3 A Sets entry RAM 3 to Option number POP AX OV HL 5 A Sets entry RAM 5 to Storage buffer higher address OV A X OV HL 4 A Sets entry RAM 4 to Storage buffer lower address OV C FLASH GET INF Sets function number to C register CALL 8100H Calls flash firmware POP PSW Restores register bank from STACK Calculate Address from Storage buffer and bank Nothing to do when Option number or Block number A Option number B 3or4 or Bank 0 or Block number
56. components host computers power plugs AC supply voltages and so forth e Network requirements In addition trademarks registered trademarks export restrictions and other legal issues may also vary from country to country GLOBAL SUPPORT http www necel com en support support html NEC Electronics America Inc U S NEC Electronics Europe GmbH NEC Electronics Hong Kong Ltd Santa Clara California Duesseldorf Germany Hong Kong Tel 408 588 6000 Tel 0211 65030 Tel 2886 9318 800 366 9782 e Sucursal en Espa a NEC Electronics Hong Kong Ltd Madrid Spain Seoul Branch Tel 091 504 27 87 Seoul Korea Tel 02 558 3737 e Succursale Fran aise V lizy Villacoublay France NEC Electronics Shanghai Ltd Tel 01 30 67 58 00 Shanghai P R China ot Tel 021 5888 5400 e Filiale Italiana Milano Italy Kne NEC Electronics Taiwan Ltd ka Taipei Taiwan e Branch The Netherlands 161 02271972317 Eindhoven The Netherlands Tel 040 2654010 NEC Electronics Singapore Pte Ltd Novena Square Singapore e Tyskland Filial Tel 6253 8311 Taeby Sweden Tel 08 63 87 200 e United Kingdom Branch Milton Keynes UK Tel 01908 691 133 J05 6 User s Manual U17516EJ1VOUM Readers Purpose Organization How to Read This Manual Conventions INTRODUCTION This manual is intended for users who wish to understand the functions of the flash memory versions of the 78K0 Kx2 and design application systems using these m
57. ction This library changes the setting of the flash information It is used to change the set information security flag and boot flag information of the flash memory Cautions 1 A flag that has already disabled processing cannot be changed to enable the processing 2 The operation is not guaranteed if this library is called with interrupts enabled Before calling this library execute the DI instruction and execute the El instruction after execution of this library is completed so that acknowledgment of an interrupt is disabled while this library is executed Register status after calling Memory Model Register Status Normal model Registers cleared A BC Registers held X DE HL Static model Registers cleared A Registers held X BC DE HL Stack size 37 bytes ROM capacity Memory Model ROM Capacity Normal model 27 bytes Static model 23 bytes User s Manual U17516EJ1VOUM 73 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Call example 74 lt C language gt UCHAR Status Declares variable UCHAR SetInfoData Declares variable SetInfoData 0b11111101 Sets flash information data to disable chip erase di Disables interrupts Calls set information library and stores status information Status FlashSetInfo SetInfoData ei Enables interrupts lt Assembly language gt SELF RAM DSEG
58. current as of July 2005 The information is subject to change without notice For actual design in refer to the latest publications of NEC Electronics data sheets or data books etc for the most up to date specifications of NEC Electronics products Not all products and or types are available in every country Please check with an NEC Electronics sales representative for availability and additional information e No part of this document may be copied or reproduced in any form or by any means without the prior written consent of NEC Electronics NEC Electronics assumes no responsibility for any errors that may appear in this document e NEC 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 NEC Electronics products listed in this document or any other liability arising from the use of such products No license express implied or otherwise is granted under any patents copyrights or other intellectual property rights of NEC Electronics or others e Descriptions of circuits software and other related information in this document are provided for illustrative purposes in semiconductor product operation and application examples The incorporation of these circuits software and information in the design of a customer s equipment shall be done under the full responsibility of the customer NEC Electronics assumes no responsibility for any lo
59. d Remark Processing time of set information library at 8 MHz Min 108 milliseconds Max 696 milliseconds If multiple interrupts occur during execution of self programming then the operation is not guaranteed Disable the acknowledging of multiple interrupts during execution of self programming If processing of the self programming sample library that was stopped by the occurrence of an interrupt is not resumed and processing of another block is to be performed then the initialize library must be called before the processing of another block is started Example To not resume erase processing of block 0 that was stopped and to execute erase processing of block 1 call the initialize library and then start the erase processing of block 1 Do not erase the entry RAM stack and data buffer until the series of processing tasks has been completed Allocate an interrupt servicing program in an area other than that of the blocks to be rewritten just as for the self programming program User s Manual U17516EJ1VOUM 31 CHAPTER 4 BOOT SWAP FUNCTION If rewriting of the vector table data the basic functions of the program or the self programming area fails because of a momentary power failure or the occurrence of a reset due to an external cause then the data being rewritten is lost the user program cannot be restarted by a reset and rewriting can no longer be performed This problem can be avoided by using a boot swap function through
60. d write library if Status TRUE FlashBlockVerify call processing VerifyBank BANKNUM VerifyBlock BLOCK Block verify library Status FlashBlockVerify Call VerifyBank VerifyBlock if Status TRUE FlashEnd Self programming end library call processing FlashEnd Normal end selse FlashEnd Self programming end library call processing FlashEnd Abnormal end while 1 NOP NOP Call processing in each library EEE EEE EEE Function name FlashBlockErase CALL Input EraseBank Erase bank EraseBlock Erase block number Output Status Return value from firm When the retry time exceeds 10 times return PARAMETER ERROR from this function Summary FlashBlockErase library call processing ea EE a Se i a i se a es E UCHAR FlashBlockErase Call UCHAR EraseBank UCHAR EraseBlock UCHAR Status UCHAR Counter User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM Counter 0 Retry counter reset while 1 Counter When the retry time exceeds 10 times it ends if Counter gt 10 Status FLASHFIRM ABNORMAL END break DI Erase library call Status FlashBlockErase EraseBank EraseBlock EI if Status STATE OF ABORT State of abort
61. d write library Call the word write library FlashWordWrite to resume data write processing that was stopped by the occurrence of an interrupt block verify library Call the block verify library FlashBlockVerify to resume block verify processing that was stopped by the occurrence of an interrupt set information library Call the set information library FlashSetInfo to resume flash information setting processing that was stopped by the occurrence of an interrupt EEPROM write library Call the EEPROM write library FlashEEPROMWrite to resume processing to write data during EEPROM emulation that was stopped by the occurrence of an interrupt Remark An interrupt is not acknowledged until all of the processing of the above self programming sample libraries has been completed because these libraries execute their processing with interrupts disabled 26 User s Manual U17516EJ1VOUM CHAPTER 3 INTERRUPT SERVICING DURING SELF PROGRAMMING 3 2 Interrupt Response Time Unlike the case for an ordinary interrupt generation of an interrupt during execution of self programming is accomplished via post interrupt servicing in the self programming sample library such as setting 0x1F as the return value from the self programming sample library Consequently the response time is longer than that for an ordinary interrupt When an interrupt occurs during self programming execution both the interrupt response time of the self programming sampl
62. ddress and bank AA Save to PSW stack Set to register bank 3 y Set write start address to entry RAM 0 1 and 2 y Set argument s write data count to entry RAM 3 AA Set argument s data buffer start address to entry RAM 4 and 5 y Set 17H to C register AA CALL 8100H y Register bank recovery through PSW recovered from stack A Set B register in register bank 3 to C register normal mode or A register static mode in register bank 80 User s Manual U17516EJ1VOUM CHAPTER6 DETAILS OF SELF PROGRAMMING CONTROL This chapter describes the registers that are used to control flash memory access and the entry RAM 6 1 Registers That Control Self Programming 6 1 1 Flash programming mode control register FLPMC This register is used to enable disable flash memory access write erase etc and indicate the self programming operation mode A particular sequence must be used when writing to this register in order to prevent inadvertent settings due to noise or manipulation errors For the specific sequence refer to 6 1 2 Flash protect command register PFCMD After reset 08H R W Symbol Note Bit 2 is a read only bit FWEDIS This flag is used to control flash memory access write erase etc enable disable through software The initial value of this flag is 1 and flash memory access is enabled by writing 0 to this flag
63. ddress of flash information acquisition structure Member of structure Option number K Bank Block number Option Number Only O5H Output Status Return value from firm Summary FlashGetInfo library call processing x When block final address information is acquired Tis ie ge ee ged e ea a eS Soe ee SA a T A Se oe E ee pe Wi UCHAR FlashGetInfo Call5 struct stGetInfo ptrl USHORT DataBufferAddress struct stGetInfoData ptr2 UCHAR Status Setting of data of flash information acquisition structure ptrl gt OptionNumber ptr2 gt OptionNumberData ptrl gt GetInfoBank ptr2 gt GetInfoBankData ptrl gt GetInfoBlock ptr2 gt GetInfoBlockData Get information library call User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM Status FlashGetInfo ptrl DataBufferAddress return Status Return value Status SSeS oS Se SSS SS Ee SED SS Se T ee Se Se SS Se EEE Function name FlashSetInfo CALL3 Input SetInfoData Flash information data x ptr Address of flash information acquisition structure For GetInfo KR DataBufferAddress The first address in buffer where get data is stored For GetInfo Output Status Return value from firm Summary FlashSetInfo library call processing x When security flag information is set W a n ks i i tb fe VE fa gh VE ee Et E Sn md ER fk er an kl UCHAR FlashSetInfo Call3 UCHAR SetInfoData st
64. e library as well as the interrupt response time of the device used are necessary Remark For the response time of each device refer to the user s manual of each device Table 3 2 and Table 3 3 show the interrupt response time of the self programming sample library Table 3 2 is a case where the internal high speed oscillator is used to generate the main system clock and Table 3 3 is a case where an external system clock is used as the main system clock Table 3 2 Interrupt Response Time with Internal High Speed Oscillator Interrupt Response Time Unit Microseconds Entry RAM outside short direct addressing Entry RAM inside short direct addressing range range from FE20H Min Max Min Max Library Name block blank check library 391 25 1300 5 81 25 727 5 block erase library 389 25 1393 5 79 25 820 5 word write library 394 75 1289 5 84 75 716 5 block verify library 390 25 1324 5 80 25 751 5 set information library 387 852 5 77 279 5 EEPROM write library 399 75 1395 5 822 5 Remark An interrupt is not acknowledged until all of the processing of the above self programming sample libraries has been completed because these libraries execute their processing with interrupts disabled User s Manual U17516EJ1VOUM 27 CHAPTER 3 INTERRUPT SERVICING DURING SELF PROGRAMMING Table 3 3 Interrupt Response Time with External System Clock Interrupt Response Time Unit Microseconds
65. ecified by the user program Program area Normal model 525 bytes Within 0000H to 7FFFH 32 KB Static model 432 bytes Caution The self programming sample library and the Remark Supplied as an user program that calls the self programming assembly language source sample library must always be located within the above range because the firmware built into the product is allocated to addresses starting from 8000H Cautions 1 The self programming operation is not guaranteed if the user manipulates the above resources Do not manipulate these resources during a self programming operation 2 The user must release the above resources used by the self programming sample library before calling the self programming sample library User s Manual U17516EJ1VOUM 21 CHAPTER 2 PROGRAMMING ENVIRONMENT 2 2 1 Entry RAM The self programming sample library uses a work area of 100 bytes This area is called entry RAM As the entry RAM 100 bytes are automatically allocated starting from the first address that is specified when the initialize library is called Therefore the first address of the entry RAM can be specified in the range from FBOOH to FE20H In addition a data buffer used by the initialize library to actually write data to the flash memory must be allocated to an area that is within the range from 1 to 256 bytes and is other than the work area For details on the data buffer refer to 2 2 2 Stack and data buffer T
66. ed to 0 Sets block number of block to be erased to 10 Disables interrupts Calls block erase library Stores status information Enables interrupts User s Manual U17516EJ1VOUM 53 54 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Flow Figure 5 5 shows the flow of the block erase library Figure 5 5 Flow of Block Erase Library a FlashBlockErase TS SE library J v Calculate block number from argument s bank and block number AA Save to PSW stack Set to register bank 3 v Set block number to entry RAM 3 v Set 03H to C register AA CALL 8100H y Register bank recovery through PSW recovered from stack y Set B register in register bank 3 to C register normal mode or A register static mode in register bank y a B C End User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY word write library Outline Writes 1 to 64 word data to specified addresses Format lt C language gt UCHAR FlashWordWrite struct stWordAddress ptr UCHAR WordNumber USHORT DataBufferAddress lt Assembly language gt CALL FlashWordWrite Argument lt C language gt Argument Explanation Note 1 struct stWordAddress ptr First address of write start address structure stWordAddress This structure must be 3 bytes in size and at a 4 byte boundary and must be secured by
67. egister bank 3 are all performed within a library register bank 3 should be included in user programs User s Manual U17516EJ1VOUM 85 CHAPTER 6 DETAILS OF SELF PROGRAMMING CONTROL Register Function Name Table 6 1 C register Function Number B Register Return Value Register Bank 3 Parameter List HL Register AX DE Register Initialize 00H Normal completion Block erase 03H Normal completion Parameter error Protect error Erase error Stopped Word write Normal completion Parameter error Protect error Write error Stopped Block verify Normal completion Parameter error Verify internal verify error Stopped Block blank check Normal completion Parameter error Blank check error Stopped Get information Normal completion Parameter error Read error Set information Normal completion Parameter error Protect error Erase error Verify internal verify error Write error Stopped Mode check Normal completion Error EEPROM write Normal completion Parameter error Protect error Write error Verify MRG12 error Blank error Stopped Start address of entry RAM Not used used by self programming sample library Note Entry RAM can be allocated to any address in the internal high speed RAM except in the short direct addressing
68. ent and medical equipment not specifically designed for life support Specific Aircraft aerospace equipment submersible repeaters nuclear reactor control systems life support systems and medical equipment for life support etc The quality grade of NEC Electronics products is Standard unless otherwise expressly specified in NEC Electronics data sheets or data books etc If customers wish to use NEC Electronics products in applications not intended by NEC Electronics they must contact an NEC Electronics sales representative in advance to determine NEC Electronics willingness to support a given application Note 1 NEC Electronics as used in this statement means NEC Electronics Corporation and also includes its majority owned subsidiaries 2 NEC Electronics products means any product developed or manufactured by or for NEC Electronics as defined above M8E 02 11 1 User s Manual U17516EJ1VOUM Regional Information Some information contained in this document may vary from country to country Before using any NEC Electronics product in your application please contact the NEC Electronics office in your country to obtain a list of authorized representatives and distributors They will verify e Device availability e Ordering information e Product release schedule e Availability of related technical literature e Development environment specifications for example specifications for third party tools and
69. entry RAM Calls the initialize library Caution It is assumed that the entry RAM has already been set 30 User s Manual U17516EJ1VOUM CHAPTER 3 INTERRUPT SERVICING DURING SELF PROGRAMMING 3 4 Cautions This section explains points to be noted during interrupt servicing If processing related to self programming is performed or a setting related to it is changed during processing of an interrupt that has occurred during execution of self programming then the operation is not guaranteed Do not perform processing related to self programming and change settings related to it during interrupt servicing Do not use register bank 3 during interrupt servicing because self programming uses register bank 3 Save and restore registers used for interrupt servicing during interrupt servicing If the set time of the watchdog timer is too short processing of the set information library may not be completed Therefore do not set a time that is too short to the watchdog timer If an interrupt successively occurs during a specific period while processing of the set information library is being executed an infinite loop may occur if processing of the set information library is resumed after it has been stopped by the interrupt because the processing is started from the beginning Therefore do not allow an interrupt to occur successively at an interval shorter than that within which processing of the set information library is to be complete
70. er is converted into the real address 5 from bank information ExchangeBlockNum It calculates from 32 to 47 block number XCH A B CMP A 32 BC SEBN end CMP A 48 BNC SEBN end Calculation of block number Bank 16 is added to block number XCH MOV CMP BNC ROL ROL ROL ROL ADD XCH XCH XCH s B A HE ms Bank 6 EBN error end s s s s A 16 Bank s s s s gt PP PPP PP oe POP s CO D cO D A Block number after it calculates B Bank C Block number before it calculates r BR EBN end User s Manual U17516EJ1VOUM 115 APPENDIX A SAMPLE PROGRAM Bank error EBN error end MOV A BANK DLC ERROR Return error number EBN end CMP A BANK DLC ERROR Bank error ET Function name ExchangeAddress Input AX Address of writing beginning address structure Member of structure Writing starting address Bank of writing starting address Output AX Writing starting address Address in two high rank bytes R C Writing starting address Lower address Summary Writing starting address of structure is converted p into the real address from bank information ExchangeAddress PUSH HL It calculates from 8000H to BFFFH address OVW HL AX OV A HL 0 Read data from writing beginning address structure Write address OV X A OV A HL 1 CMPW AX 8000H BC SEA_end CMPW AX 40C
71. f Bank 3 EPROMWriteO00 A FLASHFIRM PARAMETER ERROR Sets parameter error to return EPROMWriteO00 value Function name Input Output Summary ExchangeBlockNum A Bank B Block number A Block number New B Bank C Block number Previous Block number is converted into the real address from bank information 128 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM ExchangeBlockNum It calculates from 32 to 47 block number XCH A B CMP A 32 BC SEBN end CMP A 48 BNC SEBN end Calculation of block number Bank 16 is added to block number XCH MOV CMP BNC ROL ROL ROL ROL ADD XCH XCH XCH s B A eC an Bank 6 EBN error end s s s s A 16 Bank s s s s gt PP PP pp pop oO Pp s CO D cO D A Block number after it calculates B Bank C Block number before it calculates BR EBN end Bank error EBN error end MOV A BANK BLC ERROR Return error number EBN end CMP A ABANK DLC ERROR Bank error ET Function name ExchangeAddress av TAPUE AX Address of writing beginning address structure Member of structure Writing starting address Bank of writing starting address Output AX Writing starting address Address in two high rank bytes p C Writing starting address Lower address Su
72. f programming sample library from a user program described in C or an assembly language Caution In this manual the data type name is defined as follows Definition Name Data Type UCHAR unsigned char USHORT unsigned short Argument Indicates the argument of the self programming sample library Return value Indicates the return value from the self programming sample library Function Indicates the function details and points to be noted for the self programming sample library Register status after calling Indicates the status of registers after the self programming sample library is called Stack size Indicates the size of the stack used by the self programming sample library ROM capacity Indicates the ROM capacity necessary for self programming Call example Indicates an example of calling the self programming sample library from a user program described in C or an assembly language Supplement Indicates supplementary information on a self programming sample library other than the above Flow This indicates the program flow of the self programming sample library 40 User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY self programming start library Outline Declares the start of self programming Format lt C language gt void FlashStart void lt Assembly language gt CALL FlashStart Argument None Return value N
73. gister Summary FLPMC register control set value FLPMC register control inverted set valu FLPMC register control set value FlashEnd one one one _FlashEnd MOV MOV MOV PFCMD 0A5H FLPMC 000H FLPMC 0FFH FLPMC 000H PFCMD register control FLPMC register control set value FLPMC register control inverted set valu FLPMC register control set value Function name Input Output Destroyed register Summary N N X Entry RAM address one one Initialization processing of self programming r FlashEnv Initialization processing PUSH PUSH SEL POP OV CALL OV OV OV POP PSW AX RB3 HL C FLASH_ 8100H A 09H HL 13H HL 14H PSW ENV e A A Save Sets Sets Sets register bank in STACK to register bank 3 Entry RAM address to HL register function number to C register Calls flash firmware Set Block Erase Retry Number Set Chip Erase Retry Number Restores register bank from STACK r r Function name Input gt FlashBlockErase Erase bank User s Manual U17516EJ1VOUM 119 APPENDIX A SAMPLE PROGRAM Output Destroyed register Summary B Erase block number A Status A BC Erases of specified block 1Kbyte r r r _FlashBlockErase
74. gs or contents of registers A device is not initialized until the reset signal is received A reset operation must be executed immediately after power on for devices with reset functions POWER ON OFF SEQUENCE In the case of a device that uses different power supplies for the internal operation and external interface as a rule switch on the external power supply after switching on the internal power supply When switching the power supply off as a rule switch off the external power supply and then the internal power supply Use of the reverse power on off sequences may result in the application of an overvoltage to the internal elements of the device causing malfunction and degradation of internal elements due to the passage of an abnormal current The correct power on off sequence must be judged separately for each device and according to related specifications governing the device INPUT OF SIGNAL DURING POWER OFF STATE Do not input signals or an I O pull up power supply while the device is not powered The current injection that results from input of such a signal or I O pull up power supply may cause malfunction and the abnormal current that passes in the device at this time may cause degradation of internal elements Input of signals during the power off state must be judged separately for each device and according to related specifications governing the device User s Manual U17516EJ1VOUM e The information in this document is
75. he range in which the entry RAM can be allocated is shown below Figure 2 2 Allocation Range of Entry RAM rer Special function registers SFRs 256 bytes mem O se FFOOH PEPE Short direct addressing FES3H TI FE2OH EE Xn Internal high speed RAM i 1024 bytes Entry RAM allocation range FBOOH GH Use prohibited Buffer RAM 32 bytes FAOOH FOFFH Use prohibited F800H F7FFH Internal expansion high speed RAM 1024 bytes Caution The size of the internal expansion high speed RAM varies depending on the product For the size of the internal expansion high speed RAM refer to the user s manual of each product 22 User s Manual U17516EJ1VOUM CHAPTER 2 PROGRAMMING ENVIRONMENT 2 2 2 Stack and data buffer The self programming sample library writes data to flash memory by using the CPU Therefore a self programming operation is performed by using the stack specified by the user program The stack must be allocated by stack processing of the self programming operation so that the entry RAM and the RAM used by the user are not cleared Therefore the stack can be allocated in the internal high speed RAM at addresses other than FE20H to FE83H A data buffer is automatically allocated from the first address and by the number of data specified when the word write library is called Therefore the first address of the data buffer can be specified in the internal high speed RAM at an address other than FE20H to FE83H just
76. his appendix shows the sample program provided Caution This sample program must be used at the user s own risk Correct operation is not guaranteed if this sample program is used A 1 User Program lt sample c gt IA EE E EE E EE E EE E EE E EE E EE EE EEE E EE System Sample program that uses self programming sample library File name sample c Target CPU 78K0 Kx2 Last updated 2005 02 25 EE EE EE E EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE kk Ett d EE ke Expanded functions R pose ep ey br ee ER eee PN FE rn NE ng EN es NE sr ee es es pragma sfr pragma DI pragma EI pragma NOP EEE EEE ee deed E S Type declarations WS a Ea GE SE ee a a er nee es SE bena See et typedef unsigned char UCHAR typedef unsigned short USHORT Joe ee ee eS ee ee ee ee ee eS ee Constant definitions et Nan ae cal ts Se lp ae Se et eh wy shea Es ee sh ts Ew tip Hh E Aan a ig ay is Eee cad Gt ey Seah Sa We ev gmt he ie aS Ur pg nd ee Sea Ne x define STATE OF ABORT Ox1F State of abort define FLASHFIRM NORMAL END 0x00 Normal completion define FLASHFIRM ABNORMAL END OxFF Abnormal completion define TRUE 0x00 Normal define FALSE OxFF Abnormal define PARAMETER ERROR 0x05 Parameter error define BANKNUM 5 Bank number define BLOCK 32 Block number define ADDR 0x8000
77. icrocontrollers This manual is intended to give users an understanding of the usage of the flash memory self programming sample library which is used when rewriting the 78K0 Kx2 flash memory This manual can be generally divided into the following sections e Description of flash environment e Description of flash memory self programming sample library It is assumed that the readers of this manual have general knowledge in the fields of electrical engineering logic circuits and microcontrollers To check the hardware functions of the 78K0 Kx2 Refer to the user s manual of each 78k0 Kx2 product Data significance Higher digits on the left and lower digits on the right Active low representation Xxx overscore over pin or signal name Note Footnote for item marked with Note in the text Caution Information requiring particular attention Remark Supplementary information Numerical representation Binary xxxx or xxxxB Decimal xxxx Hexadecimal xxxxH User s Manual U17516EJ1VOUM Terminology The following describes the meanings of certain terms used in this manual Self programming Self programming operations are flash memory write operations that are performed by user programs Flash memory self programming sample library This is the library that is provided by the 78KO Kx2 for flash memory manipulation Flash environment This is the environment that supports flash memory manipulations It has restrictio
78. ion value 03H 871 25 871 375 866 866 125 337 337 125 331 75 331 875 Not acknowledged get information library option value 04H 863 375 863 5 858 125 858 25 329 125 239 25 323 875 324 Not acknowledged get information library option value 05H 1042 75 1043 625 1037 5 1038 375 502 25 503 125 497 497 875 Not acknowledged set information library 105524 75 790809 375 105523 75 790808 375 104978 5 541143 125 104977 5 541142 125 Acknowledged EEPROM write library 1496 5 1496 875 2691 5 2691 875 1489 5 1489 875 2684 5 2684 875 962 25 962 625 2157 25 2157 625 955 25 955 625 Remark Values in parentheses are when the write start address structure is placed outside of internal high speed RAM 2150 25 2150 625 Acknowledged TWHANAS YUALdVHO jenue sasn WNOALPI9 GL IN 6L Library Name self programming start library Table 1 2 Processing Time and Acknowledging Interrupt with external system clock used Processing Time unit microseconds Outside short direct addressing range In short direct addressing range Normal model Static model Normal model Static model Acknowledging Interrupt Not acknowledged initialize library 49x 485 8125 49 fx 224 6875 Not acknowledged mode check libra
79. ister Calls flash firmware Restores register bank from STACK firmware error information A C B OFEE3H A 00H Sets flash firmware error information to return value OFEE3H B register of Bank 3 Function Input Output Destroyed register Summary EEPROMWrite AX Address of writing beginning address structure Member of structure Writing starting address Bank of writing starting address STACK1 Number of writing data STACK2 Address in writing data buffer BC Status AX BC DE Data on RAM is written in the flash memory 256 bytes or less Every 4 bytes are written at a time User s Manual U17516EJ1VOUM 113 APPENDIX A SAMPLE PROGRAM r r EEPROMWrite PUSH HL Calculate Writing address from writing address and bank OVW OVW OVW OV OV OV XCH OV OVW OVW CALL BZ PUSH PUSH OV CALL POP DE X S L AX HL 4 D X D gt PP UP Ep xo Po D x UO D EEPROM write processing r r ExchangeAddress Read STACK data Number of writing data Read STACK data Address in writing data buffer AX Address of writing beginning address structure address B Number of writing data HL Address in writing data buffer Writi
80. kBlankCheck 1 Checks erasing of specified block 1 KB block erase library Status CALL FlashBlockErase FlashBlockErase EraseBANK EraseBlock Erases specified library 1 KB word write library Status CAL FlashWordWrite amp WordAddr amp DataBuffer FlashWordWrite WordNumber Writes 1 to 64 word data to specified address block verify library FlashBlockVerify Status FlashBlockVerfy VerifyBANK VerifyBlock Verifies specified block 1 KB internal verification self programming end library 7 FlashEnd Declares end of self programming get information library FlashGetInfo amp GetInfo amp DataBuffer FlashGetInfo 1 Reads flash information set information library FlashSetInfo SetInfoData FlashSetInfo Changes setting of flash information EEPROM write library FlashEEPROMWrite amp WordAdder WordNumber amp DataBuffer PROMWrite User s Manual U17516EJ1VOUM 1 Writes 1 to 64 word data to specified address during EEPROM emulation 39 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY 5 2 Explanation of Self Programming Sample Library Each self programming sample library is explained in the following format self programming sample library name Outline Outlines the function of the self programming sample library Format Indicates a format to call the sel
81. l verify error An error occurs during processing of this library Processing is stopped by the occurrence of an interrupt An interrupt occurred while processing of this library was under execution Remark The status is the UCHAR type in C and is stored in the A register in an assembly language 60 User s Manual U17516EJ1V0UM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Function This library verifies internal verification a specified block 1 KB Remark Call this library as many times as required to verify two or more blocks because only one block is verified at a time Cautions 1 After writing data verify internal verification the block including the range in which the data has been written If verification is not executed the written data is not guaranteed 2 The operation is not guaranteed if this library is called with interrupts enabled Before calling this library execute the DI instruction and execute the El instruction after execution of this library is completed so that acknowledgment of an interrupt is disabled while this library is executed Register status after calling Memory Model Register Status Normal model Registers cleared AX BC Registers held DE HL Static model Registers cleared A BC Registers held X DE HL Stack size Memory Model Stack Size Normal model 37 bytes Static model 35 bytes ROM capacity Memory Model ROM Capacity N
82. lang uage gt SELF_RAM DataBuffer WordAddr WriteBank Status DS We ELF_PROG OV A OV Dat OV A OV Dat OV A OV Dat OV A OV Dat Di Ei OVW AX OVW Wri OV A OV Wri OVW AX structure OV B 1 OVW HL DI CALL ki OV Sta DSEG DS 4 WriteAddress DS 2 DS 1 I CSEG 11H aBuffer A 22H aBuffer 1 A 33H aBuffer 2 A 44H aBuffer 3 A 0A000H teAddress AX 0 teBANK A WordAddr DataBuffer ashWordWrite tus A Sets data to be written Sets data to be written Sets data to be written Sets data to be written Sets OxAO000H as write start address Sets bank number of write start address to 0 Sets first address of write start address Sets number of data to be written First address of write data buffer Disables interrupts Calls word write library Stores status information Enables interrupts User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Flow Figure 5 6 shows the flow of the word write library Figure 5 6 Flow of Word Write Library FlashWordWrite N library Calculate write address from argument structure member s write address and bank y Save to PSW stack Set to register bank 3 y Set write start address to entry RAM 0 1 and 2 y Set argument s write data count to entry RAM 3
83. lankCheck BlankCheckBank BlankCheckBlock EI if Status STATE OF ABORT State of abort NO break return Status Return value Status User s Manual U17516EJ1VOUM 97 APPENDIX A SAMPLE PROGRAM 98 SSeS SSeS SoS SSeS 2 S S SSS 555 5 SSS See SoS os2 SS 5s 2 e SSS S555 Function name FlashGetInfo CALL Input ptrl Address of flash information acquisition structure DataBufferAddress The first address in buffer where get data is stored ptr2 Address of flash information acquisition structure Member of structure Option number Output Status Return value from firm Summary FlashGetInfo library call processing K When Security flag information or Boot flag information is acquired KE TE EN Nt Wi UCHAR FlashGetInfo Call struct stGetInfo ptrl USHORT DataBufferAddress struct stGetInfoData ptr2 UCHAR Status Setting of option number of flash information acquisition structure ptrl gt OptionNumber ptr2 gt OptionNumberData Get information library call Status FlashGetInfo ptrl DataBufferAddress return Status Return value Status SSeS eS ee ee Se ee ea Se ee eee Se ee Se ee Se Function name FlashGetInfo CALLS Input ptrl Address of flash information acquisition structure DataBufferAddress The first address in buffer where get data is stored ptr2 A
84. led from address in two high rank bytes Lower address is the state as it is XCHW AX Di MOVW HL AX MOV A HL 1 MOV X A Fl MOV A HL 2 A Most higher address X Higher address XCHW AX DE A Bank D Most higher address JE Higher address MOV HL 2 A Sets Storage buffer 2 to Bank MOV X 0 ROL A 1 User s Manual U17516EJ1VOUM 125 APPENDIX A SAMPLE PROGRAM ROL A ROL A ROL A ROL A A A A s s s ROLC XCH ROLC prad AX 40H Bank XCHW AX D XCH A SUB A XCH A A A s x Fl x zal s SUBC MOV 1 A Sets Storage buffert l to Calculated address higher ReturnAddress end Get flash firmware error information MOV A OFEE3H Sets flash firmware error information to return value OFEE3H B register of Bank 3 FlashGetInfo50 Function name _FlashSetInfo Input A Flash information data Output A Status A Destroyed register Summary Setting of flash information _FlashSetInfo Set infomation processing PUSH AX Save Flash information data in STACK PUSH PSW Save register bank in STACK SEL RB3 Sets to register bank 3 OVW AX SP ADDW AX 2 OV HL 5 A Sets entry RAM 5 to higher address of flash information data secured for stack OV A X OV HL 4 A Sets entry RAM 4 to lower address of flash information dat
85. lock 3 erased OCOOH Block 2 erased 0800H Block 1 erased 04000H Block 0 erased 0000H 36 User s Manual U17516EJ1VOUM CHAPTER 4 BOOT SWAP FUNCTION lt 10 gt Writing new program to boot cluster 0 The contents of the new program are written to 0000H to OFFFH by calling the word write library FlashWordWrite Remark The word write library writes the program in word units 256 bytes max 1FFFH CALLF entry 2048 bytes 17FFH Program area 1081H 1919 bytes Boot program area 1080H Option byte ike CALLT table 64 bytes 1000H Vector table 64 bytes OFFFH Block 3 written OCOOH Block 2 written 0800H Block 1 written 04000H Block 0 written 0000H lt 11 gt Verifying boot cluster 0 Blocks 0 to 3 are verified by calling the block verify library FlashBlockVerify Remark The block verify library verifies each block one by one lt 12 gt Reading set status of boot swapping The set status of boot swapping is read by calling the get information library FlashGetInfo User s Manual U17516EJ1VOUM 37 CHAPTER A BOOT SWAP FUNCTION lt 13 gt Setting of boot swap bit Set the boot swap bit to not execute boot swapping 1 by calling the set information library FlashSetInfo Bit7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Bit 0 Executes 0 Does not execute 1 boot swapping Bit 1 Disables 0 Enables 1 chip erasure Bit 2 Disables 0 Enables 1 block eraure Bit 3 Disables
86. m firm Summary FlashSetInfo library call processing x When boot flag information is set Ia E See SS E Se SE Se GS See See SIES Eee Eee ki UCHAR FlashSetInfo Call4 UCHAR SetInfoData struct stGetInfo ptr USHORT DataBufferAddress UCHAR Status UCHAR BootFlag UCHAR p p UCHAR DataBufferAddress while 1 DI while 1 Boot flag information acquisition ptr gt OptionNumber 0x04 Get information library call Status FlashGetInfo ptr DataBufferAddress 100 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM if Status FLASHFIRM NORMAL END The state of a present boot flag is maintained in the variable BootFlag p break Set information library call Status FlashSetInfo SetInfoData EI if Status STATE OF ABORT State of abort YES while 1 ptr gt OptionNumber 0x04 Get information library call Status FlashGetInfo ptr DataBufferAddress Normal completion YES if Status FLASHFIRM NORMAL END break if BootFlag p break selse break return Status Return value Status KE Ke ee Mb OE td TOT ep Ao DE Function name CheckFLMD CALL Input None Output Status Return value from firm Summary CheckFLMD library call processing Ka ere Se a ee te Er oe ki UCHAR CheckFLMD Call void UCHAR Status S
87. mber DS ib FlashGetInfoData DS 1 FlashBlockErase EraseBlock DS 1 M PROG CSEG AT 0400H 7 Sample program MAIN DI SEL RBO Sets to register bank 0 OVW AX STACKINI OVW SP AX Sets stack pointer OV IMS 0CCH OV IXS 00H OV PCC 00H CLR1 MSTOP MOV OSTS 05H MAIN 00 NOP BF OSTC 0 SMAIN 00 CLRI MCMO CLRI1 XSEL MAIN 01 NOP User s Manual U17516EJ1VOUM 133 APPENDIX A SAMPLE PROGRAM BT MCS MAIN 01 CLR1 RSTOP OV LVIM 00H OV LVIS 00H Fl H CALL FlashStart FlashStart Self programming start library call processing MOVW AX EntryRAM CALL FlashEnv Initialization library call CheckFLMD Mode check library call processing CALL CheckFLMD Mode check library call CMP A TRUE Normal completion BZ MAIN 02 e YES BR MAIN 09 MAIN 02 0000H 0FFFH data is copied to 1000H 1FFFH Block4 7 is first erased and 0000H 0FFFH data is written afterwards MOV A 4 MOV IEraseBlock A MAIN 03 Erase Block4 Block7 DI MOV A EraseBlock MOV B A MOV A 0 A Erase bank B Erase block number CALL FlashBlockErase Erase library call EI CMP A TRUE Normal completion BNZ MAIN 09 NO 134 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM MOV INC MOV CMP BC EraseBlock gt p EraseBlock A 8 MAIN 03 D Write 0000H 0FF
88. ment cceccccccccsceccnssceiecccoceedsescecessancvevecenocvevsancuecesencuvessancuedsseucuvesssencwvedveacevees 21 2 21 Entry PRAM solstikk aina keen 22 2 2 2 gt Stackand data buffer cusses taes SA EE 23 CHAPTER 3 INTERRUPT SERVICING DURING SELF PROGRAMMING rrrnvvnnnnvnnnnnvnnnnvnnnnnvnnnnnnnnnnvennn 24 31 e EE 24 3 2 Interrupt Response Time rrnnnnvnnnnnnnvnnnnnnnvnnnnnnnvnnnnnnnvnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnr 27 3 3 Description Example is scocesciceie cssScccesecccetans deeg EES SEELEN 29 3 4 WT EE EN CHAPTER 4 BOOT SWAP FUNCTION rnnrnrannnnvnvnnnnnvnvennnnnennnnnnnerrnnnnnervnnnnnernnnnnnennnnnnnevnnnnnnennnnnnnennnnnnenn 32 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY ernnnnvrnnnvvnnnnvnnnnnnnnnvnnnnnvnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn 39 5 1 Type of Self Programming Sample Library rrrssvnnnnvrnnnvnnnnnvnnnnnnnnnvnnnnnnnnnnnnnnnnnnnnnvnnnnnnnnnnnnnnnn 39 5 2 Explanation of Self Programming Sample Library rrnnvnnnnnvnnnnnnnnnvnnnnnvnnnnnnnnnnvnnnnvnnnnnvnnnnnennnn 40 self pr gramming start library E 41 dE Elle EE 43 MOde CheCK librat yass ssoi astra ea e E a a dhe e a aE susen 45 block blank check library dsrman kst eine sited wees iva EREN E AE A e E 47 block erase library neneng sess ated a agente geet ie ee es Ea ane ie ee edie de 51 WOM Write lee EE 55 block verify library soviet sect A i nie ee ee a de 60 self programming end library EE 64 get information library saaskrgsdanan
89. mmary Writing starting address of structure is converted into the real address from bank information ExchangeAddress PUSH HL It calculates from 8000H to BFFFH address MOVW HL AX MOV A HL 0 Read data from writing beginning address User s Manual U17516EJ1VOUM 129 APPENDIX A SAMPLE PROGRAM MOV xX A MOV A HL 1 CMPW AX 8000H BC SEA end CMPW AX 0C000H BNC SEA end Calculation of address Bank 40H Lower address is the state as it OV D A XCH A X OV C A OV X 0 OV A HL 2 P structure 6 error end s BNC ROL ROL ROL ROL ROL ROI XCH ROI XCH ADD XCH AD ZZ ZZ o D s Ka E Q s s s s E Q gt PP PPP PSPS ppm DP s UO Q x D x O BR EA normal end Bank error EA error end MOVW AX BANK ADDR ERROR BR EA normal end EA end XCH A X MOV Go AE MOV A 0 EA normal end structure Write address is added to address in two high rank bytes Je Read data from writing beginning address Bank of writing starting address AX 40H Bank Addition of Higher address Addition of Most higher address A Most higher address after it calculates X higher address after it calculates C Lower address A Most higher address after it calculates X 3 higher address after it calculates C Lower address 130 User s Manual U17516EJ1VOUM
90. mming end library call processing User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM A 5 Compiling the Flash Self Programming Sample Library and Sample Program Use the static model sample library and compile options only when using a static model Otherwise use the normal model lt 1 gt lt 3 gt lt 4 gt Normal model compile method and options for C ra78K0 exe cF054780 yC YNECTools32YDEV SelfLibrary normal asm cc78k0 exe cF054780 yC YNECTools32YDEV EEPROMCtrl c cc78k0 exe cF054780 yC YNECTools32YDEV Main c Ik78K0 exe yC NECTools32 DEV oMain Imf C NECTools32 LIB78KO sOl rel bclO lib s Main rel SelfLibrary_normal rel EEPROMCtrl rel oc78K0 exe yC NECTools32 DEV Main Imf Static model compile method and options for C ra78K0 exe cF054780 yC NECTools32 DEV SelfLibrary_static asm cc78k0 exe sm0 cF054780 yC NECTools32 DEV EEPROMCtrl c cc78k0 exe sm0 cF054780 yC NECTools32 DEV Main c Ik78K0 exe yC YNECTools32YDEV oMain Imf C YNECTools32YLIB78K0Ys0sml rel bcl0sm lib s Main rel SelfLibrary static rel EEPROMCtrl rel 0c78K0 exe yC NECTools32 DEV Main Imf Normal model compile method and options for assembler ra78K0 exe cF054780 yC YNECTools32YDEV USER MAIN asm ra78K0 exe cF054780 yC YNECTools32YDEV EEPROM asm ra78K0 exe cF054780 yC YNECTools32YDEV SelfLibrary normal asm Ik78K0 exe yYC YNECTools32YDEV USER MAIN rel EEPROM rel SelfLibrary normal rel 0
91. n and execute the EI instruction after execution of this library is completed so that acknowledgment of an interrupt is disabled while this library is executed Register status after calling Memory Model Register Status Normal model Registers cleared AX BC Registers held DE HL Static model Registers cleared A BC Registers held X DE HL Stack size Memory Model Stack Size Normal model 39 bytes Static model 37 bytes ROM capacity Memory Model ROM Capacity Normal model 67 bytes of which 30 bytes are common routine Static model 54 bytes of which 30 bytes are common routine 52 User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Call example lt C language gt UCHAR Status Declares variable UCHAR EraseBANK Declares variable UCHAR EraseBlock Declares variable EraseBANK 0 Sets bank number of block to be erased to 0 EraseBlock 10 Sets block number of block to be erased to 10 dO Disables interrupts Calls block erase library and stores status information Status FlashBlockErase EraseBANK EraseBlock ei Enables interrupts lt Assembly language gt SELF RAM DSEG Status DS I SELF PROG CSEG OV A 0 OV B 10 DI CALL FlashBlockErase OV Status A EI Sets bank number of block to be eras
92. ng address is calculated from structure member s writing address and bank Return AX Writing address It is error if the bank number is outside the range PSW Save register bank in STACK AX BC HL RB3 Sets to register bank 3 AX HL 5 A Sets entry RAM 5 to higher address in writing data buffer A X HL 4 A Sets entry RAM 4 to lower address in writing data buffer AX HL 3 A Sets entry RAM 3 to Number of writing data A X HL 0 A Sets entry RAM 0 to Writing address lower bytes AX HL 2 A Sets entry RAM 2 to Writing address most higher bytes A X HL 1 A Sets entry RAM 1 to Writing address higher bytes C FLASH EEPROM WRITE Sets function number to C register 8100H Calls flash firmware PSW Restores register bank from STACK Get flash firmware error information MOV A OFEE3H r Sets flash firmware error information to return value 114 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM OFEE3H B register of Bank 3 EPROMWriteO00 T BR Parameter error EW PErr MOV A FLASHFIRM_PARAMETER_ERROR Sets parameter error to return value EEPROMWrite00 MOV C A MOV B 00H POP HL RET Function name ExchangeBlockNum Input A Bank S B Block number Output A Block number New B Bank C Block number Previous Summary Block numb
93. ns that differ from those applied to ordinary program execution Block number Block numbers indicate blocks in flash memory They are used as units during manipulations such as erasures and blank checks Boot cluster This is the area that is used for boot swapping Boot cluster 0 and boot cluster 1 are provided and the cluster to be booted can be selected Entry RAM This is the area in RAM that is used by the flash memory self programming sample library The user program reserves this area and specifies the start address of the specific area to be used when the library is called Internal verification After writing to flash memory signal levels are checked internally to confirm correct reading of data When an internal verification error occurs the corresponding device is judged as faulty User s Manual U17516EJ1VOUM 7 CONTENTS CHAPTER 1 GENERAL enge 11 141 e TT 11 1 2 Calling Self Programming Sample Library rnnernnnvvnnnnvennnnvnnnnnnnnnvnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnner 11 1 3 Bank Number and Block Number annrnnnnnnnnnnnnnvnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnne 14 1 4 Processing Time and Acknowledging Interrupt rrnannnvnnnnnnnvnnnnnnnvnnnnnnnvnnnnnnnvnnnnnnnnennnnnnennnnnnnr 17 CHAPTER 2 PROGRAMMING ENVIRONMENT rnnnnrveennnnvvovennnnvnvennnnrnnennnnnevennnnnnrennnnnnrennnnnnnennnnnnnennnner 20 2 1 Hardware Environment a ie ae dee ege Edge eegenen 20 2 2 Software Ermiron
94. nterrupt is generated while processing of the self programming sample library is under execution and a function to perform post processing if an interrupt has been generated For details on interrupts refer to CHAPTER 3 INTERRUPT SERVICING DURING SELF PROGRAMMING User s Manual U17516EJ1VOUM 17 8L Library Name self programming start library Table 1 1 Processing Time and Acknowledging Interrupt with internal high speed oscillator Processing Time unit microseconds Outside short direct addressing range In short direct addressing range Normal model Static model Normal model Static model Acknowledging Interrupt Not acknowledged initialize library Not acknowledged mode check library 753 875 753 125 219 625 218 875 Not acknowledged block blank check library 12770 875 12765 875 12236 625 12231 625 Acknowledged block erase library 36909 5 356318 36904 5 356296 25 36363 25 355771 75 36358 25 355750 Acknowledged word write library 1214 1214 375 2409 2409 375 1207 1207 375 2402 2402 375 679 75 680 125 1874 75 1875 125 672 75 673 125 1867 75 1868 125 Acknowledged WNOALrI9LGSZLIN Menuen sasn block verify library 25618 875 25613 875 25072 625 25067 625 Acknowledged self programming end library Not acknowledged get information library opt
95. nterrupts lt Assembly language gt SELF RAM DSEG DataBuffer DS 3 GetInfo OptionNumber DS 1 GetInfoBank DS I GetInfoBlock DS I Status DS I SELF PROG CSEG OV A 5 OV OptionNumber A Specifies option value to get last address of OV A 0 specified block OV GetInfoBank A Sets bank number of block whose flash OV A 10 information is to be acquired to 0 OV GetIngoBlock A Sets block number of block whose flash information is to be acquired to 10 OVW AX GetiInfo OVW BC DataBuffer DI Disables interrupts CALL FlashGetInfo Calls get information library OV Status A Stores status information Fl H s Enables interrupts 68 User s Manual U17516EJ1V0UM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Supplement The flash information that can be acquired differs depending on the option value specified by the flash information acquisition structure The information corresponding to each option value is shown below Option Value Information Acquired Security flag information 2 bytes Boot flag information 1 byte Last address of specified block 3 bytes Each piece of information is detailed below 1 Security flag information option value 03H The setting status of the security flag is stored as data of 2 bytes in the data buffer from its beginning Offset Contents Note Security flag info
96. o completion Yes lt 6 gt E FlashBlockBlankCheck Yes E FlashBlockErase Ch Normal completion No lt 8 gt B FlashWordWrite H Normal completion Yes lt 9 gt w FlashBlockVerify Wi Normal completion Yes lt 10 gt FlashEnd E lt 11 gt FLMDO pin High gt Low End of self programming 12 User s Manual U17516EJ1VOUM CHAPTER 1 GENERAL lt 1 gt lt 2 gt lt 3 gt lt 4 gt lt 5 gt lt 6 gt lt gt lt 8 gt lt 9 gt Preprocessing setting of hardware environment As preprocessing make the FLMDO pin high refer to 2 1 Hardware Environment Preprocessing declaring start of self programming As preprocessing call the self programming start library FlashStart to declare the start of self programming Preprocessing setting of software environment As preprocessing save register bank 3 and specify a work area refer to 2 2 Software Environment Preprocessing initializing entry RAM As preprocessing call the initialize library FlashEnv to initialize the entry RAM Preprocessing checking voltage level As preprocessing call the mode check library CheckFLMD and check the voltage level Checking erasing of specified block 1 KB Call the block blank check library FlashBlockBlankCheck to check if the specified block 1 KB has been erased Erasing specified block 1 KB Call the block erase library FlashBlockErase to erase a specified block 1 KB Writing
97. ode and Memory Map uPD78F0545 rnnnnrnnanvnnnvrnnnnvnnnvrrrnvrnennnnenn 82 Write te ee RE 83 User s Manual U17516EJ1VOUM Table 1 1 Table 1 2 Table 2 1 Table 3 1 Table 3 2 Table 3 3 Table 5 1 Table 6 1 Table 6 2 Table 6 3 Table 6 4 10 LIST OF TABLES Processing Time and Acknowledging Interrupt with internal high speed oscllator 18 Processing Time and Acknowledging Interrupt with external system clock used AA 19 Software Resources uuunmndunebnenGengi and eee eee eet edie af omens eka eege 8 21 Resume Processing Stopped by Interrupt ceccceesceceneeeeneeeeneeseaeeeeaeeseaeeeaeeeseeesaeeseeeeeeeeeeeeeeaees 26 Interrupt Response Time with Internal High Speed Oscillator ronvrronvnnnnrnnnnvnnnnrnnnnrnnnvrnnnnnnennnn 27 Interrupt Response Time with External System Clock A 28 Self programming sample library Ulet ee kteettettttktstnnetntttnntintttttenatnnstnastnnenneteneen 39 Register Bank S Parameter Lists rgere dees geg evnene etn niet 86 Entry RAM Parameter List c c0cei ee ei eis ee ind 87 Data Buffer Parameter Det iss cecil ein geed as nla ied esi ape evi 88 Detailed Flash Information for Get Information Function 89 User s Manual U17516EJ1VOUM CHAPTER 1 GENERAL 1 1 Overview The self programming sample library is firmware provided on the 78K0 Kx2 and is software which is used to rewrite data in the flash memory By calling the self programming sample library from a user program the contents
98. on Disables interrupts FlashBlockBlankCheck BlankCheckBANK BlankCheckBlock Enables interrupts lt Assembly language gt SELF RAM DSEG Status DS 1 SELF PROG CSEG OV A 0 Sets bank number of block to be blank checked to 0 OV B 10 Sets block number of block to be blank checked to 10 Calls block blank check library DI Disables interrupts CALL FlashBlockBlankCheck OV Status A Stores status information EI Enables interrupts User s Manual U17516EJ1VOUM 49 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Flow Figure 5 4 shows the flow of the block blank check library Figure 5 4 Flow of Block Blank Check Library FlashBlockBlankCheck C library A Calculate block number from argument s bank and block number y Save to PSW stack Set to register bank 3 v Set block number to entry RAM 3 y Set 08H to C register hd CALL 8100H y Register bank recovery through PSW recovered from stack AA Set B register in register bank 3 to C register normal mode or A register static mode in register bank i e SE 50 User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY block erase library Outline Erases a specified block 1 KB Format lt C language gt UCHAR FlashBlockErase UCHAR EraseBANK UCHAR EraseBlock
99. one Function This self programming sample library declares the start of self programming Therefore call this library first as a self programming operation Caution The operation is not guaranteed if this library is called with interrupts enabled Before calling this library execute the DI instruction and execute the EI instruction after execution of this library is completed so that acknowledgment of an interrupt is disabled while this library is executed Register status after calling No register is cleared Stack size 0 bytes ROM capacity 12 bytes Call example lt C language gt di Disables interrupts FlashStart Calls self programming start library ei Enables interrupts lt Assembly language gt DI Disables interrupts CALL FlashStart Calls self programming start library EI Enables interrupts User s Manual U17516EJ1VOUM 41 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Flow Figure 5 1 shows the flow of the self programming start library Figure 5 1 Flow of Self Programming Start Library FlashStart library Switch to self programming mode e SE 42 User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY initialize library Outline Initializes entry RAM Format lt C language gt void FlashEnv USHORT EntryRAM lt Assembly language gt CALL
100. ored A Status AX BC HL The set up information of the flash memory is read User s Manual U17516EJ1VOUM 123 APPENDIX A SAMPLE PROGRAM _FlashGetInfo CALL BZ XCH A FlashGetInfol0 CMP A BZ CMP A BZ FlashGetInfo20 PUSH D MOVW HI MOVW A MOVW D MOV A CMP A BNZ Calculate Block number from PUSH P PUSH DI PUSH A SEL R POP A XCH A OV OV A BR F Fl Check of Option number E AX HL 0 05H FlashGetInfol0 OV X A OV A HL 2 structure Block number OV B A OV A HL 1 structure Bank ExchangeBlockNum FlashGetInfo20 X SW X B3 X rX HL 0 A X lashGetInfo40 Check of Option number error 03H FlashGetInfo30 04H FlashGetInfo30 r Get info processing When Option r Read data from flash information acquisition structure Option number Option number 5 NO block number and bank Read data from flash information acquisition Read data from flash information acquisition A Bank B Block number Block number is calculated from block number and bank Return A Block number after it calculates It is error if the bank number is outside the range A Option number X Block number number 5 Save register bank in STACK Sets to register bank 3 Sets entry RAM 0 to Block number A Option number ption number 3 ES E ption number
101. ormal model 67 bytes of which 30 bytes are common routine Static model 54 bytes of which 30 bytes are common routine User s Manual U17516EJ1VOUM 61 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Call example lt C language gt 62 UCHAR Status UCHAR VerifyBANK UCHAR VerifyBlock VerifyBANK 0 VerifyBlock 10 fe ZS Declares variable Declares variable Declares variable Sets bank number of block to be verified to 0 Sets block number of block to be verified to 10 Disables interrupts Calls block verify library and stores status information tatus FlashBlockVerify VerifyBANK VerifyBlock di S ei Enables interrupts lt Assembly language gt SELF RAM DSEG Status DS 1 SELF_PROG CSEG OV A 0 OV B 10 DI CALL FlashBlockVerify OV Status A EI Sets bank number of block to be verified to 0 Sets block number of block to be verified to 10 Disables interrupts Calls block verify library Stores status information Enables interrupts User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Flow Figure 5 7 shows the flow of the block verify library Figure 5 7 Flow of Block Verify Library FlashBlockVerify E library s v Calculate block number from argument s bank and block number v
102. r Note 66 Flash information acquisition structure Struct stGetInfo UCHAR OptionNumber Option value UCHAR GetInfoBank Bank number valid if option value is 05H Note 4 UCHAR GetInfoBlock Block number valid if option value is 05H e Note Refer to Supplement Remark Set the bank number to 0 when a product with which no bank number has to be set is used Cautions 1 Setting of a bank number and a block number is invalid when security flag information and boot flag information are checked 2 Before calling this library set a value to each member of this structure User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Return value Status Explanation Normal completion Parameter error Specified option value is outside the settable range Read error Security flag is read twice and different data are read when the option value is set to 03H Remark The status is the UCHAR type in C and is stored in the A register in an assembly language Caution Flash information corresponding to a specified option value is stored in the data buffer For details on the flash information refer to Supplement Function This library reads flash information It is used to check the set information security flag boot flag information and last address of a specified block of the flash memory Caution The operation is not guaranteed if this lib
103. r Output BC Status Destroyed register AX BC Summary Blank check of specified block 1Kbyte _FlashBlockBlankCheck PUSH HL Calculate Blank check block number from block number and bank OVW BC AX OVW AX SP OVW HL AX OV A HL 4 Read STACK data Blank check block number OV B A OV A C A Blank check bank B Blank check block number CALL ExchangeBlockNum Block number is calculated from block number and bank 108 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM Return A Blank check block number after it calculates p BZ FBBC PErr It is error if the bank number is outside the range Block blank check processing PUSH PSW Save register bank in STACK PUSH AX SEL RB3 Sets to register bank 3 POP AX OV HL 3 A Sets entry RAM 3 to Blank check block number after it calculates OV C FLASH BLOCK BLANKCHECK Sets function number to C register CALL 8100H Calls flash firmware POP PSW Restores register bank from STACK Get flash firmware error information MOV A OFEE3H Sets flash firmware error information to return value OFEE3H B register of Bank 3 BR FlashBlockBlankCheck00 Parameter error FBBC PErr MOV A FLASHFIRM PARAMETER ERROR Sets parameter error to return value FlashBlockBlankCheckO00 MOV C A MOV B 00H POP HL
104. rary is called with interrupts enabled Before calling this library execute the DI instruction and execute the EI instruction after execution of this library is completed so that acknowledgment of an interrupt is disabled while this library is executed Register status after calling Memory Model Register Status Normal model Registers cleared AX BC DE Registers held HL Static model Registers cleared AX BC HL Registers held DE Stack size 38 bytes ROM capacity Memory Model ROM Capacity Normal model 161 bytes of which 30 bytes are common routine Static model 148 bytes of which 30 bytes are common routine User s Manual U17516EJ1VOUM 67 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Call example lt C language gt Struct stGetInfo GetInfo Declares variable UCHAR DataBuffer 3 Declares variable UCHAR Status Declares variable GetInfo OptionNumber 5 Specifies option value to get last address of specified block GetInfo GetInfoBank 0 Sets bank number of block whose flash information is to be acquired to 0 GetInfo GetInfoBlock 10 Sets block number of block whose flash information is to be acquired to 10 di Disables interrupts Calls get information library and stores status information Status FlashGetInfo amp GetInfo amp DataBuffer ei Enables i
105. ress BZ SFWW_PErr It is error if the bank number is outside the range Word write processing PUSH PSW Save register bank in STACK PUSH AX PUSH BC PUSH HL SEL RB3 Sets to register bank 3 POP AX OV HL 5 A Sets entry RAM 5 to higher address in writing data buffer OV A X OV HL 4 A Sets entry RAM 4 to lower address in writing data buffer POP AX OV HL 3 A Sets entry RAM 3 to Number of writing data OV A X OV HL 0 A Sets entry RAM 0 to Writing address lower bytes 106 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM POP OV OV OV OV CALL POP AX HL 2 A Sets entry RAM 2 to Writing address most higher bytes A X HL 1 A Sets entry RAM 1 to Writing address higher bytes C FLASH WORD WRITE Sets function number to C register 8100H Calls flash firmware PSW Restores register bank from STACK Get flash firmware error information MOV BR A OFEE3H Sets flash firmware error information to return value OFEE3H B register of Bank 3 FlashWordWrite00 Parameter error A FLASHFIRM PARAMETER ERROR Sets parameter error to FNW PErr MOV FlashWordWrite00 MOV C A MOV B 00H POP HL RET return value Function name Input Output Destroyed register Summary _FlashBlockVerify AX Verify bank STACK Verify block number
106. rite amp WordAddr WordNumber amp DataBuffer ei Enables interrupts 78 User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY lt Assembly language gt SELF RAM DSEG DataBuffer DS 4 WordAddr WriteAddress DS 2 WriteBank DS 1 Status DS 1 SELF PROG CSEG OV A 11H OV DataBuffer A OV A 22H OV DataBuffertl A OV A 33H OV DataBuffert 2 A OV A 44H OV DataBuffer 3 A OVW AX 0A000H OV A 0 OV IWriteBANK A OVW AX WordAddr OV B 4 OVW HL DataBuffer DI CALL EEPROMWrite OV Status A Di H OVW IWriteAddress AX Sets data to be written Sets data to be written Sets data to be written Sets data to be written Sets AOOOH to write address Sets bank number of write start address to 0 Sets address of write start address structure Sets number of data to be written Sets first address of write data buffer Disables interrupts Calls EEPROM write library Stores status information Enables interrupts User s Manual U17516EJ1VOUM 79 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Flow Figure 5 11 shows the flow of the EEPROM write library Figure 5 11 Flow of EEPROM Write Library i EEPROMWrite Za library SR Calculate write address from argument structure member s write a
107. riteBankData while 1 DI Word write library call Status FlashWordWrite ptrl ptr2 gt WordNumber DataBufferAddress EI if Status STATE OF ABORT State of abort NO break return Status Return value Status FEE ee a ee eech EE ee Function name FlashBlockVerify CALL Input VerifyBank Verify bank x VerifyBlock Verify block number Jz User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM Output Status Return value from firm Summary FlashBlockVerify library call processing Rae ae eS ea ae ae gd ae EV SE ee ER bg a ere oe oe a eR Wi UCHAR FlashBlockVerify Call UCHAR VerifyBank UCHAR VerifyBlock UCHAR Status while 1 DI Block verify library call Status FlashBlockVerify VerifyBank VerifyBlock EI if Status STATE OF ABORT State of abort NO break return Status Return value Status Rara Bat St sen raske eS ee te Soe SSA ek eet eee Function name FlashBlockBlankCheck CALL Input i BlankCheckBank Blank check bank A BlankCheckBlock Blank check block number Output Status Return value from firm Summary FlashBlockBlankCheck library call processing Pe aes a ee ee ee a EE Sa ee ee a ee Wi UCHAR FlashBlockBlankCheck Call UCHAR BlankCheckBank UCHAR BlankCheckBlock UCHAR Status while 1 DI Block blank check library call Status FlashBlockB
108. rmation Last block number of boot area fixed to 03H Note Details on security flag information Security Flag Contents Chip erase enable flag 0 Disabled 1 Enabled Block erase enable flag 0 Disabled 1 Enabled Write enable flag 0 Disabled 1 Enabled Boot area rewrite disable flag 0 Disabled 1 Enabled Other than above Always 1 User s Manual U17516EJ1VOUM 69 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY 2 Boot flag information option value 04H The boot flag information setting status of boot swapping is stored in the data buffer as data of 1 byte Contents Note Boot flag information Note Details on boot flag information Offset Contents Boot areas are not swapped Reset and started from address 0000H Boot areas are swapped Reset and started from address 1000H 3 Last address of specified block option value 05H The last address of the specified block is stored in the data buffer from its beginning as data of 3 bytes Offset Contents Block last address Low Block last address High Bank number Example Where the last address for block of block number 00H is 0003FFH 00H 01H 02H 03H 04H 05H 06H 07H 08H 09H User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY Figure 5 9 shows the flow of the get information library Figure 5 9 Flow of Get Information Library
109. rocessing Save register bank in STACK Sets to register bank 3 Sets Entry RAM address to HL register Sets function number to C register Calls flash firmware Set Block Erase Retry Number Set Chip Erase Retry Number Restores register bank from STACK _FlashBlockErase AX Erase bank 104 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM STACK Erase block number Output BC Status Destroyed register AX BC Summary Erases of specified block 1Kbyte _FlashBlockErase PUSH HL Calculate Erase block number from block number and bank OVW BC AX OVW AX SP OVW HL AX OV A HL 4 Read STACK data Erase block number OV B A OV A C A Erase bank B Erase block number Block number is calculated from block number and bank Return A Erase block number after it calculates CALL ExchangeBlockNum BZ FBE PErr It is error if the bank number is outside the range Block erase processing PUSH PSW Save register bank in STACK PUSH AX SEL RB3 Sets to register bank 3 POP AX OV HL 3 A Sets entry RAM 3 to Erase block number after it calculates OV C FLASH BLOCK ERASE Sets function number to C register CALL 8100H Calls flash firmware POP PSW Restores register bank from STACK Get flash firmware error information
110. rogram area 2C00H g Area subject to boot 1919 bytes swappin 2800H Block 10 p y pping 2400H Block 9 S Option byte 2000H Block 8 1C00H Block 7 vane Block 6 Bare OFA CALLE entry and Block 5 72 0800H 2048 bytes 1000H Block 4 pa SOREN Program area debe Block 3 dosi 1919 bytes 0800H Block 2 ee 0400H Block 1 0000H Block 0 PR Vector table 64 bytes User s Manual U17516EJ1VOUM 15 CHAPTER 1 GENERAL Figure 1 3 Block Numbers and Boot Clusters flash memory of 96 KB or more F800H Internal expansion RAM E000H DFFFH 8000H sen 2C00H Bank 0 Program area p Area subject to boot 2800H p 1919 bytes swapping SE b Use prohibited D CALLF entry I yueg 2000H Block 8 1C00H Block 7 anne Block 6 eege Or GALLF entry ET Block 5 72 0800H 2048 bytes 1000H Block 4 e GEN Program area OCOOH Block 3 0081H 1919 bytes 0800H POE Boot cluster 0 0080H oo Block 1 oe ae oar 16 User s Manual U17516EJ1VOUM CHAPTER 1 GENERAL 1 4 Processing Time and Acknowledging Interrupt Table 1 1 and Table 1 2 show the processing time of the self programming sample library and whether interrupts can be acknowledged Table 1 1 shows a case where an internal high speed oscillator is used for the main system clock and Table 1 2 shows a case where an external system clock is used for the main system clock The self programming sample library that can acknowledge interrupts has a function to check if an i
111. rt address Number of data to be written x 4 bytes exceeds the flash memory area Protect error Specified range includes the boot area and rewriting the boot area is disabled Write error Data is verified but does not match after execution of the processing of this library Processing is stopped by the occurrence of an interrupt An interrupt occurred while processing of this library was under execution Remark The status is the UCHAR type in C and is stored in the A register in an assembly language Function This library writes the specified number of data from a specified address Set a RAM area containing the data to be written as a data buffer and call this library Data of up to 256 bytes can be written in 4 byte units at one time Remark Call this library as many times as required to write data of more than 256 bytes Cautions 1 After writing data execute verification internal verification of the block including the range in which the data has been written If verification is not executed the written data is not guaranteed 2 The operation is not guaranteed if this library is called with interrupts enabled Before calling this library execute the DI instruction and execute the El instruction after execution of this library is completed so that acknowledgment of an interrupt is disabled while this library is executed Register status after calling Memory Model Register Status
112. ruct stGetInfo ptr USHORT DataBufferAddress UCHAR Status UCHAR SecurityFlag UCHAR ep p UCHAR DataBufferAddress while 1 DI while 1 ptr gt OptionNumber 0x03 Security flag information acquisition Get information library call Status FlashGetInfo ptr DataBufferAddress if Status FLASHFIRM NORMAL END The state of a present security flag is maintained in the variable SecurityFlag p break Set information library call Status FlashSetInfo SetInfoData EI if Status STATE OF ABORT State of abort YES while 1 ptr gt OptionNumber 0x03 User s Manual U17516EJ1VOUM 99 APPENDIX A SAMPLE PROGRAM Get information library call Status FlashGetInfo ptr DataBufferAddress Normal completion YES if Status FLASHFIRM NORMAL END break Flash information rewriting completion YES if SecurityFlag p break selse break return Status Return value Status Sao See eae Se ee eee Ee ee ee ge e Ee ee eS Sie Se Se ee eS Se ee eee E Function name FlashSetInfo CALL4 Input SetInfoData Flash information data ptr Address of flash information acquisition structure For GetInfo EN DataBufferAddress The first address in buffer where get data is stored For GetInfo Output Status Return value fro
113. ruction and execute the EI instruction after execution of this library is completed so that acknowledgment of an interrupt is disabled while this library is executed Register status after calling Memory Model Register Status Normal model Registers cleared AX BC DE Registers held HL Static model Registers cleared AX C Registers held B DE HL Stack size 36 bytes User s Manual U17516EJ1VOUM 77 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY ROM capacity Memory Model ROM Capacity Normal model 117 bytes of which 57 bytes are common routine Static model 100 bytes of which 57 bytes are common routine Call example lt C language gt Struct stWordAddress WordAddr Declares variable UCHAR DataBuffer 4 Declares variable UCHAR WordNumber Declares variable UCHAR Status Declares variable DataBuffer 0 0x11 Sets data to be written DataBuffer 1 0x22 Sets data to be written DataBuffer 2 0x33 Sets data to be written DataBuffer 3 0x44 Sets data to be written WordNumber 1 Sets number of data to be written WordAddr WriteAddress 0xA000 Sets O0xA000 to write start address WordAddr WriteBANK 0 Sets bank number of write start address to 0 di Disables interrupts Calls EEPROM write library and stores status information Status EEPROMW
114. ry 35 fx 374 75 29 fx 374 75 35 fx 113 625 29 fx 113 625 Not acknowledged block blank check library 174 fx 6382 0625 134 fx 6382 0625 174 fx 6120 9375 134 fx 6120 9375 Acknowledged block erase library leng 174 fx0 31093 875 298948 125 134 60 Et Hie 31093 875 298948 125 174 00 30820 75 174 fx 298675 Et Ces 30820 75 134 fx 298675 Acknowledged word write library 318 321 fx 318 321 fx 644 125 1491 625 262 265 fx 262 265 fx 644 125 1491 625 318 321 fx 383 318 321 fx 1230 5 262 265 fx 383 262 265 fx 1230 5 Acknowledged block verify library 174 fx 13448 5625 134 fx 13448 5625 174 fx 13175 4375 134 fx 13175 4375 Acknowledged self programming end library 34h Not acknowledged get information library option value 03H 171 172 fx 432 4375 129 130 fx 432 4375 171 172 fx 171 3125 129 130 fx 171 3125 Not acknowledged get information library option value 04H 181 182 6x 427 875 139 140 fx 427 875 181 182 fx 166 75 139 140 fx 166 75 Not acknowledged get information library option value 05H 404 411 fx 496 125 362 369 fx 496 125 404 411 fx 231 875 362 369 fx 231 875 Not acknowledged
115. seken stk peneben beger i R 66 Set information IDrary EEN 72 EEPROM write library adr ear 76 CHAPTER 6 DETAILS OF SELF PROGRAMMING CONTROL rannnnnnnvnnnnnnnnnvnnnnnvnnnnnnnnnnnnnnnnnnnnnnnnnnnvnnnn 81 6 1 Registers That Control Self Programming rrrnvrnnnvnnnnnnnnnnvnnnnnvnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnvennnnnnnnnnnnnnn 81 6 1 1 Flash programming mode control register FL DM 81 6 1 2 Flash protect command register PECH 83 6 13 Fl sh statusr gister PFS uante ee kinnet dead 84 6 1 4 Self programming control parameters esseeseesseeetetttkttttettttttttttnttttttntttntttattnattnstnntnntenntnnatnnenan en 85 APPENDIX A SAMPLE PROGRAM nnnnvovennnnvvvennnnvevennnnvvvennnnvvnennnnvenennnnvenennnnvenennnnvenennnvnnennnnnenennnnvenenennn 90 At User tele E 90 A 2 Self Programming Library Normal Model rrannrnnnvvnnnnnvnnnnnnnnnvvnnnnvnnnnnnnnnnnnnnnvnnnnnnnnnnnnnnnnenn 103 A 3 Self Programming Library Static Model rrrnnnnnvnnnnvrnnnnvnnnnnvnnnvvnnnnvnnnnnnnnnnnnnnnvnnnnnnnnnnnnnnnnenr 118 A 4 BOOU SWap x badstue 132 A 5 Compiling the Flash Self Programming Sample Library and Sample Program 137 APPENDIX B INDEX ominnredet dee tee le eed een dele eh cet eee ein pen 138 8 User s Manual U17516EJ1VOUM Figure 1 1 Figure 1 2 Figure 1 3 Figure 2 1 Figure 2 2 Figure 2 3 Figure 3 1 Figure 4 1 Figure 5 1 Figure 5 2 Figure 5 3 Figure 5 4 Figure 5 5 Figure 5 6 Figure 5 7 Figure 5 8 Figure 5 9 Figure 5 10 Fig
116. special sequence gt When writing 05H to FLPMC register MOV PFCMD 0A5H Writes A5H to PFCMD MOV FLPMC 05H Writes 05H to FLPMC MOV FLPMC 0FAH Writes OFAH inverted value of 05H to FLPMC MOV FLPMC 05H Writes 05H to FLPMC Figure 6 2 Write Protection lt 3 gt FLPMC inverted value of xx lt 1 gt PFCMD A5H Protection circuit Writing to the FLPMC register is performed after the four conditions are cleared FLPMC register User s Manual U17516EJ1VOUM 83 CHAPTER 6 DETAILS OF SELF PROGRAMMING CONTROL 6 1 3 Flash status register PFS If the flash programming mode control register FLPMC is not written in the correct sequence the FLPMC register is not set and a protection error occurs At this time bit 0 FPRERR of the PFS register is set to 1 This flag is a cumulative flag After reset OOH R W Symbol Z 6 5 4 3 2 1 0 ps f o o o o Frere The FPRERR flag s operation conditions are as follows lt Setting conditions gt When the PFCMD register is written to at a time when the store instruction s operation for the latest peripheral register was not a write operation to the PFCMD register using a specified value A5H When the first store instruction operation after lt 1 gt above is for a peripheral register other than the FLPMC register When the first store instruction operation after lt 2 gt above is for a peripheral register other than the FLPMC register
117. sses incurred by customers or third parties arising from the use of these circuits software and information e While NEC Electronics endeavors to enhance the quality reliability and safety of NEC Electronics products customers agree and acknowledge that the possibility of defects thereof cannot be eliminated entirely To minimize risks of damage to property or injury including death to persons arising from defects in NEC Electronics products customers must incorporate sufficient safety measures in their design such as redundancy fire containment and anti failure features e NEC Electronics products are classified into the following three quality grades Standard Special and Specific The Specific quality grade applies only to NEC Electronics products developed based on a customer designated quality assurance program for a specific application The recommended applications of an NEC Electronics product depend on its quality grade as indicated below Customers must check the quality grade of each NEC Electronics product before using it in a particular application 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 Special Transportation equipment automobiles trains ships etc traffic control systems anti disaster systems anti crime systems safety equipm
118. t be fixed high or low by using pull up or pull down circuitry Each unused pin should be connected to Von or GND via a resistor if there is a possibility that it will be an output pin All handling related to unused pins must be judged separately for each device and according to related specifications governing the device PRECAUTION AGAINST ESD A strong electric field when exposed to a MOS device can cause destruction of the gate oxide and ultimately degrade the device operation Steps must be taken to stop generation of static electricity as much as possible and quickly dissipate it when it has occurred Environmental control must be adequate When it is dry a humidifier should be used It is recommended to avoid using insulators that easily build up static electricity Semiconductor devices must be stored and transported in an anti static container static shielding bag or conductive material All test and measurement tools including work benches and floors should be grounded The operator should be grounded using a wrist strap Semiconductor devices must not be touched with bare hands Similar precautions need to be taken for PW boards with mounted semiconductor devices STATUS BEFORE INITIALIZATION Power on does not necessarily define the initial status of a MOS device Immediately after the power source is turned ON devices with reset functions have not yet been initialized Hence power on does not guarantee output pin levels I O settin
119. tatus CheckFLMD Mode check library call User s Manual U17516EJ1VOUM 101 APPENDIX A SAMPLE PROGRAM return Status Return value Status 102 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM A 2 Self Programming Library Normal Model lt SelfLibrary_normal asm gt DEE EE EE EE EE EE EE EE EE EET EET EHP EH programming library Normal model PEEL FEEL FHP EE EE EE EE EE EE EE EE E EE EE DEER Initialization z E Word zJ BA nj LOCK Block asn LOCK zs Ki Lasn erace write verify blank check memory information read memory information setting Mode check T R EPROM write Parameter error Bank number error BLOCK Bank number error ADDRESS System Self File name SelfLibrary normal asm Version 2 00 Target CPU 78K0 Kx2 Last updated 2005 07 08 PUBLIC FlashStart PUBLIC FlashEnd PUBLIC FlashEnv PUBLIC FlashBlockErase PUBLIC FlashWordWrite PUBLIC FlashBlockVerify PUBLIC FlashBlockBlankCheck PUBLIC FlashGetInfo PUBLIC FlashSetInfo PUBLIC CheckFLMD PUBLIC EEPROMWrite EQU settings FLASH ENV EQU OOH FLASH BLOCK ERASE EQU 03H FLASH WORD WRITE EQU 04H FLASH BLOCK VERIFY EQU 06H FLASH BLOCK BLANKCHECK
120. ting the flash memory cannot be performed To manipulate the flash memory by self programming it is necessary to call this library and confirm that the FLMDO pin is at high level Register status after calling Memory Model Register Status Normal model Registers cleared A BC Registers held X DE HL Static model Registers cleared A Registers held X BC DE HL Stack size 28 bytes User s Manual U17516EJ1VOUM 45 CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY ROM capacity Memory Model ROM Capacity Normal model 14 bytes Static model 11 bytes Call example lt C language gt UCHAR Status Declares variable Status CheckFLMD Calls mode check library and stores status information lt Assembly language gt SELF RAM DSEG Status DS 1 SELF PROG CSEG CALL CheckFLMD Calls mode check library MOV Status A Stores status information Flow Figure 5 3 shows the flow of the mode check library Figure 5 3 Flow of Mode Check Library CheckFLMD E library v Save to PSW stack Set to register bank 3 y Set OEH to C register AA CALL 8100H y Register bank recovery through PSW recovered from stack y Set B register in register bank 3 to C register normal mode or A register static mode in register bank y WC 46 User s Manual U17516E
121. tput Destroyed register Summary _FlashSetInfo AX Flash information data BC Status A BC Setting of flash information _FlashSetInfo Set infomation processing OV A X PUSH AX PUSH PSW SEL RB3 OVW AX SP ADDW AX 2 OV HL 5 A Save Flash information data in STACK Save register bank in STACK Sets to register bank 3 Sets entry RAM 5 to higher address of flash information data secured for stack 112 User s Manual U17516EJ1VOUM APPENDIX A SAMPLE PROGRAM OV OV OV CALL POP POP A HL C EN X 4 A Sets entry RAM 4 to lower address of flash information data secured for stack FLASH_SET_INF Sets function number to C register OOH PSW AX Calls flash firmware Restores register bank from STACK Get flash firmware error information MOV MOV A C r OFEE3H 00H Sets flash firmware error information to return value OFEE3H B register of Bank 3 Function Input Output Destroyed register Summary _CheckFLMD None BC Status A BC Checks voltage level of FLMD pin _CheckFLMD Set infomation processing PSW PUSH SEL MOV CALL POP Get flash MOV MOV MOV RB3 C ER FLASH_CH 00H PSW Save register bank in STACK Sets to register bank 3 ECK FLMD Sets function number to C reg
122. ue Status Explanation Normal completion Parameter error Start address is not a multiple of 1 word 4 bytes The number of data to be written is 0 The number of data to be written exceeds 64 words Write end address Start address Number of data to be written x 4 bytes exceeds the flash memory area Protect error Aboot area is included in the specified range and rewriting of the boot area is disabled Write error Data cannot be written correctly Verify MRG12 error Data is verified but does not match after it has been written Blank error Area equal to the number of data to be written was not a vacant area Processing is stopped by the occurrence of an interrupt An interrupt occurred while processing of this library was under execution Remark The status is the UCHAR type in C and is stored in the A register in an assembly language Function This library writes the specified number of data to the flash memory starting from a specified address during EEPROM emulation Set a RAM area storing the data to be written as a data buffer and call this library Data of up to 256 bytes can be written in 4 byte units at one time Remark Call this library as many times as required to write data of more than 256 bytes Caution The operation is not guaranteed if this library is called with interrupts enabled Before calling this library execute the DI inst
123. ure 5 11 Figure 6 1 Figure 6 2 LIST OF FIGURES Flow of Self Programming rewriting contents of flash memorg 12 Block Numbers and Boot Clusters flash memory of up to 60 KB rrsnrnnnnrnnenvnnenrnrnnvnnnnrnnsnrnnenrnnnn 15 Block Numbers and Boot Clusters flash memory of 96 KB or more 16 FLMDO Voltage Generator gege deed divalent 20 Allocation Range of Entry HAM 22 Allocatable Range for Stack Pointer and Data Buffer sseesseeseesseeseeeieesiestrestnninetnnetnttnnntnnstnnseneenne 23 Flow of Processing in Case of Interupt 25 Flow Of Boot SWappin EE 33 Flow of Self Programming Start Library 42 Flow of Initialize Library sus etter ce fe ae et Bip nevi on ein ad ee ae ee iT 44 Flow ofiMode Check Library EEEE ETA 46 Flow of Block Blank Check Library 50 Flow of Block Erase Library Liusssiu ass punken endt Anita alte 54 Flow of Word Write Library eerste Ga i int ahd ee 59 Flow of Block Verity Libraryiv X duaohudsiarandsuketet ddmd etui a a a 63 Flow of Self Programming End Library srreonrnnnrrnnnnrnnnnrnnnnrnnnnrnnnnrnnnvenervansnvnnervrnsnnnnesnrnsnrnnssvrnsnvnnennn 65 Flow of Get Information Library 24 2 imsnkserpaniitsineiprvieenasadvna dende eea sted om in NEEN enes EEKi a pe 71 Flow of Set Information Library adansesen askeladd age keiser 75 Flow of EEPROM Write Library eonrnnonrnnnnrnnnnrnnnnrnnnnrnnnnrnnsnrnnnnrnnsnrnnnvenervnnsnnnnesvnnsnnnnesnrnsnenesnrnsnnnnenen 80 Self Programming Operation M
124. w mannnuuuunnunnnnnnnnnununnnnnnnnnnnnnnnnnunnnnnnnunnnunnnunnner 11 P Processing TIME ace CeCe eee 17 S Self programming end library sree 64 Self programming start library eessen 41 Set information library TTT 72 Software environment terete 21 Stack munnnununnnnnnnnnnnununnnnnnnnnnnnnnnnnunnnnnnnnnnnnnununnnnnnnnnnnnn 23 W Word write library DT 55 User s Manual U17516EJ1VOUM
125. y Caution Allocate the entry RAM at any address of the internal high speed RAM outside of the short direct addressing range To allocate it in the internal high speed RAM in the short direct addressing range the first address is set to FE20H Flow Figure 5 2 shows the flow of the initialize library Figure 5 2 Flow of Initialize Library FlashEnv i library y Save to PSW stack Set to register bank 3 y Set entry RAM parameter to HL register y Set 00H to C register y CALL 8100H y Register bank recovery through PSW recovered from stack v Ca 44 User s Manual U17516EJ1VOUM CHAPTER 5 SELF PROGRAMMING SAMPLE LIBRARY mode check library Outline Checks the voltage level Format lt C language gt UCHAR CheckFLMD void lt Assembly language gt CALL CheckFLMD Argument None Return value Status Explanation Normal completion FLMDO pin is at high level Abnormal termination FLMDO pin is at low level Remark The status is the UCHAR type in C and is stored in the A register in an assembly language Function This library checks the voltage level high or low of the FLMDO pin Remark Call this library after calling the self programming start library to check the voltage level of the FLMDO pin Caution If the FLMDO pin is at low level operations such as erasing and wri
Download Pdf Manuals
Related Search
Related Contents
Samsung DV665JW/XSA User Manual Warranty and Policy Manual GT 220 - GT 2200 TOP dep GREAT FRA TED 08 05 09 Manual de Instrução Copyright © All rights reserved.
Failed to retrieve file