Created
October 7, 2017 07:30
-
-
Save kategray/cde83d51fa1cb3232749acaf72ca0b31 to your computer and use it in GitHub Desktop.
MSP430FR5994 Mass Erase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This function mass-erases a MSP430FR5994 in about 3 seconds. It wipes the entirety of FRAM, losing all data. | |
* It is intended for use in tamper-resiliency applications, and runs from RAM to avoid issues with self-erasing. | |
* After the function completes, it will force a reset by writing an invalid value to the watchdog register. | |
* This code is intended for use with Code Composer Studio, and will need to be adapted to be compatable with Kiel, | |
* Rowley, or IAR. | |
*/ | |
#include <stdio.h> | |
#include <msp430.h> | |
__attribute__((ramfunc)) | |
void self_destruct(void) { | |
uint32_t addr; | |
// Disable the MPU and make everything writable | |
MPUCTL0 = MPUPW; | |
MPUSAM = (MPUSEG1WE | MPUSEG2WE | MPUSEG3WE | MPUSEG1RE | MPUSEG2RE | MPUSEG3RE | MPUSEG1XE | MPUSEG2XE | MPUSEG3XE); | |
// Disable interrupts (except for the reset interrupt) and clear their vectors | |
__disable_interrupt(); | |
for (addr = EUSCI_A3_VECTOR ; addr <= SYSNMI_VECTOR; addr += 2) | |
{ | |
__data20_write_short(addr, 0xFFFF); | |
} | |
// Wipe FRAM | |
for (addr = FRAM_START; addr < FRAM_START + FRAM_LENGTH; addr += 4) { | |
__data20_write_long(addr, 0xFFFFFFFF); | |
} | |
// Force a reset | |
WDTCTL = 0xDEAD; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment