JTAGfunc430FR.h
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 | JTAGfunc430FR.h |
36 | |
37 | JTAG Function Prototypes and Definitions |
38 |----------------------------------------------------------------------------|
39 | Project: MSP430 FRAM Replicator |
40 | Developed using: IAR Embedded Workbench 6.20 |
41 | and: Code Composer Studio 6.0 |
42 |----------------------------------------------------------------------------|
43 | Version history: |
44 | 1.0 04/14 RL Initial version. |
45 |----------------------------------------------------------------------------|
46 | Designed 2014 by Texas Instruments Germany |
47 \*==========================================================================*/
50 /****************************************************************************/
51 /* INCLUDES */
52 /****************************************************************************/
53 
54 #include "Config430FR.h" // High-level user input
55 
56 /****************************************************************************/
57 /* Global types */
58 /****************************************************************************/
59 
60 #ifndef __BYTEWORD__
61 #define __BYTEWORD__
62 typedef unsigned short word;
63 typedef unsigned char byte;
64 #endif
65 
66 /****************************************************************************/
67 /* Define section for constants */
68 /****************************************************************************/
69 
70 // Constants for flash erasing modes
72 #define ERASE_MAIN 0xA506
73 #define ERASE_BANK 0xA504
75 #define ERASE_SEGMENT 0xA502
77 #define MAIN_ERASE 0x1A1A
79 #define TOTAL_ERASE 0x1B1B
82 #define USER_CODE_ERASE 0x1A1A
85 #define STOP_DEVICE 0xA55A
86 
87 //----------------------------------------------------------------------------
88 // Constants for the JTAG instruction register (IR) require LSB first.
89 // The MSB has been interchanged with LSB due to use of the same shifting
90 // function as used for the JTAG data register (DR) which requires MSB
91 // first.
92 //----------------------------------------------------------------------------
93 
94 // Instructions for the JTAG control signal register
96 #define IR_CNTRL_SIG_16BIT 0xC8 // original value: 0x13
97 #define IR_CNTRL_SIG_CAPTURE 0x28 // original value: 0x14
99 #define IR_CNTRL_SIG_RELEASE 0xA8 // original value: 0x15
101 
102 // Instructions for the JTAG fuse
104 #define IR_PREPARE_BLOW 0x44 // original value: 0x22
105 #define IR_EX_BLOW 0x24 // original value: 0x24
107 
108 // Instructions for the JTAG data register
111 #define IR_DATA_16BIT 0x82 // original value: 0x41
112 #define IR_DATA_QUICK 0xC2 // original value: 0x43
114 
115 // Instructions for the JTAG PSA mode
117 #define IR_DATA_PSA 0x22 // original value: 0x44
118 #define IR_SHIFT_OUT_PSA 0x62 // original value: 0x46
120 
121 // Instructions for the JTAG address register
124 #define IR_ADDR_16BIT 0xC1 // original value: 0x83
125 #define IR_ADDR_CAPTURE 0x21 // original value: 0x84
127 #define IR_DATA_TO_ADDR 0xA1 // original value: 0x85
130 #define IR_BYPASS 0xFF // original value: 0xFF
132 #define IR_DATA_CAPTURE 0x42
133 
134 // JTAG identification values for all existing Flash-based MSP430 devices
136 #define JTAG_ID 0x89
137 #define JTAG_ID91 0x91
139 #define JTAG_ID98 0x98
141 #define JTAG_ID99 0x99
143 // Additional instructions for JTAG_ID91 architectures
145 #define IR_COREIP_ID 0xE8 // original value: 0x17
146 #define IR_DEVICE_ID 0xE1 // original value: 0x87
148 
149 // Instructions for the JTAG mailbox
151 #define IR_JMB_EXCHANGE 0x86 // original value: 0x61
152 #define IR_TEST_REG 0x54 // original value: 0x2A
154 #define IR_TEST_3V_REG 0xF4 // original value: 0x2F
156 
157 // Constants for JTAG mailbox data exchange
159 #define OUT1RDY 0x0008
160 #define IN0RDY 0x0001
162 #define JMB32B 0x0010
164 #define OUTREQ 0x0004
166 #define INREQ 0x0001
168 #define MAIL_BOX_32BIT 0x10
170 #define MAIL_BOX_16BIT 0x00
172 
173 // Constants for data formats
174 #ifndef __DATAFORMATS__
175 #define __DATAFORMATS__
176 #define F_BYTE 8
177 #define F_WORD 16
178 #define F_ADDR 20
179 #define F_LONG 32
180 #endif
181 
182 // dedicated addresses
184 #define V_RESET 0xFFFE
185 #define V_BOR 0x1B08
187 
188 // Constants for VPP connection at Blow-Fuse
190 #define VPP_ON_TDI 0
191 #define VPP_ON_TEST 1
193 
194 /****************************************************************************/
195 /* VARIABLES */
196 /****************************************************************************/
197 
199 static word JtagId = 0;
201 static word CoreId = 0;
203 static unsigned long DeviceIdPointer = 0;
205 static word DeviceId = 0;
206 
208 static unsigned short SegmentInfoAKey5xx = 0xA548;
209 
212 typedef struct struct_program
213 {
215  const unsigned short* textData;
217  const unsigned long* startAddress;
219  const unsigned long* sectionLength;
221  unsigned long noSections;
223  unsigned long start;
225 
226 /****************************************************************************/
227 /* FUNCTION PROTOTYPES */
228 /****************************************************************************/
229 
230 // Low level JTAG functions
231 static word DR_Shift16(word Data);
232 static unsigned long DR_Shift20(unsigned long address);
233 static word IR_Shift(byte Instruction);
234 static void ResetTAP(void);
235 static word ExecutePOR_430Xv2(void);
236 static void SetPC_430Xv2(unsigned long Addr);
237 word VerifyPSA_430Xv2(unsigned long StartAddr, unsigned long Length, unsigned short const *DataArray);
238 word GetCoreipIdXv2();
239 void jResetJtagTap(void);
240 void StartJtagJSbw(byte states);
241 void jRelease(void);
242 long jsbw_Shift(word Format, long Data);
243 long jsbw_IR_Shift(byte instruction);
244 long jsbw_DR_Shift(long data);
245 void JsbwMagicPattern(void);
246 void jsbwJtagUnlock(void);
247 
248 // High level JTAG functions
249 word GetDevice_430Xv2(void);
250 void ReleaseDevice_430Xv2(unsigned long Addr);
251 void WriteMem_430Xv2(word Format, unsigned long Addr, word Data);
252 void WriteMemQuick_430Xv2(unsigned long StartAddr, unsigned long Length, unsigned short const *DataArray);
253 word ReadMem_430Xv2(word Format, unsigned long Addr);
254 void ReadMemQuick_430Xv2(unsigned long StartAddr, unsigned long Length, word *DataArray);
255 word EraseCheck_430Xv2(unsigned long StartAddr, unsigned long Length);
256 word VerifyMem_430Xv2(unsigned long StartAddr, unsigned long Length, unsigned short const *DataArray);
257 word UnlockDevice_430Xv2(unsigned short* password, unsigned long passwordLength);
258 void EraseFRAM_430Xv2(unsigned long StartAddr, unsigned long Length);
259 word DisableMpu_430Xv2(void);
260 word ProgramLockKey(void);
261 word IsLockKeyProgrammed(void);
262 void UnlockBsl_430Xv2FRAM(void);
263 
264 // File download functions
265 short DownloadProgram(struct_Program* program);
266 short DownloadMsp430Code();
267 word EraseFRAMViaBootCode_430Xv2(word mailBoxMode, word data1, word data2);
268 
269 /****************************************************************************/
270 /* END OF SOURCE FILE */
271 /****************************************************************************/
struct struct_program struct_Program
const unsigned long * startAddress
Array of start addresses of the sections.
word IsLockKeyProgrammed(void)
This function checks if the JTAG lock key is programmed.
word EraseFRAMViaBootCode_430Xv2(word mailBoxMode, word data1, word data2)
This function performs a Erase of FRxx devices using the JTAG mailbox.
void ReleaseDevice_430Xv2(unsigned long Addr)
Function to release the target device from JTAG control.
void JsbwMagicPattern(void)
Function for applying the magic pattern via JSBW.
Definition: JSBW.c:271
void ReadMemQuick_430Xv2(unsigned long StartAddr, unsigned long Length, word *DataArray)
This function reads an array of words from the memory.
const unsigned long * sectionLength
Array of length information of the sections.
word VerifyMem_430Xv2(unsigned long StartAddr, unsigned long Length, unsigned short const *DataArray)
This function performs a Verification over the given memory range.
Configurations for the MSP430 FRAM Replicator.
word UnlockDevice_430Xv2(unsigned short *password, unsigned long passwordLength)
This function unlocks the Fram memory when a JTAG password is set.
long jsbw_DR_Shift(long data)
Function for shifting data into the JTAG data register through JSBW (MSB first, but with interchanged...
Definition: JSBW.c:249
word ProgramLockKey(void)
This function blows the security fuse.
word DisableMpu_430Xv2(void)
This function disables the Memory Protection Unit (FRAM devices only)
void jResetJtagTap(void)
Reset target JTAG interface and perform fuse-HW check.
Definition: JSBW.c:154
const unsigned short * textData
Array executable code and data sections.
word VerifyPSA_430Xv2(unsigned long StartAddr, unsigned long Length, unsigned short const *DataArray)
This function compares the computed PSA (Pseudo Signature Analysis) value to the PSA value shifted ou...
void StartJtagJSbw(byte states)
Start JTAG communication in JSBW mode.
Definition: JSBW.c:79
void jsbwJtagUnlock(void)
Function for resetting the JTAG lock via JSBW.
Definition: JSBW.c:283
unsigned long noSections
Number of sections.
void WriteMemQuick_430Xv2(unsigned long StartAddr, unsigned long Length, unsigned short const *DataArray)
This function writes an array of words into the target memory.
word EraseCheck_430Xv2(unsigned long StartAddr, unsigned long Length)
This function performs an Erase Check over the given memory range.
long jsbw_Shift(word Format, long Data)
Shift a value into TDI (MSB first) and simultaneously shift out a value from TDO (MSB first)...
Definition: JSBW.c:173
short DownloadMsp430Code()
Download a program to target.
void EraseFRAM_430Xv2(unsigned long StartAddr, unsigned long Length)
This function performs an erase of a user defined FRAM memory section. For FRAM devices the erase equ...
void WriteMem_430Xv2(word Format, unsigned long Addr, word Data)
This function writes one byte/word at a given address ( <0xA00)
void UnlockBsl_430Xv2FRAM(void)
This function unlocks the BSL memory protection.
word ReadMem_430Xv2(word Format, unsigned long Addr)
This function reads one byte/word from a given address in memory.
long jsbw_IR_Shift(byte instruction)
Function for shifting a new instruction into the JTAG instruction register through JSBW (MSB first...
Definition: JSBW.c:229
short DownloadProgram(struct_Program *program)
DownloadFile Load program data int memory sections.
void jRelease(void)
Releases the JSBW logic.
Definition: JSBW.c:65
word GetDevice_430Xv2(void)
Function to take target device under JTAG control. Disables the target watchdog. Sets the global DEVI...
unsigned long start
Execution start address.
word GetCoreipIdXv2()
Function to determine & compare core identification info (Xv2)

Copyright 2016, Texas Instruments Incorporated