AN2398 Freescale Semiconductor / Motorola, AN2398 Datasheet

no-image

AN2398

Manufacturer Part Number
AN2398
Description
In-Circuit Programming of FLASH Memory via the Universal Serial Bus for the MC68HC908JB8
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Application Note
AN2398/D
Rev. 0, 1/2003
In-Circuit Programming of
FLASH Memory via the
Universal Serial Bus for the
MC68HC908JB8
By Derek Lau
INTRODUCTION
Applications Engineering
Microcontroller Division
Hong Kong
This application note describes a method of in-circuit programming of FLASH
memory via the Universal Serial Bus for the MC68HC908JB8.
For detailed specification on MC68HC908JB8 device, please refer to the data
sheet; Motorola order number: MC68HC908JB8/D.
The Motorola MC68HC908JB8 (hereafter referred as JB8) is a member of the
HC08 Family of microcontrollers (MCUs). The features of the JB8 include a
Universal Serial Bus (USB) interface, which makes this MCU suited for
personal computer Human Interface Devices (HID), such as mice and
keyboards.
On the JB8, 8k-bytes of FLASH memory is allocated for the user code, with an
additional 16-bytes for user defined reset and interrupt vectors. A high voltage
supply is not required by the JB8 for FLASH program or erase operations; as it
is generated by an internal charge-pump.
In-circuit programming (ICP) is a process by which the device is programmed
or erased with the device on the final circuit board — the target system. This
allows the user code to be changed without having to remove the device off the
target system for reprogramming; simplifying user code changes during
product development, last minute changes during production, and code
upgrades after the product is sold.
The following sections in this application note describes a method of
implementing ICP using the USB as the communication link between host (PC)
and HID.
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
© Motorola, Inc., 2003

Related parts for AN2398

AN2398 Summary of contents

Page 1

... Freescale Semiconductor, Inc. Application Note AN2398/D Rev. 0, 1/2003 In-Circuit Programming of FLASH Memory via the Universal Serial Bus for the MC68HC908JB8 By Derek Lau Applications Engineering Microcontroller Division Hong Kong This application note describes a method of in-circuit programming of FLASH memory via the Universal Serial Bus for the MC68HC908JB8. ...

Page 2

... Freescale Semiconductor, Inc. AN2398/D OVERVIEW AND MEMORY USAGE To use the USB interface as a communications link for ICP, the user code in the JB8 must be modified to recognize some pre-defined USB commands for ICP. Since the FLASH memory cannot be erased by code running in the same area being erased, the code must be loaded into RAM and executed from RAM ...

Page 3

... Service Routine $aabb Vectors redirection $F7FE ICP_FLAG $F7FF $F800 ICP Code $FBFF $aa $ $F8 $00 Figure 2. Vector Redirecting lists interrupt vector addresses and the pseudo vector addresses for Go to: www.freescale.com AN2398/D OVERVIEW AND MEMORY USAGE Redirected KBI vector $CC (JMP instruction) $xx $yy Reset vector 3 ...

Page 4

... Freescale Semiconductor, Inc. AN2398/D Vector Address $FFF0 : $FFF1 $FFF2 : $FFF3 $FFF4 : $FFF5 $FFF6 : $FFF7 $FFF8 : $FFF9 $FFFA : $FFFB $FFFC : $FFFD $FFFE : $FFFF 1. The addresses of these pseudo vectors are selected randomly for security reasons. See the following section on security against unauthorized access. ...

Page 5

... The high byte of the pseudo reset vector ($FF7C) is invalid; i. not in range of the user FLASH area ($DC to $F7); or The ICP_FLAG word is not a checksum. Go to: www.freescale.com AN2398/D THE ICP PROCEDURE APPENDIX: Code Listing. 5 ...

Page 6

... Freescale Semiconductor, Inc. AN2398/D Figure 3 Table 1 Content of $FF7D Not $DC to $F7 When the JB8 is programmed only with the ICP code in place, the high byte of the pseudo reset vector at $F7FE equals $FF. This will cause the ICP code to continue to run in ICP mode. The user code can be programmed using the ICP functions ...

Page 7

... Start $40 $81 Address Start $40 $82 Address Start $40 $87 Address Start $C0 $8F Address Success if result is $01 Failure if result is $04 Go to: www.freescale.com AN2398/D USING THE ICP CODE wIndex wLength Data End Data Data Address Length End $00 $00 Address End Data $00 Address Length End ...

Page 8

... Freescale Semiconductor, Inc. AN2398/D Programming the Since the JB8 is designed for HID applications better to use the HID ICP_FLAG command to program the ICP_FLAG (Set_ICP_Flag) so that no extra driver is needed. One example is to use the HID Set_Feature report with 8 bytes of data as shown in using the HID Get_Feature report of 8 bytes of data (Get_Ack), but only one byte is used ...

Page 9

