Replicator430FR.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 | Replicator430FR.c |
36 | |
37 | JTAG Replicator for FRAM-based MSP430 devices |
38 | |
39 | Key features: |
40 | · Supports JTAG communication to all FRxx family 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 Device Access with user set JTAG password |
45 | · Supports deactivation of the Memory Protection Unit |
46 | · Supports Programming of JTAG Access Protection Fuse |
47 | |
48 |----------------------------------------------------------------------------|
49 | Project: MSP430 FRAM Replicator |
50 | Developed using: IAR Embedded Workbench 6.20 |
51 | and: Code Composer Studio 6.0 |
52 |----------------------------------------------------------------------------|
53 | Version history: |
54 | 1.0 04/14 RL Initial version. |
55 | 1.1 06/15 RL Commented out optional RAM operations |
56 |----------------------------------------------------------------------------|
57 | Designed 2014 by Texas Instruments Germany |
58 \*==========================================================================*/
61 /****************************************************************************/
62 /* Main section of Replicator program: User can modify/insert code as needed*/
63 /****************************************************************************/
64 /* Main function:
65  Upon execution completion, LED blinks for device target socket
66  boards when used as the target system (P1.0 drives LED).
67 
68  Note: All High Level JTAG Functions are applied here.
69 
70  A number of lines have been commented out which are not strictly required
71  to successfully program a flash or fram-based MSP430 device using the
72  Replicator concept. Please note that these lines have been commented out in
73  order to provide reference examples for calling such functions.
74  Uncommented lines below represent the minimum requirements to successfully
75  program an MSP430 device using the Replicator.
76 
77  The basic routine consists of the following steps:
78 
79  1. | Initialize the host MSP430 on the Replicator board
80  2. | Connect to the target device (provide JTAG password if needed)
81  3. | Control the target peripherals directly (optional)
82  4. | Perform a write + read + verify in the target RAM (optional)
83  5. | Operations in the device's main memory
84  6. | Program the JTAG lock key (optional)
85  7. | Release the device from JTAG control and wait for the user to press button "S1"
86 */
87 
88 /****************************************************************************/
89 /* INCLUDES */
90 /****************************************************************************/
91 
92 #include "JTAGfunc430FR.h" // JTAG functions
93 #include "Config430FR.h" // High level user configuration
94 #include "LowLevelFunc430Xv2.h" // Low level functions
95 
96 /****************************************************************************/
97 /* VARIABLES */
98 /****************************************************************************/
99 
103 unsigned long mainLength = MAIN_LENGTH;
104 
105 /****************************************************************************/
106 /* FUNCTIONS */
107 /****************************************************************************/
108 
110 void main(void)
111 {
112  runProgramm();
113 }
114 
117 void runProgramm(void)
118 {
119 
121  word WriteData[WordBufferSize];
123  word ReadData[WordBufferSize];
124 
125 /*------------------------------------------------------------------------------------------------------*/
126 /* 1. | Initialize host MSP430 (on Replicator board) & target board */
127 /*------------------------------------------------------------------------------------------------------*/
128 
129  InitController(); // Initialize the host MSP430F5437
130 
131  ShowStatus(STATUS_ACTIVE, 0); // Switch both LEDs on to indicate operation.
132 
133  InitTarget(); // Initialize target board
134 
135 /*------------------------------------------------------------------------------------------------------*/
136 /* 2. | Connect to the target device (provide JTAG password if needed) */
137 /*------------------------------------------------------------------------------------------------------*/
138 
139  // Uncomment the following section if the JTAG password is set and should be removed - FR5xx/FR6xx
140  /*{
141  // enter password & length here:
142  unsigned short Password[] = { 0x1111, 0x2222 };
143  unsigned long PasswordLength = 0x02; // password length in words
144 
145  //Unlock device with user password
146  if(UnlockDevice_430Xv2(Password, PasswordLength) != STATUS_OK)
147  {
148  ShowStatus(STATUS_ERROR, 1); // stop here password was wrong
149  }
150  } */
151 
152  // Uncomment the following section if the JTAG password is set and should be removed - FR4xx/FR2xx
153  /*if(GetDevice_430Xv2() == STATUS_FUSEBLOWN)
154  {
155  if (!EraseFRAMViaBootCode_430Xv2(MAIL_BOX_32BIT, STOP_DEVICE, USER_CODE_ERASE))
156  {
157  ShowStatus(STATUS_ERROR, 2);
158  }
159  // Check if main memory is completely erased.
160  if (!EraseCheck_430Xv2(mainStartAdress, mainLength/2))
161  {
162  ShowStatus(STATUS_ERROR, 2);
163  }
164  }*/
165 
166 
167  if (GetDevice_430Xv2() != STATUS_OK) // Set DeviceId
168  {
169  ShowStatus(STATUS_ERROR, 1); // Stop here if invalid JTAG ID or
170  }
171  // time-out. (error: red LED is ON)
172 
173 
174 
175 /*------------------------------------------------------------------------------------------------------*/
176 /* 3. | Perform a erase + 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  // DisableMpu_430Xv2() must be called prior to this, if the device's MPU is enabled
182 
183  /*
184  word i,j;
185  // write dummy data to target RAM
186  for(i = 0, j = 0; j < WordBufferSize; j++, i+=2)
187  {
188  ReadData[j] = 0;
189  WriteData[j] = j;
190  WriteMem_430Xv2(F_WORD, MAIN_START_ADDRESS + i, j);
191  }
192  // read data from target RAM and verify
193  for(i = 0, j = 0; j < WordBufferSize; j++, i+=2)
194  {
195  ReadData[j] = ReadMem_430Xv2(F_WORD, MAIN_START_ADDRESS + i);
196  MsDelay(1);
197  if(ReadData[j] != WriteData[j])
198  {
199  ShowStatus(STATUS_ERROR, 2);
200  }
201  }
202  // verify content with PSA
203  if(VerifyMem_430Xv2(MAIN_START_ADDRESS, WordBufferSize, WriteData) != STATUS_OK)
204  {
205  ShowStatus(STATUS_ERROR, 3);
206  }
207  */
208 
209 /*------------------------------------------------------------------------------------------------------*/
210 /* 4. | Operations in the device's main memory (disable MPU if necessary) */
211 /*------------------------------------------------------------------------------------------------------*/
212 
213  // The Memory Protection Unit (MPU) allows the user to set up individual access rights for up to
214  // three user defined memory segments. For detailed information see the Memory Protection Unit
215  // description in the device family user's guide.
216 
217  // Disable Memory Protection Unit
218  if (DisableMpu_430Xv2() != STATUS_OK)
219  {
221  }
222 
223  // Not possible on FR5739 - use EraseFRAM_430Xv2 instead
224  // Erase main FRAM memory using the JTAG mailbox and Bootcode
226  {
228  }
229  // Check if main memory is completely erased.
231  {
233  }
234  // Since EraseCheck executes a BOR - The MPU gets enabled again - Disable it before code download
235  if (DisableMpu_430Xv2() != STATUS_OK)
236  {
238  }
239  //Program blinking LED target code
240  if(DownloadMsp430Code() != STATUS_OK)
241  {
243  }
244 
245 /*------------------------------------------------------------------------------------------------------*/
246 /* 5. | Program the JTAG lock key (optional) */
247 /*------------------------------------------------------------------------------------------------------*/
248 
249  // Remove following comments to enable Lock Key programming routine.
250  // This makes the MSP430 device permanently inaccessible via JTAG
251 
252  /*if (DisableMpu_430Xv2() != STATUS_OK)
253  {
254  ShowStatus(STATUS_ERROR, 2);
255  }
256  if (!ProgramLockKey()) // ***Action is permanent***
257  {
258  ShowStatus(STATUS_ERROR, 15);
259  }*/
260 
261 /*------------------------------------------------------------------------------------------------------*/
262 /* 6. | Release the target device from JTAG control and wait for the user to press button "S1" */
263 /*------------------------------------------------------------------------------------------------------*/
264 
265  ReleaseDevice_430Xv2(V_RESET); // Perform Reset, release CPU from JTAG control
266  // Target board LED should start blinking
267  ShowStatus(STATUS_OK, 0); // OK: green LED is ON
268 
269  _EINT(); // Enable Interrupts
270  P1IE |= 0x040; // P1.6 interrupt enabled
271 
272  while(1); // Idle, wait for keypress (handled in ISR)
273 }
274 
275 /*------------------------------------------------------------------------------------------------------*/
276 
278 #pragma vector=PORT1_VECTOR
279 __interrupt void Port_1(void)
280 {
281  ReleaseTarget(); // Release Target Board from power
282  ShowStatus(STATUS_ACTIVE, 0); // Switch both LEDs on to indicate operation.
283  P1IE &= ~0x040; // P1.6 interrupt disabled
284  MsDelay(1000); // Wait 1s before restarting the Controller and Target
285  P1IFG = 0;
286  runProgramm(); // Restart Controller and Target
287 }
288 
289 /****************************************************************************/
290 /* END OF SOURCE FILE */
291 /****************************************************************************/
#define V_RESET
Triggers a regular reset on device release from JTAG control.
short DownloadMsp430Code()
Download a program to target.
word DisableMpu_430Xv2(void)
This function disables the Memory Protection Unit (FRAM devices only)
#define STATUS_ACTIVE
Replicator is active.
void ShowStatus(word status, word index)
This function controls the status LEDs depending on the status argument. It stops program in error ca...
void runProgramm(void)
The basic Replicator routine.
Configurations for the MSP430 FRAM Replicator.
#define WordBufferSize
Buffer size for read and write operations in words.
Definition: Config430FR.h:122
void InitController(void)
Initialization of the Controller Board.
word EraseFRAMViaBootCode_430Xv2(word mailBoxMode, word data1, word data2)
This function performs a Erase of FRxx devices using the JTAG mailbox.
#define MAIL_BOX_32BIT
JTAG mailbox mode 32 bit -.
__interrupt void Port_1(void)
This interrupt service routine calls runProgramm() if button "S1" is pressed.
unsigned long mainStartAdress
This variable holds the start address of the main memory.
void main(void)
Main function.
#define STATUS_OK
return 1 = no error
word GetDevice_430Xv2(void)
Function to take target device under JTAG control. Disables the target watchdog. Sets the global DEVI...
#define MAIN_START_ADDRESS
Enable FR4xx/FR2xx special handling.
Definition: Config430FR.h:76
void ReleaseTarget(void)
Release Target Board (switch voltages off, JTAG pins are HI-Z)
unsigned long mainLength
This variable holds the length of the main memory (in words)
void MsDelay(word milliseconds)
Delay function (resolution is 1 ms)
void ReleaseDevice_430Xv2(unsigned long Addr)
Function to release the target device from JTAG control.
#define STATUS_ERROR
return 0 = error
#define MAIN_LENGTH
Set length of main memory.
Definition: Config430FR.h:80
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 USER_CODE_ERASE
Constant for an erase of the FRAM Main & INFO memory including JTAG lock signature on FR4xx...
Definition: JTAGfunc430FR.h:84
word EraseCheck_430Xv2(unsigned long StartAddr, unsigned long Length)
This function performs an Erase Check over the given memory range.
JTAG Function Prototypes and Definitions.

Copyright 2016, Texas Instruments Incorporated