Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/h1romas4/m5stamp-c3dev
This is a development board for the M5Stamp C3 (RISC-V/FreeRTOS).
https://github.com/h1romas4/m5stamp-c3dev
arduino arduino-esp32 assemblyscript esp32 esp32c3 jtag m5stack m5stamp risc-v riscv wasm3 webassembly
Last synced: 2 months ago
JSON representation
This is a development board for the M5Stamp C3 (RISC-V/FreeRTOS).
- Host: GitHub
- URL: https://github.com/h1romas4/m5stamp-c3dev
- Owner: h1romas4
- License: mit
- Created: 2021-12-31T06:17:55.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-21T07:31:12.000Z (5 months ago)
- Last Synced: 2024-10-10T14:02:18.571Z (2 months ago)
- Topics: arduino, arduino-esp32, assemblyscript, esp32, esp32c3, jtag, m5stack, m5stamp, risc-v, riscv, wasm3, webassembly
- Language: C++
- Homepage: https://another.maple4ever.net/archives/2979/
- Size: 4.93 MB
- Stars: 21
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# m5stamp-c3dev
![](https://github.com/h1romas4/m5stamp-c3dev/workflows/Build/badge.svg)
![Main Board](https://raw.githubusercontent.com/h1romas4/m5stamp-c3dev/main/docs/images/m5stamp_c3dev_01.jpg)
This is a development board for the [M5Stamp C3](https://shop.m5stack.com/products/m5stamp-c3-mate-with-pin-headers) (RISC-V/FreeRTOS).
**Hardware**
- External USB-C port for JTAG debugging
- Support for LCD panel and SD card
- Selecting a power supply
- Switch(GPIO9) to enter loader mode
- Pin headers to expose usable GPIOs to the outside
- The size is just Japanese business card**Sample Sources Included**
![AssemblyScript and Wasm3](https://raw.githubusercontent.com/h1romas4/m5stamp-c3dev/main/docs/images/m5stamp_c3dev_04.jpg)
![AssemblyScript and Wasm3](https://raw.githubusercontent.com/h1romas4/m5stamp-c3dev/main/docs/images/m5stamp_c3dev_05.jpg)
- TrueType font with Japanese output to LCD - [test_freetype.cpp](https://github.com/h1romas4/m5stamp-c3dev/blob/main/main/test_freetype.cpp)
- Output PNG images in SD card to LCD - [test_tinypng.cpp](https://github.com/h1romas4/m5stamp-c3dev/blob/main/main/test_tinypng.cpp)
- NTP synchronization via WiFi connection - [test_nvs_wifi.cpp](https://github.com/h1romas4/m5stamp-c3dev/blob/main/main/test_nvs_wifi.cpp)
- Test ADC on GPIO0
- UNIT Light - [main.cpp](https://github.com/h1romas4/m5stamp-c3dev/blob/main/main/main.cpp#L108-L111)
- Test I2C on GPIO18, 19
- UNIT ENV III - [test_i2c_gpio1819.cpp](https://github.com/h1romas4/m5stamp-c3dev/blob/main/main/test_i2c_gpio1819.cpp#L43-L50)
- UNIT ULTRASONIC - [test_i2c_gpio1819.cpp](https://github.com/h1romas4/m5stamp-c3dev/blob/main/main/test_i2c_gpio1819.cpp#L52-L61)
- Test UART on GPIO18, 19
- UNIT GPS - [test_uart_gpio1819.cpp](https://github.com/h1romas4/m5stamp-c3dev/blob/main/main/test_uart_gpio1819.cpp)
- WebAssembly execution with Wasm3
- Analog clock using AssemblyScript - [test_wasm3_clockenv.cpp](https://github.com/h1romas4/m5stamp-c3dev/blob/main/main/test_wasm3_clockenv.cpp)
- GPS GSV viewer using AssemblyScript - [test_wasm3_gpsgsv.cpp](https://github.com/h1romas4/m5stamp-c3dev/blob/main/main/test_wasm3_gpsgsv.cpp)
- 3D Cube Demo using AssemblyScript - [test_wasm3_imu6886.cpp](https://github.com/h1romas4/m5stamp-c3dev/blob/main/main/test_wasm3_imu6886.cpp)
- Usage of SPIFFS, which stores TrueType fonts and .wasm binaries (parttool.py and spiffsgen.py tools)
- Use of NVS (cryptographically enabled key value store) that stores WiFi passwords (nvs_partition_gen.py tool)
- Building libraries and managing dependencies using the esp-idf build system
- Visual Studio Code C/C++ Extension configuration and JTAG debugging configuration in conjunction with openocd
- AssembyScript sharing method between web browser and microcontroller - [wasm](https://github.com/h1romas4/m5stamp-c3dev/tree/main/wasm)This repository contains MIT Licensed PCB data and example programs.
## Demo
### Video
- ๐ผ [Demo(LCD)](https://youtu.be/46I3Uo5Xivg)
- ๐ผ [Demo(Wasm3)](https://youtu.be/TagQuPtwKCg)
- ๐ผ [Demo(3D Cube)](https://twitter.com/h1romas4/status/1610228824607985664)### Web Simulation
- ๐ธ [AssemblyScript Analog Clock](https://h1romas4.github.io/m5stamp-c3dev/asclock/)
- ๐ธ [AssemblyScript GPS GSV Viewer](https://h1romas4.github.io/m5stamp-c3dev/asgps/)## Schematic
![Circuit Diagram](https://raw.githubusercontent.com/h1romas4/m5stamp-c3dev/main/docs/images/circuit_diagram_01.png)
|#Unit|Name|Note|Where to get it|
|----|----|----|----|
|U1|AE-USB2.0-TYPE-C|USB 2.0 Type-C Break out board|[akizukidenshi.com (JP)](https://akizukidenshi.com/catalog/g/gK-13080/)|
|U2|M5STAMP-C3|M5Stamp C3|+ [M5Stack](https://shop.m5stack.com/products/m5stamp-c3-mate-with-pin-headers?variant=40724631257260)
+ [SWITCH SCIENCE (JP)](https://www.switch-science.com/catalog/7474/)|
|U3|KMR-1.8SPI|KMR-1.8 SPI marked LCD and SD card interface|+ [amazon.co.jp (1)](https://www.amazon.co.jp/gp/product/B07RG8SJVB/)
+ [ja.aliexpress.com](https://ja.aliexpress.com/item/4000511275898.html)|
|R1 - R2|5.2K Resistor|Pull-down for USB Power supply|-|
|R3 - R7|10K Resistor|SPI pull-up|-|
|JP1|Jumper pin|Select external power supply|[akizukidenshi.com (JP)](https://akizukidenshi.com/catalog/g/gP-03687/)|
|SW1|Tact switch|for loader mode and utility|[akizukidenshi.com (JP)](https://akizukidenshi.com/catalog/g/gP-03647/)|
|J1|12 Pin header|You can use the one that comes with the M5Stamp C3 Mate|-|## PCB and Gerber data
- [KiCad 6 PCB](https://github.com/h1romas4/m5stamp-c3dev/tree/main/pcb/fg06-c3dev-revb)
- [Gerber Data](https://github.com/h1romas4/m5stamp-c3dev/raw/main/pcb/fg06-c3dev-revb/fg06-c3dev-revb-gerber.zip)
- [FG06-C3DEV REV.B (2ๆ) - M5Stamp C3 ๅใใฎ้็บ็จๅบๆฟ - ้จๅใชใๅบๆฟใฎใฟ - 130ๅ](https://h1romas4.booth.pm/items/3688492)## Example Source
### Require
- [Setup ESF-IDF **release/v5.1**](https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32c3/get-started/linux-macos-setup.html)
get_idf or (Windows) ESP-IDF command prompt
```
# Linux or macOS ->
$ alias get_idf='. $HOME/esp/esp-idf/export.sh'
$ get_idf
# <-Detecting the Python interpreter
... snip ...
Done! You can now compile ESP-IDF projects.
Go to the project directory and run:idf.py build
$ echo ${IDF_PATH}
/home/hiromasa/devel/toolchain/esp/esp-idf$ riscv32-esp-elf-gcc -v
Using built-in specs.
COLLECT_GCC=riscv32-esp-elf-gcc
... snip ...
gcc version 12.2.0 (crosstool-NG esp-12.2.0_20230208)
```openocd (Optional)
```
$ openocd -v
Open On-Chip Debugger v0.12.0-esp32-20240318 (2024-03-18-18:25)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
```### Build and Execute
1. git clone and build (Please add `--recursive`)
```
git clone --recursive https://github.com/h1romas4/m5stamp-c3dev
cd m5stamp-c3dev
idf.py build
```**Note**: If you get a compile error, change the `sdkconfig` back to the Git one. In some cases, the target of `sdkconfig` is changed to `esp32` instead of `eps32c3`.
2. Write Partition table
```
idf.py partition-table-flash
```3. Write TypeType font to SPIFFS
```
parttool.py write_partition --partition-name=font --partition-subtype=spiffs --input resources/spiffs_font.bin
```4. Write WebAssembly(.wasm) to SPIFFS
```
parttool.py write_partition --partition-name=wasm --partition-subtype=spiffs --input resources/spiffs_wasm.bin
```5. Write main program to go!
```
idf.py flash monitor
```### Setup WiFi (Optional)
1. Change WiFi Setting
`nvs_partition.csv`: Set own `[ssid]`, `[password]`
```
key,type,encoding,value
wifi,namespace,,
ssid,data,string,[ssid]
passwd,data,string,[password]
```2. Create NVS Partition file
```
python ${IDF_PATH}/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py generate nvs_partition.csv nvs_partition.bin 0x6000
```3. Write NVS Partition
```
esptool.py write_flash 0x9000 nvs_partition.bin
```4. Run
NTP synchronization is performed by pressing the SW1 after the startup logo.
```
idf.py monitor
```### Select connected GPIO18 and GPIO19 device (Optional)
```
idf.py menuconfig
```C3DEV Configuration โ Select GPIO 18/19
![](https://raw.githubusercontent.com/h1romas4/m5stamp-c3dev/main/docs/images/m5stamp_c3dev_05.png)
`3D Cube Demo`
![3D Cube](https://raw.githubusercontent.com/h1romas4/m5stamp-c3dev/main/docs/images/m5stamp_c3dev_06.jpg)
### JTAG debug with Visual Studio Code
Require setup ESP32_TOOLCHAIN_HOME
```
$ echo ${ESP32_TOOLCHAIN_HOME}
/home/hiromasa/.espressif/tools/riscv32-esp-elf
```1. Connect the PC to the USB Type-C of the U1
2. Open the source file in Visual Studio Code.
3. Run Task "openocd (debug)" @see [.vscode/tasks.json](https://github.com/h1romas4/m5stamp-c3dev/blob/main/.vscode/tasks.json#L7-L13)
4. Set a breakpoint in the source code.
5. Debug Launch (GDB) @see [.vscode/launch.json](https://github.com/h1romas4/m5stamp-c3dev/blob/main/.vscode/launch.json#L8-L23)
The first time you start the program, it will often fail, so if you get an error, retry.![vscode](https://raw.githubusercontent.com/h1romas4/m5stamp-c3dev/main/docs/images/m5stamp_c3dev_02.png)
### Note
#### If the LCD color is inverted.
`main/main.cpp`
```c
// If the color is inverted, set to 1.
tft.invertDisplay(0);
// tft.invertDisplay(1);
```#### Create SPIFFS partition file from file system
```
python ${IDF_PATH}/components/spiffs/spiffsgen.py 0x100000 resources/font resources/spiffs_font.bin
python ${IDF_PATH}/components/spiffs/spiffsgen.py 0x10000 resources/wasm resources/spiffs_wasm.bin
```#### Change the output destination of the log to U1 Serial/JTAG.(Don't forget to put it back)
Component config โ ESP System Settings โ Channel for console output
```
idf.py menuconfig
```![vscode](https://raw.githubusercontent.com/h1romas4/m5stamp-c3dev/main/docs/images/m5stamp_c3dev_03.png)
## AssemblyScript and Wasm3
## Build AssemblyScript
```
cd wasm/clockenv # or wasm/gpsgsv or wasm/imu6886
npm install
```**Web Browser Development**
```
npm run asbuild:web
npm run start
# http://localhost:1234/
```**SPIFFS Build and Flash**
```
npm run asbuild
cd ../../
python ${IDF_PATH}/components/spiffs/spiffsgen.py 0x10000 resources/wasm resources/spiffs_wasm.bin
parttool.py write_partition --partition-name=wasm --partition-subtype=spiffs --input resources/spiffs_wasm.bin
```## Dependencies
Thanks for all the open source.
|Name|Version|License|
|-|-|--|
|[esp-idf](https://docs.espressif.com/projects/esp-idf/en/release-v5.1/esp32c3/get-started/index.html)|`release/v5.1`|BSD License|
|[arduino-esp32](https://github.com/espressif/arduino-esp32/releases/tag/3.0.2)|`3.0.2`|LGPL-2.1 License|
|[M5EPD](https://github.com/m5stack/M5EPD)|`0.1.5`|MIT License|
|[UNIT_ENV](https://github.com/m5stack/UNIT_ENV)|`0.0.7`|MIT License|
|[M5Unit-Sonic](https://github.com/m5stack/M5Unit-Sonic)|`0.0.2`|MIT License|
|[Adafruit_GFX](https://github.com/adafruit/Adafruit-GFX-Library)|`1.11.9`|BSD License|
|[Adafruit_BusIO](https://github.com/adafruit/Adafruit_BusIO)|`1.16.1`|MIT License|
|[Adafruit-ST7735-Library](https://github.com/adafruit/Adafruit-ST7735-Library)|`1.10.4`|MIT License|
|[tinyPNG](https://github.com/olliiiver/tinyPNG)|`0.11`|MIT License|
|[lwgps](https://github.com/MaJerle/lwgps)|`v2.1.0`|MIT License|
|[Wasm3](https://github.com/wasm3/wasm3)|master(`045040a9`)|MIT License|
|[AssemblyScript](https://github.com/AssemblyScript/assemblyscript)|`0.27.29`|Apache-2.0 License|
|[ๆบ็ใดใทใใฏ](http://jikasei.me/font/genshin/)|-|SIL Open Font License 1.1|## License
MIT License (includes PCB data and example source)