... DATA0 [00, 01, 02, 03, 04, 05, 06, 07] DATA1 [08, 09, 0A, 0B, 0C, 0D, 0E, 0F] : DATA1 [38, 39, 3A, 3B, 3C, 3D, 3E, 3F] SETUP [C0, 8F, 00, 00, 00, 00, 01, 00] DATA0 [01] Go to: www.freescale.com AN2398/D DEMO 1: Installing The USB ICP Driver Comment Erase a Block of $DE00 - $DFFF Host sends out Get_Result Device returns result success ...

Page 10

... Freescale Semiconductor, Inc. AN2398/D 3. Select Seach for the best driver for your device and then click Next. 4. Specify the directory containing the USBICP.INF file and then click 10 In-Circuit Programming of FLASH Memory via the USB for the MC68HC908JB8 For More Information On This Product, Next ...

Page 11

... Locate the directory containing the USBICP.SYS driver if you are told to 8. Finished. DEMO 2: Running USBICP 1. Open USBICP.EXE and select the parametric file JB8ICP_END.IMP. MOTOROLA In-Circuit Programming of FLASH Memory via the USB for the MC68HC908JB8 For More Information On This Product, do so. Go to: www.freescale.com AN2398/D DEMO 2: Running USBICP 11 ...

Page 12

