platformio / platform-intel_mcs51

Intel MCS-51 (8051): development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/intel_mcs51
Apache License 2.0
56 stars 44 forks source link

Add initial support for CH559 (WIP/RFC) #29

Closed Tonymac32 closed 2 years ago

Tonymac32 commented 4 years ago

The CH559 is a USB microcontroller based on the MCS-51 architecture.

This chip requires a custom upload protocol, I have placed the framework for that in main.py, I am not clear on how to have platformIO grab the necessary python upload tool automagically from here: https://github.com/MarsTechHAN/ch552tool

This tool depends on libusb as well.

Once these details are figured out/solved I can follow with board definitions for the remainder of the CH55x family.

maxgerhardt commented 3 years ago

Great PR! This allowed be to create a blinky firmware and flash it on the device using https://github.com/LoveMHz/vnproch55x. (for me, ch55xtool.py has a bug (https://github.com/MarsTechHAN/ch552tool/issues/16) and can't find my device at all, while other tools can find it).

There is also a forked Arduino core based on SDuino (for STM8 devices) available at https://github.com/DeqingSun/ch55xduino, and it works greatly! They also use the vnproch55x flasher per above.

The nice thing with the core is is that once any ch55xduino firmware has been flashed, it exposes a USB serial port that supports the standard reset-to-bootloader mechanism via opening it at 1200 baud. That way one doesn't even have to manually reboot the device by holding a button and switching power on and off.

I'll see if I can get the Arduino core implementation to work and the other uploader based on your work! 👍

am not clear on how to have platformIO grab the necessary python upload tool automagically

The tool has to uploaded into the PIO package repository via pio package publish, then you can reference the package in the platform.json and use a bit of code to tell PIO that you need the pacakge, then use functions like platform.get_package_dir() to get the path to the installed package.

Edit: I've just published the framework-arduinoch55x package and the Win, Linux and Mac versions of tool-vnproch55x and hope they'll be approved soon for usage.

Tonymac32 commented 3 years ago

@maxgerhardt nice! The upload tool did not fare so well against some of the newer bootloader revisions on the CH55x devices, I wound up making this PR because I designed a Pi 0 form factor dev board and was hopeful to provide some decent support. After a very extended silence I'd all but forgotten about it. 👀

I'll take a look at the arduino platform, it has been a while since I tried it out.

ivankravets commented 2 years ago

@Tonymac32 could make a board file name in uppercase? We keep TARGET DEVICES in their original form (typically upper case).

@maxgerhardt what do we need to merge this PR?

Tonymac32 commented 2 years ago

I can take another run at this starting next week, I'm unfortunately in the middle of moving and don't have access to my build system until I set it back up. Thanks for the review!

ivankravets commented 2 years ago

The PR has been merged, the latest version of tool-vnproch55x has been published to the registry. Please re-test with the latest dev-platform:

  1. Upgrade PIO Core to the latest dev version pio upgrade --dev
  2. Use the GIT version of dev-platform in platformio.ini => platform = https://github.com/platformio/platform-intel_mcs51.git
  3. Open the system terminal, change the directory to the project folder, and type pio pkg update.

Does it work now?

maxgerhardt commented 2 years ago

Ah but the upload tool used in this PR is https://github.com/MarsTechHAN/ch552tool, not https://github.com/LoveMHz/vnproch55x (which I was using on the command line), which package you've uploaded.

Also a note on the original issue with ch552tool, this was related to the libusb backend file missing or being a buggy version (I think v1.0.25). Maybe it was fixed with the fresh new release put out a few hours ago, but it was buggy for a really long time. For the Python tool to use libusb devices one needs to have the libusb-1.0.dll in the Python interpreter folder or the program folder. Or use WinUSB drivers with Zadig, I have not tested that.

I have the chip and can test later in the evening.

ivankravets commented 2 years ago

I used these tools (they were recently updated) https://github.com/DeqingSun/ch55xduino/tree/ch55xduino/ch55xduino/tools

Checked on mac OS, and it works. Are they broken?

maxgerhardt commented 2 years ago

Yes ch55xduino uses vnproch55x.exe but this PR calls into ch55xtool.py. I think the binary releases of vnproch55.exe worked fine for me and this is where I had the binaries from.

ivankravets commented 2 years ago

Sorry, I removed your package to avoid duplicates. Let's summarize - should we make any changes regarding this PR?

I found some time for the OSS dev-platforms, I'm not sure that I can back to this repo in the next months. I would be great to merge all PRs and re-test them. Thanks!

maxgerhardt commented 2 years ago

I think we

maxgerhardt commented 2 years ago

Ah, I see you have already done the second point in https://github.com/platformio/platform-intel_mcs51/commit/6402cc747528692b663cd64535e1493209618b5e, so it should actually be working.

KenwoodFox commented 1 year ago

Great PR! This allowed be to create a blinky firmware and flash it on the device using LoveMHz/vnproch55x. (for me, ch55xtool.py has a bug (MarsTechHAN/ch552tool#16) and can't find my device at all, while other tools can find it).

There is also a forked Arduino core based on SDuino (for STM8 devices) available at DeqingSun/ch55xduino, and it works greatly! They also use the vnproch55x flasher per above.

The nice thing with the core is is that once any ch55xduino firmware has been flashed, it exposes a USB serial port that supports the standard reset-to-bootloader mechanism via opening it at 1200 baud. That way one doesn't even have to manually reboot the device by holding a button and switching power on and off.

I'll see if I can get the Arduino core implementation to work and the other uploader based on your work! +1

am not clear on how to have platformIO grab the necessary python upload tool automagically

The tool has to uploaded into the PIO package repository via pio package publish, then you can reference the package in the platform.json and use a bit of code to tell PIO that you need the pacakge, then use functions like platform.get_package_dir() to get the path to the installed package.

Edit: I've just published the framework-arduinoch55x package and the Win, Linux and Mac versions of tool-vnproch55x and hope they'll be approved soon for usage.

Did this every go through? Sorry to bump an old thread but I'm trying to get PIO working with the CH552! If ch55xduino got in there i should be good to target that slightly different board?

danielkucera commented 1 year ago

ch55xduino is "not there" This is how I got my board working just recently: https://github.com/danielkucera/ch552-hid/

KenwoodFox commented 1 year ago

ch55xduino is "not there" This is how I got my board working just recently: danielkucera/ch552-hid

Wow.. i am amazed at how exactly similar my current project looks to that.. i even have the commented out link_medium.py

Thank you haha! if i learn anything more ill lyk

What version of SDCC are you using?