1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# CH573F
## Background
THe CH573F is a relatively new, fairly powerful, little microcontroller. They're
about USD 1.00 a piece on AliExpress, which makes them incredibly cheap for
their abilities, which makes them an ideal replacement for my Arduinos to run my
Christmas lights!
The documentation for the controller is fairly easy to read, though examples are
few and far between and the SDK is mostly in Chinese, but that's what this
project is for. True to form, this project has no dependencies on any 3rd party
SDK or OS. It's completely bare metal from the ground up.
## Specs
The CH573 has some pretty impressive specs for its price point. For the purposes
of this project, it has:
* Royalty-free RISC-V core:
* 32-bit Qingke RISC-V processor WCH RISC-V3A
* RV32IMAC instruction set w/ hardware multiplication and division.
* System frequency from 32KHz up to 60MHz (Though I can only get 6.4MHz, 30MHz
and 60MHz to work).
* 512K FlashROM
* 32KB application data
* UART
* 4 independent UART, with 8-level FIFO
* SPI support with DMA
## Related Work
This project is very similar to:
* https://git.josher.dev/cgit/stm32l4.git/
* https://git.josher.dev/cgit/esp32-ws2812b.git/
Together they make up my microcontroller trio for my Christmas lights every
year.
## Setup
To compile this project, one needs a few things.
1. A RISC-V crosscompiler with Picolibc
1. An installed version of "Fiddle", which is my custom
register-description-language, found at https://git.josher.dev/cgit/fiddle.git
1. ch-flash, or another WCH ISP.
1. Cmake
### RISC-V Cross-compiler with Piclibc
The easiest way to get one of these is to use
[crosstool-ng](https://crosstool-ng.github.io/) with the default
`riscv32-picolibc-elf`
```bash
$ ct-ng riscv32-picolibc-elf
$ ct-ng build
$ ct-ng install
```
### Fiddle
Fiddle is a program used to take language-agnostic register descriptions and
compile them into usable source code. The register descriptions for this project
are provided as fiddle (fdl) files.
The Fiddle compiler is implemented in Haskell using the Haskell stack build
system. Install stack with:
```bash
$ apt install stack
```
get fiddle:
```bash
$ git clone https://git.josher.dev/cgit/fiddle.git
$ cd fiddle
$ stack install
```
This will compile and install `fiddlec`, which is required to build this
project.
### WCH ISP
There are many open source projects which can flash to the CH573F. I have one in
my git grove, but they're easy to find if another one works better.
```bash
$ git clone https://git.josher.dev/cgit/ch-flash.git
$ cd ch-flash
$ make
```
### CMake
Install cmake through your package manager.
```bash
$ apt install cmake
```
## Compiling and Flashing
```bash
$ git clone https://git.josher.dev/ch573.git
$ cd ch573
$ cmake -B build
$ make -C build
$ /path/to/ch-flash -f build/main.bin
```
To flash, disconnect the ch573 from USB, hold down the BOOT button, then
re-connect it, ch-flash should automatically detect it and flash it. After that,
it all should work.
|