Monday, 25 May 2020

CHUSBIE552 The CH552 Development board

For a few years I have been looking at different MCUs with USB capabilities in most cases there are not many sub $1 parts that fit the bill.

If you want something small and discreet that does a few USB functions there isn't much around, normally the barrier to entry on these types of MCUs 8 bit and 32 bit included is over the $2 mark. The issue start to become when costing the bill of materials $2 on the BOM becomes $8 by the time you get to retail price.

There are a few low cost MCUs out there like the range from STC or Nuvoton once you add a USB transceiver the cost seems to double.

I know it sees to be very focused cost but with companies form overseas being able to produce USB devices with the low retail price there must be some solution out there.

My over all goal is to demystify USB and develop a platform that gives developers confidence to develop USB devices without large overheads or in some cases complicated stacks that are beyond comprehension.

I have spoken about my admiration of the CH55x range from WCH that are a series of ultra low cost micro controllers with USB in some of the range is down in the $0.25 category in volume. Which is unbelievable a full capable MCU for the same as a discreet logic IC.

As well as the USB2.0 transceiver and the E8051 processing core itself they come with a resonable array of peripherals as well 2 x UART port, SPI  , 4 channel 8 bit ADC and 10k to 64k flash space in the case of the CH559.

There are a few dev boards out there for the CH55x range mainly from electrodragon with their CH55x range of boards. They are a nice range but I feel they have a couple of  points that I would love to see improved on. 

This is why I decided to start the CHUSBIE range starting with the CHUSBIE552 based on the CH552T or CH552G a lower cost less IO version.


With the CHUSBIE552 I have added onboard functions that I think will be the most useful to a developer like: 
  • onboard reset and bootloader buttons
  • RX and TX indicator LEDs
  • sensible pin-outs with pins and ports in order
  • optional landing for external XTAL crystal for precision timing applications 
  • Power indicator LED

I would like to see a general adoption of the CH55x range chips in a similar way to the ESP8266 and ESP32 (notably neither of which have native USB which in my humble option would be a killer addition).

I want to work on the software stacks to make them more friendly for a start making sure the Chinese comments are translated to English for the examples especially the USB ones. My point is that USB doesn't need to be this mystical black box that can't be easily accessed by most hobbyists and makers.

So far in my research I found firmware for USB CDC device, USB HID device and USB JTAG device all of which i am trying out to incorporate into a master repository.

Updates to this project can be found here:

https://hackaday.io/project/171543-chusbie552-ch552-development-board

I hope to have the completed board available on my Tindie store here:
https://www.tindie.com/stores/rabidselectronicsemporium/




Monday, 11 May 2020

Aprils Round up: Farewell Jon Conway


Farewell John Conway 

It is unfortunate when you have to start a post with an obituary. On the 11th April the Maths and Physics has lost a great. John Horton Conway passed away aged 82.

In 1970 Conway developed the 'Game of Life' one of the early cellular automatons which generates patterns to a known set of rules. which in the early days he would draw onto graph paper as it was well before the home computing revolution. This has spawned countless examples of his algorithm, and often used as an example on matrix displays. 


Remembering Mathematical Magician John Conway
Credit: Thane Plambeck Flickr (CC BY 2.0)

This is still the same today with many people celebrating his life and achievements with examples of this.


This above example by @ef1j91 on done on a TE-318 teleprinter wow!

And a very pretty example by @sethpine

Brian Corteil Looses His Beard

In the current climate of lock-down and social distancing Museums are being hit hard. Not being allowed to open their doors to paying customers while still have to fork out on rents and bills. Brian Corteil of Coretec Robots made the ultimate sacrifice by shaving his beard off. With this he raised £349 to help keep the light on.
Nice one Brian 😀

New video from the 8-bit Guy

The 8-Bit guy is one of my favorite Youtube creators when id come down Retro computing. He upload an interesting video this month on different and obscure medias types, defiantly worth checking out.

I was hoping to share some more cool projects I had found but unfortunately time has run out so i'll leave it with these this month.

Sunday, 10 May 2020

Getting started with the CH55x Microcontroller

I have not been hiding the fact that I have love for the CH55x range of microcontrollers. So much so that I decided to stock several versions on the store. If you want to get hold of a few to experiment with check it out at Rabid's Electronics Emporium


I thought it's about time to write up a little tutorial on how to get up and running with this little unsung hero.

For this getting started tutorial I will be specifically looking at the CH552G but this tutorial will also apply for the CH551x, CH552x and CH554.



Installing the Toolchain 


This is not the only way to set up this toolchain there are other compilers and toolchains available, this, however, was the most straightforward way I found to get up and running.

