atc1441 / chflasher

GNU General Public License v3.0
27 stars 7 forks source link

NameError: global name 'mode_verify' is not defined #5

Open ShaneKent opened 3 years ago

ShaneKent commented 3 years ago

I've been running into a very strange situation when using this chflasher.exe to flash a CH559. It seems like any time I try to call a memset or memcpy or similar function that I come across this error:

packihx: read 373 lines, wrote 724: OK.
hex2bin v1.0.1, Copyright (C) 1999 Jacques Pelletier
Lowest address = 00000000
Highest address = 00002C6D
Found CH559
Bootloader version: 2.40
Flash Erased
Filesize: 11374 bytes
Writing success
Traceback (most recent call last):
  File "chflasher.py", line 228, in <module>
  File "chflasher.py", line 208, in writefilev2
NameError: global name 'mode_verify' is not defined
[17208] Failed to execute script chflasher

The binary is created correctly, but flashing process fails at the verify step. The binary is loaded properly without issue if I instead utilize the WCHISPTool to flash via Serial or USB connection.

ShaneKent commented 3 years ago

I took the chflasher.py file in this repository and put it into my working directory. Doing that changed the error to this:

packihx: read 373 lines, wrote 725: OK.
hex2bin v1.0.1, Copyright (C) 1999 Jacques Pelletier
Lowest address = 00000000
Highest address = 00002C74
Found CH559
Bootloader version: 2.40
Flash Erased
Filesize: 11381 bytes
Writing success
Traceback (most recent call last):
  File "chflasher.py", line 228, in <module>
    elif mode == mode_verify_v2:
  File "chflasher.py", line 208, in writefilev2
    outbuffer[1] = (pkt_length+5)
NameError: global name 'mode_verify' is not defined
[15064] Failed to execute script chflasher

Perhaps this will add some more clarity on the issue.

nockieboy commented 2 years ago

gentle prod I'm also experiencing this problem in the same (or similar) circumstances whilst compiling and flashing code to a CH559.

From my very basic testing, I'm wondering if it's a file size issue? My code compiles with no issues with a reported file size of 11212 bytes. If I replace a 'DEBUG_OUT' command in USBHost.c (for example) with a 'printf' command, the file size goes up to 11303 and I get the reported errors:

packihx: read 369 lines, wrote 720: OK.
hex2bin v1.0.1, Copyright (C) 1999 Jacques Pelletier
Lowest address = 00000000
Highest address = 00002C26
Found CH559
Bootloader version: 2.31
Flash Erased
Filesize: 11303 bytes
Writing success
Traceback (most recent call last):
  File "chflasher.py", line 228, in <module>
  File "chflasher.py", line 208, in writefilev2
NameError: global name 'mode_verify' is not defined
[13088] Failed to execute script chflasher

I've tested and tested, and it seems a file size of up to 11267 bytes is fine, but 11268 (or more) causes the error. I've tested this by simply printing a string to serial using printf and increasing the size of the string until I found the cutoff between a successful compile and a failed one with the above error.

nockieboy commented 2 years ago

gentle prod I'm also experiencing this problem in the same (or similar) circumstances whilst compiling and flashing code to a CH559.

From my very basic testing, I'm wondering if it's a file size issue? My code compiles with no issues with a reported file size of 11212 bytes. If I replace a 'DEBUG_OUT' command in USBHost.c (for example) with a 'printf' command, the file size goes up to 11303 and I get the reported errors:

packihx: read 369 lines, wrote 720: OK.
hex2bin v1.0.1, Copyright (C) 1999 Jacques Pelletier
Lowest address = 00000000
Highest address = 00002C26
Found CH559
Bootloader version: 2.31
Flash Erased
Filesize: 11303 bytes
Writing success
Traceback (most recent call last):
  File "chflasher.py", line 228, in <module>
  File "chflasher.py", line 208, in writefilev2
NameError: global name 'mode_verify' is not defined
[13088] Failed to execute script chflasher

I've tested and tested, and it seems a file size of 11267 bytes is fine, but 11268 causes the error. I've tested this by simply printing a string to serial using printf and increasing the size of the string until I found the cutoff between a successful compile and a failed one with the above error.