AN2153 Freescale Semiconductor / Motorola, AN2153 Datasheet

no-image

AN2153

Manufacturer Part Number
AN2153
Description
A Serial Bootloader for Reprogramming the MC9S12DP256 FLASH Memory
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Semiconductor Products Sector
Application Note
A Serial Bootloader for Reprogramming
the MC9S12DP256 FLASH Memory
By Gordon Doughman
Introduction
Order this document
by AN2153/D
Field Applications Engineer, Software Specialist
Dayton, Ohio
The MC9S12DP256 is a member of the M68HC12 Family of 16-bit
microcontrollers (MCU) containing 262,144 bytes of bulk or sector
erasable, word programmable FLASH memory arranged as four
65,536 byte blocks. Including FLASH memory, rather than EPROM or
ROM, on a microcontroller has significant advantages.
For the manufacturer, placing system firmware in FLASH memory
provides several benefits. First, firmware development can be extended
late into the product development cycle by eliminating masked ROM
lead times. Second, when a manufacturer has several products based
on the same microcontroller, it can help eliminate inventory problems
and lead times associated with ROM-based microcontrollers. Finally, if
a severe bug is found in the product’s firmware during the manufacturing
process, the in-circuit reprogrammability of FLASH memory prevents the
manufacturer from having to scrap any work-in-process.
The ability of FLASH memory to be electrically erased and
reprogrammed also provides benefits for the manufacturer’s end
customers. The customer’s products can be updated or enhanced with
new features and capabilities without having to replace any components
or return a product to the factory.
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
TM
© Motorola, Inc., 2001
AN2153

Related parts for AN2153

AN2153 Summary of contents

Page 1

... Freescale Semiconductor, Inc. Order this document by AN2153/D Semiconductor Products Sector Application Note A Serial Bootloader for Reprogramming the MC9S12DP256 FLASH Memory By Gordon Doughman Field Applications Engineer, Software Specialist Dayton, Ohio Introduction The MC9S12DP256 is a member of the M68HC12 Family of 16-bit microcontrollers (MCU) containing 262,144 bytes of bulk or sector erasable, word programmable FLASH memory arranged as four 65,536 byte blocks ...

Page 2

... FLASH memory area. The remainder of this application note explores the requirements of a serial bootloader and the implementation of the programming algorithm for the MC9S12DP256’s FLASH. 2 For More Information On This Product, Go to: www.freescale.com Figure 1. While the majority AN2153 MOTOROLA ...

Page 3

... An erase sector contains 8 rows or 512 bytes. Erase operations may be performed on a sector as small as 512 bytes or on the entire 65,536-byte block. An erased word reads $FFFF and a programmed word reads $0000. AN2153 MOTOROLA For More Information On This Product, Block 3 ...

Page 4

... Note that only three of the banked registers contain usable status and control bits; the remaining nine registers are reserved for factory testing or are unused. 4 For More Information On This Product, Go to: www.freescale.com Figure 1, the upper block Figure 2, apply to all four memory MOTOROLA AN2153 ...

Page 5

... The lower protected area of block zero and the protected areas of the other FLASH blocks can be used for critical parameters that would not change when program firmware was updated. AN2153 MOTOROLA For More Information On This Product, 5 ...

Page 6

... Protection byte for FLASH block 3 $FF0B Protection byte for FLASH block 2 $FF0C Protection byte for FLASH block 1 $FF0D Protection byte for FLASH block 0 $FF0E $FF0F Figure 4 summarize the combinations of the For More Information On This Product, Go to: www.freescale.com Description Reserved Reserved Security byte AN2153 MOTOROLA ...

Page 7

... M68HC12 Family members as the background debug module (BDM) interface provided easy, uninhibited access to the FLASH and EEPROM contents using a 2-wire connection. Later revisions of the original D Family parts provided a method that AN2153 MOTOROLA For More Information On This Product, Protected ...

Page 8

... Use of the BDM interface to erase the FLASH and EEPROM memories is not present in the initial mask set (0K36N) of the MC9S12DP256. Great care must be exercised to ensure that the microcontroller is not programmed in a secure state unless the back door mechanism is supported by the target firmware. 8 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 9

... To disable security, the firmware must have access to the 64-bit value stored in the security back door comparison key located in FLASH memory from $FF00–$FF07. If AN2153 MOTOROLA For More Information On This Product, Overview of the MC9S12DP256’s FLASH ...

Page 10

... Sector erase $41 Mass erase $05 Erase verify Illegal Figure 6. FLASH Program and Erase Commands For More Information On This Product, Go to: www.freescale.com Description Program 1 aligned word, 2 bytes Erase a 512-byte sector Erase a 64-Kbyte block Verify erasure of a 64-Kbyte block Generate an access error AN2153 MOTOROLA ...

Page 11

