Microsoft Word - APB171-V0U-FlashProgMPC56x.doc

469 views
414 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
469
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Microsoft Word - APB171-V0U-FlashProgMPC56x.doc

  1. 1. Ashling Product Brief APB171 Flash Memory Programming using the PathFinder-MPC56x Debugger Contents 1 Introduction ............................................................................................................................................ 1 2 Preparing your application to run from flash memory............................................................................ 3 3 Programming Off-Chip flash using the Flash Programming Utilities Package ...................................... 3 4 Programming On-Chip flash using the Flash Programming Utilities Package....................................... 4 4.1 Erasing the internal flash ................................................................................................................ 4 4.2 Programming the On-Chip (internal) Flash Main Array ................................................................ 5 4.3 Programming the On-Chip (internal) Flash Shadow Array ............................................................ 5 5 Debugging flash-resident code with PathFinder..................................................................................... 6 6 Appendix A: Programming On-chip Flash using off-chip buffer RAM................................................. 7 7 Appendix B: The Off-Chip Flash Programming script-file .................................................................... 7 1 Introduction Ashling's PathFinder-MPC56x Debugger, together with the Vitra, Genia or Opella Emulators, provides full support for Flash programming. You can program on-chip Flash memory on the MPC56x device, or off-chip (external) Flash memory on the target system. Programming Flash memory requires only the Ashling Debugger and Emulator, with a NEXUS or BDM connection to the target system on which the Flash memory resides. You can use the Flash Programming Utilities Package to program Flash on a "new" board for the first time, by downloading the MPC56x Target Flashing Utility Program to an on-chip or off-chip SRAM area in your target, using the NEXUS or BDM debug connections. To program off-chip Flash memory, you’ll need PathFinder-MPC56x at version 0.9.3 or later; on- chip MPC56x flash programming requires version 1.0.4a or later. Ashling’s Flash Programming Utilities Package supports MPC56x On-chip Flash, as well as a number of different Flash memory devices from AMD, Intel, ST and Toshiba. Support for new devices can be easily added, because the Package includes editable Script (Groupfile) source for the Flash Script Programs and C source files for the Flashing Utility Programs (MPC56x C source). In summary, the Flash Programming Utilities Package supplied with PathFinder-MPC56x consists of: 1. Script Files (group files) for the Emulator, to provide the User-Interface for Flash programming. The Script files allow you to specify the Start Memory Address of the Flash to be programmed, and the Start and End Memory Addresses of the buffer RAM area that will be used to transfer the Flash data (MPC56x on-chip RAM, or external RAM); to download the Flash memory image into the selected RAM area on your target; and to show User-Messages ("Target Flash device detected is M58BW016BB"; "Erasing Flash device...", for example). You can readily change or update the parameters in the Flash Programming Script Files, to customize them for your memory-map. 2. MPC56x Target Flashing Utility Program that reads the Identifier and Status information from the Flash device, erases the Flash, and programs each byte/word from the target Ashling Flash Memory Programming Page 1 of 9
  2. 2. buffer RAM area into the target Flash. The MPC56x Target Flashing programs are supplied in both MPC56x-Executable and C-source form. Normally, you won’t need to alter or recompile the MPC56x Target Flashing Utility Programs, unless you want to make a substantial change to their functions. The MPC56x Target On-Chip Flashing Utility Program incorporates Motorola's "General Market C3F Driver for MPC56x on-chip flash", using Motorola-approved on-chip flash algorithms. The Script Files program your Flash memory in the following steps (see Fig. 1): 1. Download the Ashling MPC56x Target Flashing Utility Program application to on-chip RAM. 2. Download your application-code to be flashed into on-chip or off-chip buffer RAM located on your target. 3. Run the MPC56x Target Flashing Utility Program to program the Flash. PathFinder debugger Flashing Script Compiler & (Group) File Vitra, Genia or SymFinder Linker Opella Emulator Target Flash Flash code Utility Program image Application Source Nexus or Program BDM link Target Board MPC56x Target Flash Utility Program in RAM Buffer RAM On-chip Flash External Flash Fig. 1. The Flash Programming Utilities Package (the Flashing Group Files and the Target Flash Utility Programs) is used with Ashling’s Emulators and PathFinder debugger. The Script Files in PathFinder’s Flash Package can be used ‘as is’, or can be modified to suit your requirements. PathFinder’s Script language (Group file) allows you to write your own command files to automate repetitive tasks for the emulator; for example: LOCAL UNSIGNED LONG %ulFlashStartAddr declares a Local variable named %ulFlashStartAddr (of Unsigned Long size) that can subsequently be used in the Group program. ; Comments are preceded by the semi-colon character G T &main ; Execute the emulator’s G T (Go To) function, to run ; the current program to the address of symbol ‘main’ uiCounter = 0x3f ; Write the value 3f hex to a Program-variable ‘uiCounter’ For full information on Group files, please refer to Chapter 6 PathFinder Command Reference in the PathFinder User Manual. Ashling Flash Memory Programming Page 2 of 9
  3. 3. 2 Preparing your application to run from flash memory To successfully run your MPC56x application from flash, note that: 1. While you are debugging your code, the PathFinder debugger takes control of the MPC56x Watchdog timer. PathFinder initializes the Watchdog control register to a value that you specify in PathFinder’s Configuration dialog; if your program writes to the watchdog registers, all such writes are ignored while debugging. When you are ready to create a “final” version of your program and burn it into flash, you must ensure that your program either disables or services the MPC56x Watchdog timer by writing an appropriate value to the Watchdog register. 2. While you are debugging your code, you may use PathFinder’s Configuration dialog to initialize any PowerPC register(s) or memory-locations. When you are ready to create a “final” version of your program and burn it into flash, you must ensure that your program initializes those registers with the same value(s). In particular, the Base and Options registers (BRx and ORx) must be correctly set-up in your code; these are the chip-selects that control your application’s external memory map. When the PowerPC comes out of reset, it reads a configuration word from the data bus; it then uses this configuration word to configure BR0. Your startup code should configure the remaining Base and Options registers as appropriate for your application. 3 Programming Off-Chip flash using the Flash Programming Utilities Package To program flash, first prepare your application program (Flash image) in Ashling CSO format, using the Ashling SymFinder utility (see Fig. 1). Next, use a text editor to modify the parameters in the Off-Chip Flash Programming Script File in the Flash Programming Utilities Package (it’s a good idea to save a backup copy of the original group-file). By default, this Group-file is C:PFPPCFLASHEXTERNALDIABMPC56XFLASH.GRP to Erase and Program External (Off-chip) Flash memory devices. The Group File as supplied in the Flash Package contains typical values for the programming parameters; you may need to modify the following main parameters in the file: Parameter Function %szFileName Sets the Name of your Flash code (image) file For example: %szFileName = “D:ProjectFlashIMAGE.CSO” %ulFlashStartAddr Sets the address at which the Flash memory resides within the PowerPC’s memory-map For example: %ulFlashStartAddr = 0 ; (for Flash memory that includes ; the Reset vector) %ulSramStartAddr Set the Start- and End-addresses of temporary buffer RAM (the addresses within the PowerPC’s memory-map of the RAM memory %ulSramEndAddr that we will use to download the flash image). For example: %ulSramStartAddr = 0x800000 ; (For the Buffer, use 64KB of ; Off-chip RAM extending from 0x80.0000.. %ulSramEndAddr = 0x80ffff ; (...to 0x80.ffff ) Fig. 2. Modify these parameters in the FLASH.GRP Off-Chip Flash Programming Group-file Note that you can set an On-chip or Off-chip RAM address for the Buffer; a large off-chip RAM may result in faster flash programming. If the amount of temporary buffer RAM is less than the size of your flash image file then the Group file will automatically download the file in appropriate- sized blocks and will program each block before the next download. Ashling Flash Memory Programming Page 3 of 9
  4. 4. The Off-Chip Flash Script File automatically downloads and executes the MPC56x Target Flashing Utility Program C:PFPPCFLASHEXTERNALDIABMPC56XPROGRAMFLASH.CSO into On-Chip RAM at address 0x3f.8000. (If you change this address by re-linking the FLASH program, make sure that the RAM area specified for FLASH.CSO does not overlap with the flash image temporary buffer RAM!). Now choose Groupfiles→Run groupfile… from PathFinder’s menu, and select the External Flash Script file FLASH.GRP as above. PathFinder’s screen will show Programming FLASH with D:ProjectFlashIMAGE.CSO and erasing and programming will proceed. Finally, PathFinder will show a Status-message such as Flash programming completed successfully. 4 Programming On-Chip flash using the Flash Programming Utilities Package For On-Chip MPC56x Flash Programming, the Flash Programming Utilities Package includes the following Group (script) files: 1. To Erase On-Chip Flash memory (Main Array and Shadow Array) C:PFPPCFLASHINTERNALDIABMPC56XERASE.GRP 2. To Program the On-Chip Flash Main memory Array C:PFPPCFLASHINTERNALDIABMPC56XARRAY.GRP 3. To Program the On-Chip Flash Shadow memory Array C:PFPPCFLASHINTERNALDIABMPC56XSHADOW.GRP All three On-Chip Flash Script Files automatically download and run the MPC56x On-Chip Flashing Utility Program C:PFPPCFLASHINTERNALDIABMPC56XPROGRAMFLASH.CSO into On-Chip RAM at address 0x3f.8000. (If you change this address by re-linking the FLASH program, make sure that the RAM area specified for FLASH.CSO does not overlap with the flash image temporary buffer RAM!). If the amount of temporary buffer RAM specified in ARRAY.GRP or SHADOW.GRP is less than the size of your flash image file then the Group file will automatically download the file in appropriate-sized blocks and will program each block before the next download. Alternatively, you can set %bUseExternalSram = 1 and use an Off-chip RAM address for the Buffer; a large off-chip RAM may result in faster flash programming. To use Off-Chip buffer RAM, you will need to set additional parameters: please see the Appendix. 4.1 Erasing the internal flash The ERASE.GRP groupfile in the C:PFPPCFLASHINTERNALDIABMPC56X directory is used to erase both the Main and the Shadow on-chip Flash arrays. The Group File contains typical values for the programming parameters. You may need to modify the following main parameter in the file; no other parameters need be modified to erase the flash: Parameter Function %ulModule Specify Flash Module A (0) or Flash Module B (1) For example: %ulModule = 0 ; Erase Flash Module A or %ulModule = 1 ; Erase Flash Module B Fig. 3. Modify these parameters in the ERASE.GRP On-Chip Flash Erasing Group-file Now choose Groupfiles→Run groupfile… from PathFinder’s menu, and select the On-Chip Flash Erase Script file ERASE.GRP Ashling Flash Memory Programming Page 4 of 9
  5. 5. PathFinder’s screen will show Please wait, flash erasing in progress... and erasing will proceed. Finally, PathFinder will show an Erase status-message. 4.2 Programming the On-Chip (internal) Flash Main Array The ARRAY.GRP groupfile in the C:PFPPCFLASHINTERNALDIABMPC56X directory is used to program the main array of the internal flash. To program flash, first prepare your application program (Flash image) in Ashling CSO format, using the Ashling SymFinder utility (see Fig. 1). Next, use a text editor to modify the parameters in the On-Chip Flash Main Array Programming Script (group) File in the Flash Programming Utilities Package (it’s a good idea to save a backup copy of the original group-file). By default, this Group-file is C:PFPPCFLASHINTERNALDIABMPC56XARRAY.GRP to Program the MPC56x On-Chip (internal) Flash memory Main Array. The Group File as supplied in the Flash Package contains typical values for the programming parameters; you may need to modify the following main parameters in the file: Parameter Function %szFileName Sets the Name of your Flash code (image) file For example: %szFileName = “D:ProjectFlashIMAGE.CSO” %ulModule Specifies Flash Module A (0) or Flash Module B (1) For example: %ulModule = 0 ; Program Flash Module A or %ulModule = 1 ; Program Flash Module B %ulFlashStartAddr Sets the address at which the Flash memory resides within the PowerPC’s memory-map For example: %ulFlashStartAddr = 0 ; (for Flash memory that ; includes the Reset vector) %bUseExternalSram Choose Internal (on-chip) RAM (0) or External RAM (1) for the Flash application-program and the buffer RAM For example: %bUseExternalSram = 0 ; Use On-Chip RAM Fig. 4. Modify these parameters in the ARRAY.GRP On-Chip Main Array Flash Programming Group-file Now choose Groupfiles→Run groupfile… from PathFinder’s menu, and select the On-Chip Flash Script file ARRAY.GRP for Main Array Flash programming. PathFinder’s screen will show Programming FLASH with D:ProjectFlashIMAGE.CSO and Main Array programming will proceed. Finally, PathFinder will show a Status-message such as Flash programming completed successfully. 4.3 Programming the On-Chip (internal) Flash Shadow Array The SHADOW.GRP groupfile in the C:PFPPCFLASHINTERNALDIABMPC56X directory is used to program the Shadow Array of the MPC56x on-chip (internal) flash. To program the Shadow Flash Array, first prepare your application program (Flash image) in Ashling CSO format, using the Ashling SymFinder utility (see Fig. 1). Next, use a text editor to modify the parameters in the On-Chip Flash Shadow Array Programming Script (group) File in the Flash Programming Utilities Package (it’s a good idea to save a backup copy of the original group-file). By default, this Group-file is C:PFPPCFLASHINTERNALDIABMPC56XSHADOW.GRP to Program the MPC56x On-Chip (internal) Flash memory Shadow Array. Ashling Flash Memory Programming Page 5 of 9
  6. 6. The Group File as supplied in the Flash Package contains typical values for the programming parameters; you may need to modify the following main parameters in the file: Parameter Function %szFileName Sets the Name of your Flash code (image) file For example: %szFileName = “D:ProjectFlashIMAGE.CSO” %ulModule Specifies Flash Module A (0) or Flash Module B (1) For example: %ulModule = 0 ; Program Flash Module A or %ulModule = 1 ; Program Flash Module B %ulFlashStartAddr Sets the address at which the Flash memory resides within the PowerPC’s memory-map For example: %ulFlashStartAddr = 0 ; (for Flash memory that ; includes the Reset vector) %bUseExternalSram Choose Internal (on-chip) RAM (0) or External RAM (1) for the Flash application-program and the buffer RAM For example: %bUseExternalSram = 0 ; Use On-Chip RAM Fig. 5. Modify these parameters in the SHADOW.GRP On-Chip Flash Shadow Array Programming Group- file Now choose Groupfiles→Run groupfile… from PathFinder’s menu, and select the On-Chip Flash Script file SHADOW.GRP for Shadow Array Flash programming. PathFinder’s screen will show Programming FLASH with D:ProjectFlashIMAGE.CSO and Shadow Array programming will proceed. Finally, PathFinder will show a Status-message such as Flash programming completed successfully. 5 Debugging flash-resident code with PathFinder First, debug your application located in RAM. When debugging is complete, use the Flash Utilities Package to program the code into Flash. To debug flash-resident code with PathFinder, please note the following: 1. After you have compiled and linked your program, converted it using the Ashling SymFinder utility, and programmed the Flash image, you can use that same code (plus its associated symbols file) to debug the Flash-resident code using PathFinder. The code (and symbols) file that you use for debugging must be identical to that which you programming into Flash. (You should not subsequently change the Compiler or Linker options, switches or optimization settings; to do so would cause a mismatch between the flash-resident code and the Symbols information). 2. Load the Symbols information from your program into PathFinder, to allow source level debugging. Select Symbols only from the Load group in PathFinder’s File→Load… dialog. PathFinder will now load the Symbols into its symbols-table (no code will be downloaded to your target; it already resides in the Flash). 3. You can now use PathFinder to debug your application. Note, however, that you cannot set Software Breakpoints at a location in Flash; use Hardware breakpoints instead. (Software breakpoints use the PowerPC’s BKPNT instruction; as a result, Software breakpoints cannot be set in Read-Only Memory or at an address that does not contain RAM memory in your target system, because PathFinder needs to write the BKPNT instruction to the breakpoint address.) 4. Hardware breakpoints are fully supported in Flash-resident code; they are implemented using one or more of the four PowerPC Watchpoints registers. Hardware breakpoints can be set to occur on Code execution or Data access (read or write). Hardware breakpoints Ashling Flash Memory Programming Page 6 of 9
  7. 7. are indicated by a Blue marker in the BP column of PathFinder’s Source and Disassembly Windows; they can be set or cleared by pressing the Shift key and double- clicking in the BP column, or by using PathFinder’s Run→Breakpoint Configuration… dialog. 5. If Allow User Control of Watchpoint Resources is unchecked in the Breakpoint Configuration→Specify Watchpoints dialogs then PathFinder will automatically use Hardware breakpoints when stepping in Flash-resident code. If all Hardware breakpoints are already in use then PathFinder will prompt you to clear them before continuing. (Please refer to the User Manual section on Specify Watchpoints for more details.) 6 Appendix A: Programming On-chip Flash using off-chip buffer RAM Normally, the ARRAY.GRP and SHADOW.GRP Group files for programming the MPC56x on- chip Main Array and Shadow Array, respectively, set %bUseExternalSram = 0 to use an On- chip RAM address for the Buffer. If %bUseExternalSram is 0, then no external SRAM is required, and the values assigned to %ulSramStartAddr, %ulSramEndAddr, %ulBR0Value, %ulOR0Value, %ulBR1Value and %ulOR1Value don’t matter. Alternatively, you can set %bUseExternalSram = 1 and use an Off-chip RAM address for the Buffer; a large off-chip RAM may result in faster flash programming. To use Off-Chip buffer RAM, you will need to set additional parameters, as below: Parameter Function %szFileName Sets the Name of your Flash code (image) file For example: %szFileName = “D:ProjectFlashIMAGE.CSO” %ulModule Specifies Flash Module A (0) or Flash Module B (1) For example: %ulModule = 0 ; Program Flash Module A or %ulModule = 1 ; Program Flash Module B %ulFlashStartAddr Sets the address at which the Flash memory resides within the PowerPC’s memory-map For example: %ulFlashStartAddr = 0 ; (for Flash memory that ; includes the Reset vector) %bUseExternalSram Choose Internal (on-chip) RAM (0) or External RAM (1) for the Flash application-program and the buffer RAM For example: %bUseExternalSram = 1 ; Use External RAM %ulSramStartAddr Set the start- and end-addresses of temporary buffer RAM (the start- address within the PowerPC’s memory-map of the RAM memory that %ulSramEndAddr we will use to download the flash image). For example: %ulSramStartAddr = 0x800000 ; (For the Buffer, use 64KB of ; Off-chip RAM extending from 0x80.0000.. %ulSramEndAddr = 0x80ffff ; (...to 0x80.ffff ) %ulBR0Value Sets-up the MPC56x external chip-selects when using External buffer %OR0Value RAM %ulBR1Value %ulOR1Value For example: %ulBR0Value = 0x400003 %ulOR0Value = 0xFFC00010 %ulBR1Value = 0x800003 %ulOR1Value = 0xFFC00010 Fig. 6. Modify these parameters in the ARRAY.GRP and SHADOW.GRP Onf-Chip Flash Programming Group-files if you want to use External Buffer RAM 7 Appendix B: The Off-Chip Flash Programming script-file ; Flash programming Group file, v100, 11th Oct 2001 Ashling Flash Memory Programming Page 7 of 9
  8. 8. ; turn off command echoing/replies ECHO OFF COMMAND OFF ; close all windows and open the command window CLOSEWIN ALL OPENWIN C ;Declare and initialise macro variables DECLARE LOCAL STRING %CR ; for print purposes LOCAL UNSIGNED LONG %ulRelocationOffset LOCAL UNSIGNED LONG %ulFlashStartAddr LOCAL UNSIGNED LONG %ulSramStartAddr LOCAL UNSIGNED LONG %ulSramEndAddr LOCAL STRING %szFileName ENDDECLARE ; The following is the filename of the flash image to be programmed... %szFileName = "PFPPCFLASHDIABEXAMPLECONTROLR.CSO" ; The following is the base address of the FLASH device. %ulFlashStartAddr = 0x400000 ; The following are the start & end addresses of the SRAM device. %ulSramStartAddr = 0x800000 %ulSramEndAddr = 0x80FFFF ;Setup carriage return for print BINCPY %CR, 0DH,0H ;Clear the screen CLS ;Display status PRINT USER "Programming FLASH with ", %szFileName, %CR, %CR ;Reset the processor RES ;Set the PC to 3F8000 (flash programmer reset value) PC = 0x3F8000 ; Setup all the chip selects... BR0 = 0x400003 OR0 = 0xFFC00010 BR1 = 0x800003 OR1 = 0xFFC00010 ; Clear all breakpoints C ALL ; Load the programming algorithm (code only)... LOAD PFPPCFLASHDIABFLASH.CSO ; Execute till the main function. g t &main ; initialise program variables to macro equivalentsulSramStartAddr = %ulSramStartAddr ulSramEndAddr = %ulSramEndAddr ulFlashStartAddr = %ulFlashStartAddr ; Clear the screen CLS ; Print out a status message print user "Please wait, flash programming in progress...", %CR, %CR ; Now that we are passed the startup code, initialise some ; variables... bCompletedFlag = 0 ; The reloaction offset will be the difference between the FLASH ;start address and the SRAM start address... %ulRelocationOffset = %ulSramStartAddr - %ulFlashStartAddr ; Continue the following loop until we have finished programming the ; entire flash... while (bCompletedFlag == 0) ; Fill the SRAM with all 0xFF's ... ; This is optional, will take longer to execute if used. ; w FF %ulSramStartAddr t %ulSramEndAddr ; Download the next segment of the flash image... LOAD %szFileName C REL=%ulRelocationOffset STARTADDR = %ulSramStartAddr ENDADDR = %ulSramEndAddr ; Set the breakpoint ... S S &BreakpointRefill ; Start the programming algorithm G ; Wait until it halts... Ashling Flash Memory Programming Page 8 of 9
  9. 9. WAIT ; Adjust the relocation offset for the amount we just programmed... %ulRelocationOffset = %ulRelocationOffset - ((%ulSramEndAddr - %ulSramStartAddr) + 1) wend ; Now print out all the status messages... PRINT USER szStatusMessage[0] s, %CR PRINT USER szStatusMessage[1] s, %CR PRINT USER szStatusMessage[2] s, %CR PRINT USER szStatusMessage[3] s, %CR PRINT USER szStatusMessage[4] s, %CR COMMAND ON ECHO ON Ashling Microsystems, Inc. 1270 Oakmead Parkway, Suite 208 Sunnyvale, CA 94085 Tel: (408) 732 6490 Fax: (408) 732 6497 Email: support.usa@ashling.com Doc: APB171-V0U-FlashProgMPC56x Ashling Flash Memory Programming Page 9 of 9

×