Skip to content

Instantly share code, notes, and snippets.

@ytsuboi
Created June 28, 2014 06:59
Show Gist options
  • Save ytsuboi/f018c496a7480a8b83af to your computer and use it in GitHub Desktop.
Save ytsuboi/f018c496a7480a8b83af to your computer and use it in GitHub Desktop.
nRF51822のflashをCMSIS-DAPで消すツール(要pyOCD)
#!/usr/bin/env python
import argparse
from time import sleep, time
from struct import unpack
import sys
import subprocess
from pyOCD.interface import INTERFACE, usb_backend
from pyOCD.board import MbedBoard
import logging
VID = 0x0D28
PID = 0x0204
NVMC_READY = 0x4001E400
NVMC_CONFIG = 0x4001E504
NVMC_ERASEPAGE = 0x4001E508
NVMC_ERASEALL = 0x4001E50C
NVMC_ERASEUIR = 0x4001E514
if __name__ == "__main__":
adapter = None
try:
interfaces = INTERFACE[usb_backend].getAllConnectedInterface(VID, PID)
if interfaces == None:
print "Not find a mbed interface"
sys.exit(1)
# Use the first one
first_interface = interfaces[0]
adapter = MbedBoard("target_lpc1768", "flash_lpc1768", first_interface)
adapter.init()
target = adapter.target
target.halt()
target.writeMemory(NVMC_CONFIG, 2)
target.writeMemory(NVMC_ERASEALL, 1)
while target.readMemory(NVMC_READY) == 0:
pass
print "Target erased"
sleep(1)
target.reset()
finally:
if adapter != None:
adapter.uninit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment