Replicator430.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32 */
33 /*==========================================================================*\
34 | |
35 | Replicator430.c |
36 | |
37 | JTAG Replicator for the MSP430 Flash-based family devices |
38 | |
39 | Key features: |
40 | · Supports JTAG communication to all MSP430 Flash Devices |
41 | · Max. code size of target program: 57kB |
42 | · Programming speed: ~60kB/10sec (~6kB/sec) |
43 | · Fast Verification and Erase Check: ~60kB/350ms |
44 | · Supports Programming of JTAG Access Protection Fuse |
45 | |
46 |----------------------------------------------------------------------------|
47 | Project: MSP430 Replicator |
48 | Developed using: IAR Embedded Workbench 6.20 |
49 | and: Code Composer Studio 6.0 |
50 |----------------------------------------------------------------------------|
51 | Version history: |
52 | 1.0 04/02 FRGR Initial version. |
53 | 1.1 04/02 FRGR Included SPI mode to speed up shifting function by 2.|
54 | 1.2 06/02 ALB2 Formatting changes, added comments. |
55 | 1.3 06/02 ALB2 DEVICE ID info added. |
56 | 1.4 08/02 ALB2 Initial code release with Lit# SLAA149. |
57 | 1.5 01/03 ALB2 Unnecessary lines have been commented out(see below).|
58 | 1.6 09/05 JDI converted to IAR EW 3.30. F2xxx support added |
59 | SUN1 Software delays redesigned to use TimerA harware; |
60 | see MsDelay() routine. |
61 | ALB2 Added 2xx Info memory B, C, & D erase & check |
62 | 1.7 12/05 STO Adapted for 2xx devices with SpyBiWire |
63 | 1.8 02/06 STO Minor cosmetic changes |
64 | 1.9 05/06 STO Minor cosmetic changes |
65 | 2.0 04/07 WLUT Minor changes at declarations and calls |
66 | according to use srec_cat.exe |
67 | 2.1 07/09 FB Added loop for polling P1.6 / added support for |
68 | replicator |
69 | 2.2 07/12 RL Updated commentaries |
70 | 2.3 03/13 RL/MD Added InfoA unlock |
71 | 2.4 06/15 RL Commented out optional RAM operations |
72 |----------------------------------------------------------------------------|
73 | Designed 2002 by Texas Instruments Germany |
74 \*==========================================================================*/
77 /****************************************************************************/
78 /* Main section of Replicator program: User can modify/insert code as needed*/
79 /****************************************************************************/
80 /* Main function:
81  Upon execution completion, LED blinks for F1xx & F4xx device target socket
82  boards when used as the target system (P1.0 and P5.1 drive LEDs).
83 
84  Note: All High Level JTAG Functions are applied here.
85 
86  A number of lines have been commented out which are not strictly required
87  to successfully program a flash-based MSP430 device using the Replicator
88  concept. Please note that these lines have been commented out in order
89  to provide reference examples for calling such functions.
90  Uncommented lines below represent the minimum requirements to successfully
91  program an MSP430 flash device using the Replicator.
92 
93  The basic routine consists of the following steps:
94 
95  1. | Initialize the host MSP430 on the Replicator board
96  2. | Connect to the target device
97  3. | Control the target peripherals directly (optional)
98  4. | Perform a write + read + verify in the target RAM (optional)
99  5. | Operations in the device's main memory
100  6. | Blow JTAG access fuse (optional)
101  7. | Release the device from JTAG control and wait for the user to press button "S1"
102 */
103 
104 /****************************************************************************/
105 /* Includes */
106 /****************************************************************************/
107 
108 #include "JTAGfunc430.h" // JTAG functions
109 #include "LowLevelFunc430.h" // low level functions
110 #include "Devices430.h" // holds Device specific information
111 #include "Target_Code.h" // holds declarations and/or data of target program code
112 
113 /****************************************************************************/
114 /* FUNCTIONS */
115 /****************************************************************************/
116 void runProgramm(void);
117 
119 void main(void)
120 {
121  runProgramm();
122 }
123 
127 void runProgramm(void)
128 {
130  word p;
132  word ReadArray[0x40];
133 
134 /*------------------------------------------------------------------------------------------------------*/
135 /* 1. | Initialize host MSP430 (on Replicator board) & target board */
136 /*------------------------------------------------------------------------------------------------------*/
137 
138  InitController(); // Initialize the host MSP430F5437
139 
140  ShowStatus(STATUS_ACTIVE, 0); // Switch both LEDs on to indicate operation.
141 
142  InitTarget(); // Initialize target board
143 
144 /*------------------------------------------------------------------------------------------------------*/
145 /* 2. | Connect to the target device */
146 /*------------------------------------------------------------------------------------------------------*/
147 
148  if (GetDevice() != STATUS_OK) // Set DeviceId
149  {
150  ShowStatus(STATUS_ERROR, 1); // stop here if invalid JTAG ID or
151  } // time-out. (error: red LED is ON)
152 
153 /*------------------------------------------------------------------------------------------------------*/
154 /* 3. | Control the target peripherals directly (OPTIONAL) */
155 /*------------------------------------------------------------------------------------------------------*/
156 
157  // Remove the following comments to toggle Pin 1.0 (i.e flash the LED for MSP430 target socket boards)
158  /*{
159  word k;
160 
161  WriteMem(F_BYTE, 0x21, 0x01); // P1.0 for F1xx,2xx devices
162  WriteMem(F_BYTE, 0x31, 0x02); // P5.1 for F4xx devices
163 
164  for(k = 0; k < 3; k++)
165  {
166  WriteMem(F_BYTE, 0x22, 0x01);
167  WriteMem(F_BYTE, 0x32, 0x02);
168  MsDelay(500); // LED on for 0.5s
169  WriteMem(F_BYTE, 0x21, 0x00);
170  WriteMem(F_BYTE, 0x31, 0x00);
171  MsDelay(500); // LED off for 0.5s
172  }
173  }*/
174 
175 /*------------------------------------------------------------------------------------------------------*/
176 /* 4. | Perform a write + read + verify in the target RAM (OPTIONAL) */
177 /*------------------------------------------------------------------------------------------------------*/
178 
179  // The following section is not required and included only as a reference on
180  // how to access the target's RAM and alter its content
181 
182  /*
183  // Communication test: Write 2 RAM bytes
184  WriteMem(F_BYTE, 0x0200, 0x34);
185  WriteMem(F_BYTE, 0x0201, 0x12);
186  // Read back word
187  if (ReadMem(F_WORD, 0x0200) != 0x1234)
188  {
189  ShowStatus(STATUS_ERROR, 5);
190  }
191 
192  // Write RAM word
193  WriteMem(F_WORD, 0x0202, 0x5678);
194  // Read back 2 bytes
195  if (ReadMem(F_BYTE, 0x0202) != 0x78)
196  {
197  ShowStatus(STATUS_ERROR, 6);
198  }
199  if (ReadMem(F_BYTE, 0x0203) != 0x56)
200  {
201  ShowStatus(STATUS_ERROR, 7);
202  }
203 
204  // Is the Read/WriteQuick for current device possible?
205  if (DeviceHas_DataQuick())
206  {
207  // Write RAM block
208  WriteMemQuick (0x0200, 0x0010, (word*)&eprom[0]);
209  // Verify(PSA) RAM of target
210  if (!VerifyMem(0x0200, 0x0010, (word*)&eprom[0]))
211  {
212  ShowStatus(STATUS_ERROR, 8);
213  }
214  // Read RAM block
215  ReadMemQuick (0x0200, 0x0010, &ReadArray[0]);
216  // Verify(word-for-word) RAM of target
217  for (p = 0; p < 0x0010; p++)
218  {
219  if (ReadArray[p] != eprom[p])
220  {
221  ShowStatus(STATUS_ERROR, 9);
222  }
223  }
224  }
225  */
226 
227 /*------------------------------------------------------------------------------------------------------*/
228 /* 5. | Operations in the device's main memory */
229 /*------------------------------------------------------------------------------------------------------*/
230 
231  // The following section is not required and included only for reference as to the
232  // manner in which a single flash memory segment can be erased. The more common
233  // "mass erase" is used to prepare the target device for replicator programming.
234  /*{
235  // Segment 0 erase Flash (all types)
236  EraseFLASH(ERASE_SGMT, 0xFE00);
237  // Check segment 0 memory erasure
238  if (!EraseCheck(0xFE00, 0x0100))
239  {
240  ShowStatus(STATUS_ERROR, 2);
241  }
242  }*/
243 
244  // Perform a mass erase
245  EraseFLASH(ERASE_MASS, 0xFE00); // Mass-Erase Flash (all types)
246  // NOTE: the INFO memory in F2xx device will be not erased
247  // if the memory is locked. For more info See EraseFLASH() and
248  // UnlockInfoA_430() in JTAGfunc430.c
249 
250  //if (!EraseCheck(0x1000, 0x0040)) // Check info memory erasure (Fxx2..9)
251  //{
252  // ShowStatus(STATUS_ERROR, 3);
253  //}
254 
255  if (!EraseCheck(0xF800, 0x0400)) // Check main memory erasure (Fxx2..9)
256  {
258  }
259 
260  /* For all 1xx & 4xx & 2xx devices, where ALL Flash has been erased*/
261  EraseFLASH(ERASE_SGMT, 0xFE00);
262  if (!EraseCheck(0xfe00, 0x0100)) // Check part of main memory erasure (Fxx2..9)
263  {
265  }
266 
267  // For all 2xx devices, where Info A was not erased (Info A keeps calibration data)
268  /*
269  // Check info memory erasure (Fxx2..9)
270  if (!EraseCheck(0x1000, 0x0080))
271  {
272  ShowStatus(STATUS_ERROR, 4);
273  }
274  */
275 
276  // Comment in the following section to erase Info-Segments on 2xx Devices selectively
277  // Please adjust addresses for devices with special memory segment sizes (i.e. MSP430i2040)
278  /*{
279  // Comment-in the following code to unlock Info memory segment A
280  // WARNING: Info A may include calibration data!
281  {
282  // Info A unlock
283  UnlockInfoA();
284 
285  // Info A erase
286  EraseFLASH(ERASE_SGMT, 0x10C0);
287  // Check Info A memory erasure (2xx)
288  if (!EraseCheck(0x10C0, 0x0020))
289  {
290  ShowStatus(STATUS_ERROR, 2);
291  }
292  }
293 
294  // Info B erase (2xx)
295  EraseFLASH(ERASE_SGMT, 0x1080);
296  // Check Info B memory erasure (2xx)
297  if (!EraseCheck(0x1080, 0x0020))
298  {
299  ShowStatus(STATUS_ERROR, 2);
300  }
301 
302  // Info C erase (2xx)
303  EraseFLASH(ERASE_SGMT, 0x1040);
304  // Check Info C memory erasure (2xx)
305  if (!EraseCheck(0x1040, 0x0020))
306  {
307  ShowStatus(STATUS_ERROR, 2);
308  }
309 
310  // Info D erase (2xx)
311  EraseFLASH(ERASE_SGMT, 0x1000);
312  // Check Info D memory erasure (2xx)
313  if (!EraseCheck(0x1000, 0x0020))
314  {
315  ShowStatus(STATUS_ERROR, 2);
316  }
317  }*/
318 
319  // Program target code
321  {
323  }
324 
325 
326 /*------------------------------------------------------------------------------------------------------*/
327 /* 6. | Blow the JTAG access protection fuse (OPTIONAL) */
328 /*------------------------------------------------------------------------------------------------------*/
329 
330  // Remove following comments to enable the JTAG fuse blow routine.
331  // This makes the MSP430 device permanently inaccessible via JTAG
332 
333  /*if (!BlowFuse()) // ***Action is permanent***
334  {
335  ShowStatus(STATUS_ERROR, 15);
336  }*/
337 
338 /*------------------------------------------------------------------------------------------------------*/
339 /* 7. | Release the target device from JTAG control and wait for the user to press button "S1" */
340 /*------------------------------------------------------------------------------------------------------*/
341 
342  ReleaseDevice(V_RESET); // Perform Reset, release CPU from JTAG control
343  // Target board LED should start blinking
344  ShowStatus(STATUS_OK, 0); // OK: green LED is ON
345 
346  _EINT(); // Enable Interrupts
347  P1IE |= 0x040; // P1.6 interrupt enabled
348 
349  while(1); // Idle, wait for keypress (handled in ISR)
350 }
351 
352 /*------------------------------------------------------------------------------------------------------*/
353 
355 #pragma vector=PORT1_VECTOR
356 __interrupt void Port_1(void)
357 {
358  ReleaseTarget(); // Release target board from power
359  ShowStatus(STATUS_ACTIVE, 0); // Switch both LEDs on to indicate operation.
360  P1IE &= ~0x040; // P1.6 interrupt disabled
361  MsDelay(1000); // Wait 1s before restarting the Controller and Target
362  P1IFG = 0;
363  runProgramm(); // Restart Controller and Target
364 }
365 
366 /****************************************************************************/
367 /* END OF SOURCE FILE */
368 /****************************************************************************/
Header file for target code (blinking LED)
void ShowStatus(word status, word index)
This function controls the status LEDs depending on the status argument. It stops program in error ca...
JTAG Function Prototypes and Definitions.
word EraseCheck(word StartAddr, word Length)
This function performs an Erase Check over the given memory range.
Definition: JTAGfunc430.c:1220
const unsigned long eprom_address[10]
Holds the destination adresses for different sections of the target code.
Device Function Prototypes and Definitions for FLASH programming.
void ReleaseDevice(word Addr)
Function to release the target device from JTAG control.
Definition: JTAGfunc430.c:721
void main(void)
Main function.
const unsigned int eprom[10]
Holds the entire target code.
void ReleaseTarget(void)
Release Target Board (switch voltages off, JTAG pins are HI-Z)
#define STATUS_ACTIVE
Replicator is active.
#define STATUS_ERROR
return 0 = error
void EraseFLASH(word EraseMode, word EraseAddr)
This function performs a mass erase (with and w/o info memory) or a segment erase of a FLASH module s...
Definition: JTAGfunc430.c:1044
void runProgramm(void)
The basic Replicator routine.
void MsDelay(word milliseconds)
Delay function (resolution is 1 ms)
void InitController(void)
Initialization of the Controller Board.
#define ERASE_SGMT
Constant for flash erase: SELECTED segment.
Definition: Devices430.h:80
const unsigned long eprom_sections
Holds the number of memory sections.
void InitTarget(void)
Initialization of the Target Board (switch voltages on, preset JTAG pins)
#define STATUS_OK
return 1 = no error
#define ERASE_MASS
Constant for flash erase: main & info of SELECTED mem arrays.
Definition: Devices430.h:76
__interrupt void Port_1(void)
This interrupt service routine calls runProgramm() if button "S1" is pressed.
const unsigned long eprom_length_of_sections[10]
Holds the length of the different memory sections.
word WriteFLASHallSections(const unsigned int *data, const unsigned long *address, const unsigned long *length_of_sections, const unsigned long sections)
This function programs/verifies a set of data arrays of words into a FLASH memory by using the "Write...
Definition: JTAGfunc430.c:957
word GetDevice(void)
Function to take target device under JTAG control. Disables the target watchdog. Sets the global DEVI...
Definition: JTAGfunc430.c:659
Low Level function prototypes, macros, and pin-to-signal assignments regarding to user's hardware...

Copyright 2016, Texas Instruments Incorporated