Other Parts Discussed in Thread: UNIFLASH
Tool/software: Code Composer Studio
Hi
I'm struggling a little with the in field up date function on the MSP launchpad. I've developed two basic pieces of code, one will be my starting firmware, it blinks an LED on the board quickly, one button triggers the factory reset, the other, initiates a firmware upgrade. JTAG & SWD lock are enabled on first startup of the program. The second piece of code blinks the LED slowly and triggers a factory reset upon button press.
I'm trying to do a basic upgrade from the fast blinking LED to the slow blinking. I'm struggling to tell what is truely going on. It appears my security functions are working, as the debugger wont let me in after programming the board, the factory reset function works flawlessly on both programs, but when I go to run the upgrade the board stops working, no blinking LED at all and I can't re-program it or reset it in any way.
I think my issue is the way I generate the encrypted update, I've had problems with the security & update tool, it wont recognise the length of the update file (TI TXT file) and the command line keeps returning "no start address chosen" even though the "-a 0x20000" arguement is present
I even tried constructing my own file, I took the slow blinking file, padded it out with FF's up to a 0x1000 boundary and added my password on the end. I ran it through an online AES CBC encryption tool and uploaded the file with uniflash to the specified location, ran my fast blink code, pressed the update button and once again bricked the board. I've put both pieces of code below, they are only simple proof of concept pieces, hence, they aren't too tidy.
QUESTION: Has anyone used the in-field update function via flash mailbox before!? Not BSL.
#include "msp.h" //FAST BLINK
/**
* main.c
*/
volatile int * write_ptr =0;
volatile int PRG_Complete = 0;
int i = 0;
int * LOCK_ACK = 0x00200054;
__interrupt void PORT1_IRQHandler (void)
{
P1IFG = 0x00;
if (!((P1IN >> 1) % 2)) //factory reset
{
FLCTL->CLRIFG = 0xFFFFFFFF; //clear indicators
FLCTL->BANK0_INFO_WEPROT = 0x02; //Remove Erase/Program protection on section 0 of bank 0 of information memory
FLCTL->ERASE_SECTADDR = 0x00200000;
FLCTL->ERASE_CTLSTAT = 0x05; //initiate erase
PRG_Complete=0;
while(!PRG_Complete)
{
write_ptr = 0x00200000;//start
*write_ptr = 0x0115ACF6;
write_ptr = 0x00200004; //Command
*write_ptr = 0x00010000;
write_ptr = 0x0020028C;//end
*write_ptr = 0x0011E11D;
if ( !((FLCTL->IFG>>2)%1) && !((FLCTL->IFG>>2)%2) && ((FLCTL->IFG>>3)%2) ){PRG_Complete = 1;}//Programming complete with no errors
}
while ( ((FLCTL->ERASE_CTLSTAT >> 16)%2) || ((FLCTL->ERASE_CTLSTAT >> 17)%2) || ((FLCTL->PRG_CTLSTAT >>16)%2) || ((FLCTL->PRG_CTLSTAT >>17)%2) )
{FLCTL->ERASE_CTLSTAT |= 0x00080000;} //clear erase from completion to idle state to allow re-protection
FLCTL->BANK0_INFO_WEPROT = 0x03; //reprotect segment
SYSCTL->REBOOT_CTL = (0x01 | 0x6900);
}
}
void main(void)
{
FLCTL->PRG_CTLSTAT = 0x0000000D; // 0000 0000 0000 0000 0000 0000 0000 1101 : Immediate mode enabled with both Pre and Post auto verify
FLCTL->BANK0_RDCTL = 0x00000000;
NVIC->ISER[1] = 0b1000;//
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer
P2DIR = 0xFF;
P1DIR = 0x00;
P1REN = 0xFF;
P1OUT = 0xFF;
P1IE = 0x02; //0000 0000
P1IES = 0x02;
//START UP LOCK DEVICE & POLL LOCKING ACK
if (*LOCK_ACK == 0xFFFFFFFF)
{
// while(1);
FLCTL->CLRIFG = 0xFFFFFFFF; //clear indicators
FLCTL->BANK0_INFO_WEPROT = 0x02; //Remove Erase/Program protection on section 0 of bank 0 of information memory
FLCTL->ERASE_SECTADDR = 0x00200000;
FLCTL->ERASE_CTLSTAT = 0x05; //initiate erase
PRG_Complete=0;
while(!PRG_Complete)
{
write_ptr = 0x00200000; //start
*write_ptr = 0x0115ACF6;
write_ptr = 0x00200004; //Command
*write_ptr = 0x00080000;
write_ptr = 0x00200010; //Params, sec enable
*write_ptr = 0x00000000;
write_ptr = 0x00200014; //Params, sec enable
for (i=0; i < 16 ; i++)
{
*write_ptr = 0x12345678;
write_ptr = write_ptr +1;
}
write_ptr = 0x0020028C; //end
*write_ptr = 0x0011E11D;
if ( !((FLCTL->IFG>>2)%1) && !((FLCTL->IFG>>2)%2) && ((FLCTL->IFG>>3)%2) ){PRG_Complete = 1;}//Programming complete with no errors
}
while ( ((FLCTL->ERASE_CTLSTAT >> 16)%2) || ((FLCTL->ERASE_CTLSTAT >> 17)%2) || ((FLCTL->PRG_CTLSTAT >>16)%2) || ((FLCTL->PRG_CTLSTAT >>17)%2) )
{FLCTL->ERASE_CTLSTAT |= 0x00080000;} //clear erase from completion to idle state to allow re-protection
FLCTL->BANK0_INFO_WEPROT = 0x03; //reprotect segment
SYSCTL->REBOOT_CTL = (0x01 | 0x6900);
}
while (1)
{
if (!((P1IN >> 4) % 2)) //initiate update
{
FLCTL->CLRIFG = 0xFFFFFFFF; //clear indicators
FLCTL->BANK0_INFO_WEPROT = 0x02; //Remove Erase/Program protection on section 0 of bank 0 of information memory
FLCTL->ERASE_SECTADDR = 0x00200000;
FLCTL->ERASE_CTLSTAT = 0x05; //initiate erase
PRG_Complete=0;
while(!PRG_Complete)
{
write_ptr = 0x00200000;//start
*write_ptr = 0x0115ACF6;
write_ptr = 0x00200004; //Command
*write_ptr = 0x10000000;
write_ptr = 0x002001F8; //payload address
*write_ptr = 0x00020000;
write_ptr = 0x002001FC; //length to the nearest 4 sectors
*write_ptr = 0x0011010;
write_ptr = 0x00200200; //destination address
*write_ptr = 0x00000000;
write_ptr = 0x0020028C;//end
*write_ptr = 0x0011E11D;
if ( !((FLCTL->IFG>>2)%1) && !((FLCTL->IFG>>2)%2) && ((FLCTL->IFG>>3)%2) ){PRG_Complete = 1;}//Programming complete with no errors
}
while ( ((FLCTL->ERASE_CTLSTAT >> 16)%2) || ((FLCTL->ERASE_CTLSTAT >> 17)%2) || ((FLCTL->PRG_CTLSTAT >>16)%2) || ((FLCTL->PRG_CTLSTAT >>17)%2) )
{FLCTL->ERASE_CTLSTAT |= 0x00080000;} //clear erase from completion to idle state to allow re-protection
FLCTL->BANK0_INFO_WEPROT = 0x03; //reprotect segment
SYSCTL->REBOOT_CTL = (0x01 | 0x6900);
}
P2OUT |= 0x01;
for (i = 0; i < 10000 ; i++);
P2OUT &= ~0x01;
for (i = 0; i < 10000 ; i++);
}//While
}//Main
#include "msp.h" //SLOW BLINK
/**
* main.c
*/
void main(void)
{
FLCTL->PRG_CTLSTAT = 0x0000000D; // 0000 0000 0000 0000 0000 0000 0000 1101 : Immediate mode enabled with both Pre and Post auto verify
FLCTL->BANK0_RDCTL = 0x00000000;
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer
int i = 0;
int * write_ptr =0;
int PRG_Complete = 0;
P2DIR = 0xFF;
P1DIR = 0x00;
P1REN = 0xFF;
P1OUT = 0xFF;
while (1)
{
if (!((P1IN >> 4) % 2)) //initiate update
{
FLCTL->CLRIFG = 0xFFFFFFFF; //clear indicators
FLCTL->BANK0_INFO_WEPROT = 0x02; //Remove Erase/Program protection on section 0 of bank 0 of information memory
FLCTL->ERASE_SECTADDR = 0x00200000;
FLCTL->ERASE_CTLSTAT = 0x05; //initiate erase
PRG_Complete=0;
while(!PRG_Complete)
{
write_ptr = 0x00200000;//start
*write_ptr = 0x0115ACF6;
write_ptr = 0x00200004; //Command
*write_ptr = 0x00010000;
write_ptr = 0x0020028C;//end
*write_ptr = 0x0011E11D;
if ( !((FLCTL->IFG>>2)%1) && !((FLCTL->IFG>>2)%2) && ((FLCTL->IFG>>3)%2) ){PRG_Complete = 1;}//Programming complete with no errors
}
while ( ((FLCTL->ERASE_CTLSTAT >> 16)%2) || ((FLCTL->ERASE_CTLSTAT >> 17)%2) || ((FLCTL->PRG_CTLSTAT >>16)%2) || ((FLCTL->PRG_CTLSTAT >>17)%2) )
{FLCTL->ERASE_CTLSTAT |= 0x00080000;} //clear erase from completion to idle state to allow re-protection
FLCTL->BANK0_INFO_WEPROT = 0x03; //reprotect segment
SYSCTL->REBOOT_CTL = (0x01 | 0x6900);
}
P2OUT |= 0x01;
for (i = 0; i < 100000 ; i++);
P2OUT &= ~0x01;
for (i = 0; i < 100000 ; i++);
}//While