grigorig / stcgal

Open Source STC MCU ISP flash tool
678 stars 140 forks source link

Support for USB-ISP #10

Closed tpimh closed 8 years ago

tpimh commented 8 years ago

Will stcgal support USB-ISP?

USB-ISP

grigorig commented 8 years ago

I have an STC15W4 series MCU, but I haven't tried the USB mode yet, sorry.

The USB mode exposes a serial device over CDC-ACM, so it definitely seems possible to support it without major changes to stcgal. I bet it uses a simplified STC15 protocol without all the messy bits to tweak frequency and so on.

Needless to say, pull requests are welcome. I am not sure if I have enough time to work on this.

grigorig commented 8 years ago

A correction: the USB-ISP mode doesn't use CDC-ACM, but raw control packets. The protocol seems to be quite simple, though. You can expect USB-ISP support, based on libusb/pyusb, to come.

grigorig commented 8 years ago

WIP branch: https://github.com/grigorig/stcgal/tree/usbisp

grigorig commented 8 years ago

The code in the branch is somewhat functional now. Flash programming works. If you are interested, please give it a go. The implementation requires pyusb. Here's a demo output:

$ sudo ./stcgal.py -P usb15 doc/hello.bin 
Connecting to USB-ISP device: done
Target model:
  Name: STC15W4K56S4
  Magic: F528
  Code flash: 56.0 KB
  EEPROM flash: 3.0 KB
Target frequency: 0.000 MHz
Target BSL version: 7.3.4T
Target wakeup frequency: 36.672 KHz
Target options:
  reset_pin_enabled=False
  clock_source=internal
  clock_gain=high
  watchdog_por_enabled=False
  watchdog_stop_idle=True
  watchdog_prescale=64
  low_voltage_reset=False
  low_voltage_threshold=3
  eeprom_lvd_inhibit=False
  eeprom_erase_enabled=True
  bsl_pindetect_enabled=False
  por_reset_delay=long
  rstout_por_state=high
  uart2_passthrough=False
  uart2_pin_mode=normal
  cpu_core_voltage=unknown
Loading flash: 80 bytes (Binary)
Initializing: done
Erasing flash: done
Writing 256 bytes: .. done
Setting options: TODO
Disconnected!
tpimh commented 8 years ago

Thank you very much! I'm very interested, but unfortunately I don't have any IC supporting USB-ISP right now to test it.

grigorig commented 8 years ago

Setting options also works now. I'm confident this won't brick any chips, so it has been cleaned up and merged now.

wc7086 commented 10 months ago

@grigorig Can you add this support for stc8?

image