summaryrefslogtreecommitdiffstats
path: root/keyboard/infinity/tool/k20dx32_flash.cfg
blob: 1e3deb0910a6e17a22273b46c5067108bbcda301 (plain)
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
# FreeScale Kinetis K20 devices with 32kB Flash and 8kB Local On-Chip SRAM,
# Nemuisan's Special for MK20DN32VFT5,MK20DX32VFT5,MK10DN32VFT5,MK10DX32VFT5


# 0.8.0 has no these procs
proc using_jtag {} {
        set _TRANSPORT [ transport select ]
        expr { [ string first "jtag" $_TRANSPORT ] != -1 }
}

proc using_swd {} {
        set _TRANSPORT [ transport select ]
        expr { [ string first "swd" $_TRANSPORT ] != -1 }
}

proc using_hla {} {
        set _TRANSPORT [ transport select ]
        expr { [ string first "hla" $_TRANSPORT ] != -1 }
}

source [find target/swj-dp.tcl]

if { [info exists CHIPNAME] } {
    set _CHIPNAME $CHIPNAME
} else {
    set _CHIPNAME k20
}

if { [info exists ENDIAN] } {
    set _ENDIAN $ENDIAN
} else {
    set _ENDIAN little
}

if { [info exists CPUTAPID] } {
   set _CPUTAPID $CPUTAPID
} else {
   if { [using_jtag] } {
      set _CPUTAPID 0x4BA00477
   } {
      # this is the SW-DP tap id not the jtag tap id
      set _CPUTAPID 0x2BA01477
   }
}

# Work-area is a space in RAM used for flash programming
# By default use 8kB
if { [info exists WORKAREASIZE] == 0 } {
   set _WORKAREASIZE 0x2000
}

# Select "srst_only", Nemuisan said so!
echo "Kinetis MUST need Hardware SRST Control to Recover Secure-State!"
adapter_nsrst_delay 200
reset_config srst_only

swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME cortex_m -chain-position $_TARGETNAME

# It is important that "kinetis mdm check_security" is called for
# 'examine-end' event and not 'eximine-start'. Calling it in 'examine-start'
# causes "kinetis mdm check_security" to fail the first time openocd
# calls it when it tries to connect after the CPU has been power-cycled.
$_CHIPNAME.cpu configure -event examine-end {
	kinetis mdm check_security
# Uncomment when gone into s*ck'n secured state!
#	kinetis mdm mass_erase
}

# K20 has minimun 8kB of SRAM and starts at 1FFFF000.
$_TARGETNAME configure -work-area-phys 0x1FFFF000 -work-area-size $_WORKAREASIZE -work-area-backup 0 -rtos auto

# MK20DN32VFT5,MK20DX32VFT5,MK10DN32VFT5,MK10DX32VFT5 has 32kB of flash memory.
flash bank $_CHIPNAME.pflash kinetis 0x00000000 0x8000 0 4 $_TARGETNAME


proc mt_flash {IMGFILE} {
	flash write_image erase $IMGFILE
	reset run
	halt
	verify_image $IMGFILE
	reset run
	shutdown
}

proc mt_flash_bin {IMGFILE OFFSET} {
	flash write_image erase $IMGFILE $OFFSET bin
	reset run
	halt
	verify_image $IMGFILE $OFFSET bin
	reset run
	shutdown
}

proc mt_flash_hex {IMGFILE} {
	flash write_image erase $IMGFILE 0 ihex
	reset run
	halt
	verify_image $IMGFILE 0 ihex
	reset run
	shutdown
}

proc mt_flash_srec {IMGFILE} {
	flash write_image erase $IMGFILE 0 s19
	reset run
	halt
	verify_image $IMGFILE 0 s19
	reset run
	shutdown
}

proc mass_erase {} {
	kinetis mdm mass_erase
}

proc eraser {} {
# Verbose procedure confirmed erase routine
	flash info 0
# CAUTION! "flash erase_sector 0 0 last" goes into secure state!!!
# USE "mass_erase" command instead of
#	flash erase_sector 0 0 last
	mass_erase
	shutdown
}

#debug_level 3
# HLA doesn't have cortex_m commands 
if {![using_hla]} {
   # if srst is not fitted use SYSRESETREQ to
   # perform a soft reset
   cortex_m reset_config sysresetreq
}
adapter_khz 1000
reset_config srst_only srst_nogate connect_assert_srst
gdb_target_description disable
init
reset init