@libs-scripts-mep/grav-fw-pvi 4.0.0 → 4.0.2

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 (2) hide show
  1. package/grav-fw-pvi.js +65 -27
  2. package/package.json +1 -1
package/grav-fw-pvi.js CHANGED
@@ -7,7 +7,7 @@ export default class GravaFW {
7
7
  * @param {String} dirFirm
8
8
  * @param {String} dirOpt
9
9
  * @param {Object} objArguments
10
- * @param {Number} timeOut
10
+ * @param {Number} [timeOut=5000]
11
11
  * @returns
12
12
  *
13
13
  * # Exemplos
@@ -144,14 +144,13 @@ export default class GravaFW {
144
144
  /**
145
145
  *
146
146
  * @param {String} dirProject
147
- * @param {Number} timeOut
147
+ * @param {Number} [timeOut=5000]
148
148
  * @returns
149
149
  *
150
150
  * # Exemplos
151
151
  *
152
152
  * ```js
153
153
  * const programPath = "I:/script_repo/fw_repo/fw_v1_0.2.rpj"
154
- * const optionPath = "I:/script_repo/fw_repo/opt.hex"
155
154
  * const writeFirmware = await GravaFW.Renesas(programPath)
156
155
  * ```
157
156
  *
@@ -226,48 +225,87 @@ export default class GravaFW {
226
225
  })
227
226
  }
228
227
 
228
+
229
229
  /**
230
- * Realiza gravacao nos microcontroladores Nuvoton atraves do PVI, via JLink command line
230
+ * Realiza gravacao nos microcontroladores Nuvoton atraves do PVI, via JLink command line.
231
+ *
231
232
  * @param {string} dirProject caminho do firmware
232
- * @param {string} commandFile Arquivo de comandos JLink, pseudo-script de gravação
233
+ * @param {string} nameFile nome para o arquivo de comandos JLink que ficará na pasta 'C:/Temp/', sujestão: código effective
233
234
  * @param {string} device modelo do micrcontrolador
234
- * @param {number} timeOut
235
+ * @param {number} [speed=4000] velocidade de gravação
236
+ * @param {number} [timeOut=5000] tempo máximo de gravação
237
+ * @returns {Promise<{success: boolean, msg: string}>} - resultado da gravação
238
+ *
239
+ * # Exemplos
240
+ *
241
+ * ```js
242
+ * const programPath = "I:/script_repo/fw_repo/fw_v1_0.2.hex"
243
+ * const codigo_effective = "1234"
244
+ * const device = "STM32C031K6"
245
+ * const writeFirmware = await GravaFW.JLink_v7(programPath, codigo_effective, device)
246
+ * ```
247
+ *
248
+ * # Retorno
249
+ *
250
+ * ```js
251
+ * { success: Boolean, msg: String }
252
+ * ```
235
253
  */
236
- static async JLink_v7(dirProject = null, commandFile = null, device, timeOut = 10000) {
254
+ static async JLink_v7(dirProject = null, nameFile, device, speed = 4000, timeOut = 5000) {
237
255
 
238
- let logGravacao = ""
256
+ return new Promise((resolve) => {
239
257
 
240
- const id = FWLink.PVIEventObserver.add((msg, param) => {
258
+ pvi.runInstructionS("JLINK7.init", []) // Inicializa o JLink
259
+
260
+ let logGravacao = ""
241
261
 
242
- console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
243
- logGravacao = logGravacao + param[0]
262
+ const id = FWLink.PVIEventObserver.add((msg, param) => {
244
263
 
245
- if (data == "Script processing completed.") {
264
+ console.log(`%cLog Program: ${param[0]}`, ' color: #B0E0E6')
265
+ logGravacao = logGravacao + param[0]
246
266
 
247
- FWLink.PVIEventObserver.remove(id)
267
+ if (param == "Script processing completed.") {
248
268
 
249
- if (logGravacao.includes(`O.K.`)) {
269
+ FWLink.PVIEventObserver.remove(id)
250
270
 
251
- clearTimeout(timeOutGravacao)
252
- resolve({ success: true, msg: dirProject })
271
+ if (logGravacao.includes('Program & Verify speed')) {
253
272
 
254
- } else if (logGravacao.includes(`Cannot connect to target.`)) {
273
+ clearTimeout(timeOutGravacao)
274
+ resolve({ success: true, msg: dirProject })
255
275
 
256
- clearTimeout(timeOutGravacao)
257
- resolve({ success: false, msg: `Cannot connect to target.` })
276
+ } else if (logGravacao.includes(`Cannot connect to target.`)) {
258
277
 
259
- }
278
+ clearTimeout(timeOutGravacao)
279
+ resolve({ success: false, msg: `Cannot connect to target.` })
260
280
 
261
- }
262
- }, "sniffer.exec")
281
+ }
263
282
 
264
- FWLink.runInstructionS("EXEC", [`${FWLink.runInstructionS("GETPVIPATH", [])}\\Plugins\\JLINK7\\JLink.exe`, `-device ${device} -CommandFile ${commandFile}`, "true", "true"])
283
+ }
284
+ }, "sniffer.exec")
285
+
286
+ const commandFile = commandJlink(nameFile, speed, dirProject)
287
+ FWLink.runInstructionS("EXEC", [`${FWLink.runInstructionS("GETPVIPATH", [])}\\Plugins\\JLINK7\\JLink.exe`, `-device ${device} -CommandFile ${commandFile}`, "true", "true"])
265
288
 
266
- let timeOutGravacao = setTimeout(() => {
267
- FWLink.PVIEventObserver.remove(id)
268
- resolve({ success: false, msg: `Falha na gravação, verifique a conexão USB do gravador.` })
269
- }, timeOut)
289
+ let timeOutGravacao = setTimeout(() => {
290
+ FWLink.PVIEventObserver.remove(id)
291
+ resolve({ success: false, msg: `Falha na gravação, verifique a conexão USB do gravador.` })
292
+ }, timeOut)
293
+ })
270
294
 
295
+ function commandJlink(nameFile, speed, dirProject) {
296
+ if (FWLink.runInstructionS("vfs.directoryexists", [`C:/Temp/`]) == '1') {
297
+ if (FWLink.runInstructionS("vfs.fileexists", [`C:/Temp/${nameFile}.txt`]) == '1') {
298
+ FWLink.runInstructionS("EXEC", ["cmd.exe", `/c (echo si 1 & echo speed ${speed} & echo r & echo h & echo erase & echo loadfile ${dirProject} & echo exit) > C:/Temp/${nameFile}.txt`, true, true])
299
+ return `C:/Temp/${nameFile}.txt`
300
+ } else {
301
+ FWLink.runInstructionS("EXEC", ["cmd.exe", `/c (echo texto invalido) > C:/Temp/${nameFile}.txt`, true, true])
302
+ return commandJlink(nameFile, speed, dirProject)
303
+ }
304
+ } else {
305
+ FWLink.runInstructionS("vfs.createdirectory", [`C:/Temp/`])
306
+ return commandJlink(nameFile, speed, dirProject)
307
+ }
308
+ }
271
309
  }
272
310
 
273
311
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libs-scripts-mep/grav-fw-pvi",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Auxilia na gravação de microcontroladores por linha de comando através do PVI",
5
5
  "main": "grav-fw-pvi.js",
6
6
  "scripts": {