Okay, look, I realize that the MSP430 is an embedded chip and might require a little more clue than average to program. But for fuck's sake TI, none of the following should ever be required to write a word to flash:
- Copying code to RAM
- Running code from RAM
- Having execution return to the address just after the last address in the block you erased (I'm not kidding - this is actually how it works)
All of the above are known, in technical terms, as UR DOIN' IT RONG.
For the love of god, STOP USING THE GODDAMN PROGRAM COUNTER AS YOUR FLASH WRITE ADDRESS! There is no reason to do that! If your silicon designers are telling you that you don't have enough die space for one more 16 bit register, SHOOT THEM IN THE FUCKING HEAD AND GET DESIGNERS WITH A CLUE! Shit, man, you put no less than three separate FCNTL registers in this thing! How about deleting two of those, and using that silicon space for your flash address register!
You know how writes should work? I write the address to the FADDR register, I write the data to the FDATA register, I wait for !BUSY, I set the write bit. Interrupts (other than WDT) should be disabled automatically. And the PC should stay right the fuck where it is - not jump off to some random location in Flash memory. (If you want to disallow writes to the same block that the PC is in, that's fine with me.)
I'm going to end up writing more lines of code just to put a single word in flash, than I am for all the rest of my project combined. That's how much of an enormous pain in the ass you're making this for me.
It would be easier for me to redesign my board and tack on an external SPI flash, and bit-bang the goddamn SPI, than to write the routines to write to the internal flash. That's how much of an enormous pain in the ass you're making this for me.
All I have to say about this is, you are damn lucky that I didn't get to pick the chip this project was done on. Cuz I would have trashed the MSP430 in a fucking heartbeat when I found out about this incredible shit-cockery. I'd have trashed my board layout and started again with an AVR or PIC. In a fucking picosecond.
You guys are nutjobs to drag your customers through this shit-pile. Do you even use your own chips?? I don't think so. You would already know that this was fucking broken as hell if you did. What the fuck were you morons thinking??