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





Tuesday, 28 April 2020

The CH552 MCU

There is a collection of super low cost very capable MCU's on the market but I find myself fascinated with a manufacturer based In china called Jiangsu Heng Qin Ltd. (WCH)

WCH offers a range of hardware including the CH340 USB to UART converter IC the CH438 which is a parallel interface to 8 UART ports and an extensive range of 8 and 32 bit MCU's.



The one I want to look at currently is the CH552 MCU this chip is an 8 bit MCU based on the 8051 instruction set with an E8051 core but the most interesting point is that it has an extensive peripheral set including a USB controller.



These are the onboard peripherals
  • Built-in 16KB Code Flash, 1KB XRAM, 256B iRAM, 128B DataFlash, support byte read and write;
  • Built-in BootLoader, support USB and UART ISP, provide ISP download library;
  • Built-in USB controller and USB transceiver, support USB-Device mode, support USB type-C master and slave detection, support USB 2.0 full speed 12Mbps or low speed 1.5Mbps. Support up to 64 bytes of data packets, built-in FIFO, support DMA;
  • 3 timer / counter, support 2-channel capture and 2 PWM;
  • Provide two full-duplex UART, all support high baud rate communication, UART0 is a standard MCS51 serial port;
  • Provides SPI communication interface, built-in FIFO, support Master / Slave mode;
  • Provides 4-channel 8-bit A / D converters;
  • Supports 6-channel capacitance detection;
  • Supports four reset signal sources, built-in power-on reset, support software and watchdog time-out reset, selectable pin external reset;
  • Built-in 24MHz clock source and PLL;
  • Built-in unique ID number;
  • Package: TSSOP-20, SOP-16, MSOP-10.
There is one downside to how the CH552 operates the 'Code Flash' as they call it is only writable about 200 times. This section of the flash is read only once your program is uploaded. To account for this there is a section of the flash memory called 'Data Flash' this is able to be written over 1 million times which makes it great for storing variables that you wish to keep after the power goes off.



There are many other little surprises as you dig into this component once you start looking into the clock selection register you find out that this little MCU is quite capable of running up to 32Mhz from the internal oscillator.
The device also has a built-in USB and UART bootloader which can be accessed by pulling P3.6 of P1.5 High when the device resets (depending on your configuration).

This chip comes in a variety of packages with different numbers of pins exposed. These include a SOIC16 package the CH552G, a  tiny MSOP10 package the CH552E, and a TSSOP20 package which has all the available IO and functions exposed the CH552T.

  

Software


There is a header file and examples available from WCH which help to get started including examples of how the USB device works. I would like to in time make this far more user friendly and much more generic.
There are a couple of software stacks fro the device:
https://github.com/HonghongLu/CH554 (for C51 in keil)
https://github.com/Blinkinlabs/ch554_sdcc (for SDCC )

As well as the Official ISP tool there is also an open source programming tool:
https://github.com/rgwan/librech551

The Store

I personally have a lot of love for this little USB hero and want to give it the exposure and credit it deserves. So to that fact, I have decided to stock it on my Tindie Store Rabid's Electronics Emporium.

I also have a Development board range on the horizon called CHUSBIE the I hope that you all grow to like this chip range as much as I do and I will do my best to make it available in many forms and a reasonable cost.
The overlaid packages look a little odd this is so the same PCB can be used for either the CH552T or G. I will keep you up to date on how that goes.

Monday, 20 April 2020

Restarting the YouTube channel

It's been a while and I have decided that it was time to restart the YouTube channel.

I decided a few months ago it was time to start again to try and make some content more in reflection of how my life is now, this is because a lot of the content was well over 5 years old and in some cases much older.

I want to try and make this channel great and informative from the beginning and with help from my beautiful supportive wife 💗 I believe this is possible.

