summaryrefslogtreecommitdiff
path: root/util/openocd/target/npcx99nf.cfg
blob: 14dbac9f1329bbfc628b2f7788798ddaf4bfe8b5 (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
# Copyright 2022 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

source [find mem_helper.tcl]

set _ENDIAN little

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

if { [info exists WORKAREAADDR] } {
    set _WORKAREAADDR $WORKAREAADDR
} else {
    set _WORKAREAADDR 0
}

if { [info exists WORKAREASIZE] } {
    set _WORKAREASIZE $WORKAREASIZE
} else {
    set _WORKAREASIZE 0
}

if { [info exists CPUTAPID ] } {
   set _CPUTAPID $CPUTAPID
} else {
   set _CPUTAPID 0x2ba01477
}

if { [info exists FLASHADDR] } {
    set _FLASHADDR $FLASHADDR
} else {
    set _FLASHADDR 0x64000000
}

adapter speed 600

swd newdap $_CHIPNAME cpu -enable
dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu

set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap

# Work area in RAM used during flashing
$_TARGETNAME configure -work-area-phys $_WORKAREAADDR -work-area-size $_WORKAREASIZE -work-area-backup 0

# The npcx driver detects and autoconfigures various flash parameters
set _FLASHNAME $_CHIPNAME.internal_flash
flash bank $_FLASHNAME npcx $_FLASHADDR 0 0 0 $_TARGETNAME

# use sysresetreq to perform a system reset
cortex_m reset_config sysresetreq
adapter srst delay 100

# Freeze various clocks, counters and destructive reads
# Otherwise something like the watchdog time can interfere with debugging/flashing
proc debug_freeze { } {
    mwb 0x400C3078 0x7F
}

proc handle_gdb_attach { } {
    halt
    debug_freeze

    # Read the address of the reset handler from the vector table
    # The bootloader runs first, but it's not a good place to halt
    # as it sets up various things, including debug support
    set RESET_HANDLER [mrw 0x10080004]
    bp $RESET_HANDLER 2 hw
    reset run

    # Wait to hit the reset handler bp
    wait_halt 250
    # OpenOCD can get stuck in the reset handler
    # removing the BP prevents that
    rbp $RESET_HANDLER
}

proc handle_gdb_detach { } {
    shutdown
}

proc flash_target { image verify } {
    global _FLASHADDR
    echo "Resetting and halting target..."
    reset halt
    echo "Flashing image..."
    flash write_image erase $image $_FLASHADDR bin
    if { $verify == 1} {
        echo "Verifying image..."
        flash verify_image $image $_FLASHADDR bin
    }
    echo "Resuming target..."
    reset run
}

$_TARGETNAME configure -event halted debug_freeze

# GDB connection config
$_TARGETNAME configure -event gdb-attach handle_gdb_attach
$_TARGETNAME configure -event gdb-detach handle_gdb_detach

gdb_memory_map enable