target: add generic Xtensa LX support
[fw/openocd] / tcl / target / esp32s2.cfg
1 # SPDX-License-Identifier: GPL-2.0-or-later
2 #
3 # The ESP32-S2 only supports JTAG.
4 transport select jtag
5
6 set CPU_MAX_ADDRESS 0xFFFFFFFF
7 source [find bitsbytes.tcl]
8 source [find memory.tcl]
9 source [find mmr_helpers.tcl]
10
11 if { [info exists CHIPNAME] } {
12         set _CHIPNAME $CHIPNAME
13 } else {
14         set _CHIPNAME esp32s2
15 }
16
17 if { [info exists CPUTAPID] } {
18         set _CPUTAPID $CPUTAPID
19 } else {
20         set _CPUTAPID 0x120034e5
21 }
22
23 set _TARGETNAME $_CHIPNAME
24 set _CPUNAME cpu
25 set _TAPNAME $_CHIPNAME.$_CPUNAME
26
27 jtag newtap $_CHIPNAME $_CPUNAME -irlen 5 -expected-id $_CPUTAPID
28
29 proc esp32s2_memprot_is_enabled { } {
30         # IRAM0, DPORT_PMS_PRO_IRAM0_0_REG
31         if { [get_mmr_bit 0x3f4c1010 0] != 0 } {
32                 return 1
33         }
34         # DRAM0, DPORT_PMS_PRO_DRAM0_0_REG
35         if { [get_mmr_bit 0x3f4c1028 0] != 0 } {
36                 return 1
37         }
38         # PERI1, DPORT_PMS_PRO_DPORT_0_REG
39         if { [get_mmr_bit 0x3f4c103c 0] != 0 } {
40                 return 1
41         }
42         # PERI2, DPORT_PMS_PRO_AHB_0_REG
43         if { [get_mmr_bit 0x3f4c105c 0] != 0 } {
44                 return 1
45         }
46         return 0
47 }
48
49 target create $_TARGETNAME esp32s2 -endian little -chain-position $_TAPNAME
50
51 $_TARGETNAME configure -event gdb-attach {
52         # necessary to auto-probe flash bank when GDB is connected and generate proper memory map
53         halt 1000
54         if { [esp32s2_memprot_is_enabled] } {
55                 # 'reset halt' to disable memory protection and allow flasher to work correctly
56                 echo "Memory protection is enabled. Reset target to disable it..."
57                 reset halt
58         }
59 }
60
61 xtensa maskisr on
62
63 $_TARGETNAME configure -event reset-assert-post { soft_reset_halt }
64
65 gdb_breakpoint_override hard
66
67 source [find target/xtensa-core-esp32s2.cfg]