Code Monkey home page Code Monkey logo

ch552tool's Introduction

It's Hanxiao!

EE major in Rose-Hulman Institute of Technology.

Research on edge computing, hardware-aware NAS, power/latency/energy predictors.

Hanxiao's GitHub stats

ch552tool's People

Contributors

bbbsnowball avatar ishiyakazuo avatar karlp avatar marstechhan avatar pe3uctop avatar vowstar avatar zerosensei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ch552tool's Issues

Starting the code with -r switch

Hi,
if i start the code on the ch559 with this command:
python3 -m ch55xtool -r

The code starts running on the CH559 (good!)

But I also get the following error:
Found CH559 with SubId:17
BTVER:02.40
UID:72-03-48-BC-00-00-00-00
Traceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/edo/.local/lib/python3.8/site-packages/ch55xtool/main.py", line 12, in
sys.exit(_main())
File "/home/edo/.local/lib/python3.8/site-packages/ch55xtool/ch55xtool.py", line 898, in main
ret, ret_pl = __end_flash_ch5xx(dev, restart_after = args.reset_at_end)
File "/home/edo/.local/lib/python3.8/site-packages/ch55xtool/ch55xtool.py", line 388, in __end_flash_ch5xx
return cmd_exec(dev, "End", cmd_pl)
File "/home/edo/.local/lib/python3.8/site-packages/ch55xtool/ch55xtool.py", line 141, in cmd_exec
return cmd_reply_receive(dev, cmd_bin)
File "/home/edo/.local/lib/python3.8/site-packages/ch55xtool/ch55xtool.py", line 123, in cmd_reply_receive
reply = ep_in.read(ep_in.wMaxPacketSize, USB_MAX_TIMEOUT)
File "/home/edo/.local/lib/python3.8/site-packages/usb/core.py", line 423, in read
return self.device.read(self, size_or_buffer, timeout)
File "/home/edo/.local/lib/python3.8/site-packages/usb/core.py", line 1029, in read
ret = fn(
File "/home/edo/.local/lib/python3.8/site-packages/usb/backend/libusb1.py", line 846, in bulk_read
return self.__read(self.lib.libusb_bulk_transfer,
File "/home/edo/.local/lib/python3.8/site-packages/usb/backend/libusb1.py", line 954, in __read
_check(retval)
File "/home/edo/.local/lib/python3.8/site-packages/usb/backend/libusb1.py", line 604, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error

Or this should be normal since the CH559 will be re-set and cuts communication on USB with the PC ?

usb.core.USBError: [Errno 32] Pipe error

On freshly installed manjaro, anyt suggestions on what to try?

python3 -m ch55xtool -f build/spi/spi.bin -r
Found CH559 with SubId:17
BTVER:02.40
UID:BE-41-BF-48-00-00-00-00
Erasing chip flash. Done.
Flashing chip. Done.
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/home/fabio/.local/lib/python3.11/site-packages/ch55xtool/main.py", line 12, in
sys.exit(_main())
^^^^^^^
File "/home/fabio/.local/lib/python3.11/site-packages/ch55xtool/ch55xtool.py", line 898, in main
ret, ret_pl = __end_flash_ch5xx(dev, restart_after = args.reset_at_end)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/fabio/.local/lib/python3.11/site-packages/ch55xtool/ch55xtool.py", line 388, in __end_flash_ch5xx
return cmd_exec(dev, "End", cmd_pl)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/fabio/.local/lib/python3.11/site-packages/ch55xtool/ch55xtool.py", line 141, in cmd_exec
return cmd_reply_receive(dev, cmd_bin)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/fabio/.local/lib/python3.11/site-packages/ch55xtool/ch55xtool.py", line 123, in cmd_reply_receive
reply = ep_in.read(ep_in.wMaxPacketSize, USB_MAX_TIMEOUT)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/fabio/.local/lib/python3.11/site-packages/usb/core.py", line 423, in read
return self.device.read(self, size_or_buffer, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/fabio/.local/lib/python3.11/site-packages/usb/core.py", line 1029, in read
ret = fn(
^^^
File "/home/fabio/.local/lib/python3.11/site-packages/usb/backend/libusb1.py", line 846, in bulk_read
return self.__read(self.lib.libusb_bulk_transfer,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/fabio/.local/lib/python3.11/site-packages/usb/backend/libusb1.py", line 954, in __read
_check(retval)
File "/home/fabio/.local/lib/python3.11/site-packages/usb/backend/libusb1.py", line 604, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error
Finalize communication.make: *** [../ch55x/Makefile:78: flash] Error 1

USB_ERROR_CANNOT_SET_CONFIG error on CH552

Hi there, I would like to flash CH552 on linux, then your tool seems be a good option. When I just run python ch55xtool.py I always get the USB_ERROR_CANNOT_SET_CONFIG error.

BTW, usb rules has been added, and I can see the USB device from lsusb:

Bus 001 Device 007: ID 4348:55e0 WinChipHead
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Any hint to debug on this?

no debug mode

The readme refers to a -d flag for debug mode, but this does not seem to be implemented.

Fails to verify once the size is big

In several projects, the tool works flawlessly for small files. Once I reach a certain size, it stars giving this kind of error

`python3 -m ch55xtool -f build/fat32.bin -r

Found CH559.

BTVER: V2.40.

Failed to verify firmware of CH55x.`

I attach a CH559 binary file that fails. In all the cases, the official programmer works.

fat32.zip

Tried with CH568L , unsuccess. But solution found :) will place PR in near weeks.

First of all , nice work !
But, would like to see more output.
Like:
Erasing ...
Flashing ...
Verifying ..

I added :

CH55X_IC_REF[0x68] = {
    'device_name': 'CH568',
    'device_flash_size': (128+64)*1024,
    'device_dataflash_size': 32*1024,
    'chip_id': 0x68}

and got response when tried to flash:

Found CH568.
BTVER: V2.40.
Flash done.
Restart and run.

But board do not startup / do not work.
When uploading with WCHISPTool 3.0 result in working board.
Will continue next week, will try to capture USB traffic for both applications.

Failed to flash firmware of CH55x

I can not flash my CH554 with this tool

python -m ch55xtool -f C:\Users\Gigabyte\Documents\Keil\CH554EXAM\USB\U_DISK\EXAM1\EXAM1.bin -r
Found CH554.
BTVER: V2.31.
Failed to flash firmware of CH55x.

Do you need any other information? I am using a converted version of U_DISK example bin from their official example pack.

I am using Windows, with Zadig and libusb-win32 properly installed, I can see an unknown device that manufactured by WinChipHead.

Add ch582 debug enabling feature

by adding :
[CH582] Tested=1 CFGs={ '_reserved': { FLAG_CFG1 :{'mask':0xffffffff,'value':0xffffffff }, FLAG_CFG2 :{'mask':0xffffffff,'value':0xffffffff }, FLAG_CFG3 :{'mask':0xffffffff,'value':0xffffffff } }, 'default': { FLAG_CFG2 :{'mask':0xffffffff,'value':0xffffffff }, FLAG_CFG3 :{'mask': 0xffffffff, 'value': 0x4FFF0FD5}, 'help':'Write default CFGs values' }, 'Dis_Debug': { FLAG_CFG3 :{'mask': 0xffffffff , 'value': 0x4FFF0F4D }, 'help':'Enable Debug port ' }, 'En_Debug': { FLAG_CFG3 :{'mask': 0xffffffff, 'value': 0x4FFF0FD5 }, 'help':'Disable Debug port' } }
to file extended.wcfg it is possible to enable/disable debug feature on wch582, it could be extended to ch592 (tested by me), it probably works also on al ch58x and ch59x family

CH32V203C8T6 working

Chip CH32V203C8T6 (board nanoCH32V203 or CH32V203EVT):

$  python3 -m ch55xtool -v -p
Chip ID: 31 is not known = not supported
Welcome to report this issue with a screen shot from the official CH5xx tool.

31 - hexadecimal value, is not clear at once.

Added to the typeall.wcfg:

[CH32V203C8T6]
McuType=9
MaxFlashSize=65536
MaxEepromSize=0
IsNetworkDown=0
IsUsbDown=1
IsSerialDown=1
chipid=49
eepromStartAddr=0
Introduction = ""

flash/verify_flash/print configuration - working !

McuType has to correspond to bMCULine from WCHISPTool?

Why CH32V307 in typeall.wcfg has only one point?
According to WCHISPTool CH32V307 has three different chipid:

	CH32V307WCU6 - 115
	CH32V307VCT6 - 112
	CH32V307RCT6 - 113

Support Mac OS

Hi @MarsTechHAN

I am testing this script and not work in Mac OS, python3 with CH559

Chip is always in mode boot

Thanks

Failed to get device for CH559

I've put my device into USB bootloader mode and I've previously installed libusb-win32 drivers via Zadig.

When I try to upload the firmware I get

>python  -m ch55xtool  -f .pio\build\ch559\firmware.bin -r
Failed to get device, please check your libusb installation.

When I call into the tool by https://github.com/LoveMHz/vnproch55x, directly after that, with no USB device reconnected or anything

>C:\Users\Max\Desktop\tools\win\vnproch55x.exe .pio\build\ch559\firmware.bin
------------------------------------------------------------------
CH55x Programmer by VNPro
------------------------------------------------------------------
Found Device CH559
Bootloader: 2.3.1
ID: 1B AC 4B 41
XOR Mask: 53 53 53 53 53 53 53 AC
Write 194 bytes from bin file.
..................................................
Write complete!!!
Verify chip
..................................................
Verify complete!!!
------------------------------------------------------------------

It can do it, as well as when I use the Python version of

>python C:\Users\Max\chflasher\chflasher.py .pio\build\ch559\firmware.bin
Could not access USB Device
Traceback (most recent call last):
  File "C:\Users\Max\chflasher\chflasher.py", line 36, in <module>
    dev.set_configuration()
  File "C:\Users\Max\AppData\Local\Programs\Python\Python38\lib\site-packages\usb\core.py", line 905, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "C:\Users\Max\AppData\Local\Programs\Python\Python38\lib\site-packages\usb\core.py", line 113, in wrapper
    return f(self, *args, **kwargs)
  File "C:\Users\Max\AppData\Local\Programs\Python\Python38\lib\site-packages\usb\core.py", line 159, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "C:\Users\Max\AppData\Local\Programs\Python\Python38\lib\site-packages\usb\backend\libusb1.py", line 812, in set_configuration
    _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
  File "C:\Users\Max\AppData\Local\Programs\Python\Python38\lib\site-packages\usb\backend\libusb1.py", line 604, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 5] Input/Output Error

but when I use the precompile .exe version

>C:\Users\Max\chflasher\chflasher.exe .pio\build\ch559\firmware.bin
Found CH559
Bootloader version: 2.31
Flash Erased
Filesize: 194 bytes
Error: Something wrong with the bin file

(a related bug for that is opened at atc1441/chflasher#4)

In any case, with the tool in this repository I can't get my device recognized.

It is interesting that the chflasher tool is also written in Python and the script also doesn't see my device..

Any ideas?

Running on Windows 10, Python 3.8.6, pyUSB 1.1.1, Zadig libusb-win32 drivers were installed for the device.

Protocol for downloading the program into the CH552?

Could you please tell me if there is a document describing the protocol for downloading the program into the CH552?
Is this possible only via USB or is it possible through a com-port?

Thank you for your reply.

add shebang

the script should have:
#!/usr/bin/env python3
as the first line.

Cannot use Zadig with Maix Bit due to "[Port2] FailedEnumeration: Unknown USB Device (Device Descriptor Request Failed)"

Hi there.

I have tried to follow your instructions to fix an issue someone suggested here: https://en.bbs.sipeed.com/t/topic/2484 could be fixed using Zadig. Unfortunately, I cannot flash a device that I cannot even get to enumerate properly.

Also, when I attempt to update the driver to the Maix Bit Zadig says: "Driver Installation: FAILED (Resource already exists)".

I found another thread that suggested turning off the USB device then turning it back on and trying again would allow Zadig to install the driver on the second attempt. That does not work with the Maix Bit.

Any advice would be appreciated.

CH554 programming error ...

Howdy!

Just experiment with the ch552 this morning ...

lsusb returns

Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 003: ID 7392:a812 Edimax Technology Co., Ltd
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 002: ID 04f2:1825 Chicony Electronics Co., Ltd
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 015: ID 04e8:3315 Samsung Electronics Co., Ltd ML-2540 Series Laser Printer
Bus 001 Device 034: ID 4348:55e0 WinChipHead
Bus 001 Device 026: ID 239a:8019
Bus 001 Device 004: ID 0bda:0181 Realtek Semiconductor Corp.
Bus 001 Device 002: ID 058f:6254 Alcor Micro Corp. USB Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

I can see WinChipHead ...

Got this error, when I attempted to flash ...

rasyoung@vic2016:~/code_test/8051/wch/ch554_sdcc/examples/blink$ sudo python ch55xtool.py --file blink.hex
Found CH554.
BTVER: V2.31.

Traceback (most recent call last):
File "ch55xtool.py", line 337, in
__main()
File "ch55xtool.py", line 314, in __main
ret = __write_flash_ch55x_v23(dev, chk_sum, payload)
File "ch55xtool.py", line 143, in __write_flash_ch55x_v23
payload = payload + [0] * ((math.ceil(len(payload) / 56) * 56) - len(payload)) # Payload needs to be padded, 56 is a good number
TypeError: can't multiply sequence by non-int of type 'float'

I notice in the hex file ... the first lines are "short"

:03000000020006F5
:03005F0002000399
:0300030002006296
:1000620012007C53930CAF92747F5FF5924393809E
:100072009000641200A4B29780F675A15575A1AAEA
:1000820074F855B94405F5B975A10022AE82AF8363

It reports the correct chip type and bootloader version. Wondered if you know what was the issue?

Thanks for posting this code!

Randy

Document how to put the chip in DFU mode

Hi,

I have just flashed a blink.c with the ch552tool, if I try to flash it again it does not find the device in lsusb with a NO_DEV_FOUND error.

Any idea how to get the chip in bootloader mode? Do I have to wire a RST pin to GND?

Cannot flash CH559 board, but WCHISP can do it.

Hello,

I seem to have a CH559 board with bootloader 2.31 that cannot be flashed using this program even though it can be flashed fine using the WCHISP tool under Windows. Using ch55xtool flashes fail with a verification error, although nothing gets written to the board.

Now, I've captured the USB traffic on Windows by WCHISP if that helps, along with the firmware I flashed - so you can eventually check what WCHISP is doing differently.

In the meantime is there anything I can do on my end to further debug the issue in ch55xtool?

Thanks!

firmware.bin.gz
usb_flash.pcapng.gz

Put CH569 in debug mode

Hi,
When I send those commands, I can put the CH569 in debug mode (or disable it):

ENABLE_DEBUG_CMD = [
    0xa8, 0x0e, 0x00, 0x07, 0x00,
    0x11, 0xbf, 0xf9, 0xf7, 
    0x13, 0xbf, 0xf9, 0xec,
    0xe5,       
    0xf2,        
    0xff, 0x8f 
]

DISABLE_DEBUG_CMD = [
    0xa8, 0x0e, 0x00, 0x07, 0x00,
    0x11, 0xbf, 0xf9, 0xf7,
    0x13, 0xbf, 0xf9, 0xec,
    0x45,
    0xf2,
    0xff, 0x8f
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.