... Freescale Semiconductor, Inc. AN2398/D USBICP program window appears. 2. Erase FLASH and then do Blank Check (skip for first time programming, 3. Select the file to be programed (e.g.: JB8-USB.SX) 4. Select Program device and then select Verify. 12 In-Circuit Programming of FLASH Memory via the USB for the MC68HC908JB8 For More Information On This Product, i ...

Page 13

... Select SetICP (kbd, mse) (change Vendor ID and Product ID if necessary). 3. Change ICP security code if necessary and then click OK. 4. Unplug and replug to cause the device to enter ICP mode. MOTOROLA In-Circuit Programming of FLASH Memory via the USB for the MC68HC908JB8 For More Information On This Product, Go to: www.freescale.com AN2398/D DEMO 3: Running SETICP.EXE 13 ...

Page 14

... Freescale Semiconductor, Inc. AN2398/D FURTHER INFORMATION MC68HC908JB8 Technical Data, Motorola document number: MC68HC908JB8/D. 14 In-Circuit Programming of FLASH Memory via the USB for the MC68HC908JB8 For More Information On This Product, Go to: www.freescale.com MOTOROLA ...

Page 15

... Should Buyer purchase or use or unauthorized application, hold Motorola and its officers, employees, and distributors harmless against all claims, any claim of personal injury or unauthorized use, was negligent regarding the design or Go to: www.freescale.com AN2398/D APPENDIX: Code Listing application or situation death even if such 15 ...

Page 16

... Freescale Semiconductor, Inc. AN2398/D ;* Parameter Equates ; include "jb8-eqs.h" include "macro8-asm.h" ; ICP_BUF_SIZE equ $40 ; ;************************************* ;* ;* Variables Definition ;* ;************************************* ; ORG RAM_BEG+8 ICP_RAM_BEG: V_ChkSumH equ * V_CtrByte ds 1 b_MASSBIT equ 6 V_CPUSpeed ds 1 V_LAddr ds 2 Q_RAM_Blk_Erase equ * Q_Work_Buf equ * Q_ICP_Buf ds ICP_BUF_SIZE ; UICP_RAM_BEGIN: ;* ----------------------------------------------------------------- Q_Setup_Buf equ * VI_bmReqType ds 1 b_Rcpt0 ...

Page 17

... H:L>,X ; <for Device Command Handler> ; Opcode of LDA(16-bit Idx) = $D6 ; Offset(High byte) ; Offset(Low byte) ; Opcode of STA(direct) = $D7 ; Offset(High) ; Offset(Low) ; Opcode of RTS = $81 Go to: www.freescale.com AN2398/D APPENDIX: Code Listing 17 ...

Page 18

... Freescale Semiconductor, Inc. AN2398/D ;* --------------------------------------------------------------------- ;* parameters to pass into ICP subroutine ;* START_ADD equ * V_Start_Add_H ds 1 V_Start_Add_L END_ADD equ * V_End_Add_H ds 1 V_End_Add_L MONITOR_VERIFY equ $FC03 MONITOR_PROGRAM equ $FC09 ; V_Source ds 1 V_Destination UICP_RAM_END equ * ;*-------------------------------------------------------------------------- UICP_RAM_SIZE equ UICP_RAM_END-UICP_RAM_BEGIN ; ;**************************************************************************** ;* ;* CONSTANT DEFINITION ;* ;**************************************************************************** NUM_BLK equ !16 FEATURE_SIZE ...

Page 19

... READ BLOCK CMMD - ; { %01000000,$84,Start_Adr_L,Start_Adr_H,End_Adr_L,End_Adr_H,CMMD_Length } ; ; GET_INFO CMMD - ; { %11000000,$85,$0,$0,$0,$0,$8,$ EXIT_ICP CMMD - ; { %11000000,$86,$0,$0,$0,$0,$0,$ VERIFY_CODE CMMD - ; { %11000000,$87,Start_Adr_L,Start_Adr_H,End_Adr_L,End_Adr_H,$40,$ GET STATUS CMMD - ; { %11000000,$8F,$0,$0,$0,$0,$1,$ MOTOROLA In-Circuit Programming of FLASH Memory via the USB for the MC68HC908JB8 For More Information On This Product, Go to: www.freescale.com AN2398/D APPENDIX: Code Listing 19 ...

Page 20

... Freescale Semiconductor, Inc. AN2398/D SET_PROG equ $81 SET_ERASE equ $82 ERASE_ALL equ $83 SET_READ equ $84 VERIFY_CODE equ $87 GET_ICP_STATUS equ $8F ; ;**************************************************************************** ;* ;* Return: Acc = $AF if erase/program succeeds ;* Acc = $5F if erase/program fails ;* ;**************************************************************************** ; DMCR equ $0016 ALIF equ $0007 NAKIF equ $0006 BB equ $0005 MAST equ $0004 DADR equ ...

Page 21

... ICP_FLAG high byte ; add checksum high byte ; ICP mode if sum <> jmp to application program ; set SP end of RAM ; disable COP, enable STOP ; disable interrupt ; reset high byte of H:X ; init and enable USB module ; V_CPUSpeed = unprotect FLASH Go to: www.freescale.com AN2398/D APPENDIX: Code Listing 21 ...

Page 22

... Freescale Semiconductor, Inc. AN2398/D ;* =============================== ;* ;* Clear Page Zero RAM area ;* ;* =============================== ldx #UICP_RAM_SIZE CLR_RAM_L: clr (UICP_RAM_BEGIN+1),x dbnzx CLR_RAM_L ; ;* ---------------------------------------- ;* ;* Set up RAM routine ;* ;* ---------------------------------------- mov #$D6,VI_LDA mov #$D7,VI_STA mov #$81,VI_RTS ;==================================================================== ; Main Loop ;==================================================================== MAIN_LOOP_ICP ; ;* ------------------------------------------------------------------- brclr b_OUT_DONE,V_TRF_Status,END_PROC_OUT bclr b_OUT_DONE,V_TRF_Status ; brset b_PROG_Set,V_ICP_CMMD,GOT_PROG_BLK bsr CODE_VERIFY bra END_DATA_OK ; GOT_PROG_BLK: jsr PROG_CODE ...

Page 23

... In-Circuit Programming of FLASH Memory via the USB for the MC68HC908JB8 For More Information On This Product, ; loop while timer not overflow ; enable internal D- pullup ; restore default addr($00), enable USB ; enable EP0 rx ; clear int. flags ; A ; Program FLASH in monitor code Go to: www.freescale.com AN2398/D APPENDIX: Code Listing * 23 ...

Page 24

... Freescale Semiconductor, Inc. AN2398/D ;====================================================================== ; Verify ; ; Input: Flash address = START_ADD (2 bytes), END_ADD (2 bytes) ; Data address = $0100 - $02FF (max 512 bytes Usage: START_ADD (2 bytes), SOURCE_INX (2 bytes), TARGET_ADD (2 bytes Output: Acc = #ACK_SIGNAL ; Acc = #NOACK_SIGNAL (fail) ; ;====================================================================== CODE_VERIFY: ldhx END_ADD lda END_ADD KCMPHI $F7,PROG_FAIL sthx V_LAddr ...

Page 25

... Dly_8ms needs (4) cycles ; [3] ; (3) ; KBD interrupt vector ; TIM overflow interrupt vector ; TIM Ch_1 interrupt vector ; TIM Ch_0 interrupt vector ($FFF6) ; IRQ1 interrupt vector ($FFF8) ; USB device interrupt vector ($FFFA) ; SWI interrupt vector ($FFFC) Go to: www.freescale.com AN2398/D APPENDIX: Code Listing 25 ...

Page 26

... Freescale Semiconductor, Inc. AN2398/D NOTES: 26 In-Circuit Programming of FLASH Memory via the USB for the MC68HC908JB8 For More Information On This Product, Go to: www.freescale.com MOTOROLA ...

Page 27

... Freescale Semiconductor, Inc. MOTOROLA In-Circuit Programming of FLASH Memory via the USB for the MC68HC908JB8 For More Information On This Product, Go to: www.freescale.com AN2398/D NOTES: 27 ...

Page 28

... Motorola and the Stylized M Logo are registered in the U.S. Patent and Trademark Office. digital dna is a trademark of Motorola, Inc. All other product or service names are the property of their respective owners. Motorola, Inc Equal Opportunity/Affirmative Action Employer. © Motorola, Inc. 2003 AN2398/D Rev. 0 1/2003 Go to: www.freescale.com ...

Related keywords