This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Self programming the msp430fr

Other Parts Discussed in Thread: MSP430FR5959

I have been working getting the msp430 to do software updates.. using msp430fr5959

I cut my fram in half so that i have a place to store the code.

FRAM : origin = 0x4400, length = 0x4000
FRAMX : origin = 0x8400, length = 0x7A00
FRAMBL : origin = 0xFE00, length = 0x0180
FRAM2 : origin = 0x10000,length = 0x4000

FRAMX is where i store the code
FRAMBL is where store my function.

I can successful deliver a software pack to the device. 

my main loop looks like this

while (!deploy_flag) {
// normal code
}

if (deploy_flag) {
deploy();
}

I trigger the reprogram with deploy_flag. It breaks out the program loop and runs deploy.

#pragma CODE_SECTION(deploy, ".BL")

void deploy() {
	__disable_interrupt(); // disable interrupts
	unsigned int line;
	unsigned int i;
	for (line = 0; line < 900; line++) {
		if (code[line][0] == code_Address) { //address
			address = (((unsigned long) code[line][1]) << 16) + (((unsigned long) code[line][2] << 8)) + code[line][3];
			add = (unsigned int*) address;
		} else if (code[line][0] == code_FullLine) {
			size = 16;
			for (i = 0; i < 16; i++) {
				codeblock[i] = code[line][i + 1];
			}
			writeblock();
		} else if (code[line][0] == code_ShortLine) {
			size = code[line][1];
			for (i = 0; i < size; i++) {
				codeblock[i] = code[line][i + 2];
			}
			writeblock();
		} else if (code[line][0] == code_EOF) {
			WDTCTL = 0;
			break;
		}
	}
}
#pragma CODE_SECTION(writeblock, ".BL")
void writeblock() {
	unsigned int i;
	for (i = 0; i < size; i += 2) {
		*add++ = (codeblock[1 * i + 1] << 8) + codeblock[1 * i];
	}
}

As you can see the first thing i do is kill the interrupts.. then i read my code that is in a format i created to build a block of code to write.. 
Also memory protection is off


I guarantee that i never write in the FRAMX and FRAMBL areas..

It seems to work fine.. i successful deployed an update. 

after im finish writing i call WDTCTL = 0; to reset the device

But i noticed before i call the reset that interrupts came on. I was not expecting this.

My question is am i doing something dangerous here? unsafe?
Is there areas of code that i should not be writing?

I do have checks that verifies the integrity of the package. so we can assume im writing what im expecting to write.

Anything i should be looking out for?   

  • It looks fine. But if you want a safer way, u can enable MPU to protect certain memory range.
  • i ran into a problem.. i decided to wipe the memory first.. and it stopped working.. i track the problem down to the << shift call.. if i wipe the memory msp430 function for shift gets wiped... now if i dont wipe i think it only works because im overwriting and the function is still in the same place in memory.. in memory it shows as (__mspabi_divi, __mspabi_remi).. so some how i need to protect this function.. place in in a part of memory i can protect.. or rewrite without using shift.. also bring up the question is anything else in my deploy code using functions that are located in my main program space.. any help world be appreciated

**Attention** This is a public forum