@libs-scripts-mep/grav-fw-pvi 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +48 -0
  2. package/grav-fw-pvi.js +124 -0
  3. package/package.json +25 -0
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Gravação de Firmware PVI
2
+
3
+ Biblioteca que auxilia na gravação de microcontroladores por linha de comando através do PVI.
4
+
5
+ ## Instalando
6
+
7
+ Abra o terminal, e na pasta do script, execute:
8
+
9
+ ```
10
+ npm i @libs-scripts-mep/grav-fw-pvi
11
+ ```
12
+
13
+ ## Desinstalando
14
+
15
+ Abra o terminal, e na pasta do script, execute:
16
+
17
+ ```
18
+ npm uninstall @libs-scripts-mep/grav-fw-pvi
19
+ ```
20
+
21
+ <br>
22
+
23
+ | Fabricante | Ferramenta | Suporte |
24
+ | ---------- | ------------------------ | ------- |
25
+ | ST | STVP | ✔️ |
26
+ | Renesas | Renesas Flash Programmer | ❌ |
27
+
28
+ ## Resumo da Classe
29
+
30
+ ```js
31
+
32
+ GravaFW.STM8(params , callback , timeOut = 5000){
33
+
34
+ //invoca o STVP passando os parametros informados
35
+ let result = pvi.runInstructionS("stvp", [params])
36
+
37
+ //executa callback dependendo do resultado
38
+ if (result.includes(`Verify OPTION BYTE succeeds`)) {
39
+ callback(true, result)
40
+ } else if (result.includes(`ERROR : Cannot communicate with the tool`)) {
41
+ callback(null, "Gravador não respondeu")
42
+ } else {
43
+ callback(false, "Falha na gravação do firmware final")
44
+ }
45
+ }
46
+
47
+ ```
48
+
package/grav-fw-pvi.js ADDED
@@ -0,0 +1,124 @@
1
+ class GravaFW {
2
+
3
+ static STM8(dirFirm = null, dirOpt = null, modelo_uC = null, callback = () => { }, timeOut = 5000) {
4
+
5
+ if (dirFirm != null && dirOpt != null) {
6
+
7
+ let result = pvi.runInstructionS("ST.writefirmwarestm8_stlink", [
8
+ dirFirm.replace(/[\\]/g, "\/").replace(/\.stp|\.STP/, ".HEX"),
9
+ dirOpt.replace(/[\\]/g, "\/").replace(/\.stp|\.STP/, ".HEX"),
10
+ modelo_uC
11
+ ])
12
+
13
+ let monitor = setInterval(() => {
14
+
15
+ if (result != null) {
16
+
17
+ clearInterval(monitor)
18
+ clearTimeout(timeoutMonitor)
19
+
20
+ if (result.includes(`Verify OPTION BYTE succeeds`)) {
21
+
22
+ console.log(`%cLog Program:\n\n${result}`, ' color: #00EE66')
23
+ callback(true, result)
24
+
25
+ } else if (result.includes(`ERROR : Cannot communicate with the tool`)) {
26
+
27
+ console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
28
+ callback(null, "Gravador não respondeu")
29
+
30
+ } else {
31
+
32
+ console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
33
+ callback(false, "Falha na gravação do firmware final")
34
+
35
+ }
36
+ }
37
+ }, 100)
38
+
39
+ let timeoutMonitor = setTimeout(() => {
40
+ clearInterval(monitor)
41
+ callback(false, "Tempo de gravação excedido")
42
+ }, timeOut)
43
+
44
+ } else if (dirFirm != null) {
45
+
46
+ let result = pvi.runInstructionS(`ST.writeprogramstm8_stlink`, [
47
+ dirFirm.replace(/[\\]/g, "\/").replace(/\.stp|\.STP/, ".HEX"),
48
+ modelo_uC
49
+ ])
50
+
51
+ let monitor = setInterval(() => {
52
+
53
+ clearInterval(monitor)
54
+ clearTimeout(timeoutMonitor)
55
+
56
+ if (result != null) {
57
+
58
+ if (result.includes(`Verifying PROGRAM MEMORY succeeds`)) {
59
+
60
+ console.log(`%cLog Program:\n\n${result}`, ' color: #00EE66')
61
+ callback(true)
62
+
63
+ } else if (result.includes(`ERROR : Cannot communicate with the tool`)) {
64
+
65
+ console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
66
+ callback(null, "Gravador não respondeu")
67
+
68
+ } else {
69
+
70
+ console.log(`%cLog Program:\n\n${result}`, ' color: #EE0033')
71
+ callback(false, "Falha na gravação do firmware")
72
+
73
+ }
74
+ }
75
+ }, 100)
76
+
77
+ let timeoutMonitor = setTimeout(() => {
78
+ clearInterval(monitor)
79
+ callback(false, "Tempo de gravação excedido")
80
+ }, timeOut)
81
+
82
+ } else if (dirOpt != null) {
83
+
84
+ let result = pvi.runInstructionS("ST.writeoptionstm8_stlink", [
85
+ dirOpt.replace(/[\\]/g, "\/").replace(/\.stp|\.STP/, ".HEX"),
86
+ modelo_uC
87
+ ])
88
+
89
+ let monitor = setInterval(() => {
90
+
91
+ clearInterval(monitor)
92
+ clearTimeout(timeoutMonitor)
93
+
94
+ if (result != null) {
95
+
96
+ if (result.includes(`Verify OPTION BYTE succeeds`)) {
97
+
98
+ console.log(`%cLog Desprotect:\n\n${result}`, ' color: #00EE66')
99
+ callback(true, result)
100
+
101
+ } else if (result.includes(`ERROR : Cannot communicate with the tool`)) {
102
+
103
+ console.log(`%cLog Desprotect:\n\n${result}`, ' color: #EE0033')
104
+ callback(null, "Gravador não respondeu")
105
+
106
+ } else {
107
+
108
+ console.log(`%cLog Desprotect:\n\n${result}`, ' color: #EE0033')
109
+ callback(false, "Falha na gravação do option byte")
110
+
111
+ }
112
+ }
113
+ }, 100)
114
+
115
+ let timeoutMonitor = setTimeout(() => {
116
+ clearInterval(monitor)
117
+ callback(false, "Tempo de gravação excedido")
118
+ }, timeOut)
119
+
120
+ } else {
121
+ callback(false, "Nenhum diretório de firmware ou option byte informado.")
122
+ }
123
+ }
124
+ }
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@libs-scripts-mep/grav-fw-pvi",
3
+ "version": "1.0.0",
4
+ "description": "Auxilia na gravação de microcontroladores por linha de comando através do PVI",
5
+ "main": "grav-fw-pvi.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/libs-scripts-mep/grav-fw-pvi.git"
12
+ },
13
+ "keywords": [
14
+ "gravacao",
15
+ "firmware",
16
+ "uc",
17
+ "microcontrolador"
18
+ ],
19
+ "author": "Lucas Kroth",
20
+ "license": "ISC",
21
+ "bugs": {
22
+ "url": "https://github.com/libs-scripts-mep/grav-fw-pvi/issues"
23
+ },
24
+ "homepage": "https://github.com/libs-scripts-mep/grav-fw-pvi#readme"
25
+ }