-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisp_test.go
117 lines (102 loc) · 2.63 KB
/
isp_test.go
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
package isp
import (
"fmt"
"go.bug.st/serial"
"log"
"testing"
)
func TestISP_Main(t *testing.T) {
// ports, err := enumerator.GetDetailedPortsList()
// if err != nil {
// log.Fatal(err)
// }
// if len(ports) == 0 {
// fmt.Println("No serial ports found!")
// return
// }
// for _, Port := range ports {
// fmt.Printf("Found Port: %s\n", Port.Name)
// if Port.IsUSB {
// fmt.Printf(" USB ID %s:%s\n", Port.VID, Port.PID)
// fmt.Printf(" USB serial %s\n", Port.SerialNumber)
// }
// }
mode := &serial.Mode{
BaudRate: 115200,
DataBits: 8,
StopBits: serial.OneStopBit,
Parity: serial.EvenParity,
InitialStatusBits: &serial.ModemOutputBits{RTS: false, DTR: false},
}
port, err := serial.Open("COM4", mode)
if err != nil {
log.Fatal(err)
}
isp := ISP{Port: port}
// ===========================================
fmt.Println("进入ISP模式")
if err := isp.Activation(); err != nil {
panic(err)
}
// ===========================================
fmt.Println("开始波特率对码")
if err := isp.RightCode(); err != nil {
panic(err)
}
// ===========================================
if err := isp.GetCommand(); err != nil {
panic(err)
}
fmt.Printf("获取支持指令: %02X\r\n", isp.Supported)
// // ===========================================
// version, _, _, err := isp.GetVersion()
// if err != nil {
// panic(err)
// }
// fmt.Printf("获取版本号: %.1f\r\n", version)
//
// // ===========================================
// id, err := isp.GetID()
// if err != nil {
// panic(err)
// }
// fmt.Printf("获取芯片PID: 0x%08X\r\n", id)
// ===========================================
fmt.Println("准备擦除芯片")
if err = isp.ExtendedEraseMemoryAll(); err != nil {
if err == NACKError {
if err = isp.ReadoutProtect(); err != nil {
if err == NACKError {
fmt.Println("芯片已设读保护")
fmt.Println("开始解除读保护(擦除中)")
if err = isp.ReadoutUnprotect(); err != nil {
panic(err)
}
} else {
panic(err)
}
}
} else {
panic(err)
}
}
// ===========================================
fmt.Println("进入ISP模式")
if err = isp.Activation(); err != nil {
panic(err)
}
// ===========================================
fmt.Println("开始波特率对码")
if err = isp.RightCode(); err != nil {
panic(err)
}
if err = isp.WriteFile(0x08000000, "E:/JY_F407VE_IAP_V1.0.15.bin", true, func(progress float64) {
fmt.Printf("progress:%.2f%%\r\n", progress)
}); err != nil {
panic(err)
}
if err := isp.Reset(); err != nil {
panic(err)
}
fmt.Println("任务完成")
}