-
Notifications
You must be signed in to change notification settings - Fork 133
/
uvk5.cfg
109 lines (79 loc) · 3.53 KB
/
uvk5.cfg
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
transport select swd
adapter speed 100
set _CPUTAPID 0x0bb11477
swd newdap chip cpu -enable
# Create the DAP instance, this must be explicitly created according to the OpenOCD docs
dap create chip.dap -chain-position chip.cpu
# Set up the GDB target for the CPU, cortex_m is the CPU type,
target create chip.cpu cortex_m -dap chip.dap
gdb_breakpoint_override hard
init
# Read out the information from the DAP, including the ROM table
# dap info
# reset halt
proc clear_flash_sector {sector_number} {
echo [format "Eerasing sector 0x%02x = offset 0x%04x" [expr {$sector_number}] [expr {$sector_number*512}] ]
write_memory 0x4006F000 32 {0x09} ;#set erasing mode
write_memory 0x4006F004 32 [expr {$sector_number << 7}]
write_memory 0x4006F01c 32 {0xAA} ;#unlock flash
write_memory 0x4006F010 32 {0x01} ;#set OPSTART=1
read_memory 0x4006F014 32 1 ;#check status
write_memory 0x4006F018 32 {0x55} ;#lock flash
}
proc clear_whole_flash {} {
for {set i 0} {$i < 0x78} {incr i} {
clear_flash_sector $i
}
}
proc uv_flash_write {address value} {
echo [format "Writing 0x%04x to address 0x%04x (FLASH_ADDR_REG=0x%04x)" $value $address [expr {($address>>2)+0xC000}] ]
write_memory 0x4006F000 32 {0x05} ;#set writing mode
write_memory 0x4006F004 32 [expr {($address>>2)+0xC000}] ;#set address in flash
write_memory 0x4006F008 32 $value ;#set data
write_memory 0x4006F01c 32 {0xAA} ;#unlock flash
write_memory 0x4006F010 32 {0x01} ;#set OPSTART=1
read_memory 0x4006F014 32 1 ;#check status for 0x04
write_memory 0x4006F018 32 {0x55} ;#lock flash
}
proc uv_toggle_porta_pin {pin} {
write_memory 0x40060000 16 [expr {[read_memory 0x40060000 16 1] ^(1<<$pin) }]
}
proc uv_toggle_portb_pin {pin} {
write_memory 0x40060800 16 [expr {[read_memory 0x40060800 16 1] ^(1<<$pin) }]
}
proc uv_toggle_portc_pin {pin} {
write_memory 0x40061000 16 [expr {[read_memory 0x40061000 16 1] ^(1<<$pin) }]
}
proc uv_set_porta_pin {pin value} {
if {$value == 0} {
write_memory 0x40060000 16 [expr {[read_memory 0x40060000 16 1] &~(1<<$pin) }]
} else {
write_memory 0x40060000 16 [expr {[read_memory 0x40060000 16 1] |(1<<$pin) }]
}
}
proc uv_set_portb_pin {pin value} {
if {$value == 0} {
write_memory 0x40060800 16 [expr {[read_memory 0x40060800 16 1] &~(1<<$pin) }]
} else {
write_memory 0x40060800 16 [expr {[read_memory 0x40060800 16 1] |(1<<$pin) }]
}
}
proc uv_set_portc_pin {pin value} {
if {$value == 0} {
write_memory 0x40061000 16 [expr {[read_memory 0x40061000 16 1] &~(1<<$pin) }]
} else {
write_memory 0x40061000 16 [expr {[read_memory 0x40061000 16 1] |(1<<$pin) }]
}
}
proc uv_flashlight_toggle {} {
write_memory 0x40061000 16 [expr {[read_memory 0x40061000 16 1] ^8 }] ;# toggles PORTC.3
}
proc uv_flashlight_on {} {
write_memory 0x40061000 16 [expr {[read_memory 0x40061000 16 1] |8 }] ;# set PORTC.3 high
}
proc uv_flashlight_off {} {
write_memory 0x40061000 16 [expr {[read_memory 0x40061000 16 1] & ~8 }] ;# set PORTC.3 to low
}
proc uv_backlight_toggle {} {
write_memory 0x40060800 16 [expr {[read_memory 0x40060800 16 1] ^0x40 }] ;# toggles PORTB.6
}