tcl/target: replace event trace-config
[fw/openocd] / tcl / target / stm32wbx.cfg
1 # SPDX-License-Identifier: GPL-2.0-or-later
2
3 # script for stm32wbx family
4
5 #
6 # stm32wb devices support both JTAG and SWD transports.
7 #
8 source [find target/swj-dp.tcl]
9 source [find mem_helper.tcl]
10
11 if { [info exists CHIPNAME] } {
12    set _CHIPNAME $CHIPNAME
13 } else {
14    set _CHIPNAME stm32wbx
15 }
16
17 set _ENDIAN little
18
19 # Work-area is a space in RAM used for flash programming
20 # By default use 64kB
21 if { [info exists WORKAREASIZE] } {
22    set _WORKAREASIZE $WORKAREASIZE
23 } else {
24    set _WORKAREASIZE 0x10000
25 }
26
27 #jtag scan chain
28 if { [info exists CPUTAPID] } {
29    set _CPUTAPID $CPUTAPID
30 } else {
31    if { [using_jtag] } {
32       set _CPUTAPID 0x6ba00477
33    } else {
34       # SWD IDCODE (single drop, arm)
35       set _CPUTAPID 0x6ba02477
36    }
37 }
38
39 swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID
40 dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
41
42 if {[using_jtag]} {
43    jtag newtap $_CHIPNAME bs -irlen 5
44 }
45
46 set _TARGETNAME $_CHIPNAME.cpu
47 target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap
48
49 $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0
50
51 flash bank $_CHIPNAME.flash stm32l4x 0x08000000 0 0 0 $_TARGETNAME
52 flash bank $_CHIPNAME.otp   stm32l4x 0x1fff7000 0 0 0 $_TARGETNAME
53
54 # Common knowledges tells JTAG speed should be <= F_CPU/6.
55 # F_CPU after reset is MSI 4MHz, so use F_JTAG = 500 kHz to stay on
56 # the safe side.
57 #
58 # Note that there is a pretty wide band where things are
59 # more or less stable, see http://openocd.zylin.com/#/c/3366/
60 adapter speed 500
61
62 adapter srst delay 100
63 if {[using_jtag]} {
64  jtag_ntrst_delay 100
65 }
66
67 reset_config srst_nogate
68
69 if {![using_hla]} {
70    # if srst is not fitted use SYSRESETREQ to
71    # perform a soft reset
72    cortex_m reset_config sysresetreq
73 }
74
75 $_TARGETNAME configure -event reset-init {
76     # CPU comes out of reset with MSI_ON | MSI_RDY | MSI Range 4 MHz.
77     # Configure system to use MSI 24 MHz clock, compliant with VOS default Range1.
78     # 2 WS compliant with VOS=Range1 and 24 MHz.
79     mmw 0x58004000 0x00000102 0  ;# FLASH_ACR |= PRFTBE | 2(Latency)
80     mmw 0x58000000 0x00000091 0  ;# RCC_CR = MSI_ON | MSI Range 24 MHz
81     # Boost JTAG frequency
82     adapter speed 4000
83 }
84
85 $_TARGETNAME configure -event reset-start {
86     # Reset clock is MSI (4 MHz)
87     adapter speed 500
88 }
89
90 $_TARGETNAME configure -event examine-end {
91     # Enable debug during low power modes (uses more power)
92     # DBGMCU_CR |= DBG_STANDBY | DBG_STOP | DBG_SLEEP
93     mmw 0xE0042004 0x00000007 0
94
95     # Stop watchdog counters during halt
96     # DBGMCU_APB1_FZR1 |= DBG_IWDG_STOP | DBG_WWDG_STOP
97     mmw 0xE004203C 0x00001800 0
98 }
99
100 tpiu create $_CHIPNAME.tpiu -dap $_CHIPNAME.dap -ap-num 0 -baseaddr 0xE0040000
101
102 lappend _telnet_autocomplete_skip _proc_pre_enable_$_CHIPNAME.tpiu
103 proc _proc_pre_enable_$_CHIPNAME.tpiu {_targetname} {
104     targets $_targetname
105
106     # Set TRACE_IOEN; TRACE_MODE is set to async; when using sync
107     # change this value accordingly to configure trace pins
108     # assignment
109     mmw 0xE0042004 0x00000020 0
110 }
111
112 $_CHIPNAME.tpiu configure -event pre-enable "_proc_pre_enable_$_CHIPNAME.tpiu $_TARGETNAME"