/mass-erase.s
.text
.thumb

.global _start
_start:
	ldr r0, OCMR
	ldr r1, OPCR
	bl idle_check

	mov r2, #0xA
	str r2, [r0]    // store 0xA in OCMR
	lsl r2, #1      // Shift left into OPM location
	str r2, [r1]    // store 0xa in OPCR.OPM

	bl idle_check

end:
	b end

idle_check:
	mov r3, #8      // Compare bit 3
1:
	ldr r2, [r1]    // load OPCR
	and r2, r3      // If bit 3 is clear,
	beq 1b          // a flash operation is in progress
	bx lr

.align
OCMR:	.word 0x4008000c
OPCR:	.word 0x40080010