... FIFO are empty. NOTE: Because the interrupt vectors are located in FLASH block zero, memory locations in block zero cannot be erased or programmed when utilizing FLASH interrupts in a target application. AN2153 MOTOROLA For More Information On This Product, Overview of the MC9S12DP256’s FLASH Go to: www.freescale.com ...

Page 12

... SET ? YES NO WRITE ALIGNED DATA WORD Figure 7. Erase and Verify Flowchart For More Information On This Product, Go to: www.freescale.com CLEAR CBEIF FLAG ACCERR FLASH ARRAY OR PVIOL PROTECTED OR FLAG SET BAD COMMAND ? NO DELAY 5 BUS CYCLES CCIF YES COMMAND FLAG COMPLETED SET ? AN2153 MOTOROLA ...

Page 13

... FLASH due to high voltage over stress. Setting FCLKDIV such that the state machine clock is greater than 200 kHz can result in improperly programmed memory locations. AN2153 MOTOROLA For More Information On This Product, Overview of the MC9S12DP256’s FLASH Figure 8 ...

Page 14

... For all erase operations, the data written to the FLASH block is ignored the value of the FLASH block number decreases with For More Information On This Product, Go to: www.freescale.com Figure 1 reveals that the AN2153 MOTOROLA ...

Page 15

... As the flowchart in each programming command to complete, a new programming command is issued as soon as the CBIEF flag is set. This allows the programming voltage to remain applied to the array as long as the next AN2153 MOTOROLA For More Information On This Product, Overview of the MC9S12DP256’s FLASH Figure 9 shows, rather than waiting for Go to: www ...

Page 16

... DATA WORD WRITE COMMAND TO FCMD REGISTER Figure 9. Programming Flowchart For More Information On This Product, Go to: www.freescale.com CLEAR CBEIF FLAG FLASH ARRAY ACCERR OR PVIOL PROTECTED OR FLAG SET BAD COMMAND ? NO DELAY 5 BUS CYCLES DONE YES BLOCK PROGRAM WITH DATA COMPLETED BLOCK ? NO AN2153 MOTOROLA ...

Page 17

... JMP instruction that uses the CPU12’s indexed-indirect program counter relative addressing mode. This form of the JMP instruction uses four bytes of AN2153 MOTOROLA For More Information On This Product, General FLASH Serial Bootloader Requirements Go to: www ...

Page 18

... S1 records only contain a 16-bit address, they are inadequate to specify a load address for a memory space greater than 64 Kbytes. S2 records, which contain a 24-bit load address, were originally defined for loading object files into the memory space of the M68000 Family. It would seem 18 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 19

... NOTE: The bootloader is limited to receiving S-records containing a maximum of 64 bytes in the code/data field S-record containing more than 64 bytes in the code/data field is received, an error message will be displayed. AN2153 MOTOROLA For More Information On This Product, General FLASH Serial Bootloader Requirements Go to: www.freescale.com ...

Page 20

... For More Information On This Product, Go to: www.freescale.com Memory Type Off-chip memory On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH On-chip FLASH AN2153 MOTOROLA ...

Page 21

... ASCII numeric characters highly likely that one of them would be understood as a valid command. MC9S12DP256Bootloader a) Erase Flash b) Program Flash c) Set Baud Rate ? AN2153 MOTOROLA For More Information On This Product, General FLASH Serial Bootloader Requirements Figure 12. Serial Bootloader Prompt Go to: www.freescale.com Application Note ...

Page 22

... FLASH may have been received. The S-record data must have load addresses in the range $C0000–$FFFFF. This address range represents the upper 256 Kbytes of the 1-MB address space of the MC9S12DP256. 22 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 23

... S-record loader and a secondary interrupt vector jump table. The code is written in a position independent manner so that the generated object code will execute properly from any address. AN2153 MOTOROLA For More Information On This Product displayed on the host terminal’s screen. Entering a ...

Page 24

