108 static word DR_Shift16(word data)
110 #ifdef SPYBIWIRE_MODE
148 static unsigned long DR_Shift20(
unsigned long address)
150 #ifdef SPYBIWIRE_MODE
189 static word IR_Shift(byte instruction)
191 #ifdef SPYBIWIRE_MODE
232 static void ResetTAP(
void)
236 #ifdef SPYBIWIRE_MODE
238 for (i = 6; i > 0; i--)
251 for (i = 6; i > 0; i--)
272 static word ExecutePOR_430Xv2(
void)
316 if(DR_Shift16(0) & 0x0301)
327 static void SetPC_430Xv2(
unsigned long Addr)
333 Mova += (
unsigned short)((Addr>>8) & 0x00000F00);
334 Pc_l = (
unsigned short)((Addr & 0xFFFF));
338 if(DR_Shift16(0) & 0x0301)
366 static unsigned long i_ReadJmbOut(
void)
368 unsigned short sJMBINCTL;
369 unsigned long lJMBOUT = 0;
370 unsigned short sJMBOUT0, sJMBOUT1;
375 lJMBOUT = DR_Shift16(sJMBINCTL);
380 lJMBOUT = DR_Shift16(sJMBINCTL);
381 sJMBOUT0 = (
unsigned short)DR_Shift16(0);
382 sJMBOUT1 = (
unsigned short)DR_Shift16(0);
384 lJMBOUT = ((
unsigned long)sJMBOUT1<<16) + sJMBOUT0;
395 static short i_WriteJmbIn16(word dataX)
397 unsigned short sJMBINCTL;
398 unsigned short sJMBIN0;
399 unsigned long Timeout = 0;
400 sJMBIN0 = (
unsigned short)(dataX & 0x0000FFFF);
412 while(!(DR_Shift16(0x0000) &
IN0RDY) && Timeout < 3000);
415 DR_Shift16(sJMBINCTL);
426 static short i_WriteJmbIn32(
unsigned short dataX,
unsigned short dataY)
428 unsigned short sJMBINCTL;
429 unsigned short sJMBIN0,sJMBIN1;
430 unsigned long Timeout = 0;
432 sJMBIN0 = (
unsigned short)(dataX & 0x0000FFFF);
433 sJMBIN1 = (
unsigned short)(dataY & 0x0000FFFF);
445 while(!(DR_Shift16(0x0000) & IN0RDY) && Timeout < 3000);
450 DR_Shift16(sJMBINCTL) ;
469 const word POLY = 0x0805;
470 word PSA_CRC = (word)(StartAddr-2);
474 SetPC_430Xv2(StartAddr);
486 for (i = 0; i < Length; i++)
489 if ((PSA_CRC & 0x8000) == 0x8000)
500 &DataArray[0] == 0 ? (PSA_CRC ^= 0xFFFF) : (PSA_CRC ^= DataArray[i]);
504 #ifdef SPYBIWIRE_MODE
543 TDOword = DR_Shift16(0x0000);
561 static void ConnectJTAG()
569 static void StopJtag (
void)
578 static void EntrySequences_RstHigh_SBW()
612 static void EntrySequences_RstLow_SBW()
644 static void EntrySequences_RstHigh_JTAG()
677 static void EntrySequences_RstLow_JTAG()
714 static word magicPattern(
void)
716 word deviceJtagID = 0;
724 EntrySequences_RstLow_SBW();
728 EntrySequences_RstLow_JTAG();
733 if(i_WriteJmbIn16(STOP_DEVICE) ==
STATUS_OK)
738 EntrySequences_RstHigh_SBW();
742 EntrySequences_RstHigh_JTAG();
758 #ifdef LPM5_ACTIVATED
760 #ifdef SPYBIWIREJTAG_IF // run 2 wire mode of 4 wire selection because 4wire pins are locked by JTAG lock
777 EntrySequences_RstHigh_JTAG();
795 static word GetCoreID (
void)
810 EntrySequences_RstHigh_SBW();
814 EntrySequences_RstHigh_JTAG();
827 if(i >= MAX_ENTRY_TRY)
831 #ifdef ACTIVATE_MAGIC_PATTERN
835 JtagId = magicPattern();
837 if((JtagId == 1) || (i >= MAX_ENTRY_TRY))
870 CoreId = DR_Shift16(0);
876 DeviceIdPointer = DR_Shift20(0);
885 static word SyncJtag_AssertPor (
void)
897 while(!(DR_Shift16(0) & 0x0200) && i < 50)
993 if(DR_Shift16(0) & 0x0301)
997 if (Format == F_WORD)
1032 for (i = 0; i < Length; i++)
1050 FlashWrite_o[2] = (
unsigned short)(StartAddr);
1051 FlashWrite_o[3] = (
unsigned short)(StartAddr>>16);
1052 FlashWrite_o[4] = (
unsigned short)(Length);
1053 FlashWrite_o[5] = (
unsigned short)(Length>>16);
1054 FlashWrite_o[6] = SegmentInfoAKey5xx;
1061 unsigned long Jmb = 0;
1062 unsigned long Timeout = 0;
1066 Jmb = i_ReadJmbOut();
1069 while(Jmb != 0xABADBABE && Timeout < 3000);
1075 for(i = 0; i < Length; i++)
1077 i_WriteJmbIn16(DataArray[i]);
1083 unsigned long Jmb = 0;
1084 unsigned long Timeout = 0;
1088 Jmb = i_ReadJmbOut();
1091 while(Jmb != 0xCAFEBABE && Timeout < 3000);
1094 SyncJtag_AssertPor();
1100 for (i = 0; i < FlashWrite_o_length/2; i++)
1118 word
WriteFLASHallSections_430Xv2(
const unsigned int *data,
const unsigned long *address,
const unsigned long *length_of_sections,
const unsigned long sections)
1122 for(i = 0; i < sections; i++)
1125 WriteFLASH(address[i], length_of_sections[i], (word*)&data[init-1]);
1126 if (!VerifyMem(address[i], length_of_sections[i], (word*)&data[init-1]))
1130 init += length_of_sections[i];
1146 if(DR_Shift16(0) & 0x0301)
1151 if (Format == F_WORD)
1164 TDOword = DR_Shift16(0x0000);
1183 unsigned long i, lPc = 0;
1191 SetPC_430Xv2(StartAddr);
1199 for (i = 0; i < Length; i++)
1203 *DataArray++ = DR_Shift16(0);
1226 FlashErase_o[2] = (
unsigned short)(EraseAddr);
1227 FlashErase_o[3] = (
unsigned short)(EraseAddr>>16);
1228 FlashErase_o[4] = EraseMode;
1229 FlashErase_o[5] = SegmentInfoAKey5xx;
1236 unsigned long Jmb = 0;
1237 unsigned long Timeout = 0;
1241 Jmb = i_ReadJmbOut();
1244 while(Jmb != 0xCAFEBABE && Timeout < 3000);
1247 SyncJtag_AssertPor();
1253 for (i = 0; i < FlashErase_o_length/2; i++)
1274 FlashErase_o[2] = (
unsigned short)(EraseAddr);
1275 FlashErase_o[3] = (
unsigned short)(EraseAddr>>16);
1276 FlashErase_o[4] = EraseMode;
1277 FlashErase_o[5] = SegmentInfoAKey5xx;
1284 SetPC_430Xv2(startAddr);
1306 SyncJtag_AssertPor();
1312 for (i = 0; i < FlashErase_o_length/2; i++)
1347 word LockKey[2] = { 0xDEAD, 0xBABE };
1351 WriteMem(F_WORD, 0x0182, 0x0003);
1354 WriteFLASH(0x17FC, 2, LockKey);
1373 for (i = 3; i > 0; i--)
1376 if (DR_Shift16(0xAAAA) == 0x5555)
1388 unsigned short BslCur;
1393 BslCur &= ~SYSBSLPE;
1402 SegmentInfoAKey5xx = 0xA508;
void usDelay(word microseconds)
Delay function (resolution is ~1 us)
#define ClrTST()
SBW macro: clear TEST pin signal.
#define IR_CNTRL_SIG_RELEASE
Release the CPU from JTAG control.
word ProgramLockKey(void)
This function disables JTAG access to the target device.
#define IR_SHIFT_OUT_PSA
Shift out the PSA pattern generated by IR_DATA_PSA.
#define OUTREQ
JTAG mailbox constant -.
#define V_BOR
Triggers a "brown-out" reset on device release from JTAG control.
#define SetTCLK()
SBW macro: set TCLK signal.
#define IR_DATA_QUICK
Set the MSP430 MDB to a specific 16-bit value (RAM only)
#define OUT1RDY
JTAG mailbox constant -.
byte tdo_bit
Holds the value of TDO-bit.
#define RAM_START_ADDRESS
Set the start address of the device RAM.
unsigned long AllShifts(word Format, unsigned long Data)
Shift a value into TDI (MSB first) and simultaneously shift out a value from TDO (MSB first)...
void WriteFLASH_430Xv2(unsigned long StartAddr, unsigned long Length, word *DataArray)
This function programs/verifies an array of words into the FLASH memory by using the FLASH controller...
JTAG Function Prototypes and Definitions.
#define IR_DATA_TO_ADDR
Set the MSP430 MDB with a specific 16-bit value and write it to the memory address which is currently...
#define JTAG_ID99
JTAG identification value for 430Xv2 architecture FR59XX devices.
word EraseCheck_430Xv2(unsigned long StartAddr, unsigned long Length)
This function performs an Erase Check over the given memory range.
#define SetTST()
SBW macro: set TEST pin signal.
word VerifyPSA_430Xv2(unsigned long StartAddr, unsigned long Length, word *DataArray)
This function compares the computed PSA (Pseudo Signature Analysis) value to the PSA value shifted ou...
#define IR_TEST_3V_REG
Instruction for 3 volt test register in 5xx.
#define IR_TEST_REG
Instruction for test register in 5xx.
#define IR_ADDR_16BIT
Set the MSP430 MAB to a specific 16-bit value.
byte TCLK_saved
Holds the last value of TCLK before entering a JTAG sequence.
#define SBWDATO
JTAG data_out pin in SBW mode -separate pin in MSP430F5437 - common IO translator.
unsigned short FlashErase_o[]
Holds the target code for a flash erase operation.
#define IR_CNTRL_SIG_CAPTURE
Read out the JTAG control signal register.
word VerifyMem_430Xv2(unsigned long StartAddr, unsigned long Length, word *DataArray)
This function performs a Verification over the given memory range.
#define IR_DATA_PSA
Switch JTAG data register to PSA mode.
#define INREQ
JTAG mailbox constant -.
#define JTAG_ID91
JTAG identification value for 430Xv2 architecture devices.
#define STATUS_FUSEBLOWN
GetDevice returns this if the security fuse is blown.
void jResetJtagTap(void)
Reset target JTAG interface and perform fuse-HW check.
void jsbwJtagUnlock(void)
Function for resetting the JTAG lock via JSBW.
#define JMB32B
JTAG mailbox constant -.
word GetCoreipIdXv2()
Function to determine & compare core identification info (Xv2)
word GetDevice_430Xv2(void)
Function to take target device under JTAG control. Disables the target watchdog. Sets the global DEVI...
#define IR_DEVICE_ID
Instruction to determine device's DeviceID.
void ReleaseDevice_430Xv2(unsigned long Addr)
Function to release the target device from JTAG control.
#define SetTCK()
JTAG macro: set TCK signal.
void UnlockBsl_430Xv2Flash(void)
This function unlocks the BSL memory protection.
#define IN0RDY
JTAG mailbox constant -.
#define IR_DATA_16BIT
Set the MSP430 MDB to a specific 16-bit value with the next 16-bit data access.
void WriteMemQuick_430Xv2(unsigned long StartAddr, unsigned long Length, word *DataArray)
This function writes an array of words into the target memory.
unsigned short FlashWrite_o[]
Holds the target code for an flash write operation.
#define ClrRST()
SBW macro: clear RST signal.
#define SetTMS()
JTAG macro: set TMS signal.
#define INTERFACE
Select the interface to be used to communicate with the device.
void ReadMemQuick_430Xv2(unsigned long StartAddr, unsigned long Length, word *DataArray)
This function reads an array of words from the memory.
#define STATUS_OK
return 1 = no error
Funclet for Flash write operations.
#define ClrTCLK()
SBW macro: clear TCLK signal.
void WriteMem_430Xv2(word Format, unsigned long Addr, word Data)
This function writes one byte/word at a given address ( <0xA00)
void StartJtagJSbw(byte states)
Start JTAG communication in JSBW mode.
#define V_RESET
Triggers a regular reset on device release from JTAG control.
#define IR_JMB_EXCHANGE
Request a JTAG mailbox exchange.
word WriteFLASHallSections_430Xv2(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...
void MsDelay(word milliseconds)
Delay function (resolution is 1 ms)
void jRelease(void)
Releases the JSBW logic.
#define STATUS_ERROR
return 0 = error
void EraseFLASH_430Xv2(word EraseMode, unsigned long EraseAddr)
This function performs a mass erase (with and w/o info memory) or a segment erase of a FLASH module s...
#define MAX_ENTRY_TRY
Maximum number of tries for the determination of the core identification info.
word IsLockKeyProgrammed(void)
This function checks if the JTAG lock key is programmed.
void JsbwMagicPattern(void)
Function for applying the magic pattern via JSBW.
word ReadMem_430Xv2(word Format, unsigned long Addr)
This function reads one byte/word from a given address in memory.
#define IR_ADDR_CAPTURE
Read out the MAB data on the next 16/20-bit data access.
Funclet for Flash erase operations.
#define ClrTCK()
JTAG macro: clear TCK signal.
#define SetTDI()
JTAG macro: set TDI signal.
#define IR_COREIP_ID
Instruction to determine device's CoreIP.
#define IR_CNTRL_SIG_16BIT
Set the JTAG control signal register.
void RlsSignals(void)
Release I/O pins.
Low Level function prototypes, macros, and pin-to-signal assignments regarding to user's hardware...
void UnlockInfoA_430Xv2(void)
This function unlocks segment A of the InfoMemory (Flash)
void configure_IO_JTAG(void)
Set JTAG pins to output direction - from REP430F to target.
#define SPYBIWIRE_IF
Spy-Bi-Wire interface.
void EraseFLASH_430Xv2_wo_release(word EraseMode, unsigned long EraseAddr)
This function performs a mass erase (with and w/o info memory) or a segment erase of a FLASH module s...
#define SetRST()
SBW macro: set RST signal.
void DrvSignals(void)
Set up I/O pins for JTAG communication.
#define ClrTMS()
JTAG macro: clear TMS signal.