Replicator430Xv2.c
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the
15  * distribution.
16  *
17  * Neither the name of Texas Instruments Incorporated nor the names of
18  * its contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33 */
34 /*==========================================================================*\
35 | |
36 | Replicator430Xv2.c |
37 | |
38 | JTAG Replicator for the MSP430Xv2 Flash-based family (5xx/6xx) |
39 | devices. |
40 | |
41 | Key features: |
42 | · Supports JTAG communication to all 5xx/6xx MSP430 Flash devices |
43 | · Max. code size of target program: 57kB |
44 | · Programming speed: ~60kB/10sec (~6kB/sec) |
45 | · Fast Verification and Erase Check: ~60kB/350ms |
46 | · Supports Device Access with user set JTAG password (FRAM only) |
47 | · Supports deactivation of the Memory Protection Unit (FRAM only) |
48 | · Supports Programming of JTAG Access Protection Fuse |
49 | |
50 |----------------------------------------------------------------------------|
51 | Project: MSP430 Replicator |
52 | Developed using: IAR Embedded Workbench 6.20 |
53 | and: Code Composer Essentials 6.0 |
54 |----------------------------------------------------------------------------|
55 | Version history: |
56 | 1.0 08/08 WLUT Initial version. |
57 | 1.1 06/09 FB add Loop for 'Go'Button P1.6 |
58 | 1.2 06/09 FB updated Constants for flash erasing modes & |
59 | added section with "erase the all Flash memory banks |
60 | in main memory and verify them. |
61 | 1.3 10/10 FB update code examples for F6638 family, F5509 family |
62 | and F5132 Family |
63 | 1.4 04/12 RL updated commentaries |
64 | 1.5 11/12 RL Fixed erase main memory flow |
65 | 1.6 03/13 RL/MD Added InfoA/BSL unlock |
66 | 1.7 05/14 RL Removed FRAM functionality (see Replicator430FR) |
67 | 1.8 06/15 RL Commented out optional RAM operations |
68 |----------------------------------------------------------------------------|
69 | Designed 2008 by Texas Instruments Germany |
70 \*==========================================================================*/
73 /****************************************************************************/
74 /* Main section of Replicator program: User can modify/insert code as needed*/
75 /****************************************************************************/
76 /* Main function:
77  Upon execution completion, LED blinks for F5xx/F6xx device target socket
78  boards when used as the target system (P1.0 drives LED).
79 
80  Note: All High Level JTAG Functions are applied here.
81 
82  A number of lines have been commented out which are not strictly required
83  to successfully program a flash-based MSP430 device using the
84  Replicator concept. Please note that these lines have been commented out in
85  order to provide reference examples for calling such functions.
86  Uncommented lines below represent the minimum requirements to successfully
87  program an MSP430 device using the Replicator.
88 
89  The basic routine consists of the following steps:
90 
91  1. | Initialize the host MSP430 on the Replicator board
92  2. | Connect to the target device
93  3. | Control the target peripherals directly (optional)
94  4. | Perform a write + read + verify in the target RAM (optional)
95  5. | Operations in the device's main memory
96  6. | Program the JTAG lock key (optional)
97  7. | Release the device from JTAG control and wait for the user to press button "S1"
98 */
99 
100 /****************************************************************************/
101 /* INCLUDES */
102 /****************************************************************************/
103 
104 #include "JTAGfunc430Xv2.h" // JTAG functions
105 #include "Config430Xv2.h" // High level user configuration
106 #include "LowLevelFunc430Xv2.h" // Low level functions
107 #include "Target_Code.h" // holds declarations and/or data of target program code
108 
109 /****************************************************************************/
110 /* VARIABLES */
111 /****************************************************************************/
112 
116 unsigned long mainLength = MAIN_LENGTH;
117 
118 /****************************************************************************/
119 /* FUNCTIONS */
120 /****************************************************************************/
121 
123 void main(void)
124 {
125  runProgramm();
126 }
127 
130 void runProgramm(void)
131 {
132 
134 word WriteData[WordBufferSize];
136 word ReadData[WordBufferSize];
137 
138 /*------------------------------------------------------------------------------------------------------*/
139 /* 1. | Initialize host MSP430 (on Replicator board) & target board */
140 /*------------------------------------------------------------------------------------------------------*/
141 
142  InitController(); // Initialize the host MSP430F5437
143 
144  ShowStatus(STATUS_ACTIVE, 0); // Switch both LEDs on to indicate operation.
145 
146  InitTarget(); // Initialize target board
147 
148 /*------------------------------------------------------------------------------------------------------*/
149 /* 2. | Connect to the target device */
150 /*------------------------------------------------------------------------------------------------------*/
151 
152  if (GetDevice() != STATUS_OK) // Set DeviceId
153  {
154  ShowStatus(STATUS_ERROR, 1); // Stop here if invalid JTAG ID or
155  } // time-out. (error: red LED is ON)
156 
157 /*------------------------------------------------------------------------------------------------------*/
158 /* 3. | Control the target peripherals directly (optional) */
159 /*------------------------------------------------------------------------------------------------------*/
160 
161  // Remove the following comments to toggle Pin 1.0 (i.e flash the LED for MSP430 target socket boards)
162  /*{
163  word k;
164 
165  WriteMem(F_BYTE, 0x204, 0x01); // P1.0 for F1xx,2xx devices
166 
167  for(k = 0; k < 3; k++)
168  {
169  WriteMem(F_BYTE, 0x202, 0x01);
170  MsDelay(500); // LED on for 0.5s
171  WriteMem(F_BYTE, 0x202, 0x00);
172  MsDelay(500); // LED off for 0.5s
173  }
174 
175  WriteMem(F_BYTE, 0x202, 0x01);
176  }*/
177 
178 /*------------------------------------------------------------------------------------------------------*/
179 /* 4. | Perform a write + read + verify in the target RAM (optional) */
180 /*------------------------------------------------------------------------------------------------------*/
181 
182  // The following section is not required and included only as a reference on
183  // how to access the target's RAM and alter its content
184  /*
185  {
186  word i,j;
187 
188  // write dummy data to target RAM
189  for (i = 0, j = 0; j < WordBufferSize; j++, i+=2)
190  {
191  ReadData[j] = 0;
192  WriteData[j] = j;
193  WriteMem(F_WORD, RAM_START_ADDRESS + i, j);
194  }
195  // read data from target RAM and verify
196  for (i = 0, j = 0; j < WordBufferSize; j++, i+=2)
197  {
198  ReadData[j] = ReadMem(F_WORD, RAM_START_ADDRESS + i);
199  if(ReadData[j] != WriteData[j])
200  {
201  ShowStatus(STATUS_ERROR, 2);
202  }
203  }
204  // verify content with PSA
205  if(VerifyMem(RAM_START_ADDRESS, WordBufferSize, WriteData) != STATUS_OK)
206  {
207  ShowStatus(STATUS_ERROR, 3);
208  }
209  }
210  */
211 
212 /*------------------------------------------------------------------------------------------------------*/
213 /* 5. | Operations in the device's main memory */
214 /*------------------------------------------------------------------------------------------------------*/
215 
216  // Check Flash memory access
217  {
218  // Program Flash in main memory
219  EraseFLASH(ERASE_SEGMENT, mainStartAdress);
220  WriteFLASH(mainStartAdress, WordBufferSize, WriteData);
221  if(VerifyMem(mainStartAdress, WordBufferSize, WriteData) != STATUS_OK)
222  {
224  }
225  }
226 
227  // This will erase all Flash memory banks in main memory.
228  // Additionally an erase check is performed
229  {
230  // Erase all Flash memory banks in main memory.
231  EraseFLASH(ERASE_MAIN, mainStartAdress);
232  // Check, if main memory is erased completely
233  if (!EraseCheck(mainStartAdress, mainLength))
234  {
236  }
237  }
238 
239  // This will only erase one flash memory bank (64KB) in main memory.
240  // I.e. the second memory bank of an MSP430F5438 can be erased by calling:
241  {
242  //EraseFLASH(ERASE_BANK, 0x10100);
243  }
244 
245  // The following section shows how to erase Info-Segments on 5xx Devices selectively
246  {
247  // Comment-in the following code to unlock Info memory segment A
248 
249  /*{
250  UnlockInfoA_430Xv2();
251 
252  // Info A memory erase
253  EraseFLASH(ERASE_SEGMENT, 0x1980);
254 
255  // Check Info A memory erasure
256  if (!EraseCheck(0x1980, 0x0040))
257  {
258  ShowStatus(STATUS_ERROR, 2);
259  }
260  }*/
261 
262  // Info B memory erase
263  EraseFLASH(ERASE_SEGMENT, 0x1900);
264 
265  // Check Info B memory erasure
266  if (!EraseCheck(0x1900, 0x0040))
267  {
269  }
270  // Info C erase
271  EraseFLASH(ERASE_SEGMENT, 0x1880);
272  // Check Info C memory erasure
273  if (!EraseCheck(0x1880, 0x0040))
274  {
276  }
277  // Info D erase
278  EraseFLASH(ERASE_SEGMENT, 0x1800);
279  // Check Info D memory erasure
280  if (!EraseCheck(0x1800, 0x0040))
281  {
283  }
284  }
285 
286  // The following code unlocks the BSL memory on 5xx/6xx devices with flash memory
287  // for reading/writing/erasure.
288  // WARNING: The code in the BSL memory area should only be erased if another BSL is
289  // programmed immediately afterwards. Otherwise, the device might not start
290  // up properly anymore.
291  /*{
292  UnlockBsl_430Xv2Flash();
293  }*/
294 
295  // Program target code
296  if (!WriteFLASHallSections(&eprom[0], &eprom_address[0], &eprom_length_of_sections[0], eprom_sections))
297  {
299  }
300 
301 /*------------------------------------------------------------------------------------------------------*/
302 /* 6. | Program the JTAG lock key (optional) */
303 /*------------------------------------------------------------------------------------------------------*/
304 
305  // Remove following comments to enable Lock Key programming routine.
306  // This makes the MSP430 device permanently inaccessible via JTAG
307 
308  /*if (!ProgramLockKey()) // ***Action is permanent***
309  {
310  ShowStatus(STATUS_ERROR, 15);
311  }*/
312 
313 /*------------------------------------------------------------------------------------------------------*/
314 /* 7. | Release the target device from JTAG control and wait for the user to press button "S1" */
315 /*------------------------------------------------------------------------------------------------------*/
316 
317  ReleaseDevice(V_RESET); // Perform Reset, release CPU from JTAG control
318  //MsDelay(3000); // Target board LED should start blinking
319  ShowStatus(STATUS_OK, 0); // OK: green LED is ON
320 
321  _EINT(); // Enable Interrupts
322  P1IE |= 0x040; // P1.6 interrupt enabled
323 
324  while(1); // Idle, wait for keypress (handled in ISR)
325 }
326 
327 /*------------------------------------------------------------------------------------------------------*/
328 
330 #pragma vector=PORT1_VECTOR
331 __interrupt void Port_1(void)
332 {
333  ReleaseTarget(); // Release Target Board from power
334  ShowStatus(STATUS_ACTIVE, 0); // Switch both LEDs on to indicate operation.
335  P1IE &= ~0x040; // P1.6 interrupt disabled
336  MsDelay(1000); // Wait 1s before restarting the Controller and Target
337  P1IFG = 0;
338  runProgramm(); // Restart Controller and Target
339 }
340 
341 /****************************************************************************/
342 /* END OF SOURCE FILE */
343 /****************************************************************************/
#define STATUS_ACTIVE
Replicator is active.
#define ERASE_SEGMENT
Constant for an erase of the selected flash memory segment.
void ShowStatus(word status, word index)
This function controls the status LEDs depending on the status argument. It stops program in error ca...
Header file for target code (blinking LED)
__interrupt void Port_1(void)
This interrupt service routine calls runProgramm() if button "S1" is pressed.
const unsigned long eprom_address[10]
Holds the destination adresses for different sections of the target code.
Configurations for the MSP430 Replicator Xv2.
JTAG Function Prototypes and Definitions.
#define MAIN_LENGTH
Set length of main memory.
Definition: Config430Xv2.h:80
unsigned long mainStartAdress
This variable holds the start address of the main memory.
const unsigned int eprom[10]
Holds the entire target code.
void main(void)
Main function.
void InitController(void)
Initialization of the Controller Board.
unsigned long mainLength
This variable holds the length of the main memory (in words)
#define MAIN_START_ADDRESS
Set start address of the main memory.
Definition: Config430Xv2.h:76
const unsigned long eprom_sections
Holds the number of memory sections.
void runProgramm(void)
The basic Replicator routine.
#define STATUS_OK
return 1 = no error
void ReleaseTarget(void)
Release Target Board (switch voltages off, JTAG pins are HI-Z)
#define V_RESET
Triggers a regular reset on device release from JTAG control.
void MsDelay(word milliseconds)
Delay function (resolution is 1 ms)
#define ERASE_MAIN
Constant for an erase of the entire flash main memory.
#define STATUS_ERROR
return 0 = error
const unsigned long eprom_length_of_sections[10]
Holds the length of the different memory sections.
void InitTarget(void)
Initialization of the Target Board (switch voltages on, preset JTAG pins)
Low Level function prototypes, macros, and pin-to-signal assignments regarding to user's hardware...
#define WordBufferSize
Buffer size for read and write operations in words.
Definition: Config430Xv2.h:149

Copyright 2016, Texas Instruments Incorporated