The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers.    


Datasheet Search Engine   
 
Part # or Description: • 5V RS232 Driver • 2SC5066* • "Real Time Clock" • "USB connector" • "blue led" 5mm • 10 watt zener diode • 2N3055* motorola
 
Search Tip: Try entering the part number only. Include a wildcard (eg. lm317* or 1n4148*)

 

 

AN1756 Freescale Semiconductor, Inc. Demonstration Bootloade


Datasheet Thumbnail

  

Download PDF



Top Searches for this datasheet



Order this document AN1756/D
AN1756
Freescale Semiconductor, Inc.
Demonstration Bootloader Method Reprogramming FLASH MMC2107 Through Implementation Field Update System
William Home Networking Group Austin, Texas
Introduction
MMC2107 general-purpose 32-bit microcontroller unit (MCU) that uses (central processor unit) contains Kbytes onboard FLASH. This application note shows program FLASH without using special FLASH programming setup. also demonstrates FLASH programming routines implementing field update system requiring only serial port separate programs used implement this field update system: FLASH downloader that allows programming FLASH through (serial communications interface) port from terminal program running bootloader that included application that allows user choose between running FLASH downloader running "main" application
This application note also provides detailed description FLASH programming model tools program FLASH.
Motorola, Inc., 2000
AN1756
More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
(programmable interval timer) modules also discussed briefly, tools common usage ports presented.
Development System
system used write debug these programs with Windows running CodeWarrior CMB2107 development board.
Freescale Semiconductor, Inc.
Background
FLASH special programming algorithm that must implemented software. involves varying programming voltages programming pulse widths. FLASH arranged eight 16-Kbyte blocks form 128-Kbyte array. Also, nature FLASH fact there only array, cannot programmed from within itself; therefore, FLASH downloader must from RAM. application, bootloader accomplishes this copying block data that contains FLASH downloader from FLASH into then executing Figure represents memory first part FLASH used example application. shows location exception vector table, user supplied information, FLASH downloader code, main program. first word FLASH reset, boot, vector. fetches address stored this location then jumps this case beginning main program. data port, clock frequency, baud rate that using. FLASH downloader actually compiled separately then included with rest application. information about known location downloader find information changes rest application, FLASH downloader does need recompiled. This explained greater detail FLASH Downloader.
Windows registered trademark Microsoft U.S. other countries. CodeWarrior registered trademark Metrowerks, Inc., wholly owned subsidiary Motorola, Inc. trademark Motorola, Inc.
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Module Descriptions
0x00
BOOT VECTOR MAIN PROGRAM) MISALIGNED ACCESS VECTOR ACCESS ERROR VECTOR PORT SYSTEM CLOCK FREQUENCY BAUD RATE
VECTOR TABLE
0x17F 0x180 0x181 0x182
DATA
ASSEMBLY LANGUAGE COPY ROUTINE FLASH DOWNLOADER DATA BOOTLOADER (STARTUP ROUTINE) "ACTUAL" APPLICATION
FLASH DOWNLOADER DATA
MAIN PROGRAM
Freescale Semiconductor, Inc.
Figure Memory FLASH Used Example Application bootloader first routine main program. user chooses FLASH downloader, returns main program runs rest application. user selects FLASH downloader, assembly language copy routine called which copies downloader into then executes
Module Descriptions
Both bootloader FLASH downloader share same communication routines. addition, bootloader uses module keep track 10-second countdown timer.
Routines
routines included \example\sci_util\sci_util.c. routines first call setup_sci() with port, baud rate clock frequency parameters SCI. routines require port sent argument. 8/N/1 bits, parity, stop bit). functions implemented are: check_for_byte() byte available read, return otherwise, return get_a_byte() Wait byte then return
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
get_bytes() Wait multiple bytes return them character array. send_byte() Send byte. send_string() Send null terminated string. setup_sci() port.
Freescale Semiconductor, Inc.
More detailed descriptions functions found listing sci_util.c. comments include specific methods enabling calculating divisors various baud rates clock frequencies.
Routines
used bootloader count seconds. routines routine, start_timer(), accepts clock frequency number seconds delay. assumes prescalar 32,768 because accuracy critical. then sets timer right number seconds delay. other routine, timeup(), checks timer flag set. set, returns false. set, disables timer returns true. Commented code available listings bootloader.c.
Description FLASH Programming Erasing Routines
FLASH erase routine described this application note allows erasing block Kbytes) FLASH time erasing whole array. FLASH programming routine allows 64-byte page time programmed. FLASH control registers program/erase algorithms detailed Section Non-Volatile Memory FLASH (CMFR) MMC2107 Advance Information, Motorola document order number MMC2107/D.
NOTE:
descriptions presented here outline specific implementation algorithms. Care should taken routines modified conform program/erase specifications. routines presented here have been tested versions them used production FLASH test cycling.
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Description FLASH Programming Erasing Routines
FLASH cannot really over-erased, implementing wrong algorithm programming cause problems. And, while overprogramming FLASH does really damage FLASH, will cause margin read failures integrity data programmed cannot guaranteed. 128-K FLASH array arranged eight 16-Kbyte blocks, numbered zero seven. blocks accessed (read) 32-byte pages programmed 64-byte pages. minimum resolution erasing block minimum resolution programming 64byte page.
Freescale Semiconductor, Inc.
NOTE:
limitations FLASH, program erase operations cannot performed with system clock below MHz.
FLASH Register Descriptions
Three registers used program erase FLASH. control bits related actual programming erasing described here. More detailed descriptions FLASH registers available Section Non-Volatile Memory FLASH (CMFR) MMC2107 Advance Information. CMFRMCR controls operation FLASH module. shadow information enable (SIE) enables shadow reading programming. protect bits (PROTECT[7:0]) allow FLASH blocks protected from programming erasing. Also this register bits that restrict various blocks supervisor mode access only bits that restrict blocks data only. CMFRMTR controls voltage levels applied during programming erasing. negative voltage range (NVR) pulse amplitude width select (PAWS) bits used different combination produce different voltages. gate drain/source select (GDB) control what part FLASH cell programming erase voltages applied
CMFRMCR CMFR Module Configuration Register
CMFRMTR CMFR Module Test Register
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
CMFRCTL CMFR High-Voltage Control Register CMFRCTL register controls programming erase operations FLASH. high-voltage status (HVS) indicates there high-voltage operations taking place. system clock range field (SCLKR[2:0]) bits control scaling clock. clock period exponent field (CLKPE[2:0]) bits clock period multiplier field (CLKPM[6:0]) bits combined produce different lengths programming erase pulses. BLOCK bits control which block programming erase voltage applied program erase select (ERASE) selects programming erasing. start/end sequence (SES) starts programming pulse.
Freescale Semiconductor, Inc.
Erasing
process erasing described Section Non-Volatile Memory FLASH (CMFR) MMC2107 Advance Information. Here implementation required algorithm described. This algorithm requires manipulation gate voltages changing pulse widths provide optimal erasing. (See Table
NOTE:
CMFR FLASH erased state 0xFF (all 1s). shadow always erases with block Table Required Erase Algorithm
Voltage Step PAWS[2:0] Negative Voltage Range Pulse Width Pulses
Note: margin read required after each -9-volt pulse.
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Erasing
Table voltage step gate voltage which selected combination PAWS[2:0] (pulse amplitude/width select field) (negative voltage range select) bit. pulse width CMFRCTL register. bulk_erase() routine takes system clock frequency block erase parameters. block number greater than seven passed routine whole array will erased. clock frequency needed calculate registers values pulse width.
Freescale Semiconductor, Inc.
This flow follows flowchart erase section FLASH specification. Just sure, write reset values into CMFRCTL (CMFR high-voltage control) CMFRMCR (CMFR module configuration) registers.
CMFRMTR (CMFR module test register), PAWS[2] override firmware modulation.
NOTE:
Although FLASH module does contain firmware erase program algorithms, they should used, been updated reflect required algorithm. MMC2107 tested using this algorithm, reliability cannot guaranteed used, especially temperature data retention. advance information book part mentions firmware, technical data book will include references Clear PROTECT bits protect none blocks.
NOTE:
There ways control erasing programming block FLASH. PROTECT bits protect block FLASH from being modified. PROTECT bits themselves locked LOCKCTL CMFRMCR register, write-once that disabled only master reset. Also, BLOCKS bits control which blocks programming voltages applied seems little redundant, makes sense really want control FLASH gets modified.
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
clock pulse width. first step setting pulse width determine correct clock scaling frequency range SCLKR[2:0] appropriate value. Table
Table System Clock Range
SCKLR[2:0] System Clock Frequency (MHz) Minimum Maximum Reserved Reserved Clock Scaling
Freescale Semiconductor, Inc.
NOTE:
Maximum system clock frequency MHz. clock scaling selected based frequency parameter saved numerator, clksc_num, denominator, clksc_den. This avoids floating point math makes sure that subsequent integer math calculations that values truncated soon. Then CLKPE[1:0] (clock period exponent field) determined. CLKPE[1:0] exponent determined from information Table Because this erase ERASE will range chosen from lower half table. Inspection table shows that ranges would include increased accuracy smallest range selected (CLKPE[1:0] 00), which chooses exponent 15).
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Erasing
Table Clock Period Exponent Pulse Width Range
Pulse Width Range System Clock Frequencies from 33.0 Minimum 1.25E 4.00 8.00 16.00 32.00 4.096 8.192 16.39 32.77 Maximum(1) 8.33E
ERASE
CLKPE [1:0]
Exponent
0.34 0.68 1.36 2.73 349.5 699.0 1.398 2.796
Freescale Semiconductor, Inc.
maximum system clock frequency MHz.
Then CLKPM[6:0] (clock period multiplier field) determined.
formula presented specification Pulse width system clock period Where CLKPME[6:0], system clock period 1/system clock frequency, were determined previous steps. bulk_erase() procedure formula reduced CLKPM (clockfreq*1000000*clksc_den) (10*clksc_num*32,768) Note that clockfreq passed into function megahertz. been expanded 32,768. pulse width (100 been changed fraction 1/10. This been arranged that integers truncated soon accurate result received. desired pulse width (100 correctly system clock frequency.
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
ERASE CMFRCTL register. BLOCK bits according block parameter passed into routine. supplied code, block number greater than seven, bits erase whole array. block number seven less, only corresponding block set. BLOCK bits where code controls where erase voltages applied. begin erase sequence, (start/end sequence) CMFRCTL register set. This followed interlock write, which write location FLASH erased. actual erase pulses then applied: PAWS[2:0] bits appropriate values current pulse (see algorithm). (enable high voltage) CMFRCTL register. Wait (high-voltage status) CMFRCTL register clear.
Freescale Semiconductor, Inc.
Clear bit. Perform margin read, required. Repeat pulses until margin read successful more than pulses applied.
routine, CMFRMCR CMFRCTL bits back their reset states. margin read consists reading whole area being erased verifying that certain electrical margin achieved FLASH cell guarantee reliability. During margin read, successfully erased bits read According recommended algorithm, margin read required only after first pulse because first eight pulses virtually guarantee that array erased.
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Erasing
Programming
programming algorithm follows similar process erase algorithm. main difference necessity change pulse widths certain points. This section describes detail required algorithm shown Table Again, complete description available Section Non-Volatile Memory FLASH (CMFR) MMC2107 Advance Information.
Table Required Programming Algorithm
Freescale Semiconductor, Inc.
Voltage Step
PAWS[2:0]
Negative Voltage Range
Pulse Width
Pulses additional needed
Note: Margin reads required after every pulse.
program_page() routine takes parameters system clock frequency, address program FLASH, address 64-byte (page size) array. This flow follows flowchart program section FLASH specification: Just sure, write reset values into CMFRCTL (CMFR high-voltage control) CMFRMCR (CMFR module configuration) registers. PAWS[2] bits CMFRMTR registers. Clear PROTECT bits protect none blocks
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
clock pulse width. Clock scaling determined identically erase flow. Then CLKPE[1:0] (clock period exponent field) determined exactly described erase flow. CLKPE[1:0] exponent determined from information Table Because this program, ERASE will range chosen from upper half table. Inspection table shows that first range (PE[1:0] includes three values needed (250 µs), which chooses exponent Then CLKPM[6:0] (clock period multiplier field) determined. This also identical erase flow. Here, because three pulse widths needed, values calculated saved three variables clkpm_250us, clkpm_100us, clkpm_50us. CLKPM then initial value BLOCK bits that programming voltage gets applied only FLASH blocks programmed. This determined masking lower bits address, which leaves block number bits [16:14]. This value then shifted right obtain block number. Then shifted left block number mask needed. reg_CMFRCTL.bit.BLOCK (address 0x0001c000) values programmed then written page.
Freescale Semiconductor, Inc.
NOTE:
This done byte time code because word half-word reads must aligned appropriately boundaries cannot guaranteed data RAM. Pulse loop then entered: PAWS[2:0] bits appropriate values current pulse (see algorithm).
AN1756
More Information This Product, www.freescale.com
MOTOROLA
Application Note Bootloader
(enable high voltage) CMFRCTL register. Wait (high-voltage status) CMFRCTL register clear.
Clear bit. Perform margin read. Repeat pulses until margin read successful more than maximum pulses applied. programming margin read performs same function erase margin read. During margin read, successfully programmed reads critical thing note that least read each half page must read perform actual margin read that half page. algorithm stops soon sees non-programmed bit, read occurred second half page, does dummy read second half page. Once again, margin read verifies electrical margin FLASH cells guarantee reliability. routine, CMFRMCR CMFRCTL bits back their reset states.
Freescale Semiconductor, Inc.
Bootloader
bootloader inserted beginning project compiled with user program allow choice between running either main program running FLASH downloader. bootloader scheme requires MMC2107-based system connected serial communications port
Functional Description
bootloader communicates with user through serial connection. terminal program such HyperTerminal, which included with
HyperTerminal registered trademark Hilgraeve Inc.
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
Windows, required. bootloader this example allows user either wait seconds main program FLASH downloader. user hits key, bootloader will assembly language routine that copies block specially formatted data into executes instructions contained data. confirmation portion code could rewritten look certain port driven high some other external stimulus.
Freescale Semiconductor, Inc.
Perl Script s2asm.pl
copied data assembly text file that been converted from S-record Perl script s2asm.pl. data machine code FLASH downloader compiled RAM. conversion necessary data compiled into bootloader program, which used from FLASH. data formatted similar S-record consists location copy number bytes copy. actual data follows that. This repeated until end-of-data signal given assembly language routine form address 0x99999999. complete description, listing s2asm.pl. this script, Perl must installed Notes, Perl entry that tells acquire Perl, free programming/scripting language.
Assembly Language Copy Routine
copy routine assembly works solely from registers. This necessary because possible that copy routine will copy data over stack. assembly language routine stored file copyblock.h. named with that file included CodeWarrior project compiler will compile itself. pulled into file downloader.s through #include statement. Note that keeps track page alignment register always shift next full word (4-byte) boundary read next address. executes starting address stored first word data. listing copyblock.h more detailed description.
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note FLASH Downloader
FLASH Downloader
FLASH downloader allows specially processed S-record downloaded microcontroller through port.
FLASH Downloader
FLASH downloader used separate instances: Standalone FLASH downloader With bootloader setup
Freescale Semiconductor, Inc.
Stand-Alone Mode
only change that needs made project standalone uncommenting #define STANDALONE program used standalone. This #define located beginning downloader.c downloader project, this code snippet.
#include "sci_util.h" #include "sikaFLASH.h" #include "mmc2107.h" uncomment STANDALONE FLASH programmer itself #define STANDALONE #define SA_PORT #define SA_BAUD 9600 #define SA_FREQ /*******************/ comment USING_EVB disable write enable #define USING_EVB; /*******************/
Compiling Inclusion with Bootloader With CMB/EVB
Compiling inclusion bootloader requires #define STANDALONE commented out. actual downloader remains same. Using downloader CMB/EVB requires that #define USING_EVB commented out. Also, CMB/EVB must master mode that enabled; cannot enabled when board single-chip mode. downloader program actually sets chip selects that CMB/EVB used. board master mode #define USING_EVB commented program being
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
CMB/EVB, program will hang transfer error. possible provide your CMB/EVB removing resistor soldering header. (See Notes details this.) Using with Target Application finished product, volts) must supplied, #define USING_EVB must commented out. shouldn't matter whether part master mode single-chip mode. Also, necessary provide user-defined (clock) setup routine. call user_set_PLL() code when #define USING_EVB commented out. compile will generate error this routine does exist removed. This serves reminder take care clock properly when using downloader EVB/CMB. interface ports also needs considered. RS-232 transceiver required between ports MMC2107. (See Notes possible transceiver setup.) Before using downloader, S-records FLASH data must processed downloader recognize data programmed only page (64-byte) boundaries. This processing page aligns data makes sure that only complete pages data sent. This processing also done that terminal program blind download with pauses between lines. Additionally, processing reduces size downloader programmer eliminating need interpret page align S-record directly. processing program short Perl script included .zip file named sikadown.pl. program command line program used with this format:
sikadown.pl inputfile.elf.s outputfile.txt
Freescale Semiconductor, Inc.
Processing S-Record
Where inputfile.elf.s S-record convert outputfile.txt name output file. Setting Downloader Open terminal program (such HyperTerminal) connection whatever port want baud rate that FLASH downloader program (original value 19,200). port terminal needs 8/N/1 mode with least
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note FLASH Downloader
75-ms pause between lines. Notes about using HyperTerminal. target board then turned Programming FLASH After program started, terminal program should display:
MMC2107 (Sika) FLASH Programmer
Hitting (question mark symbol) will display list available options:
Freescale Semiconductor, Inc.
MMC2107 (Sika) FLASH Programmer download FLASH: bulk erase necessary Make sure delay time between lines least Type Send S-record (processed with perl script "sikadown.pl") text file Program FLASH Verify FLASH bulk erase FLASH
procedure program FLASH described. Erase FLASH necessary. Type (lowercase then download processed S-record text file. there error during programming downloader will report error message what page error occurred additionally verify FLASH programming successful, type (lowercase resend S-record. downloader will check file against contents FLASH. page does verify, will show error message.
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note Compiling Using Example Project
This section details compile example program downloader. Figure shows complete compile process .txt file ready downloaded with downloader.
DOWNLOADER SOURCE
COMPILE WITH CODEWARRIOR
Downloader.elf.s S-RECORD
s2asm.pl
Freescale Semiconductor, Inc.
INCLUDE EXAMPLE SOURCE
downloader.s ASSEMBLY FILE
EXAMPLE SOURCE
COMPILE WITH CODEWARRIOR
example.elf.s S-RECORD
sikadown.pl
example.txt READY DOWNLOADED WITH DOWNLOADER
Figure Compile Process Compiling Downloader with Bootloader Follow these steps compile downloader.
NOTE:
Skip this section downloader.s file example\bootloader directory hasn't been changed. Make sure that #define STANDALONE commented downloader.c file. This will force program baud rate clock frequency information from saved location FLASH. Compile program. this case, output name should downloader.elf. name output file, Base Project settings->Target->Mcore Target. addition, make
AN1756
More Information This Product, www.freescale.com
MOTOROLA
Application Note Compiling Using Example Project
sure that S-record will generated checking Generate Srecord File Base Project settings->Linker->Mcore Linker.
NOTE:
maximum size file should which indicates limit size S-record generated will named downloader.elf.s. This needs processed Perl script that converts into file compiling into main program. Perl script called s2asm.pl included .zip file. script format
Freescale Semiconductor, Inc.
s2asm.pl downloader.elf.s downloader.s
Where downloader.elf.s name input file downloader.s name output file. This will generate downloader.s assembly file, which needs copied into example\bootloader directory.
NOTE:
output name important because start label assembly generated from code that copies downloader into depends that label. portion generated code
File: downloader.s Generated s2asm v0.1 9/27/2000
#include "copyblock.h" .data .export _downloader_s_start: .long .byte .byte .byte .byte .byte 0x00800000 0xFA 0x00 0x80 0x00 0x04 _downloader_s_start
this section code, start label named _downloader_s_start. assembly language copy routine copyblock.h depends that label being named correctly. snippet copyblock.h
load value start downloader program r7,_downloader_s_start load first address copy to*/ ld.w r1,(r7,0)
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
Compiling Example Program Follow these steps compile example program. After making sure downloader.s file example\bootloader\ directory, project needs compiled. This project also needs generate S-record download into FLASH. (See Notes compiling bootloader.) Finally, S-record into FLASH. have FLASH downloader that; otherwise, generated Srecord through sikadown.pl script downloader download processed S-record detailed description downloader.
Freescale Semiconductor, Inc.
Using Example Program
After example program loaded into FLASH, reset part following should appear terminal program:
MMC2107 FLASH Programmer Bootloader start FLASH Programmer Otherwise wait seconds main program.
This will give user seconds start FLASH downloader just wait main program. example main program just infinite loop that echoes back characters that sent terminal program.
NOTE:
program boot FLASH, necessary make sure that CodeWarrior currently debug session flip power switch CMB/EVB first time. After that, reset switch worked.
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Including Bootloader Another Project
Including Bootloader Another Project
include bootloader FLASH programmer another project, copy \bootloader \sci_util directories into project directory, then include bootloader.h call bootloader with port, baud rate, clock frequency being used before main program. example program meant possible setup, with main() routine calling bootloader then calling "real" main routine. Removing bootloader from program only requires commenting call bootloader. bootloader adds about overall program. Once project with bootloader FLASH programmer compiled into project written into FLASH, used download project again again. project will have bootloader downloader embedded will redownloaded with each version program.
Freescale Semiconductor, Inc.
Notes
Free software specifications helpful using this application note available World Wide Web.
Perl
free version Perl Windows available through ActiveState Tool Corp. company's site. ActiveState sells many Perl-related development tools, distribution Perl (free use). company calls distribution ActivePerl, found Products sections site.
RS-232 Transceiver
Several chips available construction transceiver. aspect ability operate 3.3-V level MMC2107.
ActivePerl trademark ActiveState Tool Corp.
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
Motorola surface mount part, MC145583V, which used CMB/EVB. Specifications available Motorola site, www.motorola.com. Maxim Integrated Products, Inc. 20-PIN part, MAX218, that might more convenient hand wiring test board. Specification documentation available Maxim site. transceiver circuit could included custom board simply interface when programming FLASH needed (for instance, separate board).
Freescale Semiconductor, Inc.
HyperTerminal
pause between line setting found setup HyperTerminal. working setup HyperTerminal included .zip file sikacom1.ht sikacom2.ht respectively. Both 19,200 baud. Make sure serial cable connected correct device When using CMB/EVB2107, port refers SCI1 port refers SCI2.
Setting EVB/CMB External Source
EVB/CMB modified accept optional external VPP.
XILINX
LEDs
CPLD
Connection point externally supplied Board-supplied VPP, volts Ground point
Figure Detail EVB/CMB This procedure recommended only have fair amount confidence your soldering ability person doing soldering).
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Notes
NOTE:
overheat board, could possibly damage multi-layer board. Remove resistor from back board (behind area shown Figure Solder headers into J14, J15, optionally connection ground). Attach external J14. careful connect J15, especially when Prog There resistor between output voltage supply, probably wouldn't damage anything, better safe than sorry. board-supplied VPP, simply jumper between J15. Note that there convenient source volts board breadboard area near serial ports. header soldered into 5-volts section jumper wire from will provide singlechip mode.
Freescale Semiconductor, Inc.
AN1756 MOTOROLA
More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note Code Listings
Table contains summary code listing entries that appear this application note. Table Code Listing Summary
File \example\sikadown.pl Description record converter downloader Converts records assembly FLASH programming/erasing routines Startup file downloader Main program downloader program Bootloader routines Header bootloader.c Assembly language copy routine routines Header sci_util.c Main file example application Startup file main application
Freescale Semiconductor, Inc.
\example\s2asm.pl \example\downloader\startup.s \example\sci_util\sci_util.c \example\sci_util\sci_util.h \example\main.c \example\startup.s
Perl Scripts \example\sikadown.pl
#!/usr/local/bin/perl strict; $versioninfo "sikadown v0.1 9/12/2000 AM"; $infile=""; $outfile=""; $aline=""; $count=64; $lastaddress; $address; @bytes; ($length,$i,$j); $firsttime=1;
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
$lineid; $addstr=""; $ARGV[0] go_die(); $ARGV[1] go_die(); $infile $ARGV[0]; $outfile $ARGV[1]; open (INFILE, $infile) go_die("Can't open $infile read",1); open (OUTFILE, ">$outfile") go_die("Can't open $outfile write",1);
Freescale Semiconductor, Inc.
print print print print
"$versioninfo\n"; "infile: $infile\n"; "outfile: $outfile\n"; "-\n";
chomp ($aline=<INFILE>); unless ($aline=~ /^S0/) go_die("$infile S-record",1); while(1) unless(($aline=<INFILE>) (!($aline=~/^S7/))) {#as long have line line while ($count <64){ #finish page print OUTFILE "FF"; $count++; print OUTFILE "\n"; print OUTFILE "99"x68; #address 99999999 file print OUTFILE "\n"; go_die ("S-Record end\n",1) chomp($aline); #get address line #print "$aline\n"; unpack"A2A2A8"."A2"x300,$aline; $length=hex($length); $length-=5; address, checksum #print "$length\n"; $address=hex($address); #print "$address\n";
#subtract account length
unless ($firsttime){ ($lastaddress==$address){ elsif print (64-$count); print "\n"; printf %X\n",$lastaddress, $address; print OUTFILE "FF"; $count++; else while ($count <64){ #finish page print OUTFILE "FF"; $count++;
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
print OUTFILE "\n" else $firsttime=0; $i=0; while ($i<$length) ($count==64){ ($address #make sure we're page aligned $addstr sprintf("%X", ($address ($address %64) print OUTFILE $addstr; ($j=1; $j<=$address %64; $j++) print OUTFILE "FF"; $count $address else $addstr=sprintf("%X",$address); print OUTFILE $addstr; printf OUTFILE "%8.lx",$address;#print address $count=0; print OUTFILE "$bytes[$i]"; $i++; $count++; $address++; if($count print OUTFILE "\n"; $lastaddress=$address; #save address #go_die("test");
Freescale Semiconductor, Inc.
go_die my($message,$supressformat)=@_; ($message) {print "$message";} close (INFILE); close (OUTFILE); unless ($supressformat) print "format \n"; print sikadown <s-file> <outfile>\n"; else print "-\n"; ("\n");
\example\s2asm.pl
#!/usr/local/bin/perl File: s2asm Purpose: Perl script that takes .elf.s translates into assembly language file that contains data record
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
Freescale Semiconductor, Inc.
This compile program ram, translate with this program include program that goes flash, then copy block data from flash into program. format created assembly file .long [starting address write .byte [number bytes until next address] .byte [first byte] .byte [last byte line] .long [second starting address] .byte [number bytes] .long 0x99999999 (indicates last chunk memory) label creates reference data output filename with replaced with '_start' appended base_s.s _base_s_s_start puts #include "copyblock.h" which contains code copy block code into from flash. named file CodeWarrior project wouldn't compile itself. strict; $versioninfo "s2asm v0.1 9/27/2000 AM"; $infile=""; $outfile=""; $aline=""; $count; $address; @bytes; ($length,$i,$j); $firsttime=1; $lineid;
$label; $addstr=""; $ARGV[0] go_die(); $ARGV[1] go_die(); $infile $ARGV[0]; $outfile $ARGV[1]; open (INFILE, $infile) go_die("Can't open $infile read",1); open (OUTFILE, ">$outfile") go_die("Can't open $outfile write",1);
print print print print
"$versioninfo\n"; "infile: $infile\n"; "outfile: $outfile\n"; "-\n";
chomp ($aline=<INFILE>); unless ($aline=~ /^S0/) go_die("$infile S-record",1);
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
print OUTFILE "\/* File: $outfile *\/\n"; print OUTFILE "\/* Generated $versioninfo *\/\n"; print OUTFILE "\n\n"; $label=$outfile; $label=~s/\./_/g; $label="_".$label."_start";
#replace with
Freescale Semiconductor, Inc.
print OUTFILE "#include \"copyblock.h\"\n"; print OUTFILE "\t.data\n"; print OUTFILE "\t.export\t$label\n"; print OUTFILE "$label:\n"; #print OUTFILE "\t.long\t$label\n"; #format will .long address copy .byte bytes copy followed appropriate number bytes will marked .long 0x99999999 while(1){ unless($aline=<INFILE>){ print OUTFILE "\t.long\t0x99999999\n"; go_die("end record reached without line encountered",1); chomp($aline); ($aline=~/S7/) print OUTFILE "\t.long\t0x99999999\n"; go_die("end record reached",1); unpack"A2A2A8"."A2"x300,$aline; $length=hex($length); $length-=5; #subtract account length address, checksum print OUTFILE "\t.long\t0x$address\n"; printf OUTFILE "\t.byte\t0x%X\n",$length; ($count=0; $count<$length; $count++) print OUTFILE "\t.byte\t0x$bytes[$count]\n"; go_die my($message,$supressformat)=@_; ($message) {print "$message\n";} close (INFILE); close (OUTFILE); unless ($supressformat) print "format \n"; print s2asm <s-file> <outfile>\n"; else print "-\n"; ("\n");
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
Downloader Code FLASH Programming/Erasing Routines
//Desc: Flash programming Sika //Author: Billy //Date: 10-17-2000*/ #include "sikaflash.h"
Freescale Semiconductor, Inc.
********* bulk_erase bulk erase block whole array, shadow erase with block send clock frequency block erase (0-7) number bigger than erase whole array. ********/ bulk_erase(INT8U clockfreq, INT8U block) INT32Upulse; /*pulse number*/ INT32Uver_add;/*verify address*/ INT32U erase_start;/*start erase*/ INT32U erase_end;/*end erase INT8Uclksc_num; /*numerator denominator clock scalar (R)*/ INT8Uclksc_den /*-*/ reg_CMFRCTL.reg 0x00000000;/* reset reset state (just sure)*/ reg_CMFRMCR.reg 0x000000FF;/* reset CMFR_MCR reset state (just sure) start addresses (block>7) want erase whole array*/ erase_start 0x00000000; erase_end 0x0001FFFF; else erase_start block 0x4000;/* blocks erase_end erase_start 0x3FFF; reg_CMFRMTR.bit.PAWS /*Set PAWS[2:0]=111 (disable firmware PWM) reg_CMFRMCR.bit.PROTECT PROTECT_NONE;/* PROTECT protect none /*determine SCLKR[2:0], CLKPE N=15 (clockfreq clksc_num reg_CMFRCTL.bit.SCLKR /*SCLKR[2:0]=b001;*/ else (clockfreq<=18) clksc_num clksc_den
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
reg_CMFRCTL.bit.SCLKR /*SCLKR[2:0]=b010;*/ else (clockfreq<=24) clksc_num reg_CMFRCTL.bit.SCLKR /*SCLKR[2:0]=b011;*/ else (clockfreq<=33) clksc_num reg_CMFRCTL.bit.SCLKR /*SCLKR[2:0]=b100;*/
Freescale Semiconductor, Inc.
Find clkpm pulse pulse width System Clock Period (clksc_num/clksc_den) reg_CMFRCTL.bit.CLKPM reg_CMFRCTL.bit.ERASE 1;/* ERASE (block>7) erasing whole array*/ reg_CMFRCTL.bit.BLOCK 0xFF;/* blocks erase else reg_CMFRCTL.bit.BLOCK (1<<block);/* block erase reg_CMFRCTL.bit.SES start erase sequence (*(volatile INT32U *)(erase_start)) 0xffffffff; erase interlock write*/
pulse=1; while (pulse MAX_ERASE_PULSE) (pulse<=PULSE1) {reg_CMFRMTR.reg 0x00000c00;} /*set NVR=1, PAWS=100*/ else (pulse<=PULSE2) {reg_CMFRMTR.reg 0x00000d00;}/*set NVR=1, PAWS=101*/ else (pulse<=PULSE3){reg_CMFRMTR.reg 0x00000e00;}/*set NVR=1, PAWS=110*/ else (pulse<=PULSE4){reg_CMFRMTR.reg 0x00000f00;}/*set NVR=1, PAWS=111*/ else (pulse<=PULSE5){reg_CMFRMTR.reg 0x00000400;}/*set NVR=0, PAWS=100*/ else (pulse<=PULSE6){reg_CMFRMTR.reg 0x00000500;}/*set NVR=0, PAWS=101*/ else (pulse<=PULSE7){reg_CMFRMTR.reg 0x00000600;}/*set NVR=0, PAWS=110*/ else {reg_CMFRMTR.reg 0x00000700;}/*set NVR=0, PAWS=111*/ reg_CMFRCTL.bit.EHV /*set EHV*/ while (reg_CMFRCTL.bit.HVS);/*wait clear*/ reg_CMFRCTL.bit.EHV /*clear EHV*/ /*margin verify*/ (pulse PULSE_BEFORE_CHECK) /*if point want start margin reads*/ ver_add erase_start; while (ver_add erase_end)/* margin verify loop address doesn't read ones, break then handle problems ((*(volatile INT32U (ver_add)) 0xffffffff) break; ver_add+=4; margin read passed (ver_add erase_end) have gone through whole area erase break; break while loop
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
pulse++;/* next pulse /*end while (pulse MAX_ERASE_PULSE)
reg_CMFRCTL.reg 0x00000000;/* reset reset state reg_CMFRMCR.reg 0x000000FF;/* reset CMFR_MCR reset state (ver_add erase_end)/* didn't make block erase*/ return FALSE return false*/ else return TRUE; otherwise return true program_page() program page, clockfreq clock frequency address starting address page flash dataloc starting address page program_page(INT8U clockfreq, INT32U address, INT32U dataloc) INT8U i=0; counter INT32U curr_add address;/* holds current address programmed INT32Udata_add dataloc; holds current address read from INT32Upulse number pulses
Freescale Semiconductor, Inc.
INT8Uall_programmed 0;/* programmed INT8Uword_programmed 0;/* individual word programmed INT8Uclksc_num; INT8Uclksc_den /*numerator denominator clock scalar (R)*/
volatile INT32U junk; /*make this volatile doesn't optimized away somehow*/ INT8Uclkpm_250us; INT8Uclkpm_100us; INT8Uclkpm_50us; /*-*/ reg_CMFRCTL.reg 0x00000000;/* reset reset state (just sure)*/ reg_CMFRMCR.reg 0x000000FF;/* reset CMFR_MCR reset state (just sure) reg_CMFRMTR.bit.PAWS /*Set PAWS[2:0]=111 (disable firmware PWM) reg_CMFRMTR.bit.GDB= 1;/*set GDB=1*/ reg_CMFRMCR.bit.PROTECT PROTECT_NONE;/* PROTECT protect none /*determine SCLKR[2:0], CLKPE (clockfreq clksc_num reg_CMFRCTL.bit.SCLKR /*SCLKR[2:0]=b001;*/ else (clockfreq<=18) clksc_num clksc_den
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
reg_CMFRCTL.bit.SCLKR /*SCLKR[2:0]=b010;*/ else (clockfreq<=24) clksc_num reg_CMFRCTL.bit.SCLKR /*SCLKR[2:0]=b011;*/ else (clockfreq<=33) clksc_num reg_CMFRCTL.bit.SCLKR /*SCLKR[2:0]=b100;*/
Freescale Semiconductor, Inc.
Find clkpm 250uS, 100uS 50uS pulse width System Clock Period (clksc_num/clksc_den) (1/PW) keep calculations above /*for 250us*/ clkpm_250us /*for 100us*/ clkpm_100us /*for 50us*/ clkpm_50us
ERASE remains clear*/ reg_CMFRCTL.bit.CLKPM clkpm_250us;/*set initial CLKPM*/ determine block we're mask lower bits, which leaves block number bits [16:14], shift right block number Shift left resulting block number form mask. (this only works with blocks like MMC2107) reg_CMFRCTL.bit.BLOCK ((address 0x0001c000) /*set reg_CMFRCTL.bit.SES=1; /*now start programming page*/ /*write buffer*/ (i=0;i<64;i++)/*page words, bytes*/ (*(volatile INT8U (curr_add)) (*(volatile INT8U (data_add)); curr_add++; data_add++; all_programmed FALSE; /*initialize flag*/ program while (pulse <=MAX_PROG_PULSE) change voltages according which step on*/ (pulse PROG_STEP8) /*don't waste time past when stuff changes*/
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
Freescale Semiconductor, Inc.
(pulse PROG_STEP1) reg_CMFRMTR.reg 0x00000c20;/* else (pulse PROG_STEP2) reg_CMFRMTR.reg 0x00000d20;/* else (pulse PROG_STEP3) reg_CMFRMTR.reg 0x00000e20;/* else (pulse PROG_STEP4) reg_CMFRMTR.reg 0x00000f20;/* else (pulse PROG_STEP5) reg_CMFRMTR.reg 0x00000420;/* else (pulse PROG_STEP6) reg_CMFRMTR.reg 0x00000520;/* else (pulse PROG_STEP7) reg_CMFRMTR.reg 0x00000620;/* else (pulse PROG_STEP8) reg_CMFRMTR.reg 0x00000720;/*
NVR=1, PAWS=100, GDB=1 NVR=1, PAWS=101, GDB=1 NVR=1, PAWS=110, GDB=1 NVR=1, PAWS=111, GDB=1 NVR=0, PAWS=100, GDB=1 NVR=0, PAWS=101, GDB=1 NVR=0, PAWS=110, GDB=1 NVR=0, PAWS=111, GDB=1
/*do pulse*/ reg_CMFRCTL.bit.EHV 1;/*set EHV*/ while (reg_CMFRCTL.bit.HVS); /*wait clear*/ change pulse width needed*/ (pulse PROG_50US) going 50uS pulses*/ reg_CMFRCTL.bit.CLKPM clkpm_50us; else (pulse PROG_100US)/* going 100uS pulses*/ reg_CMFRCTL.bit.CLKPM clkpm_100us; reg_CMFRCTL.bit.EHV 0;/*clear EHV*/ margin verify loop curr_add address; all_programmed FALSE; i=0; while(i<16)/* check words page check programmed, then break loop*/ ((*(volatile INT32U (curr_add))) 0x00000000 break; curr_add+=4; i++; (i<8)/* didn't make second half page*/ reading second half page critical margin read, make sure this doesn't optimized away some junk ((*(volatile INT32U (address+32))); /*do dummy read*/ else (i==16)/*else through pages*/ all_programmed TRUE;/* flag true break; pulse++; while (pulse <=MAX_PROG_PULSE)
reg_CMFRCTL.reg 0x00000000;/* reset CMFRCTL
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
reg_CMFRMCR.reg 0x000000FF;/* reset CMFRMCR return all_programmed;
Header File sikaflash.c
sikaflash.h header sikaflash.c*/ 10-17-2000*/ #ifndef SIKAFLASH_H #define SIKAFLASH_H
Freescale Semiconductor, Inc.
#include "mmc2107.h"
FLASH Defines #define FLASHSTART #define FLASHEND #define FLASHSIZE #define BLOCKSIZE #define PROTECT_NONE programming defines #define PULSE_BEFORE_CHECK margin read #define MAX_ERASE_PULSE #define PROG_STEP1 #define PROG_STEP2 #define PROG_STEP3 #define PROG_STEP4 #define PROG_STEP5 #define PROG_STEP6 #define PROG_STEP7 #define PROG_STEP8 50us pulses*/ #define PROG_STEP9 100us pulses*/ #define PROG_50US #define PROG_100US #define MAX_PROG_PULSE
0x00000000 0x0001FFFF/* 128K flash 0x00020000 0x4000/* size block 0x00/*mask protect none
7/*number erase pulses before first 28/*max erase pulses /*first pulse count when NVR=1, PAWS=100 /*first pulse count when NVR=1, PAWS=101 /*first pulse count when NVR=1, PAWS=110 /*first pulse count when NVR=1, PAWS=111 /*first pulse count when NVR=0, PAWS=100 /*first pulse count when NVR=0, PAWS=101 /*first pulse count when NVR=0, PAWS=110 /*first pulse count when NVR=0, PAWS=111 /*first pulse count when NVR=0, PAWS=111
16/*pulse count before switching 50US*/ 96/*pulse count before switching 100US*/ 1000 /*max program pulses
#define #define #define #define
MAX_NVR1_PAWS100_1 MAX_NVR1_PAWS101_2 MAX_NVR1_PAWS110_3 MAX_NVR1_PAWS111_4
/*max pulse count /*max pulse count /*max pulse count /*max pulse count
when when when when
NVR=1, NVR=1, NVR=1, NVR=1,
PAWS=100 PAWS=101 PAWS=110 PAWS=111
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
#define MAX_NVR0_PAWS100_5 #define MAX_NVR0_PAWS101_6 #define MAX_NVR0_PAWS110_7 #define MAX_NVR0_PAWS110_8_50US 50us pulses*/ #define MAX_PROG_PULSE 100us pulses*/ /*erase #define #define #define #define #define #define #define used #define #define #define #define #define #define #define #define #define defines*/ PULSE1 PULSE2 PULSE3 PULSE4 PULSE5 PULSE6 PULSE7 with bulk_erase() routine BLOCK0 BLOCK1 BLOCK2 BLOCK3 BLOCK4 BLOCK5 BLOCK6 BLOCK7 ALLBLOCKS
/*max pulse count when NVR=0, PAWS=100 /*max pulse count when NVR=0, PAWS=101 /*max pulse count when NVR=0, PAWS=110 /*max pulse count when NVR=0, PAWS=111
1000 /*max program pulses (after 96th pulse NVR=0, PAWS=111
Freescale Semiconductor, Inc.
0x00000001/*used pulse counting*/ 0x00000002 0x00000003 0x00000004 0x00000005 0x00000006 0x00000007
/*prototypes*/ bulk_erase(INT8U clockfreq, INT8U block); program_page(INT8U clockfreq, INT32U address, INT32U dataloc); #endif /*#ifndef SIKAFLASH_H*/
example\downloader\startup.s Startup File Downloader
startup.s MCore Startup code. Initialize Stack Pointer register (ie. R0); Init section Call main() Following defined Linker. .extern _sbss .extern _ebss .extern _stack_begin .extern _stack_end //.extern _call_static_initializers .extern main .text .export .export
_start _program_end
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
exception interupt vectors .align //set .long //exceptions .long .long .long .long .long .long .long .long .long .long .long .long .space .long .long .long .long .space //normal interupts .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long _start//0 reset vector 0x0000//1 Misaligned Access 0x0000//2 Access error 0x0000//3 Divide zero 0x0000//4 Illegal instruction 0x0000//5 Privilage violation 0x0000//6 Trace exception 0x0000//7 Breakpoint exception 0x0000//8 Unrecoverable Error 0x0000//9 Soft Reset 0x0000//10 /INT autovector 0x0000//11 /FINT autovector 0x0000//12 Hardware accelerator 0x0C//(13-15) reserved vectors 0x0000// TRAP instruction 0x0000// TRAP instruction 0x0000// TRAP instruction 0x0000// TRAP instruction 0x2C//(20-31) reserved vectors 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority lowest highest
Freescale Semiconductor, Inc.
vector vector vector vector
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
Freescale Semiconductor, Inc.
//fast interupts .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long
0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000//
(priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority
lowest highest*/
_start program entry point. .function "_start", _start, _end_start _start _start: Just make "_stack_end" appear final ELF. _stack_end init stack pointer. _stack_begin r0,r8 Initialize section _sbss _ebss cmphs r5,r6 _call_main subi r6,1 r4,r4 _zero_bss: st.b r4,(r6,0) cmplt r5,r6 loopt _zero_bss //_call_static_init: jbsr _call_static_initializers _call_main: jbsr main pull main()
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
bkpt _program_end: bkpt bkpt //_exit: bkpt bkpt _end_start: .literals
Freescale Semiconductor, Inc.
Main Program Downloader Program
File: downloader.c Author: Billy Eno, Product Engineer, Motorola Microcontroller Division flash downloader. This allows flash MMC2107 (Sika) programmed through serial port. S-record that been massaged with Perl script "sikadown.pl" sent terminal program (like Hyperterminal) text file program will interpret file program flash designed either stand alone, with STANDALONE #define uncommented part bootloader program. program part bootloader program, retrieves port use, clock frequency baudrate from flash 0x180,0x181 0x182 respectively. These locations first four bytes after full vector table that starts 0x0000. #include "sci_util.h" #include "sikaflash.h" #include "mmc2107.h" uncomment STANDALONE flash programmer itself #define STANDALONE #define SA_PORT #define SA_BAUD 19200 #define SA_FREQ /*******************/ comment USING_EVB disable write enable #define USING_EVB; /*******************/ void void void void command_loop(INT8U port, INT8U clockfreq); program_flash(INT8U port, INT8U clockfreq); get_a_page(INT8U port, INT32U addr, char save_addr[], INT8U data[]); verify_flash(INT8U port);
command_loop Command loop flash programmer. void command_loop(INT8U port, INT8U clockfreq) char inny;
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
while(1) send_string(port, "\n\r: inny get_a_byte(port); send_byte(port, inny); instrunctions (inny=='?') send_string(port, "\n\rTo download flash:"); send_string(port, "\n\r bulk erase necessary"); send_string(port, "\n\r Make sure delay time between lines"); send_string(port, "\n\r least ms"); send_string(port, "\n\r Type f"); send_string(port, "\n\r Send S-record (processed with perl"); send_string(port, "\n\r script \"sikadown.pl\") text file"); send_string(port, "\n\r"); send_string(port, "\n\rf Program flash"); send_string(port, "\n\rv Verify flash"); send_string(port, "\n\rb bulk erase flash"); send file else (inny=='f') send_string(port, "\n\rProgram flash."); send_string(port, "\n\rSend file now.\n\r"); program_flash(port,clockfreq); bulk erase flash else (inny=='b') send_string(port, "\n\rErasing flash."); send_string(port, "\n\rDone."); else send_string(port, "\n\rError Erasing flash."); verify program else (inny=='v') send_string(port, "\n\rVerify flash."); send_string(port, "\n\rSend file now.\n\r"); verify_flash(port); otherwise tell user instructione else send_string(port, "\n\r type help"); program_flash program flash with massaged S-record text file must sent with sufficient pauses between lines allow flash program void program_flash(INT8U port, INT8U clockfreq) INT32U addr=0; /*address program*/
Freescale Semiconductor, Inc.
AN1756 MOTOROLA
More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
INT8U data[64]; /*data program*/ location data /*save address string*/
INT32U dataloc; char save_addr[9]; while (addr!=0x99999999) dataloc (INT32U)(&data); (addr!=0x99999999)
location data
send_string(port, "\n\rError page address:"); send_string(port, save_addr);
Freescale Semiconductor, Inc.
send_string(port, "."); send_string(port, "\n\rDone."); verify_page verify page flash INT8U verify_page(INT32U addr, INT8U data[]) INT8U page bytes long (i=0; i<64; i++) (*(volatile INT8U*) (addr)) data[i] return FALSE; addr++; return TRUE; verify_flash verify that downloaded program correct flash void verify_flash(INT8U port) INT32U addr=0; /*address program*/ INT8U data[64]; /*data program*/ char save_addr[9]; while (addr!=0x99999999) /*save address string*/
(addr!=0x99999999) (!verify_page(addr,data)) send_string(port, "\n\rError page address:"); send_string(port, save_addr); send_string(port, "."); send_string(port, "\n\rDone.");
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
trans_hex translates (ascii) digit into numerical value, must capital char trans_hex(char adigit) adigit '0'; subtract take care values 0->9 (adigit value over subtract A->F adigit return adigit; void get_a_page(INT8U port, INT32U addr, char save_addr[], INT8U data[]) INT32U temp=0; char char char INT8U aline[136]; addrstr[8]; indata[128];
Freescale Semiconductor, Inc.
get_bytes(port, 8,addrstr); get_bytes(port, 128,indata); get_a_byte(port); /*get line character*/
*addr=0; /*translate address numeric save character representation*/ (i=0;i<8;i++) save_addr[i]=addrstr[i]; save address string*/ *addr trans_hex(addrstr[i]); translate digit in*/ (i<7) *addr<<=4; /*shift i<7*/ save_addr[i]=0; /*add string*/ /*translate digits*/ (i=0; i<128; i++) indata[i] trans_hex(indata[i]); /*calculate bytes*/ (i=0; i<128; i=i+2) data[i/2] (indata[i]<<4)+(indata[i+1]); return; main(void) INT8U INT8U INT16U port; clockfreq; baud;
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
#ifdef STANDALONE stand alone stand alone settings port SA_PORT; baud SA_BAUD; clockfreq SA_FREQ; #else otherwise setup from flash*/ port (*(volatile INT8U*) (0x180)); clockfreq (*(volatile INT8U*) (0x181)); baud (*(volatile INT16U*) (0x182)); #endif USING Chip selects enabled*/ #ifdef USING_EVB
Freescale Semiconductor, Inc.
/*Chip Select Control CSR0 reg_CSCR0.reg 0x3403; /*Chip Select Control CSR1*/ reg_CSCR1.reg 0x3103; /*Chip Select Control CSR2*/ reg_CSCR2.reg 0x3403; /*Chip Select Control CSR3*/ reg_CSCR3.reg 0x3403; /*turn Vpp*/ (*(volatile INT8U*) (0x807ffffd)) 0x10; /*setup PLL, this assumes 8MHz input clock produces 32MHz clock*/ reg_SYNCR.reg 0x2000; #else /*this here that error will generated used user-defined (clock) routine defined*/ user_set_PLL(); #endif disable watchdog timer reg_WCR.bit.EN setup_sci(port, baud, clockfreq); send_string(port, "\n\rMMC2107 (Sika) Flash Programmer"); command_loop(port, clockfreq); return;
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
Bootloader Code Bootloader Routines
File: bootloader.c Author: Billy Eno, Product Engineer, Motorola Microcontroller Division bootloader MMC2107. Waits input from specified port recieved loads into executes another program, this case flash programmer #include "mmc2107.h" #include "bootloader.h"
Freescale Semiconductor, Inc.
private prototypes void start_timer(INT8U clockfreq, INT8U seconds); BOOLEAN timeup(); bootloader Waits seconds input from pressed calls _copyblock() flash programmer otherwise returns "main" program void bootloader(INT8U port, INT16U baud, INT8U clockfreq) INT8U /*counter*/ char junk; setup_sci(port, baud, clockfreq); send_string(port, "\n\rMMC2107 Flash Programmer Bootloader\n\r"); send_string(port, "\n\rHit start Flash Programmer"); send_string(port, "\n\rOtherwise wait seconds the"); send_string(port, "\n\rmain program.\n\r"); (i=0;i<10;i++) start_timer(clockfreq, while (!timeup()); junk check_for_byte(port); (junk /*if hit, break, programmer*/ break; send_byte(port, '.'); (junk==0) return; just return main program else _copyblock(); copy flash programmer into ram, execute return;
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
start_timer start PIT1 number seconds maximum seconds 32MHz maximum seconds 16MHz void start_timer(INT8U clockfreq, INT8U seconds) INT16U counter seconds counter value*/ /*set with prescalar 32,768, Counter Overwrite, /*Clear flag, Counter Reload, enable*/ reg_PCSR1.reg 0x0F17; reg_PMR1 counter; /*put counter into Modulus Register
Freescale Semiconductor, Inc.
return; timeup time disable timer, return true BOOLEAN timeup() (reg_PCSR1.bit.PIF) flag set, reg_PCSR1.reg 0x0004; /*Disable return TRUE; /*return true else return FALSE;
Header bootloader.c
#ifndef BOOTLOADER_H #define BOOTLOADER_H #include "sci_util.h" prototypes void bootloader(INT8U port, INT16U baud, INT8U clockfreq); #endif
\example\bootloader\copyblock.h Assembly Language Copy Routine
File: copyblock.h Author: Billy Eno, Product Engineer, Motorola Microcontroller Division assembly language routine that copies block data from flash into jumps location held first word data.
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
data load needs created from record perl script 's2asm.pl' statement that includes this file. with other programs, label '_down_s_s_start' changed match start label created assembly file .text .export _copyblock pointer data flash (source) pointer destination (destination) holds remaining number bytes copy intermidiate storage data holds alignment data, number bytes next word boundary saves starting location code holds compare value last address (99999999)*/
Freescale Semiconductor, Inc.
create compare value adding shifting _copyblock: movi lsli addi lsli addi lsli addi lsli addi lsli addi lsli addi lsli addi r9,9 r9,4 r9,9 r9,4 r9,9 r9,4 r9,9 r9,4 r9,9 r9,4 r9,9 r9,4 r9,9 r9,4 r9,9
load value start downloader program r7,_downloader_s_start load first address copy to*/ ld.w r1,(r7,0) this will also location vector, save copy ld.w r8,(r7,0) initialize indicates there four bytes next word boundary*/ movi r6,4 next_address: increment addi load with ld.b increment addi subi next_byte: load data into from flash, store into ld.b r3,(r7,0) st.b r3,(r1,0) next locations addi r7,1 addi r1,1 number bytes starting this loc*/ r7,4 number bytes, will used counter r2,(r7,0) first byte data, decrement r6*/ r7,1 r6,1
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
/*decrement compare zero, reinit true subi r6,1 cmpnei r6,0 skip_reinit movi r6,4 skip_reinit: /*subtract from compare equal zero, branch true subi r2,1 cmpnei r2,0 next_byte /*see word boundary ahead load word*/ /*otherwise, next word boundary, then reinit cmpnei r6,4 load_next_add addu r7,r6 movi r6,4 load_next_add: ld.w cmpne r1,(r7,0) r1,r9 next_address
Freescale Semiconductor, Inc.
just jump location stored first word transfered data ld.w .literals r1,(r8,0)
\example\sci_util\sci_util.c Routines
File: sci_util.c Author: Billy Eno, Product Engineer, Motorola Microcontroller Division sci_utilities that allow text communication between terminal program another SCI) Uses 8/N/1 format. used with either port,any clock frequency baud rate #include "sci_util.h" check_for_byte single byte available arguments port: SCI1 SCI2 char check_for_byte(INT8U port) (port SCI1) (reg_SCI1SR1.bit.RDRF) /*if RDRF set*/ return reg_SCI1DRL; /*return data*/ else return /*otherwise return else (reg_SCI2SR1.bit.RDRF) /*if RDRF set*/ return reg_SCI2DRL; /*return data*/ else return /*otherwise return
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
Freescale Semiconductor, Inc.
get_a_byte wait single byte arguments port: SCI1 SCI2 char get_a_byte(INT8U port) (port SCI1) while (!reg_SCI1SR1.bit.RDRF); /*wait RDRF*/ return reg_SCI1DRL; /*return data*/ else while (!reg_SCI2SR1.bit.RDRF); /*wait RDRF*/ return reg_SCI2DRL; /*return data*/ get_byte wait specific number bytes arguments port: SCI1 SCI2 strlength: number bytes astring: array length strlength void get_bytes(INT8U port, INT16U strlength, char astring[]) for(i=0;i<strlength;i++) astring[i]=get_a_byte(port); return; send_byte send single byte wait TDRE arguments port: SCI1 SCI2 void send_byte(INT8U port, char achar) (port SCI1) reg_SCI1DRL achar; while(!reg_SCI1SR1.bit.TDRE); /*wait TDRE*/ else reg_SCI2DRL achar; while(!reg_SCI2SR1.bit.TDRE); /*wait TDRE*/ return; send_string
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
send null terminated single arguments port: SCI1 SCI2 astring: null terminated string void send_string(INT8U port, char astring[]) INT16U i=0; while (astring[i] 0x00) send_byte(port,astring[i]); i++; while(!reg_SCI1SR1.bit.TC); /*wait (transmission complete)*/ return; setup_sci initialize mode baud rate, then enable arguments port: SCI1 SCI2 baud: baud rate clockfreq: clock frequency void setup_sci(INT8U port, INT16U baud, INT8U clockfreq) INT8U junk; INT16U divisor; calculate divsor based clock freq MHz) baud rate*/ divisor (clockfreq 1000000)/(16*baud); (port SCI1) reg_SCI1BD divisor; reg_SCI1CR1.reg 0x00; reg_SCI1CR2.bit.TE reg_SCI1CR2.bit.RE junk reg_SCI1SR1.reg; /*wait TDRE high (wait while(!reg_SCI1SR1.bit.TDRE); else reg_SCI2BD divisor; reg_SCI2CR1.reg 0x00; reg_SCI2CR2.bit.TE reg_SCI2CR2.bit.RE junk reg_SCI2SR1.reg; /*wait TDRE high (wait while(!reg_SCI2SR1.bit.TDRE);
Freescale Semiconductor, Inc.
/*reset values (8/N/1)*/ /*enable transmitter*/ /*enable reciever*/ /*transmitter actually enabled here*/ preamble)*/
/*reset values (8/N/1)*/ /*enable transmitter*/ /*enable reciever*/ /*transmitter actually enabled here*/ preamble)*/
return;
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
\example\sci_util\sci_util.h Header sci_util.c
#ifndef SCI_UTIL_H #define SCI_UTIL_H #include "mmc2107.h" #define SCI1 #define SCI2 #define #define BAUD4800 #define BAUD9600 #define #define prototypes char char void void void void check_for_byte(INT8U port); get_a_byte(INT8U port); get_bytes(INT8U port, INT16U strlength, char astring[]); send_byte(INT8U port, char achar); send_string(INT8U port, char astring[]); setup_sci(INT8U port, INT16U baud, INT8U clockfreq); BAUD2400 2400 4800 9600
Freescale Semiconductor, Inc.
MHZ16 MHZ32
#endif #ifndef SCI_UTIL_H
Example Application \example\main.c- Main File Example Application
Project: example.mcp File: main.c Author: Billy Eno, Product Engineer, Motorola Microcontroller Division Demonstration flash programmer bootloader. This project calls bootloader that allows user choose between "main program" (just returns) flash programmer that copied into executed. flash programmer allows user download record that been massaged with Perl script. flash programmer seperate project that been compiled then converted assembly data file Perl script. Both bootloader flash programmer also demonstrate port text communication with terminal program. #include "mmc2107.h" #include "bootloader.h"
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
sci_setup.h contains port, baudrate clockfreq used this seperate startup.s values into beginning program flash programmer read values continue communication with terminal program #include "sci_setup.h" void mainprogram(void); main starting point calls bootloader bootloader returns, calls mainprogram() main(void) disable watchdog timer reg_WCR.bit.EN bootloader(SCIPORT, BAUDRATE, CLOCKFREQ); mainprogram(); mainprogram this represents "real" application, does echo back characters void mainprogram(void) char junk; setup_sci(SCIPORT, BAUDRATE, CLOCKFREQ); send_string(SCIPORT, "\n\rNow running main program."); send_string(SCIPORT, "\n\r(all this does echo back characters)\n\r"); while(1) junk=get_a_byte(SCIPORT); send_byte(SCIPORT,junk); return;
Freescale Semiconductor, Inc.
\example\startup.s Startup File Main Application
startup.s MCore Startup code. Initialize Stack Pointer register (ie. R0); Init section Call main() #include "sci_setup.h" Following defined Linker. .extern _sbss .extern _ebss .extern _stack_begin
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
.extern _stack_end //.extern _call_static_initializers .extern main .text .export .export
_start _program_end
exception interupt vectors .align
Freescale Semiconductor, Inc.
//set exception vector table .long //exceptions .long .long .long .long .long .long .long .long .long .long .long .long .space .long .long .long .long .space //normal interupts .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long
_start//0 reset vector 0x0000//1 Misaligned Access 0x0000//2 Access error 0x0000//3 Divide zero 0x0000//4 Illegal instruction 0x0000//5 Privilage violation 0x0000//6 Trace exception 0x0000//7 Breakpoint exception 0x0000//8 Unrecoverable Error 0x0000//9 Soft Reset 0x0000//10 /INT autovector 0x0000//11 /FINT autovector 0x0000//12 Hardware accelerator 0x0C//(13-15) reserved vectors 0x0000// TRAP instruction 0x0000// TRAP instruction 0x0000// TRAP instruction 0x0000// TRAP instruction 0x2C//(20-31) reserved vectors 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority lowest
vector vector vector vector
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
.long .long .long .long .long .long .long .long .long .long //fast interupts .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long .long 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// 0x0000// (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority (priority highest lowest highest
Freescale Semiconductor, Inc.
downloader knows wher find info this also leaves room vbr*/ .org 0x180 _sci_port: .byte SCIPORT _clock_freq: .byte _baud_rate: .short
CLOCKFREQ
BAUDRATE
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
_start program entry point. _start: Just make "_sci_port", "_clock_freq", "_baud_rate" appear final ELF. _sci_port _clock_freq _baud_rate*/ Just make "_stack_end" appear final ELF. _stack_end init stack pointer. _stack_begin r0,r8 Initialize section _sbss _ebss cmphs r5,r6 _call_main subi r6,1 r4,r4 _zero_bss: st.b r4,(r6,0) cmplt r5,r6 loopt _zero_bss //_call_static_init: jbsr _call_static_initializers _call_main: jbsr main pull main() bkpt _program_end: bkpt bkpt //_exit: bkpt bkpt _end_start: .literals .function "_start", _start, _end_start _start
Freescale Semiconductor, Inc.
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
Freescale Semiconductor, Inc.
AN1756 More Information This Product, www.freescale.com MOTOROLA
Application Note Code Listings
Freescale Semiconductor, Inc.
AN1756 MOTOROLA More Information This Product, www.freescale.com
Freescale Semiconductor, Inc. Application Note
Freescale Semiconductor, Inc.
Motorola reserves right make changes without further notice products herein. Motorola makes warranty, representation guarantee regarding suitability products particular purpose, does Motorola assume liability arising application product circuit, specifically disclaims liability, including without limitation consequential incidental damages. "Typical" parameters which provided Motorola data sheets and/or specifications vary different applications actual performance vary over time. operating parameters, including "Typicals" must validated each customer application customer's technical experts. Motorola does convey license under patent rights rights others. Motorola products designed, intended, authorized components systems intended surgical implant into body, other applications intended support sustain life, other application which failure Motorola product could create situation where personal injury death occur. Should Buyer purchase Motorola products such unintended unauthorized application, Buyer shall indemnify hold Motorola officers, employees, subsidiaries, affiliates, distributors harmless against claims, costs, damages, expenses, reasonable attorney fees arising directly indirectly, claim personal injury death associated with such unintended unauthorized use, even such claim alleges that Motorola negligent regarding design manufacture part. Motorola registered trademarks Motorola, Inc. Motorola, Inc. Equal Opportunity/Affirmative Action Employer.
reach
USA/EUROPE/Locations Listed: Motorola Literature Distribution; P.O. 5405, Denver, Colorado 80217. 1-303-675-2140 1-800-441-2447 JAPAN: Motorola Japan Ltd.; SPS, Technical Information Center, 3-20-1, Minami-Azabu, Minato-ku, Tokyo 106-8573 Japan. 81-3-3440-3569 ASIA/PACIFIC: Motorola Semiconductors H.K. Ltd.; Silicon Harbour Centre, King Street, Industrial Estate, N.T., Hong Kong. 852-26668334 Technical Information Center: 1-800-521-6274 HOME PAGE:
Motorola, Inc., 2000
AN1756/D More Information This Product, www.freescale.com

Other recent searches


VIC64 - VIC64   VIC64 Datasheet
Si4376DY - Si4376DY   Si4376DY Datasheet
PSD4235G2 - PSD4235G2   PSD4235G2 Datasheet
HM514260D - HM514260D   HM514260D Datasheet
HCF4041UB - HCF4041UB   HCF4041UB Datasheet
BAS19W - BAS19W   BAS19W Datasheet
BAS21W - BAS21W   BAS21W Datasheet

 

Privacy Policy | Disclaimer
© 2012 Datasheet Archive