-
Notifications
You must be signed in to change notification settings - Fork 44
/
flashSTM32.py
41 lines (35 loc) · 921 Bytes
/
flashSTM32.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import time
import sys
import array
from PirateSWD import *
from SWDCommon import *
from STM32 import *
def loadFile(path):
arr = array.array('L')
try:
arr.fromfile(open(sys.argv[1], 'rb'), 1024*1024)
except EOFError:
pass
return arr.tolist()
def main():
busPirate = PirateSWD("/dev/ttyUSB0")
debugPort = DebugPort(busPirate)
stm32 = STM32(debugPort)
print "DP.IDCODE: %08X" % debugPort.idcode()
print "AP.IDCODE: %08X" % stm32.ahb.idcode()
print ""
print "Loading File: '%s'" % sys.argv[1]
vals = loadFile(sys.argv[1])
print "Halting Processor"
stm32.halt()
print "Erasing Flash"
stm32.flashUnlock()
stm32.flashErase()
print "Programming Flash"
stm32.flashProgram()
stm32.ahb.writeHalfs(0x08000000, vals)
stm32.flashProgramEnd()
print "Resetting"
stm32.sysReset()
if __name__ == "__main__":
main()