First off the best thing to do is to install the compiler for this tutorial. We are going to use SDCC (Small Device C Compiler) this compiler runs natively in most linux flavours but if you're developing on a windows machine like I am then it will be worth setting up WLS (Windows Linux Subsystem) and installing Ubuntu.

Details on how to do that can be found here:
https://codebriefly.com/setup-windows-subsystem-linux-wsl-windows-10/

Once you are at the Linux command line SDCC can be installed with:

apt-get install sdcc build-essential

The next step will be to download the codebase for SDCC and the CH554 from GitHub:

git clone https://github.com/Blinkinlabs/ch554_sdcc.git 
Then navigate into the examples and compile them:

cd ch554_sdcc/examples/
make 
 If this completes correctly then your toolchain is setup.
You should have something similar to above.

After a little searching around, there is a way to setup SDCC in windows natively which can be found at the link below.

https://www.instructables.com/id/8051-C-development-using-FREE-compiler-SDCC/

As I mentioned I didn't use this method but if you feel a little more comfortable using it instead of installing WSL and Ubuntu it's worth a shot.

Preparing the hardware 

The MCU itself requires very little hardware to run in USB programming mode. Though a reasonable soldering skill is needed to solder the chip into a proto-board. There are many tutorials online on the best method to do this.

  
The above video is a very similar method to what I use. I am also considering stocking some already soldered on the store, as I will soon have the prototyping boards available.  


Once you have your board soldered and pins attached the rest of the circuit can be made up, on a breadboard. For me, I found the easiest way to attach the USB signal was to Butcher an old USB cable and solder Dupont jumper wire onto the exposed ends.


This has been really handy while I have experimented with this MCU.

The rest of the supporting circuitry can be made up, on a breadboard all it requires is 2 x 100nF ceramic capacitors between 3v3 and GND and between VCC and GND as down below.


If the chip is new and fresh from the factory then from my experience it drops straight into bootloader mode no a widows PC it makes the always familiar USB device sound :).

Of course, if this doesn't happen then the MCU will need to be set into bootloader mode.

Putting the MCU into USB Bootloader mode


There are two possible bootloader pins ton the CH552 the default from the factory is on P3.6. To active the bootloader the pin must be pulled to 3V3 briefly after reset. This can, however, be very problematic as the same pin is shared with USB DP. So for my purposes, I like to set up the bootloader pin as the available alternative which is P1.5 there is a catch though this pin ins needed to be pulled to GND.


Writing Firmware to the MCU 

First of all, you will need to download and install WCHISPTool this is the official and poorly translated to English tools from WCH themselves. 

This can be downloaded from here: http://www.wch.cn/products/CH552.html

Oddly enough the English WCH site doesn't give you any of the download links to the tools of datasheets so you will have to go through the Chinese site. 


once the software is installed and running it will look much like the above. You will need to select the '8-Bit CH55x series' tab and select the CH552 as you devise then all being well your device should appear in the device list below. 

 This tool gives you a few configuration options like:
  • Disabling the reset pin 
  • Enabling slow reset
  • Erasing the data flash 
  • Swapping the bootloader pin to P1.5
From my own experience swapping the bootloader pin is worth doing for me it helps getting it into bootloaders mode as P3.6 (the default pin) is shared with USB Data + which cam make things awkward. Where you have P1.5 tied to GND was very helpful for me as the MCU then automatically goes into USB bootloader mode every time it is reset or powered. 

To test the function everything is well if you select the user firmware you would like to use I used blink which but this point should be in the toolchain examples.

\ch554_sdcc\examples\blink\blink.bin
This will need to be selected as your 'User file' the click on Download(D) all being well you will have some lovely green text in the download record below saying the process was successful.

All being well if you hook and LED and resistor between pin P1.7 and GND then you will have a lovely blinky LED.



Starting your own application

This is very simple from mine I copied one of the examples and I started to edit form and just use the make command to compile it.

After a bit of trail and error managed to make it run LPD8806 strips of LEDs.


Messy but works :D


What I would like to do now is to add a USB CDC driver so I am able to adjust the colours over USB.

I have a both the CH552G and CH552T which has more IO are listed on my Tindie store.

Further Info on the CH552 can be found here:

datasheet(translated) https://github.com/rabid-inventor/document-archive/blob/master/datasheets/WCH/MCUs/CH552%20Datasheet_C111367.zh-CN.en.pdf

Improved Pinout table https://github.com/rabid-inventor/document-archive/blob/master/datasheets/WCH/MCUs/CH552-Pinout-details.csv