Onto the first video (don't get too excited it is just a channel update) 😊 but I have spent some time on the title sequence and eventually should have an ending sequence.The music by the way is free for non commercial use from fesliyanstudios so a big special thanks to them for providing that free for use as I believe it really works for my content.




I have several open projects that I started this year and I'm hoping to keep you in the loop and up to date on.

SimpleJTAG (low cost JTAG programmer)
Basic-MC6800 (Retro computer board)
Rabid's Electronics Emporium (My Tindie Store)
GOWIN GN1SE board
CH552 Dev board ( Yet to come up with a good name )

My filming schedule:
I am hoping that I can release two videos a month or a video every two weeks.

Let me know what you think either down below, twitter or Hackaday.io 

Ta Ta For Now




Tuesday, 10 March 2020

Designing and building a computer that's 40 year out of date (part1)

achI have seems to have taken on several personal projects this year. I have been wanting to learn about FPGA's and have been fascinated by the prospect of running a whole processing core inside a programmable silicon matrix. But to get to that point I seem to be taking a long convoluted route around it. Let me try to explain.

I want to design a board based around the Gowin littlebee FPGA I think it is going to be the GW1NSE-C2 which has an embedded ARM Cortex M4 processing core. So deep into the datasheet jungle, I go and start designing a board. After much reading, I realize that is going to need a JTAG programmer of some type. so after much research, I find a project for as low-cost JTAG programmer based on an MCU from WCH who also makes a low-cost USB->UART chip which I have looked at in the past. So this sparks off another PCB project, SimpleJTAG.

Somewhere in the middle of this, I run into the low-cost RISC-V MCU's from Gigadevice and with a fascination in RISC-V and a new JTAG programmer on the horizon I start investigating how to source these. Is everyone still with me :)?

Back to the FPGA project, I started with so now I have a JTAG programmer on the horizon and maybe another MCU board not even going to mention the Tindie shop (yes another thing I'm working on). I dive into Gowin's EDA tool for configuring their chips. After much poking around in the dark I find out how to activate the ARM core and become totally lost as I am made aware of my huge gaps in my knowledge when it comes to SOC architecture. Though there is an ARM core on this chip all the flash, ram and peripherals need to be configured inside the FPGA fabric and with the choice of either Verilog or VHDL to program this in I discovered in need a better understanding of computing architecture.

This is where I run into a video series from 'The 8-Bit Guy' on the history of commodore computers with some really nice detail on the system architecture. So to solve the gaps in my knowledge its time to design and build an 8-bit computer from the 80's.

Why make something so outdated?

The early home computers have a very straightforward system architecture ROM, RAM, and peripherals. I can understand the system as a whole and can break it down into constituent parts. Modern hardware has so much integrated that there is no chance of having a complete understanding. Also, there is a big nostalgia factor I can remember going to my neighbors and loading games into is ZX spectrum and using my brothers ZX+3 while he was out and writing early programs in basic.   

Of course, the first task ahead it to try and pick a processor for this design (MPU) I need something simple which old acts a processing unit if it contained its own ROM or RAM then I would defeat the process of the learning system architecture. I looked at both the Zilog Z80 and the MOS6502 as possible options, then I ran into ubiquitous almost forgotten Motorola MC6800 which proceeded the other two by a couple of years.

The first look at the datasheet of the MC6800 I was slightly put off with the clocking requirements. It required two clock signals.
The signals are not quite inverse to each other and would require additional hardware to generate. There is a single chip clock generator also made by Motorola the MC6875 but after a quick search it seems to be quite rare and at over $10 e a bit rich for me.

But then I found a later version of the same processor the MC6809 which had some extra features and had the clock generator internal to the IC and only requires an external xtal to run it.

This was the MPU I was going to use. I found a similar project which gave me some initial guidance. https://sites.google.com/site/gogleoops/mc6809-min-board Which is giving me a lot of direction when it comes to working out address select logic and how bus timing and R/W.

So the first board its basic structure looks like this.

I found an online assembler and debugger which seems pretty good

https://www.asm80.com/
The compiler has options to step through the program and see how it operates its really shown me the specifics when it comes to what the Reset Vector is (I thought it had the first instruction but in fact, it is a memory address which is written to the program counter where the first instruction is located). Also how the stack pointer works with subroutines and how easy it is to cause a stack overflow :).

I have routed the first revision of this board I think it looks pretty good.
I decided to go for a mix of surface mount and through-hole parts as this project is just for me o don't see myself making huge numbers of them. 


Updates on this project can be found on Hackaday.io
https://hackaday.io/project/170307-basic-mc6800-interface-board