... An O cycle can be a free cycle ( program word access cycle (P). When the first byte of an instruction with an odd number of bytes is misaligned (at an odd address), the O cycle becomes 24 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 25

... LOCK bit not being cleared until several bus cycles after a write to the SYNR register had occurred. Also note that a 24-MHz bus clock was chosen to support a baud rate of 115,200. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com ...

Page 26

... Examining the command table at label CmdTable, it can be seen that the table does not contain the absolute address of the command to execute. Rather each table entry contains an offset from the beginning of the table to the start of the command. This offset, when added to the 26 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 27

... If either value is odd, an error code is stored in the ErrorFlag global variable and the FLASH programming operation is terminated. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com ...

Page 28

... S-record data was successfully programmed into the FLASH. 28 Figure 11. After initializing the PPAGE register, the PPAGE 1, it can be determined that the block number for any of the For More Information On This Product, Go to: www.freescale.com Figure 10, only S2 AN2153 MOTOROLA ...

Page 29

... NumWords is zero. Before verifying that all of the FLASH locations programmed properly, the firmware must wait until the CCIF flag is set, indicating that all issued programming commands have completed. Failure to observe this AN2153 MOTOROLA For More Information On This Product, Figure Figure 11, will always point within the PPAGE window ...

Page 30

... EraseFlash subroutine. This value, $3C, places the lower FLASH block zero into the PPAGE window. The block select bits are initialized to zero. After loading the X index register with the address 30 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 31

... X index register. The SRecBytes variable is used to hold the converted value of the S-record length field. This value includes the number of bytes contained in the load address field, the length of the code/data field, and the length of the AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com ...

Page 32

... GetHexByte, IsHex, and CvtHex. The GetHexByte subroutine retrieves two ASCII hex bytes from the serial port and converts them into a single 8-bit data byte that is returned in the B accumulator. The IsHex subroutine is used to check received byte to 32 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 33

... When the value is zero, the queue is full. Using a byte for the index does not allow support of queue sizes greater than 255 bytes. However, this should not pose severe restrictions for most applications. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com ...

Page 34

... XOn. Because the host’s characteristics can vary widely, a value of the receive buffer minus eight was arbitrarily chosen. Note that the value of XOnCount represents the number of characters available in the receive queue. 34 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 35

... XOffCount, two variables, SendXOff and XOffSent, are set to a non-zero value and transmitter interrupts are enabled. These actions cause an XOff character to be sent to the host computer the next time a transmit AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com ...

Page 36

... XOn character should be sent to the host computer XOff character was previously sent and the number of characters left in the receive queue is less than XOnCount, an XOn character is sent to the host by calling the putchar routine. 36 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 37

... CPU12’s indexed-indirect program counter relative addressing mode. This form of the JMP instruction uses four bytes of memory and requires just six CPU clock cycles to execute. The table in each vector source with the secondary interrupt table address. AN2153 MOTOROLA For More Information On This Product, Secondary Interrupt Vector Jump Table Go to: www ...

Page 38

... ATD1 $EFD0 ATD0 $EFD2 SCII $EFD4 SCI0 $EFD6 SPI0 $EFD8 $EFDA $EFDC $EFDE $EFE0 $EFE2 $EFE4 $EFE6 $EFE8 $EFEA $EFEC $EFEE $EFF0 IRQ $EFF2 XIRQ $EFF4 SWI $EFF6 $EFF8 $EFFA $EFFC $EFFE MOTOROLA AN2153 ...

Page 39

... Freescale Semiconductor, Inc. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com Application Note Code Listing 39 ...

Page 40

... Freescale Semiconductor, Inc. Application Note 40 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 41

... Freescale Semiconductor, Inc. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com Application Note Code Listing 41 ...

Page 42

... Freescale Semiconductor, Inc. Application Note 42 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 43

... Freescale Semiconductor, Inc. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com Application Note Code Listing 43 ...

Page 44

... Freescale Semiconductor, Inc. Application Note 44 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 45

... Freescale Semiconductor, Inc. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com Application Note Code Listing 45 ...

Page 46

... Freescale Semiconductor, Inc. Application Note 46 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 47

... Freescale Semiconductor, Inc. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com Application Note Code Listing 47 ...

Page 48

... Freescale Semiconductor, Inc. Application Note 48 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 49

... Freescale Semiconductor, Inc. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com Application Note Code Listing 49 ...

Page 50

... Freescale Semiconductor, Inc. Application Note 50 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 51

... Freescale Semiconductor, Inc. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com Application Note Code Listing 51 ...

Page 52

... Freescale Semiconductor, Inc. Application Note 52 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 53

... Freescale Semiconductor, Inc. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com Application Note Code Listing 53 ...

Page 54

... Freescale Semiconductor, Inc. Application Note 54 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 55

... Freescale Semiconductor, Inc. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com Application Note Code Listing 55 ...

Page 56

... Freescale Semiconductor, Inc. Application Note 56 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 57

... Freescale Semiconductor, Inc. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com Application Note Code Listing 57 ...

Page 58

... Freescale Semiconductor, Inc. Application Note 58 For More Information On This Product, Go to: www.freescale.com AN2153 MOTOROLA ...

Page 59

... Freescale Semiconductor, Inc. AN2153 MOTOROLA For More Information On This Product, Go to: www.freescale.com Application Note Code Listing 59 ...

Page 60

... ASIA/PACIFIC: Motorola Semiconductors H.K. Ltd.; Silicon Harbour Centre, 2 Dai King Street, Tai Po Industrial Estate, Tai Po, N.T., Hong Kong. 852-26668334 Technical Information Center: 1-800-521-6274 HOME PAGE: http://www.motorola.com/semiconductors/ are registered trademarks of Motorola, Inc. Motorola, Inc Equal Opportunity/Affirmative Action Employer. For More Information On This Product, Go to: www.freescale.com © Motorola, Inc., 2001 AN2153/D ...

Related keywords