61 #include "msp430CodeFR4xx.h"
65 #include "msp430CodeFR57_6xx.h"
83 static word DR_Shift16(word data)
123 static unsigned long DR_Shift20(
unsigned long address)
125 #ifdef SPYBIWIRE_MODE
164 static word IR_Shift(byte instruction)
166 #ifdef SPYBIWIRE_MODE
207 static void ResetTAP(
void)
211 #ifdef SPYBIWIRE_MODE
213 for (i = 6; i > 0; i--)
226 for (i = 6; i > 0; i--)
241 #define SAFE_FRAM_PC 0x0004
248 static word ExecutePOR_430Xv2(
void)
268 DR_Shift16(SAFE_FRAM_PC);
275 IR_Shift(IR_DATA_CAPTURE);
313 if(DR_Shift16(0) & 0x0301)
324 static void SetPC_430Xv2(
unsigned long Addr)
330 Mova += (
unsigned short)((Addr>>8) & 0x00000F00);
331 Pc_l = (
unsigned short)((Addr & 0xFFFF));
335 if(DR_Shift16(0) & 0x0301)
364 static unsigned long i_ReadJmbOut(
void)
366 unsigned short sJMBINCTL;
367 unsigned long lJMBOUT = 0;
368 unsigned short sJMBOUT0, sJMBOUT1;
373 lJMBOUT = DR_Shift16(sJMBINCTL);
378 lJMBOUT = DR_Shift16(sJMBINCTL);
379 sJMBOUT0 = (
unsigned short)DR_Shift16(0);
380 sJMBOUT1 = (
unsigned short)DR_Shift16(0);
381 lJMBOUT = ((
unsigned long)sJMBOUT1<<16) + sJMBOUT0;
391 static short i_WriteJmbIn16(word dataX)
393 unsigned short sJMBINCTL;
394 unsigned short sJMBIN0;
395 unsigned long Timeout = 0;
396 sJMBIN0 = (
unsigned short)(dataX & 0x0000FFFF);
408 while(!(DR_Shift16(0x0000) &
IN0RDY) && Timeout < 3000);
411 DR_Shift16(sJMBINCTL);
424 unsigned short sJMBINCTL;
425 unsigned short sJMBIN0,sJMBIN1;
426 unsigned long Timeout = 0;
428 sJMBIN0 = (
unsigned short)(dataX & 0x0000FFFF);
429 sJMBIN1 = (
unsigned short)(dataY & 0x0000FFFF);
441 while(!(DR_Shift16(0x0000) & IN0RDY) && Timeout < 3000);
446 DR_Shift16(sJMBINCTL) ;
461 word
VerifyPSA_430Xv2(
unsigned long StartAddr,
unsigned long Length,
unsigned short const *DataArray)
465 const word POLY = 0x0805;
466 word PSA_CRC = (word)(StartAddr-2);
470 SetPC_430Xv2(StartAddr);
482 for (i = 0; i < Length; i++)
485 if ((PSA_CRC & 0x8000) == 0x8000)
496 &DataArray[0] == 0 ? (PSA_CRC ^= 0xFFFF) : (PSA_CRC ^= DataArray[i]);
500 #ifdef SPYBIWIRE_MODE
540 TDOword = DR_Shift16(0x0000);
558 static void ConnectJTAG()
568 static void EntrySequences_RstHigh_SBW()
602 static void EntrySequences_RstLow_SBW()
634 static void EntrySequences_RstHigh_JTAG()
667 static void EntrySequences_RstLow_JTAG()
700 static void StopJtag (
void)
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();
762 #ifdef LPM5_ACTIVATED
764 #ifdef SPYBIWIREJTAG_IF // run 2 wire mode of 4 wire selection because 4wire pins are locked by JTAG lock
781 EntrySequences_RstHigh_JTAG();
804 unsigned short i = 0;
815 EntrySequences_RstLow_SBW();
819 EntrySequences_RstLow_JTAG();
837 EntrySequences_RstHigh_SBW();
841 EntrySequences_RstHigh_JTAG();
846 while(i < passwordLength)
860 static word GetCoreID (
void)
874 EntrySequences_RstHigh_SBW();
878 EntrySequences_RstHigh_JTAG();
891 if(i >= MAX_ENTRY_TRY)
894 #ifdef ACTIVATE_MAGIC_PATTERN
898 JtagId = magicPattern();
900 if((JtagId == 1) || (i >= MAX_ENTRY_TRY))
933 CoreId = DR_Shift16(0);
939 DeviceIdPointer = DR_Shift20(0);
948 static word SyncJtag_AssertPor (
void)
962 while(!(DR_Shift16(0) & 0x0200) && i < 50)
1057 if(DR_Shift16(0) & 0x0301)
1061 if (Format == F_WORD)
1096 for (i = 0; i < Length; i++)
1109 short WriteFram_430Xv2(
unsigned long StartAddr,
unsigned long Length,
unsigned short const *DataArray)
1111 unsigned long Jmb = 0;
1112 unsigned long Timeout = 0;
1116 FramWrite_o[2] = (
unsigned short)(StartAddr);
1117 FramWrite_o[3] = (
unsigned short)(StartAddr>>16);
1118 FramWrite_o[4] = (
unsigned short)(Length);
1119 FramWrite_o[5] = (
unsigned short)(Length>>16);
1128 Jmb = i_ReadJmbOut();
1131 while(Jmb != 0xABADBABE && Timeout < 3000);
1137 for(i = 0; i < Length; i++)
1139 i_WriteJmbIn16(DataArray[i]);
1147 Jmb = i_ReadJmbOut();
1150 while(Jmb != 0xCAFEBABE && Timeout < 3000);
1161 for (i = 0; i < FramWrite_o_length/2; i++)
1178 #ifdef MailBoxWriteFram
1179 int sectionIndex = 0;
1180 unsigned long memTarget;
1181 unsigned short const *dataPointer;
1185 for(sectionIndex=0; sectionIndex < program->
noSections; sectionIndex++)
1193 dataPointer = dataPointer + program->
sectionLength[sectionIndex];
1197 for(sectionIndex=0; sectionIndex < program->
noSections; sectionIndex++)
1205 dataPointer = dataPointer + program->
sectionLength[sectionIndex];
1210 unsigned long memTarget;
1211 unsigned short const *dataPointer;
1216 for(sectionIndex=0; sectionIndex < program->
noSections; sectionIndex++)
1221 dataPointer = dataPointer + program->
sectionLength[sectionIndex];
1225 for(sectionIndex=0; sectionIndex < program->
noSections; sectionIndex++)
1233 dataPointer = dataPointer + program->
sectionLength[sectionIndex];
1246 prog.
textData = (
unsigned short const *)&msp430Code;
1247 prog.
startAddress = (
unsigned long const *)&msp430Code_address;
1248 prog.
sectionLength = (
unsigned long const *)&msp430Code_length_of_sections;
1250 prog.
start = msp430Code_start;
1266 if(DR_Shift16(0) & 0x0301)
1271 if (Format == F_WORD)
1284 TDOword = DR_Shift16(0x0000);
1302 unsigned long i, lPc = 0;
1310 SetPC_430Xv2(StartAddr);
1318 for (i = 0; i < Length; i++)
1322 *DataArray++ = DR_Shift16(0);
1345 FramErase_o[2] = (
unsigned short)(EraseAddr);
1346 FramErase_o[3] = (
unsigned short)(EraseAddr>>16);
1347 FramErase_o[4] = (
unsigned short)(Length);
1348 FramErase_o[5] = (
unsigned short)(Length>>16);
1353 unsigned long Jmb = 0;
1354 unsigned long Timeout = 0;
1359 Jmb = i_ReadJmbOut();
1363 while(Jmb != 0xCAFEBABE && Timeout < Length);
1366 SyncJtag_AssertPor();
1372 for (i = 0; i < FramErase_o_length/2; i++)
1398 word
VerifyMem_430Xv2(
unsigned long StartAddr,
unsigned long Length,
unsigned short const *DataArray)
1408 word LockKey[2] = { 0x5555, 0x5555 };
1430 for (i = 3; i > 0; i--)
1433 if (DR_Shift16(0xAAAA) == 0x5555)
1441 #define FR4xx_LOCKREGISTER 0x160
1451 unsigned short newRegisterVal =
ReadMem_430Xv2(F_WORD, FR4xx_LOCKREGISTER);
1452 newRegisterVal &= ~0xFF03;
1453 newRegisterVal |= 0xA500;
1464 unsigned short MPUCTL0 =0x0000;
1465 unsigned short FramCtlKey = 0xA500;
1471 if((MPUCTL0 & 0x1)==0)
1477 if((MPUCTL0 & 0x3)!=0x1)
1500 EntrySequences_RstHigh_SBW();
1504 EntrySequences_RstHigh_JTAG();
1520 if((MPUCTL0 & 0x1)==0)
1532 word sysBslAddress = 0x0182;
1535 sysBslAddress = 0x0142;
1537 unsigned short BslCur;
1541 BslCur &= ~SYSBSLPE;
1554 short mailBoxError = 0;
1562 EntrySequences_RstLow_SBW();
1566 EntrySequences_RstLow_JTAG();
1577 mailBoxError = i_WriteJmbIn16(data1);
1586 EntrySequences_RstHigh_SBW();
1590 EntrySequences_RstHigh_JTAG();
word VerifyMem_430Xv2(unsigned long StartAddr, unsigned long Length, unsigned short const *DataArray)
This function performs a Verification over the given memory range.
#define V_RESET
Triggers a regular reset on device release from JTAG control.
short DownloadMsp430Code()
Download a program to target.
unsigned short FramWrite_o[]
Holds the target code for an FRAM write operation.
const unsigned long * startAddress
Array of start addresses of the sections.
void usDelay(word microseconds)
Delay function (resolution is ~1 us)
word DisableMpu_430Xv2(void)
This function disables the Memory Protection Unit (FRAM devices only)
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...
#define IN0RDY
JTAG mailbox constant -.
#define ClrTST()
SBW macro: clear TEST pin signal.
#define IR_CNTRL_SIG_CAPTURE
Read out the JTAG control signal register.
void ReadMemQuick_430Xv2(unsigned long StartAddr, unsigned long Length, word *DataArray)
This function reads an array of words from the memory.
short DownloadProgram(struct_Program *program)
DownloadFile Load program data int memory sections.
#define IR_DATA_PSA
Switch JTAG data register to PSA mode.
#define IR_ADDR_16BIT
Set the MSP430 MAB to a specific 16-bit value.
#define JTAG_ID91
JTAG identification value for 430Xv2 architecture devices.
word IsLockKeyProgrammed(void)
This function checks if the JTAG lock key is programmed.
#define IR_DATA_16BIT
Set the MSP430 MDB to a specific 16-bit value with the next 16-bit data access.
#define SetTCLK()
SBW macro: set TCLK signal.
void EraseFRAM_430Xv2(unsigned long EraseAddr, unsigned long Length)
This function performs an erase of a user defined FRAM memory section. For FRAM devices the erase equ...
Funclet for FRAM write operations on FR2xx/FR4xx family devices.
#define JTAG_ID98
JTAG identification value for 430Xv2 architecture FR4XX/FR2xx devices.
void WriteMem_430Xv2(word Format, unsigned long Addr, word Data)
This function writes one byte/word at a given address ( <0xA00)
#define IR_CNTRL_SIG_16BIT
Set the JTAG control signal register.
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)...
word ProgramLockKey(void)
This function blows the security fuse.
word UnlockDevice_430Xv2(unsigned short *password, unsigned long passwordLength)
This function unlocks the Fram memory when a JTAG password is set.
const unsigned long * sectionLength
Array of length information of the sections.
#define IR_DEVICE_ID
Instruction to determine device's DeviceID.
#define IR_ADDR_CAPTURE
Read out the MAB data on the next 16/20-bit data access.
#define SetTST()
SBW macro: set TEST pin signal.
Funclet for FRAM erase operations.
short WriteFram_430Xv2(unsigned long StartAddr, unsigned long Length, unsigned short const *DataArray)
This function programs/verifies an array of words into the Fram memory.
void configure_IO_JTAG(void)
Set JTAG pins to output direction - from REP430F to target.
word ReadMem_430Xv2(word Format, unsigned long Addr)
This function reads one byte/word from a given address in memory.
byte tdo_bit
Holds the value of TDO-bit.
#define SBWDATO
JTAG data_out pin in SBW mode -separate pin in MSP430F5437 - common IO translator.
word EraseFRAMViaBootCode_430Xv2(word mailBoxMode, word data1, word data2)
This function performs a Erase of FRxx devices using the JTAG mailbox.
#define MAX_ENTRY_TRY
Maximum number of tries for the determination of the core identification info.
#define MAIL_BOX_32BIT
JTAG mailbox mode 32 bit -.
word GetCoreipIdXv2()
Function to determine & compare core identification info (Xv2)
unsigned short FramErase_o[]
Holds the target code for an FRAM erase operation.
#define IR_COREIP_ID
Instruction to determine device's CoreIP.
#define IR_JMB_EXCHANGE
Request a JTAG mailbox exchange.
#define OUTREQ
JTAG mailbox constant -.
#define IR_DATA_QUICK
Set the MSP430 MDB to a specific 16-bit value (RAM only)
#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.
const unsigned short * textData
Array executable code and data sections.
#define SetTCK()
JTAG macro: set TCK signal.
#define V_BOR
Triggers a "brown-out" reset on device release from JTAG control.
Funclet for FRAM erase operations on FR2xx/FR4xx family devices.
unsigned long noSections
Number of sections.
#define ClrRST()
SBW macro: clear RST signal.
#define SetTMS()
JTAG macro: set TMS signal.
#define IR_SHIFT_OUT_PSA
Shift out the PSA pattern generated by IR_DATA_PSA.
short i_WriteJmbIn32(unsigned short dataX, unsigned short dataY)
Write a 32bit value into the JTAG mailbox system. The function timeouts if the mailbox is not empty a...
#define STATUS_OK
return 1 = no error
#define ClrTCLK()
SBW macro: clear TCLK signal.
word GetDevice_430Xv2(void)
Function to take target device under JTAG control. Disables the target watchdog. Sets the global DEVI...
void WriteMemQuick_430Xv2(unsigned long StartAddr, unsigned long Length, unsigned short const *DataArray)
This function writes an array of words into the target memory.
void StartJtagJSbw(byte states)
Start JTAG communication in JSBW mode.
#define INREQ
JTAG mailbox constant -.
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.
void jRelease(void)
Releases the JSBW logic.
struct_Program prog
Executable code and meta data about downloaded program.
#define STATUS_ERROR
return 0 = error
#define IR_CNTRL_SIG_RELEASE
Release the CPU from JTAG control.
void JsbwMagicPattern(void)
Function for applying the magic pattern via JSBW.
#define IR_TEST_3V_REG
Instruction for 3 volt test register in 5xx.
#define RAM_START_ADDRESS
Set the start address of the device RAM.
#define ClrTCK()
JTAG macro: clear TCK signal.
#define INTERFACE
Select the interface to be used to communicate with the device.
#define OUT1RDY
JTAG mailbox constant -.
#define SetTDI()
JTAG macro: set TDI signal.
void RlsSignals(void)
Release I/O pins.
Low Level function prototypes, macros, and pin-to-signal assignments regarding to user's hardware...
#define IR_TEST_REG
Instruction for test register in 5xx.
#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 SPYBIWIRE_IF
Spy-Bi-Wire interface.
#define JTAG_ID99
JTAG identification value for 430Xv2 architecture FR59XX devices.
byte TCLK_saved
Holds the last value of TCLK before entering a JTAG sequence.
void UnlockBsl_430Xv2FRAM(void)
This function unlocks the BSL memory protection.
unsigned long start
Execution start address.
#define JMB32B
JTAG mailbox constant -.
#define SetRST()
SBW macro: set RST signal.
Funclet for FRAM write operations.
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.
void DrvSignals(void)
Set up I/O pins for JTAG communication.
#define ClrTMS()
JTAG macro: clear TMS signal.