-
Notifications
You must be signed in to change notification settings - Fork 4
/
flash
executable file
·76 lines (55 loc) · 2.56 KB
/
flash
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
#!/bin/sh
# Hugh O'Brien [email protected] 2014-05-25
# Program the nRF51822, based on nRF51_Series_Reference_Manual_v2.1.pdf
# Uses SEGGER JLINK
# Presume SoftDevice S110 usage
# Check application for SoftDevice offset however it does not check that
# the application has been compiled against the _correct_ SoftDevice.
[ -z $(command -v JLinkExe) ] && echo "Put Segger's JLinkExe on the path" && exit
soft_device="/home/hugh/nrf/s110/s110_nrf51822_7.0.0_softdevice.hex"
application="a.hex"
[ ! -f "$soft_device" ] && echo "Set SoftDevice Path" && exit
[ ! -f "$application" ] && echo "$application not found" && exit
#as per s110_nrf51822_7.0.0-3.alpha_migration_document.pdf
s110_v7_code_r1_base="0x16000"
#as per s110_nrf51822_6.0.0_migration-document.pdf
s110_v4_v5_v6_code_r1_base="0x14000"
case "$(basename "$soft_device")" in
s110_nrf51822_5.2.1_softdevice.hex) region1_start=$s110_v4_v5_v6_code_r1_base ;;
s110_nrf51822_6.0.0_softdevice.hex) region1_start=$s110_v4_v5_v6_code_r1_base ;;
s110_nrf51822_7.0.0_softdevice.hex) region1_start=$s110_v7_code_r1_base ;;
*) echo "Unknown SoftDevice, check official docs for r1_base value" && exit ;;
esac
region0_start="0"
#The ESAR has a strict format, defined here https://en.wikipedia.org/wiki/Intel_HEX#Format
#It's also shorter than a normal line, so let's just count characters to detect it.
[ "$(< "$application" head --lines=1 | wc --chars)" != "17" ] &&
echo "No Extended Segment Address Record found at the start of the application." &&
echo "This places the application within the code space of the SoftDevice." &&
echo "Was it linked with the correct SoftDevice linker profile?" && exit
device="nrf51822"
speed="1000" #unit is KHz, nordic docs recommed 1MHz
wait_time="300" #unit is ms
write_32bit="w4"
base_addr="4001e" #non-volatile memory controller
config_offset="504" #config register, 0 RO, 1 RW, 2 ERASEable
enable_write="1"
set_device="Device"
set_speed="speed"
write_program="loadbin"
reset_device="rx" #use the 'delay after reset' version
start_device="g"
close_and_quit="qc"
script_file="flash.jlink"
rm $script_file 2>/dev/null #suppress error if not found
touch $script_file
echo $set_device $device >> $script_file
echo $set_speed $speed >> $script_file
echo $write_32bit $base_addr$config_offset $enable_write >> $script_file
echo $write_program $soft_device $region0_start >> $script_file
echo $write_program $application $region1_start >> $script_file
echo $reset_device $wait_time >> $script_file
echo $start_device >> $script_file
echo $close_and_quit >> $script_file
JLinkExe $script_file
rm $script_file