Replicator430X.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 | Replicator430X.c |
36 | |
37 | JTAG Replicator for the MSP430X 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 05/12 RL Updated commentaries |
68 | 2.2 03/13 RL/MD Added InfoA unlock |
69 | 2.3 06/15 RL Commented out optional RAM operations |
70 |----------------------------------------------------------------------------|
71 | Designed 2002 by Texas Instruments Germany |
72 \*==========================================================================*/
75 /****************************************************************************/
76 /* Main section of Replicator program: User can modify/insert code as needed*/
77 /****************************************************************************/
78 /* Main function:
79  Upon execution completion, LED blinks for F1xx & F4xx device target socket
80  boards when used as the target system (P1.0 and P5.1 drive LEDs).
81 
82  Note: All High Level JTAG Functions are applied here.
83 
84  A number of lines have been commented out which are not strictly required
85  to successfully program a flash-based MSP430 device using the Replicator
86  concept. Please note that these lines have been commented out in order
87  to provide reference examples for calling such functions.
88  Uncommented lines below represent the minimum requirements to successfully
89  program an MSP430 flash device using the Replicator.
90 
91  The basic routine consists of the following steps:
92 
93  1. | Initialize the host MSP430 on the Replicator board
94  2. | Connect to the target device
95  3. | Control the target peripherals directly (optional)
96  4. | Perform a write + read + verify in the target RAM (optional)
97  5. | Operations in the device's main memory
98  6. | Blow JTAG access fuse (optional)
99  7. | Release the device from JTAG control and wait for the user to press button "S1"
100 */
101 
102 /****************************************************************************/
103 /* INCLUDES */
104 /****************************************************************************/
105 
106 #include "JTAGfunc430X.h" // JTAG functions
107 #include "LowLevelFunc430X.h" // low level functions
108 #include "Devices430X.h" // holds Device specific information
109 #include "Target_Code.h" // holds declarations and/or data of target program code
110 
111 /****************************************************************************/
112 /* FUNCTIONS */
113 /****************************************************************************/
114 void runProgramm(void);
115 
117 void main(void)
118 {
119  runProgramm();
120 }
121 
125 void runProgramm(void)
126 {
128  word p;
130  word ReadArray[0x40];
131 
132 /*------------------------------------------------------------------------------------------------------*/
133 /* 1. | Initialize host MSP430 (on Replicator board) & target board */
134 /*------------------------------------------------------------------------------------------------------*/
135 
136  InitController(); // Initialize the host MSP430F5437
137 
138  ShowStatus(STATUS_ACTIVE, 0); // Switch both LEDs on to indicate operation.
139 
140  InitTarget(); // Initialize target board
141 
142 /*------------------------------------------------------------------------------------------------------*/
143 /* 2. | Connect to the target device */
144 /*------------------------------------------------------------------------------------------------------*/
145 
146  if (GetDevice() != STATUS_OK) // Set DeviceId
147  {
148  ShowStatus(STATUS_ERROR, 1); // stop here if invalid JTAG ID or
149  } // time-out. (error: red LED is ON)
150 
151 /*------------------------------------------------------------------------------------------------------*/
152 /* 3. | Control the target peripherals directly (optional) */
153 /*------------------------------------------------------------------------------------------------------*/
154 
155  // Remove the following comments to toggle Pin 1.0 (i.e flash the LED for MSP430 target socket boards)
156  /*{
157  word k;
158 
159  WriteMem(F_BYTE, 0x21, 0x01); // P1.0 for F1xx,2xx devices
160  WriteMem(F_BYTE, 0x31, 0x02); // P5.1 for F4xx devices
161 
162  for(k = 0; k < 3; k++)
163  {
164  WriteMem(F_BYTE, 0x22, 0x01);
165  WriteMem(F_BYTE, 0x32, 0x02);
166  MsDelay(500); // LED on for 0.5s
167  WriteMem(F_BYTE, 0x21, 0x00);
168  WriteMem(F_BYTE, 0x31, 0x00);
169  MsDelay(500); // LED off for 0.5s
170  }
171  }*/
172 
173 /*------------------------------------------------------------------------------------------------------*/
174 /* 4. | Perform a write + read + verify in the target RAM (optional) */
175 /*------------------------------------------------------------------------------------------------------*/
176 
177  // The following section is not required and included only as a reference on
178  // how to access the target's RAM and alter its content
179  /*
180  // Communication test: Write 2 RAM bytes
181  WriteMem(F_BYTE, 0x0200, 0x34);
182  WriteMem(F_BYTE, 0x0201, 0x12);
183  // Read back word
184  if (ReadMem(F_WORD, 0x0200) != 0x1234)
185  {
186  ShowStatus(STATUS_ERROR, 5);
187  }
188 
189 
190  // Write RAM word
191  WriteMem(F_WORD, 0x0202, 0x5678);
192  // Read back 2 bytes
193  if (ReadMem(F_BYTE, 0x0202) != 0x78)
194  {
195  ShowStatus(STATUS_ERROR, 6);
196  }
197  if (ReadMem(F_BYTE, 0x0203) != 0x56)
198  {
199  ShowStatus(STATUS_ERROR, 7);
200  }
201 
202  // Is Read/WriteQuick possible for current device?
203  if (DeviceHas_DataQuick())
204  {
205  // Write RAM block
206  WriteMemQuick (0x0200, 0x0010, (word*)&eprom[0]);
207  // Verify(PSA) RAM of target
208  if (!VerifyMem(0x0200, 0x0010, (word*)&eprom[0]))
209  {
210  ShowStatus(STATUS_ERROR, 8);
211  }
212  // Read RAM block
213  ReadMemQuick (0x0200, 0x0010, &ReadArray[0]);
214  // Verify(word-for-word) RAM of target
215  for (p = 0; p < 0x0010; p++)
216  {
217  if (ReadArray[p] != eprom[p])
218  {
219  ShowStatus(STATUS_ERROR, 9);
220  }
221  }
222  }
223  */
224 
225 /*------------------------------------------------------------------------------------------------------*/
226 /* 5. | Operations in the device's main memory */
227 /*------------------------------------------------------------------------------------------------------*/
228 
229  // The following section is not required and included only for reference as to the
230  // manner in which a single flash memory segment can be erased. The more common
231  // "mass erase" is used to prepare the target device for replicator programming.
232  /*{
233  // Segment 0 erase Flash (all types)
234  EraseFLASH(ERASE_SGMT, 0xFE00);
235  // Check segment 0 memory erasure
236  if (!EraseCheck(0xFE00, 0x0100))
237  {
238  ShowStatus(STATUS_ERROR, 2);
239  }
240  }*/
241 
242  // Perform a mass erase
243  if (DeviceHas_CpuX())
244  {
245  EraseFLASH(ERASE_GLOB, 0xFE00); // Global-Erase Flash
246  } // (for all devices with CPU-X)
247  else
248  {
249  EraseFLASH(ERASE_MASS, 0xFE00); // Mass-Erase Flash (all types)
250  // NOTE: the INFO memory in F2xx device will be not erased,
251  // if the memory is locked. For more info See EraseFLASH() and
252  // UnlockInfoA_430x() in JTAGfunc430.c
253  }
254 
255  // Check main memory erasure
256  if (!EraseCheck(0xF800, 0x0400))
257  {
259  }
260 
261  // For all 1xx & 4xx & 2xx devices, where ALL Flash has been erased
262  EraseFLASH(ERASE_SGMT, 0xFE00);
263  // Check part of main memory erasure (Fxx2..9)
264  if (!EraseCheck(0xfe00, 0x0100))
265  {
267  }
268 
269  // For all 2xx devices, where Info A was not erased (Info A keeps calibration data)
270  /*
271  // Check info memory erasure (Fxx2..9)
272  if (!EraseCheck(0x1000, 0x0080))
273  {
274  ShowStatus(STATUS_ERROR, 4);
275  }
276  */
277 
278  // Following section shows how to erase Info-Segments on 2xx Devices selectively
279  {
280  // Comment-in the following code to unlock Info memory segment A
281  // WARNING: Info A may include calibration data!
282  /*{
283  // Info A unlock
284  UnlockInfoA();
285 
286  // Info A erase
287  EraseFLASH(ERASE_SGMT, 0x10C0);
288  // Check Info A memory erasure (2xx)
289  if (!EraseCheck(0x10C0, 0x0020))
290  {
291  ShowStatus(STATUS_ERROR, 2);
292  }
293  }*/
294 
295  // Info B erase (2xx)
296  EraseFLASH(ERASE_SGMT, 0x1080);
297  // Check Info B memory erasure (2xx)
298  if (!EraseCheck(0x1080, 0x0020))
299  {
301  }
302 
303  // Info C erase (2xx)
304  EraseFLASH(ERASE_SGMT, 0x1040);
305  // Check Info C memory erasure (2xx)
306  if (!EraseCheck(0x1040, 0x0020))
307  {
309  }
310 
311  // Info D erase (2xx)
312  EraseFLASH(ERASE_SGMT, 0x1000);
313  // Check Info D memory erasure (2xx)
314  if (!EraseCheck(0x1000, 0x0020))
315  {
317  }
318  }
319 
320  // Program target code
321  if (!WriteFLASHallSections(&eprom[0], &eprom_address[0], &eprom_length_of_sections[0], eprom_sections))
322  {
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 /****************************************************************************/
#define STATUS_ACTIVE
Replicator is active.
Header file for target code (blinking LED)
JTAG Function Prototypes and Definitions.
const unsigned long eprom_address[10]
Holds the destination adresses for different sections of the target code.
bool DeviceHas_CpuX(void)
Function to check if current device has the extended CPUX.
Definition: Devices430X.c:156
const unsigned int eprom[10]
Holds the entire target code.
#define STATUS_OK
return 1 = no error
void InitTarget(void)
Initialization of the Target Board (switch voltages on, preset JTAG pins)
void runProgramm(void)
The basic Replicator routine.
void MsDelay(word milliseconds)
Delay function (resolution is 1 ms)
#define ERASE_SGMT
Constant for flash erase: SELECTED segment.
Definition: Devices430X.h:80
Low Level function prototypes, macros, and pin-to-signal.
Device Function Prototypes and Definitions for FLASH programming.
__interrupt void Port_1(void)
This interrupt service routine calls runProgramm() if button "S1" is pressed.
void ReleaseTarget(void)
Release Target Board (switch voltages off, JTAG pins are HI-Z)
const unsigned long eprom_sections
Holds the number of memory sections.
#define ERASE_GLOB
Constant for flash erase: main & info of ALL mem arrays.
Definition: Devices430X.h:72
void main(void)
Main function.
#define STATUS_ERROR
return 0 = error
void InitController(void)
Initialization of the Controller Board.
void ShowStatus(word status, word index)
This function controls the status LEDs depending on the status argument. It stops program in error ca...
const unsigned long eprom_length_of_sections[10]
Holds the length of the different memory sections.
#define ERASE_MASS
Constant for flash erase: main & info of SELECTED mem arrays.
Definition: Devices430X.h:76

Copyright 2016, Texas Instruments Incorporated