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*)

 

 

Volker Rzehak ABSTRACT bootstrap loader (sometimes called bootloa


Datasheet Thumbnail

  

Download PDF



Top Searches for this datasheet



Application Bootstrap Loader MSP430F11x Hardware Software Proposal
Volker Rzehak
ABSTRACT bootstrap loader (sometimes called bootloader) MSP430 derivatives with flash memory allows accessing their embedded memories during prototyping, production, even field. possible download modify code flash memory (electricallyerasable programmable memory) store calibration data other system-relevant data flash memory RAM. This application note describes simple low-cost hardware software solutions access bootstrap-loader functions MSP430F11x devices (F1121, F1101, F112, F110 devices) serial port (RS-232) personal computer (PC). description provided C-source code software routines allows adapting software specific requirements.
MSP/ALP Design
Contents Introduction Bootstrap-Loader Basics Invoking Bootstrap Loader Access Bootstrap Loader Bootstrap-Loader Functions 2.3.1 Unprotected Functions 2.3.2 Protected Functions Hardware Description Power Supply Serial Interface 3.2.1 Level Shifting 3.2.2 Control RST/NMI TEST Pins Parts List
Software Description Global Variables Initialization RS-232 Port Invoking Bootstrap Loader Access Bootstrap Loader 4.4.1 Synchronization 4.4.2 Transmission Frame Calling Bootstrap-Loader Functions Releasing RS-232 Port
SLAA096
Complete Application Error Recovery Patch First Version Bootstrap Loader References Appendix Listings Appendix Layout Suggestion Appendix Demonstration Program Usage List Figures RST/NMI TEST Sequence Start User Program RST/NMI TEST Sequence Start Bootstrap Loader Frame Sent Bootstrap Loader Bootstrap-Loader Interface Schematic Component Placement Layout List Tables Bootstrap Loader UART Settings Bootstrap-Loader Functions Overview Serial-Port Signals Assignments RS-232 Levels Parts List Additional Connectors/Pads Bootstrap-Loader Access Functions Command Line Parameters Program-Flow Modifiers Invocation Examples
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
Introduction
introduction MSP430 derivatives with flash memory (electrically-erasable programmable memory) allows modification data program code matter seconds. Erasure cycles using light clear EPROM longer required. control unit required access these features. Part this control unit bootstrap loader, implemented MSP430 devices with flash memory. Hardware software solutions access loader from provide control simplify bootstrap loader described this report.
Bootstrap-Loader Basics
This section reviews basic principals bootstrap loader. Please documentation MSP430F11x (SLAS256) MSP430F11x1 (SLAS241), application note Features MSP430 Bootstrap Loader MSP430F1121 (SLAA089) more details. bootstrap loader program that allows communication with MSP430 serial link, even when flash memory completely erased. confuse with programs found some digital signal processors (DSP) that automatically load program code (and data) from external memory internal memory DSP. These programs often referred bootstrap loaders, too.
Invoking Bootstrap Loader
MSP430 bootstrap loader does start automatically-a special sequence required RST/NMI TEST pins. user program, with reset vector located memory address 0FFFEh, starts when TEST pulled while RST/NMI goes from high (see Figure Figure shows sequence required start bootstrap loader. Please documentation mentioned previous section more information start-up sequences.
RST/NMI Test/VPP User Program Starts
Figure RST/NMI TEST Sequence Start User Program
RST/NMI Test/VPP Boot Loader Starts Test/VPP Intern
Figure RST/NMI TEST Sequence Start Bootstrap Loader
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
Access Bootstrap Loader
After invoking bootstrap loader using TEST RST/NMI pins, communication established using standard-asynchronous-serial protocol. MSP430 port P1.1 (BSLTX) used transmit data, port P2.2 (BSLRX) used receive data. UART settings shown Table Table Bootstrap Loader UART Settings
SETTING Baudrate Data bits Parity Stop bits VALUE 9600 baud (binary) Even
protocol used communicate with bootstrap loader derived from more complex one; this adds some overhead. First must send synchronization byte. bootstrap loader receives this character correctly, will return acknowledge byte. After successful synchronization, sends frame containing command data. frame (see Figure divided into header section, data section, check-sum bytes. data section always contains least four bytes data: usually start address length, some commands ignore contents interpret differently. case word data bytes), byte order always byte-high byte.
(lo) (hi) (hi) Data Data Data Data Check Address (Start) Length Byte High Byte
Header Section Hdr: Cmd: (Always) Code Requested Function Number Bytes Data Section
Data Section (lo): (hi):
Figure Frame Sent Bootstrap Loader After processing frame, bootstrap loader either returns acknowledge signal, negative acknowledge frame valid, command-failed signal. This command-failed signal issued command allowed.
Bootstrap-Loader Functions
bootstrap loader protected unprotected functions. enable protected functions fully-programmed interrupt-vector table (located address range 0FFE0h 0FFFFh) must sent bootstrap loader. This section gives brief overview commands available. commands their usage described more detail separate document software section this application note.
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
2.3.1
Unprotected Functions
password, enables protected functions Mass erase, completely erases flash memory. Afterwards password access protected functions times 0FFFFh.
2.3.2
Protected Functions
Transmit block, writes data into MSP430's memory. Receive block, reads data MSP430's memory. Erase segment Load program counter, starts execution. Table Bootstrap-Loader Functions Overview
FUNCTION password Mass erase Transmit byte Receive byte Erase Load L1=L2 ADDRESS Flash Start Start Segment Start LENGTH 0A506h 0A502h DATA Password Data byte)
Hardware Description
low-cost hardware presented this application note (Figure consists mainly low-dropout voltage regulator, some inverters, operational amplifier. There also some resistors, capacitors, diodes. complete parts list provided later this section. functional blocks described more detail following subsections.
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
PINHD-1X10
PINHD-2X7 JTAG 0603
LM358D IC3B
SERIAL
P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.0 P2.4 P2.3
330k
MSP430
P2.5 XOUT P2.0 P2.1
330k
PINHD-1X10
PINHEAD
7414 IC2A 7414 IC2B 7414 IC2D
330k
330k BAV70
Quarz CON2 CON1 I-meassure
7414 IC2C
330k
680k
680k
TPS76030 2.2yF 6.3V
680k
BAV70
33yF 33yF BAR43C
IC3A LM358D
100nF 100nF RESET CON3
IC2P
7414 IC2F
IC2E 7414
Figure Bootstrap-Loader Interface Schematic
Power Supply
Power bootstrap-loader hardware supplied RS-232 interface. RS-232 signals (Pin serial connector) (Pin serial connector) should normally deliver positive voltage load capacitor power low-dropout voltage regulator (Texas Instruments TPS76030 LP2980-3.0, equivalent low-dropout regulator). Using fairly capacitor, possible draw short-duration current that higher than driving serial port supply. This feature required program flash memory, example. also possible connect external supply voltage (Vext, CON4), supply power hardware JTAG connector. Diodes should prevent reverse-polarity flow.
Serial Interface
Table shows signals used communicate with bootstrap loader. names refer function seen from example, receives data pin, whereas bootstrap loader needs drive this signal. assignment shown sub-D connector refers connector assembled into seen from outside).
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
Vext CON4
SLAA096
Table Serial-Port Signals Assignments
NAME FULL NAME Receive data Transmit data Data terminal ready Request send Ground SERIAL 3-PIN SUB-D (PC)
3.2.1
Level Shifting
Simple CMOS inverters with Schmitt-trigger characteristics (IC2) used transform RS-232 levels (see Table CMOS levels. Table RS-232 Levels
LOGIC LEVEL RS-232 LEVEL Mark Space RS-232 VOLTAGE LEVEL
Depending overvoltage protection device family selected, excess voltage either conducted 74HC14) 74AHC14). protection diode conducts Vcc, voltage regulator needs compensate overvoltage. Thus 74AHC14 device, which conducts ground (GND), recommended; however, 74HC14 also works well. avoid excessive power dissipation damage protection diodes, series resistors (R1, used limit input current. operational amplifier (IC3) used generate RS-232 levels CMOS levels. level positive input Vcc/2 (1.5-V nominal). level negative input rises above this level, output pulled negative supply operational amplifier (mark). level drops below Vcc/2 output pulled positive rail (space). positive supply operational amplifier same input voltage regulator. separate capacitor (C10) used generate negative-supply voltage. This capacitor charged receiving signal bootstrap-loader hardware (Pin SERIAL connector). During asynchronous serial communication, combination stop start used synchronize sender receiver. After transmission data byte, stop forces transmission line into defined state, which usually logic RS-232 terms, mark. This means that transmission-line voltage negative when there transmission capacitor charged. Diodes used prevent discharge capacitor during transmission. Because protocol used communicate with bootstrap loader half duplex (there only sender time), voltage receiving line negative stable used supply operational amplifier with required voltage.
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
3.2.2
Control RST/NMI TEST Pins
RST/NMI TEST pins MSP430 controlled signals, respectively. already mentioned, these signals must normally deliver positive voltage supply bootstrap-loader hardware. They also used control levels RST/NMI TEST pins. levels RST/NMI TEST during normal operation logic logic respectively. achieve these levels corresponding RS-232 signals power-supply lines, necessary inverters RST/NMI inverter TEST pin. Diodes prevent discharge capacitor allow control RS-232 lines (RTS DTR).
Parts List
Table Parts List
PART JTAG SERIAL
VALUE/ PART NUMBER BAV70 BAV70 BAR43C MSP430F11x TPS76030 74AHC14 LM358D PINHD-1X10 PINHD-1X10 PINHD-2X7 PINHD-2x5
PACKAGE 7243 0805 1206 0805 7243 SOT23 SOT23 SOT23 SO20 SOT23/5 SO14 0603 0603 0603 0603 0603 0603 0603 0603 0603 0603 2X05 2X05 2X07 2X05 RS-232 connector (see Table High-speed double diode High-speed double diode Schottky (alternate: 74HC14 text)
COMMENT
Assemble only with programming adapter: forces Vext Access pins 11-20 MSP430F11x Access pins 1-10 MSP430F11x
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
Table Additional Connectors/Pads
NAME CON1 CON2 CON3 CON4 DESCRIPTIVE NAME I-measure Quartz RESET Vext LAYOUT 0805 0805 0805 0805 COMMENT current measurements connect optional quartz connect optional reset button connect optional external-power supply
Software Description
This section explains basic sequences required access bootstrap loader using RS-232 interface code presented here written language using 32-bit WindowsAPI calls under Microsoft Visual C++5.0 should also work seamlessly under version 6.0). code originally written 16-bit Windows ported 32-bit Windows (Win32TM, Windows 95/98TM, Windows NTTM) mainly replacing function names. Some Win32 features were used maintain portability. commercial library used instead Windows interface. detailed description titled Serial Communications Win32 available online consult online documentation Visual from Microsoft development network library. Please consult Windows software development (SDK) documentation detailed description functions used. Complete listings found Appendix
Global Variables
following global variables used throughout code examples. definitions types DCB, COMSTAT, COMMTIMEOUTS found Windows documentation.
HANDLE COMSTAT COMMTIMEOUTS hComPort; comDCB; comState; orgTimeouts; COM-port COM-port COM-port Original handle control settings status information COM-port time-out
Initialization RS-232 Port
access serial RS-232 port, program needs request handle port wants (usually either COM1 COM2). following code used this request:
Size internal WINDOWS-Comm buffer: #define QUEUE_SIZE char* lpszDevice= "COM1" example hComPort= CreateFile(lpszDevice, GENERIC_READ GENERIC_WRITE, OPEN_EXISTING, (hComPort INVALID_HANDLE_VALUE) Error! (SetupComm(hComPort, QUEUE_SIZE, QUEUE_SIZE) Error!
Microsoft, Windows, Win32, Windows Windows Visual trademarks Microsoft Corporation.
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
operation known overlapped input/output (I/O) performed under Win32. This means that system immediately return caller, even operation finished, signal caller when operation complete. Overlapped operation good choice when portability concern because most operating systems support this reason used this program, corresponding parameters required when calling CreateFile zero. After receiving valid handle, settings communication port need defined assigned (see Table original settings first:
(!GetCommState(hComPort, &comDCB)) Error!
Then they modified. most important settings communication with bootstrap loader shown following program section:
comDCB.BaudRate comDCB.ByteSize comDCB.Parity comDCB.StopBits comDCB.fBinary comDCB.fParity comDCB.fRtsControl CBR_9600; EVENPARITY; ONESTOPBIT; TRUE; TRUE; RTS_CONTROL_ENABLE; Startup Baudrate: 9,6kBaud
comDCB.fDtrControl DTR_CONTROL_ENABLE;
Enable Binary Transmission Enable Parity Check power supply TEST control power supply RST/NMI control
Finally, modified settings assigned port:
(!SetCommState(hComPort, &comDCB)) Error!
Win32 application should always communication time-outs when using communication port; otherwise, default settings left-over values from previous applications used. This application does require time-out functionality. Therefore, time-outs completely disabled once original settings saved they restore program:
Save original time-out values: GetCommTimeouts(hComPort, &orgTimeouts); Windows time-out values (disable built-in time-outs): COMMTIMEOUTS timeouts; timeouts.ReadIntervalTimeout= (!SetCommTimeouts(hComPort, &timeouts)) Error!
transmit receive buffers cleared complete initialization sequence:
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
PurgeComm(hComPort, PURGE_TXCLEAR PURGE_TXABORT); PurgeComm(hComPort, PURGE_RXCLEAR PURGE_RXABORT);
complete example initialization routine found under Serial Communication Implementation File listing (see Appendix routine:
comInit(LPCSTR lpszDevice, DWORD aTimeout, aProlongFactor)
Invoking Bootstrap Loader
levels RST/NMI TEST must toggled shown section invoke bootstrap loader. following subroutines used control corresponding RS-232 lines DTR:
void SetRSTpin(BOOL level) Controls RST/NMI GND; VCC) (level TRUE) comDCB.fDtrControl DTR_CONTROL_ENABLE; else comDCB.fDtrControl DTR_CONTROL_DISABLE; SetCommState(hComPort, &comDCB); SetRSTpin void SetTESTpin(BOOL level) Controls TEST VCC; GND) (level TRUE) comDCB.fRtsControl RTS_CONTROL_ENABLE; else comDCB.fRtsControl RTS_CONTROL_DISABLE; SetCommState(hComPort, &comDCB); SetTESTpin
Calling function SetRSTpin with pulls RST/NMI ground, whereas calling function SetTESTpin with applies TEST pin. This difference different number inverters used these pins (see Section following subroutine allows resetting MSP430 bootstrap-loader hardware using functions previously shown. First necessary charge capacitor supply power board. Then RST/NMI TEST pins toggled required. possible reset MSP430 start user program (invokeBSL=FALSE), invoke bootstrap loader with invokeBSL=TRUE:
void bslReset(BOOL invokeBSL) charge capacitor boot loader hardware: SetRSTpin(1); SetTESTpin(1); delay(250); SetRSTpin(0); pin: (invokeBSL)
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
SetTESTpin(1); SetTESTpin(0); SetTESTpin(1); SetTESTpin(0); SetRSTpin (1); SetTESTpin(1);
TEST TEST TEST TEST TEST
pin: pin: pin: pin: pin: pin:
else SetRSTpin(1); pin: Give MSP430's oscillator time stabilize: delay(250); Clear buffers: PurgeComm(hComPort, PURGE_TXCLEAR); PurgeComm(hComPort, PURGE_RXCLEAR); bslReset
possible gain access RS-232 interface invoke bootstrap loader using functions presented far. ready access bootstrap loader.
Access Bootstrap Loader
This section describes basic routines access bootstrap loader. Table gives overview functions presented indicates sections within Appendix where their complete listings found. constant definitions located header listings. Table Bootstrap-Loader Access Functions
SECTIONS Bootstrap-loader communication header file, bootstrap-loader communication implementation file Serial-communication header file, serial-communication implementation file FUNCTIONS bslReset, bslSync, bslTxRx comInit, comTxRx, comDone
4.4.1
Synchronization
MSP430 need synchronized before each frame that calls function. following character (0x80) must sent MSP430 this purpose:
#define BSL_SYNC 0x80
Therefore, this value assigned variable function WriteFile called with communication-port handle first parameter. number bytes transmit must specified used here). last parameters unimportant ignored this particular case.
Send synchronization byte: BSL_SYNC; WriteFile(hComPort, &ch, &NrTx, NULL);
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
bootstrap loader receives this character correctly, returns DATA_ACK (0x90); otherwise, returns unknown value because loader needs this synchronization character generate timing (for serial communication, example). also possible that character returned, like when MSP430 with bootstrap-loader function connected. following subroutine used check given number characters received within given time period. uses function ClearCommError receive actual status communication port. field cbInQue COMSTAT structure holds number received bytes:
comWaitForData(int count, DWORD timeout) DWORD errors; rxCount= DWORD startTime= GetTickCount(); ClearCommError(hComPort, &errors, &comState); while (((rxCount= comState.cbInQue) count) (calcTimeout(startTime) timeout)); return(rxCount);
This subroutine used synchronization function wait character. characters received, they queried using function ReadFile, seen following program section. synchronization successful when character received DATA_ACK.
Wait byte; time-out: 100ms rxCount= comWaitForData(1, 100); (rxCount ReadFile(hComPort, &ch, &NrRx, NULL); DATA_ACK) return(ERR_NONE); Sync. successful
routine bslSync() implements function previously described.
4.4.2
Transmission Frame
following function used send receive frame:
comTxRx(BYTE cmd, BYTE data[], BYTE length)
This function implements functionality Standard Serial Protocol. Only subset functionality needed supported bootstrap-loader communication. This routine uses Win32 functions already described. function
bslTxRx(BYTE cmd, WORD addr, WORD len, BYTE blkout[], BYTE blkin[])
combines synchronization transmission frame. also prepares frame requirements bootstrap loader. important requirement that number bytes sent bootstrap loader (using command TXBLK, instance) requested loader (using command RXBLK) should always even.
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
Calling Bootstrap-Loader Functions
fairly simple call functions bootstrap loader using function bslTxRx presented before. parameters should required within function call (see examples Section 4.7). constant definitions corresponding available commands found Bootstrap Loader Communication Header File (see Appendix
Releasing RS-232 Port
program, RS-232 port must released using function
CloseHandle(hComPort)
otherwise other applications this port because access rights serial communication ports usually granted only program time. routine
comDone()
provides more sophisticated method this. waits until remaining data transmitted, clears buffers, restores original time-out settings. Note that closing serial communication port usually cuts power application which powered serial port because corresponding control lines disabled.
Complete Application
small application developed this section program file TI-TXT format into MSP430's flash memory. complete demonstration program code contained listing Bootstrap Loader Demonstration Program appendix definitions variables used also found there. First, communication port opened. COM-port name changed particular needs, obtained from command line.
(comInit("COM1", DEFAULT_TIMEOUT, Error!
Then bootstrap loader invoked:
bslReset(1);
next step, flash memory completely erased using mass erase command:
((error= bslTxRx(BSL_MERAS, 0xff00, 0xa506, NULL, blkin)) Error! Command: Mass Erase address within flash memory. Required setting mass erase!
password access protected functions bootstrap loader gets reset when flash memory erased. memory cells 0FFh. protected functions enabled sending corresponding password.
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
Fill blkout with 0xff 0x20; i++) blkout[i]= 0xff; ((error= bslTxRx(BSL_TXPWORD, Command: transmit password 0xffe0, Address interrupt vectors 0x0020, Number bytes blkout, blkin)) Error! Special case here: 7(ERR_RX_NAK): Password accepted!
Afterwards, file TI-TXT format parsed data programmed into flash memory verified. There separate subroutine demonstration listing that called from main program parse file program verify flash contents:
Program: ((error= programFlash("TEST.TXT", ACTION_PROGRAM)) Error! Verify: ((error= programFlash("TEST.TXT", ACTION_VERIFY)) Error!
routine programFlash simply parses file with given name (the file name derived from command line), fills buffer with extracted data, calls another subroutine when buffer almost full. data must programmed, sent bootstrap loader using transmit-block command (BSL_TXBLK).
error= bslTxRx(BSL_TXBLK, addr, len, blkout, blkin);
Data read from bootstrap-loader (receive block, BSL_RXBLK) compared against contents transmission buffer verification:
error= bslTxRx(BSL_RXBLK, addr, len, NULL, blkin); (error Cancel! else len; i++) Compare data blkout blkin: (blkin[i] blkout[i]) printf("Verification failed (%x, %x)\n", addr+i, blkin[i], blkout[i]);
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
return(ERR_VERIFY_FAILED); Verify failed!
Note that similar sequence used check erasure this range. this case, contents blkin compared against erasure pattern 0xff. After successful verification MSP430 reset user program start executing:
bslReset(0);
serial communication port must released program:
comDone();
users have pieces together write their applications access MSP430 bootstrap loader adapt their special needs.
Error Recovery
There error-recovery mechanism implemented within demonstration program. program aborted when error detected. some cases might useful implement some kind error-recovery mechanism. data frame transmitted MSP430 rejected with data-not-acknowledge signal (DATA_NAK), transmission frame simply repeated. possible that wrong data been programmed flash, more complex recovery mechanism that includes verification, erasure, reprogramming might required. received frame correct (wrong checksum, inconsistent lengths) command previously sent receive block from MSP430 needs repeated.
Patch First Version Bootstrap Loader
first version bootstrap loader requires small patch program flash. patch described this section handling included program BSLDEMO.C (see Bootstrap Loader Demonstration Program listing appendix TI-TXT-file WAROUND.TXT, that found Appendix also required. patch handling within demonstration program switched (for future versions bootstrap loader) deleting, commenting out, following line:
#define WORKAROUND
parts code required workaround surrounded preprocessor commands:
#ifdef WORKAROUND #endif
After obtaining access protected bootstrap-loader commands, subroutine within loader's code needs called prepare position stack pointer patch. This achieved loading with address routine within bootstrap loader:
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
((error= bslTxRx(BSL_LOADPC, Command: load 0x0C22, Address load into additional data! NULL, blkin)) Error!
Calling this function locks protected commands again, password must resent. Afterwards patch written into RAM. file WROUND.TXT holding patch found Appendix download done using flash-programming function that parses file:
programFlash("WAROUND.TXT", ACTION_PROGRAM ACTION_VERIFY);
this case, masks ACTION_PROGRAM ACTION_VERIFY used together program verify patch single pass. This means that file WAROUND.TXT read only once. Note that patch must located same directory executable program. everything prepared program flash memory. programming range extends into, lies within address range 0x1000 0xffff (the range where flash memory located), only needs loaded with start address patch (0x0220) before sending frame with programming data:
#ifdef WORKAROUND (addr 0x1000) error= bslTxRx(BSL_LOADPC, Command: Load 0x0220, Address load into additional data! NULL, blkin); (error return(error); #endif error= bslTxRx(BSL_TXBLK, addr, len, blkout, blkin);
There another small that might affect memory cells (either peripheral module registers) transmitted frame certain checksum. Unfortunately general workaround provided. This error removed within patch program flash memory; only assistance that provided other cases warning this situation occurs. This done within comRxTx function contained file SSP.C (see Serial Communication Implementation File listing Appendix global variable BSLMemAccessWarning allows turning message off.
WORD accessAddr= (0x0212 (checksum^0xffff)) 0xfffe; (BSLMemAccessWarning (accessAddr 0x1000)) printf("WARNING: This command might change data address %x!\n", accessAddr, accessAddr
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
References
MSP430F11x Mixed Signal Microcontroller data sheet, literature number SLAS256 MSP430F11x1 Mixed Signal Controller data sheet, literature number SLAS241 Graf, Franz. Features MSP430 Bootstrap Loader MSP430F1121, literature number SLAA089. Denver, Allen. Serial Communication Win32, Microsoft Developer Network (MSDN) Library Microsoft Win32 Software Development (SDK) Documentation
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
Appendix
Building Demonstration Program
Listings
build demonstration program, necessary compile files bslcomm.c bsldemo.c, link resulting object files. necessary compile file ssp.c separately because directly included file bslcomm.c. prefer different approach, copy paste contents ssp.c into bslcomm.c position following line, remove this line:
#include "ssp.c"
example, using Visual C++, create project select Win32 Console Application template. project created should empty. Include files bsldemo.c, bslcomm.c, bslcomm.h your project build stated before, files ssp.c ssp.h included automatically. building process will fail include ssp.c file your project.
Bootstrap Loader Communication Header File-bslcomm.h
Copyright 1999-2000 Texas Instruments, Inc. #ifndef BSLComm_H #define BSLComm_H #include "ssp.h" Transmit password boot loader: #define BSL_TXPWORD 0x10 Transmit block boot loader: #define BSL_TXBLK 0x12 Receive block from boot loader: #define BSL_RXBLK 0x14 Erase segment: #define BSL_ERASE 0x16 Erase complete FLASH memory: #define BSL_MERAS 0x18 Load start execution: #define BSL_LOADPC 0x1A Bootstrap loader synchronization error: #define ERR_BSL_SYNC #ifdef _cplusplus extern #endif extern BSLMemAccessWarning; void bslReset(BOOL invokeBSL); Applies entry sequence RST/NMI TEST/VPP pins Parameters: invokeBSL TRUE: complete sequence invokeBSL FALSE: only RST/NMI accessed bslSync();
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
Transmits Synchronization character expects receive Acknowledge character Return Return Sync. failed. bslTxRx(BYTE cmd, WORD addr, WORD len, BYTE blkout[], BYTE blkin[]); Transmits command (cmd) with parameters: start-address (addr), length (len) additional data (blkout) boot loader. Parameters return boot loader passed blkin. Return Return Error! #ifdef _cplusplus #endif #endif
Bootstrap Loader Communication Implementation File-bslcomm.c
Copyright 1999-2000 Texas Instruments, Inc. #include <windows.h> #include <string.h> #include <stdio.h> #include <fcntl.h> #include "bslcomm.h" #include "ssp.c" #define BSL_SYNC 0x80 Warning, access memory below 0x1000 possible. This happen error first version(s) bootstrap loader code combination with specific checksum values. Warning. BSLMemAccessWarning= Default: warning. void SetRSTpin(BOOL level) Controls RST/NMI GND; VCC) (level TRUE) comDCB.fDtrControl DTR_CONTROL_ENABLE; else comDCB.fDtrControl DTR_CONTROL_DISABLE; SetCommState(hComPort, &comDCB); SetRSTpin void SetTESTpin(BOOL level) Controls TEST VCC; GND)
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
(level TRUE) comDCB.fRtsControl RTS_CONTROL_ENABLE; else comDCB.fRtsControl RTS_CONTROL_DISABLE; SetCommState(hComPort, &comDCB); SetTESTpin void bslReset(BOOL invokeBSL) Applies entry sequence RST/NMI TEST/VPP pins Parameters: invokeBSL TRUE: complete sequence invokeBSL FALSE: only RST/NMI accessed inverted twice boot loader hardware TEST inverted (only once) Need positive voltage DTR, power-supply hardware charge capacitor boot loader hardware: SetRSTpin(1); SetTESTpin(1); delay(250); SetRSTpin(0); pin: (invokeBSL) SetTESTpin(1); TEST pin: SetTESTpin(0); TEST pin: SetTESTpin(1); TEST pin: SetTESTpin(0); TEST pin: SetRSTpin (1); pin: SetTESTpin(1); TEST pin: else SetRSTpin(1); pin: Give MSP430's oscillator time stabilize: delay(250); Clear buffers: PurgeComm(hComPort, PURGE_TXCLEAR); PurgeComm(hComPort, PURGE_RXCLEAR); bslReset bslSync() Transmits Synchronization character expects receive Acknowledge character Return Return Sync. failed. BYTE rxCount, loopcnt; const BYTE cLoopOut Max. trials synchronization DWORD NrTx;
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
DWORD NrRx; (loopcnt=0; loopcnt cLoopOut; loopcnt++) PurgeComm(hComPort, PURGE_RXCLEAR); Clear receiving queue Send synchronization byte: BSL_SYNC; WriteFile(hComPort, &ch, &NrTx, NULL); Wait byte; Timeout: 100ms rxCount= comWaitForData(1, 100); (rxCount ReadFile(hComPort, &ch, &NrRx, NULL); DATA_ACK) return(ERR_NONE); Sync. successful (loopcount) return(ERR_BSL_SYNC); Sync. failed bslSync bslTxRx(BYTE cmd, WORD addr, WORD len, BYTE* blkout, BYTE* blkin) Transmits command (cmd) with parameters: start-address (addr), length (len) additional data (blkout) boot loader. Parameters return boot loader passed blkin. Return Return Error! BYTE dataOut[MAX_FRAME_SIZE]; error; WORD length= Make sure that even, when sending data BSL: ((cmd BSL_TXBLK) ((len Inc. fill blkout with 0xFF even number bytes send! blkout[(len++)]= 0xFF; Make sure that even, receiving data from BSL: ((cmd BSL_RXBLK) ((len len++; ((cmd BSL_TXBLK) (cmd BSL_TXPWORD)) length necessary information data frame: dataOut[0] (BYTE)( addr 0x00ff); dataOut[1] (BYTE)((addr 0x00ff);
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
dataOut[2] dataOut[3]
(BYTE)( (BYTE)((len
0x00ff); 0x00ff);
(blkout NULL) Copy data blkout into frame: memcpy(&dataOut[4], blkout, len); (bslSync() ERR_NONE) return(ERR_BSL_SYNC); Send frame: error comTxRx(cmd, dataOut, (BYTE)length); (blkin NULL) Copy received data frame buffer into blkin: memcpy(blkin, &rxFrame[4], rxFrame[2]); return (error);
Serial Communication Header File-ssp.h
Copyright 1998-2000 Texas Instruments, Inc. #ifndef SSP_H #define SSP_H #include <windows.h> #define MODE_SSP #define MODE_BSL Error Codes: Error: #define ERR_NONE Unspecific error: #define ERR_COM OpenComm failed: #define ERR_OPEN_COMM SetCommState failed: #define ERR_SET_COMM_STATE Synchronization failed: #define ERR_SYNC_FAILED Unspecific error concerning transmission command: #define ERR_SEND_COMMAND Timeout while receiving header": #define ERR_RX_HDR_TIMEOUT received: #define ERR_RX_NAK Command send ACK: indicates that didn't complete correctly: #define ERR_CMD_NOT_COMPLETED
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
Command failed, defined allowed: #define ERR_CMD_FAILED CloseComm failed: #define ERR_CLOSE_COMM Header Definitions: #define CMD_FAILED 0x70 #define DATA_FRAME 0x80 #define DATA_ACK 0x90 #define DATA_NAK 0xA0 #define QUERY_POLL 0xB0 #define QUERY_RESPONSE 0x50 #define OPEN_CONNECTION 0xC0 #define ACK_CONNECTION 0x40 #define DEFAULT_TIMEOUT #define DEFAULT_PROLONG #define MAX_FRAME_SIZE #define MAX_DATA_BYTES #define MAX_DATA_WORDS #ifdef _cplusplus extern #endif Support Subroutines: extern DWORD calcTimeout(DWORD startTime); Calculates difference between startTime actual windows time milliseconds). extern void delay(DWORD time); Delays execution given time extern comWaitForData(int count, DWORD timeout); Waits until given number (count) bytes received given time (timeout) passed. extern void comTxHeader(const BYTE txHeader); Communication Subroutines: extern comGetLastError(); Returns error code generated last function call SERCOMM-Function. this function returned without errors, comGetLastError will return zero (errNoError) well. #ifdef _cplusplus extern comInit(LPCSTR lpszDevice "COM1", DWORD aTimeout DEFAULT_TIMEOUT,
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
aProlongFactor= DEFAULT_PROLONG); #else extern comInit(LPCSTR lpszDevice, DWORD aTimeout, aProlongFactor); #endif Tries open serial port given 'lpszDevice' initializes port global variables. timeout number allowed errors multiplied 'aProlongFactor' after transmission command give plenty time micro controller finish command. Returns zero function successful. extern comDone(); Closes used serial port. This function must called program, otherwise serial port might released used other programs. Returns zero function successful. #ifdef _cplusplus #endif #endif
Serial Communication Implementation File-ssp.c
Copyright 1998-2000 Texas Instruments, Inc. #include <string.h> #include <stdio.h> #include <windows.h> #include "ssp.h" Global Constants: Size internal WINDOWS-Comm-Buffer: #define QUEUE_SIZE #define MAX_FRAME_COUNT #define MAX_ERR_COUNT Global Variables: const unsigned short protocolMode= MODE_BSL; HANDLE hComPort; COM-Port Handle comDCB; COM-Port Control-Settings COMSTAT comState; COM-Port Status-Information COMMTIMEOUTS orgTimeouts; Original COM-Port Time-out Time milliseconds until timeout occurs: DWORD timeout DEFAULT_TIMEOUT; Factor which timeout after sending frame prolonged: prolongFactor= DEFAULT_PROLONG; Variable save latest error (used comGetLastError): lastError;
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
BYTE seqNo, reqNo, txPtr, rxPtr; BYTE rxFrame[MAX_FRAME_SIZE]; DWORD nakDelay; Delay before DATA_NAK will send DWORD calcTimeout(DWORD startTime) exported! Calculates difference between startTime actual windows time milliseconds). return((DWORD)(GetTickCount() startTime)); void delay(DWORD time) exported! Delays execution given time #ifndef WIN32 DWORD startTime= GetTickCount(); while (calcTimeout(startTime) time); #else Sleep(time); #endif WORD calcChecksum(BYTE data[], WORD length) Calculates checksum "data". WORD* i_data; WORD checksum= BYTE i_data= (WORD*)data; length/2; i++) checksum^= i_data[i]; xor-ing return(checksum 0xffff); inverting comWaitForData(int count, DWORD timeout) exported! Waits until given number (count) bytes received given time (timeout) passed. DWORD errors; rxCount= DWORD startTime= GetTickCount(); ClearCommError(hComPort, &errors, &comState); while (((rxCount= comState.cbInQue) count) (calcTimeout(startTime) timeout)); return(rxCount);
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
comRxHeader(BYTE *rxHeader, BYTE *rxNum, DWORD timeout) BYTE Hdr; DWORD dwRead; (comWaitForData(1, timeout) ReadFile(hComPort, &Hdr, &dwRead, NULL); *rxHeader= 0xf0; *rxNum 0x0f; (protocolMode MODE_BSL) reqNo= seqNo= *rxNum= return(ERR_NONE); else *rxHeader= *rxNum= return(lastError= ERR_RX_HDR_TIMEOUT); void comTxHeader(const BYTE txHeader) DWORD dwWrite; BYTE Hdr= txHeader; WriteFile(hComPort, &Hdr, &dwWrite, NULL); comGetLastError() Returns error code generated last function call SERCOMM-Function. this function returned without errors, comGetLastError will return zero (errNoError) well. return(lastError); comInit(LPCSTR lpszDevice, DWORD aTimeout, aProlongFactor) Tries open serial port given 'lpszDevice' initializes port global variables. timeout number allowed errors multiplied 'aProlongFactor' after transmission command give plenty time micro controller finish command. Returns zero function successful. COMMTIMEOUTS timeouts; DWORD dwCommEvents; Init. global variables:
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
seqNo= reqNo= rxPtr= txPtr= timeout= aTimeout; prolongFactor= aProlongFactor; hComPort= CreateFile(lpszDevice, GENERIC_READ GENERIC_WRITE, OPEN_EXISTING, this application serial port used nonoverlapped mode! (hComPort INVALID_HANDLE_VALUE) hComPort= return (lastError= ERR_OPEN_COMM); Error! (SetupComm(hComPort, QUEUE_SIZE, QUEUE_SIZE) CloseHandle(hComPort); hComPort= return (lastError= ERR_OPEN_COMM); Error! Save original timeout values: GetCommTimeouts(hComPort, &orgTimeouts); Windows timeout values (disable build-in timeouts): timeouts.ReadIntervalTimeout= (!SetCommTimeouts(hComPort, &timeouts)) CloseHandle(hComPort); hComPort= return (lastError= ERR_OPEN_COMM); Error! dwCommEvents= EV_RXCHAR EV_TXEMPTY EV_RXFLAG EV_ERR; SetCommMask(hComPort, dwCommEvents); state modify (!GetCommState(hComPort, &comDCB)) CloseHandle(hComPort); hComPort= return (lastError= ERR_OPEN_COMM); Error! comDCB.BaudRate CBR_9600; Startup-Baudrate: 9,6kBaud comDCB.ByteSize nakDelay= comDCB.Parity EVENPARITY; comDCB.StopBits ONESTOPBIT; comDCB.fBinary TRUE; Enable Binary Transmission comDCB.fParity TRUE; Enable Parity Check
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
comDCB.ErrorChar (char)0xff; Char. Parity-Err replaced with 0xff *(if fErrorChar TRUE) comDCB.fRtsControl RTS_CONTROL_ENABLE; power supply comDCB.fDtrControl DTR_CONTROL_ENABLE; power supply comDCB.fOutxCtsFlow= FALSE; comDCB.fOutxDsrFlow= FALSE; comDCB.fOutX FALSE; comDCB.fInX FALSE; comDCB.fNull FALSE; comDCB.fErrorChar FALSE; Assign state: (!SetCommState(hComPort, &comDCB)) CloseHandle(hComPort); hComPort= return(lastError= ERR_SET_COMM_STATE); Error! Clear buffers: PurgeComm(hComPort, PURGE_TXCLEAR PURGE_TXABORT); PurgeComm(hComPort, PURGE_RXCLEAR PURGE_RXABORT); return(lastError= comInit comDone() Closes used serial port. This function must called program, otherwise serial port might released used other programs. Returns zero function successful. DWORD errors; DWORD startTime= GetTickCount(); Wait until data transmitted, long. (Timeout-Time) ClearCommError(hComPort, &errors, &comState); while ((comState.cbOutQue (calcTimeout(startTime) timeout)); Clear buffers: PurgeComm(hComPort, PURGE_TXCLEAR PURGE_TXABORT); PurgeComm(hComPort, PURGE_RXCLEAR PURGE_RXABORT); Restore original timeout values: SetCommTimeouts(hComPort, &orgTimeouts); Close COM-Port: (!CloseHandle(hComPort)) return(lastError= ERR_CLOSE_COMM); Error! else return(lastError= ERR_NONE); comDone
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
comRxFrame(BYTE *rxHeader, BYTE *rxNum) DWORD dwRead; WORD checksum; BYTE* rxLength; WORD rxLengthCRC; rxFrame[0]= DATA_FRAME *rxNum; (comWaitForData(3, timeout) ReadFile(hComPort, &rxFrame[1], &dwRead, NULL); ((rxFrame[1] (rxFrame[2] rxFrame[3])) rxLength= &rxFrame[2]; Pointer rxFrame[2] rxLengthCRC= *rxLength CRC-Bytes length (comWaitForData(rxLengthCRC, timeout) rxLengthCRC) ReadFile(hComPort, &rxFrame[4], rxLengthCRC, &dwRead, NULL); Check received frame: checksum= calcChecksum(rxFrame, (WORD)(*rxLength+4)); rxLength+4: Length with header ((rxFrame[*rxLength+4] (BYTE)checksum) (rxFrame[*rxLength+5] (BYTE)(checksum 8))) return(ERR_NONE); Frame received correctly send next frame) (Checksum correct?) (Data: timeout?) (Add. header info. correct?) (Add. header info.: timeout?) return(ERR_COM); Frame errors! comRxFrame comTxRx(BYTE cmd, BYTE dataOut[], BYTE length) Sends command with data given dataOut microcontroller expects either acknowledge frame with result from microcontroller. results stored dataIn NULL pointer passed). this routine necessary protocol stuff handled. Returns zero function successful. DWORD dwWrite; DWORD errors; BYTE txFrame[MAX_FRAME_SIZE]; WORD checksum= errCtr= resendCtr= BYTE rxHeader= BYTE rxNum= resentFrame=
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
pollCtr= Transmitting part Prepare data transmit ((length Fill with byte have even number bytes send (protocolMode MODE_BSL) dataOut[length++]= 0xFF; fill with 0xFF else dataOut[length++]= fill with zero txFrame[0]= DATA_FRAME seqNo; txFrame[1]= cmd; txFrame[2]= length; txFrame[3]= length; reqNo= (seqNo MAX_FRAME_COUNT; memcpy(&txFrame[4], dataOut, length); checksum= calcChecksum(txFrame, (WORD)(length+4)); txFrame[length+4]= (BYTE)(checksum); txFrame[length+5]= (BYTE)(checksum WORD accessAddr= (0x0212 (checksum^0xffff)) 0xfffe; 0x0212: Address wCHKSUM (BSLMemAccessWarning (accessAddr 0x1000)) printf("WARNING: This command might change data address %x!\n", accessAddr, accessAddr Transmit data: Clear receiving queue: PurgeComm(hComPort, PURGE_RXCLEAR PURGE_RXABORT); WriteFile(hComPort, &txFrame[k++], &dwWrite, NULL); ClearCommError(hComPort, &errors, &comState); while length (comState.cbInQue 0)); Check after each transmitted character, microcontroller send character (probably NAK!). Receiving part rxFrame[2]= rxFrame[3]= lengths received data lastError= Clear last error (comRxHeader(&rxHeader, &rxNum, timeout*prolongFactor) prolong timeout allow execution sent command Header received
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
resentFrame= switch (rxHeader) case DATA_ACK: (rxNum reqNo) seqNo= reqNo; return(lastError= ERR_NONE); Acknowledge received correctly next frame break; case DATA_ACK case DATA_NAK: return(lastError= ERR_RX_NAK); break; case DATA_NAK case DATA_FRAME: (rxNum reqNo) (comRxFrame(&rxHeader, &rxNum) return(lastError= ERR_NONE); break; case DATA_FRAME case CMD_FAILED: Frame command failed. return(lastError= ERR_CMD_FAILED); break; case CMD_FAILED default: switch errCtr= MAX_ERR_COUNT; while ((resentFrame (errCtr MAX_ERR_COUNT)); (comRxHeader) else Timeout while receiving header errCtr= MAX_ERR_COUNT; else (comRxHeader) while (errCtr MAX_ERR_COUNT); (lastError ERR_CMD_NOT_COMPLETED) Accept QUERY_RESPONSE real correct Seq.-No.: seqNo= reqNo; (lastError ERR_NONE) return(lastError= ERR_COM); else return(lastError); comTxRx
Bootstrap Loader Demonstration Program-bsldemo.c
Copyright 1999-2000 Texas Instruments, Inc. Project: MSP430 Bootstrap Loader Demonstration Program
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
File: BSLDEMO.C Description: This main program bootstrap loader demonstration. main function holds general sequence access bootstrap loader program/verify file. parsing file done separate function. couple parameters passed program control functions. detailed description appendix corresponding application note. #include <string.h> #include <stdio.h> #include <windows.h> #include "bslcomm.h" Defines: "WORKAROUND" definition includes code workaround required first version(s) bootstrap loader. #define WORKAROUND "DEBUG" defined, checked programmed blocks logged screen. //#define DEBUG Error: verification failed: #define ERR_VERIFY_FAILED Error: erase check failed: #define ERR_ERASE_CHECK_FAILED Error: unable open input file: #define ERR_FILE_OPEN Mask: program data: #define ACTION_PROGRAM 0x01 Mask: verify data: #define ACTION_VERIFY 0x02 Mask: erase check: #define ACTION_ERASE_CHECK 0x04 Mask: transmit password: Note: Should used conjunction with other action! #define ACTION_PASSWD 0x08 Max. bytes sent within frame parsing file. n*16 MAX_DATA_BYTES!) const maxData= Global Variables:
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
Buffers used store data transmitted received from BSL: BYTE blkin [MAX_DATA_BYTES]; Receive buffer BYTE blkout[MAX_DATA_BYTES]; Transmit buffer struct toDoList unsigned MassErase unsigned EraseCheck: unsigned Program unsigned Verify unsigned Reset unsigned Wait Wait <Enter> program yes): unsigned OnePass EraseCheck, Program Verify pass file read only once) toDo; Functions: verifyBlk(WORD addr, WORD len, unsigned action) error= ((action (ACTION_VERIFY ACTION_ERASE_CHECK)) #ifdef DEBUG printf("Check starting bytes. addr, len); #endif error= bslTxRx(BSL_RXBLK, addr, len, NULL, blkin); #ifdef DEBUG printf("Error: %i\n", error); #endif (error return(error); Cancel, read error else len; i++) ((action ACTION_VERIFY) Compare data blkout blkin: (blkin[i] blkout[i]) printf("Verification failed (%x, %x)\n", addr+i, blkin[i], blkout[i]); return(ERR_VERIFY_FAILED); Verify failed! continue; ((action ACTION_ERASE_CHECK)
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
Compare data blkin with erase pattern: (blkin[i] 0xff) printf("Erase Check failed (%x)\n", addr+i, blkin[i]); return(ERR_ERASE_CHECK_FAILED); Erase Check failed! continue; ACTION_ERASE_CHECK else ACTION_VERIFY ACTION_ERASE_CHECK return(error); programBlk(WORD addr, WORD len, unsigned action) error= ((action ACTION_PASSWD) return(bslTxRx(BSL_TXPWORD, Command: Transmit Password addr, Address interupt vectors len, Number bytes blkout, blkin)); ACTION_PASSWD Check, specified range erased: error= verifyBlk(addr, len, action ACTION_ERASE_CHECK); (error return(error); ((action ACTION_PROGRAM) #ifdef WORKAROUND (addr 0x1000) Load with 0x0220. This will invoke patched flash programming subroutine. error= bslTxRx(BSL_LOADPC, Command: Load 0x0220, Address load into additional data! NULL, blkin); (error return(error); BSLMemAccessWarning= Error removed within workaround code #endif #ifdef DEBUG printf("Program starting bytes. addr, len); #endif Program block: error= bslTxRx(BSL_TXBLK, addr, len, blkout, blkin);
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
#ifdef DEBUG printf("Error: %i\n", error); #endif #ifdef WORKAROUND BSLMemAccessWarning= Turn warning back #endif (error return(error); Cancel, error (ACTION_VERIFY skipped!) ACTION_PROGRAM Verify block: error= verifyBlk(addr, len, action ACTION_VERIFY); (error return(error); return(error); programBlk programTIText (char *filename, unsigned action) next= error=0; linelen= linepos= WORD dataframelen=0; WORD currentAddr; char strdata[128]; FILE* infile; ((infile fopen(filename, "rb")) return(ERR_FILE_OPEN); Convert data MSP430, TXT-File parsed line line: (next= next>=1; Read line: ((fgets(strdata, 127, infile) File (strdata[0] 'q')) (last character file) send frame quit (dataframelen Data frame? error= programBlk(currentAddr, dataframelen, action); dataframelen=0; next=0; Quit! continue; linelen= strlen(strdata); (strdata[0] '@') address send frame addr.
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
(dataframelen error= programBlk(currentAddr, dataframelen, action); dataframelen=0; sscanf(&strdata[1], "%lx\n", &currentAddr); continue; Transfer data line into blkout: for(linepos= linepos linelen-3; linepos+= dataframelen++) sscanf(&strdata[linepos], "%3x", &blkout[dataframelen]); (Max bytes line!) (dataframelen maxData-16) frame getting full send frame error= programBlk(currentAddr, dataframelen, action); currentAddr+= dataframelen; dataframelen=0; (error next=0; Cancel loop, error fclose(infile); return(error); programTIText txPasswd(char* passwdFile) (passwdFile NULL) Send "standard" password access protected functions. printf("Transmit Password.\n"); Fill blkout with 0xff (Flash completely erased, contents Flash cells 0xff) 0x20; i++) blkout[i]= 0xff; return(bslTxRx(BSL_TXPWORD, Command: Transmit Password 0xffe0, Address interupt vectors 0x0020, Number bytes blkout, blkin)); else Send file holding interrupt vector data password: printf("Transmit password file %s.\n", passwdFile); ACTION_PASSWD)); txPasswd
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
signOff(int error, BOOL passwd) (toDo.Reset) bslReset(0); Reset MSP430 start user program. switch (error) case ERR_NONE: printf("Programming completed!\n"); break; case ERR_BSL_SYNC: printf("ERROR: Synchronization failed!\n"); printf("Device with boot loader connected?\n"); break; case ERR_VERIFY_FAILED: printf("ERROR: Verification failed!\n"); break; case ERR_FILE_OPEN: printf("ERROR: Unable open input file!\n"); break; default: ((passwd) (error ERR_RX_NAK)) last command transmit password Error: printf("ERROR: Password accepted!\n"); else printf("ERROR: Communication Error!\n"); switch (toDo.Wait) printf("Press <ENTER> .\n"); getchar(); comDone(); Release serial communication port. After having released serial port, target longer supplied this port! (error ERR_NONE) return(0); else return(1); signOff Main: main(int argc, char *argv[]) error= char comPortName[10]= "COM1"; Default setting. char *filename= NULL; char *passwdFile= NULL; Default: actions turned
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
toDo.MassErase toDo.EraseCheck= toDo.Program toDo.Verify toDo.Reset toDo.Wait toDo.OnePass
wait <Enter> end! erase check, program verify sequential!
#ifdef WORKAROUND Show memory access warning, working with bootstrap loader version(s) requiring workaround patch. BSLMemAccessWarning= #endif Parse Command Line Parameters (argc (argc i++) switch (argv[i][0]) case '-': switch (argv[i][1]) case 'c': case 'C': memcpy(comPortName, &argv[i][2], strlen(argv[i])-2); break; case 'p': case 'P': passwdFile= &argv[i][2]; break; case 'w': case 'W': toDo.Wait= wait <Enter> end! break; case '1': toDo.OnePass= #ifdef WORKAROUND printf("WARNING: pass programming discouraged!\n"); #endif break; default: printf("ERROR: Illegal command line parameter!\n"); switch argv[i][1] break; case '+': Turn actions off: toDo.MassErase toDo.EraseCheck= toDo.Program toDo.Verify
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
toDo.Reset toDo.Wait Turn only specified actions back (int)(strlen(argv[i])); j++) switch (argv[i][j]) case 'e': case 'E': Erase Flash toDo.MassErase break; case 'c': case 'C': Erase Check file) toDo.EraseCheck= break; case 'p': case 'P': Program file toDo.Program break; case 'v': case 'V': Verify file toDo.Verify break; case 'r': case 'R': Reset MSP430 before waiting <Enter> toDo.Reset break; case 'w': case 'W': Wait <Enter> before closing serial port toDo.Wait break; default: printf("ERROR: Illegal action specified!\n"); switch break;
default: printf("ERROR: Illegal command line parameter!\n"); switch argv[i][0] filename= argv[i]; else printf("ERROR: Filename required!\n"); return(1); Communication with Bootstrap Loader Open COMx port (Change COM-port name your needs!):
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
(comInit(comPortName, DEFAULT_TIMEOUT, printf("ERROR: Opening COM-Port failed!\n"); return(1); bslReset(1); Invoke boot loader. (toDo.MassErase) Erase flash memory completely (with mass erase command): printf("Mass Erase.\n"); ((error= bslTxRx(BSL_MERAS, Command: Mass Erase 0xff00, address within flash memory. 0xa506, Required setting mass erase! NULL, blkin)) return(signOff(error, FALSE)); passwdFile= NULL; password file required! ((error= txPasswd(passwdFile)) return(signOff(error, TRUE)); Password transmitted! #ifdef WORKAROUND Execute function within bootstrap loader prepare stack pointer following patch. This function will lock protected functions again. printf("Load with 0x0C22.\n"); ((error= bslTxRx(BSL_LOADPC, Command: Load 0x0C22, Address load into additional data! NULL, blkin)) return(signOff(error, FALSE)); Re-send password re-gain access protected functions. ((error= txPasswd(passwdFile)) return(signOff(error, TRUE)); Password transmitted! printf("Load verify patch.\n"); Programming verification done pass. "WAROUND.TXT" only read parsed once. ((error= programTIText("WAROUND.TXT", File program ACTION_PROGRAM ACTION_VERIFY)) return(signOff(error, FALSE)); #endif (!toDo.OnePass)
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
(toDo.EraseCheck) Parse file TXT-Format check erasure required flash cells. printf("Erase Check file %s.\n", filename); ((error= programTIText(filename, ACTION_ERASE_CHECK)) return(signOff(error, FALSE)); (toDo.Program) Parse file TXT-Format program data into flash memory. printf("Program %s.\n", filename); ((error= programTIText(filename, ACTION_PROGRAM)) return(signOff(error, FALSE)); (toDo.Verify) Verify programmed data: printf("Verify %s.\n", filename); ((error= programTIText(filename, ACTION_VERIFY)) return(signOff(error, FALSE)); else unsigned action= (toDo.EraseCheck) action ACTION_ERASE_CHECK; printf("EraseCheck (toDo.Program) action ACTION_PROGRAM; printf("Program (toDo.Verify) action ACTION_VERIFY; printf("Verify (action printf("%s .\n", filename); error= programTIText(filename, action); (error
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
return(signOff(error, FALSE)); return(signOff(ERR_NONE, FALSE));
File Bootstrap Loader Patch-waround.txt
@0220
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
Appendix
Layout Suggestion
Figure B-1. Component Placement
Bottom
Figure B-2. Layout
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
SLAA096
Appendix
Demonstration Program Usage
bootstrap loader demonstration program simple command-line interface. only parameter required name file program. other parameters optional must entered before file name. file name must last parameter. Table shows command-line parameters available. Table C-1. Command-Line Parameters
PARAMETER
-c{COM-port name} -p{TI TXT-file name}
DESCRIPTION
Specifies port used (default: COM1). Specifies file containing actual password access bootstrap loader. program will wait after successful programming reset <ENTER> key. application powered serial port. erase-check, programming, verification pass (the file read parsed only once). This option discouraged with first version(s) bootstrap loader that require workaround patch.
EXAMPLE
-cCOM2 -pint_vect.txt
addition these command-line parameters, parameter exists that allows control program flow. example, possible just verify contents flash memory. This parameter introduced character. character followed specification steps taken (and only these steps taken). Table shows modifiers available. steps taken order modifiers within Table C-2. Table C-2. Program-Flow Modifiers
MODIFIER
Erase complete flash (mass erase) Check erasure Program given file Verify against given file Reset device Wait <ENTER>
DESCRIPTION
Table shows some examples demonstration program's invocation. Table C-3. Invocation Examples
EXAMPLE
bsldemo test.txt bsldemo -cCOM2 test.txt bsldemo +vrw -pint_vect.txt test.txt bsldemo -pint_vect.txt test.txt
DESCRIPTION
Erase flash, check erasure, program verify file test.txt, exit Same above, hardware connected COM2; erase-check, program, verify done pass through file test.txt; program waits <ENTER> end. data within file int_vect.txt password, verify against file test.txt erasure programming), reset MSP430, wait <ENTER> end. Reset MSP430 wait <ENTER> end. Password file name also required.
Application Bootstrap Loader MSP430F11x Hardware Software Proposal
IMPORTANT NOTICE Texas Instruments subsidiaries (TI) reserve right make changes their products discontinue product service without notice, advise customers obtain latest version relevant information verify, before placing orders, that information being relied current complete. products sold subject terms conditions sale supplied time order acknowledgment, including those pertaining warranty, patent infringement, limitation liability. warrants performance semiconductor products specifications applicable time sale accordance with TI's standard warranty. Testing other quality control techniques utilized extent deems necessary support this warranty. Specific testing parameters each device necessarily performed, except those mandated government requirements. Customers responsible their applications using components. order minimize risks associated with customer's applications, adequate design operating safeguards must provided customer minimize inherent procedural hazards. assumes liability applications assistance customer product design. does warrant represent that license, either express implied, granted under patent right, copyright, mask work right, other intellectual property right covering relating combination, machine, process which such semiconductor products services might used. TI's publication information regarding third party's products services does constitute TI's approval, warranty endorsement thereof.
Copyright 2000, Texas Instruments Incorporated

Other recent searches


UGF6C232G811CL - UGF6C232G811CL   UGF6C232G811CL Datasheet
SOP22 - SOP22   SOP22 Datasheet
SM2040-37 - SM2040-37   SM2040-37 Datasheet
RD1010 - RD1010   RD1010 Datasheet
LM119 - LM119   LM119 Datasheet
LM219 - LM219   LM219 Datasheet
LM319 - LM319   LM319 Datasheet
EPL43102 - EPL43102   EPL43102 Datasheet
CLV0575A - CLV0575A   CLV0575A Datasheet

 

Privacy Policy | Disclaimer
© 2012 Datasheet Archive