-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathopenocd.cfg
More file actions
178 lines (140 loc) · 4.36 KB
/
openocd.cfg
File metadata and controls
178 lines (140 loc) · 4.36 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Combined script for easy flashing of nrf52840 controllers connected to stlinkv2 adapters - OpenSourceEBike controller/remote.
# Copy this config file into the same folder as openocd binary
# Copy fw into same folder
# Update filename below if necessary
# Run openocd to flash the firmware
set _fw_filename TSDZ2_bootloader_with_sd.hex
adapter driver st-link
st-link vid_pid 0x0483 0x3744 0x0483 0x3748 0x0483 0x374b 0x0483 0x374d 0x0483 0x374e 0x0483 0x374f 0x0483 0x3752 0x0483 0x3753
transport select dapdirect_swd
#
# Nordic nRF52 series: ARM Cortex-M4 @ 64 MHz
#
# ARM Debug Interface V5 (ADI_V5) utility
# ... Mostly for SWJ-DP (not SW-DP or JTAG-DP, since
# SW-DP and JTAG-DP targets don't need to switch based
# on which transport is active.
#
# declare a JTAG or SWD Debug Access Point (DAP)
# based on the transport in use with this session.
# You can't access JTAG ops when SWD is active, etc.
# params are currently what "jtag newtap" uses
# because OpenOCD internals are still strongly biased
# to JTAG .... but for SWD, "irlen" etc are ignored,
# and the internals work differently
# for now, ignore non-JTAG and non-SWD transports
# (e.g. initial flash programming via SPI or UART)
# split out "chip" and "tag" so we can someday handle
# them more uniformly irlen too...)
if [catch {transport select}] {
echo "Error: unable to select a session transport. Can't continue."
shutdown
}
proc swj_newdap {chip tag args} {
if [using_jtag] {
eval jtag newtap $chip $tag $args
} elseif [using_swd] {
eval swd newdap $chip $tag $args
} else {
echo "Error: transport '[ transport select ]' not supported by swj_newdap"
shutdown
}
}
if { [info exists CHIPNAME] } {
set _CHIPNAME $CHIPNAME
} else {
set _CHIPNAME nrf52
}
# Work-area is a space in RAM used for flash programming
# By default use 16kB
if { [info exists WORKAREASIZE] } {
set _WORKAREASIZE $WORKAREASIZE
} else {
set _WORKAREASIZE 0x4000
}
if { [info exists CPUTAPID] } {
set _CPUTAPID $CPUTAPID
} else {
set _CPUTAPID 0x2ba01477
}
swj_newdap $_CHIPNAME cpu -expected-id $_CPUTAPID
dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME cortex_m -dap $_CHIPNAME.dap
adapter speed 1000
$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
if { [using_hla] } {
echo ""
echo "nRF52 device has a CTRL-AP dedicated to recover the device from AP lock."
echo "A high level adapter (like a ST-Link) you are currently using cannot access"
echo "the CTRL-AP so 'nrf52_recover' command will not work."
echo "Do not enable UICR APPROTECT."
echo ""
} else {
cortex_m reset_config sysresetreq
$_TARGETNAME configure -event examine-fail nrf52_check_ap_lock
}
flash bank $_CHIPNAME.flash nrf5 0x00000000 0 1 1 $_TARGETNAME
flash bank $_CHIPNAME.uicr nrf5 0x10001000 0 1 1 $_TARGETNAME
# Test if MEM-AP is locked by UICR APPROTECT
proc nrf52_check_ap_lock {} {
set dap [[target current] cget -dap]
set err [catch {set APPROTECTSTATUS [$dap apreg 1 0xc]}]
if {$err == 0 && $APPROTECTSTATUS != 1} {
echo "****** WARNING ******"
echo "nRF52 device has AP lock engaged (see UICR APPROTECT register)."
echo "Debug access is denied."
echo "Use 'nrf52_recover' to erase and unlock the device."
echo ""
poll off
}
}
# Mass erase and unlock the device using proprietary nRF CTRL-AP (AP #1)
# http://www.ebyte.com produces modules with nRF52 locked by default,
# use nrf52_recover to enable flashing and debug.
proc nrf52_recover {} {
set target [target current]
set dap [$target cget -dap]
set IDR [$dap apreg 1 0xfc]
if {$IDR != 0x02880000} {
echo "Error: Cannot access nRF52 CTRL-AP!"
return
}
poll off
# Reset and trigger ERASEALL task
$dap apreg 1 4 0
$dap apreg 1 4 1
for {set i 0} {1} {incr i} {
set ERASEALLSTATUS [$dap apreg 1 8]
if {$ERASEALLSTATUS == 0} {
echo "$target device has been successfully erased and unlocked."
break
}
if {$i == 0} {
echo "Waiting for chip erase..."
}
if {$i >= 150} {
echo "Error: $target recovery failed."
break
}
sleep 100
}
# Assert reset
$dap apreg 1 0 1
# Deassert reset
$dap apreg 1 0 0
# Reset ERASEALL task
$dap apreg 1 4 0
sleep 100
$target arp_examine
poll on
}
add_help_text nrf52_recover "Mass erase and unlock nRF52 device"
init
reset halt
nrf5 mass_erase
program $_fw_filename verify
reset
init
shutdown
exit