8

Espressif ESP32-C3-DevKit RISC-V Review

 1 year ago
source link: https://smist08.wordpress.com/2023/06/21/espressif-esp32-c3-devkit-risc-v-review/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Introduction

I’ve been working with the Starfive Visionfive 2 SBC which is similar to the Raspberry Pi 4. Now I’m playing with an Espressif ESP32-C3 Devkit which is a RISC-V based microcontroller similar to a Raspberry Pi Pico. It seems you can do more and more in the RISC-V world. There are many RISC-V microcontrollers on the market, but I chose this one because it has an extensive SDK allowing you to program in MicroPython, C/C++ or Assembly Language. The documentation is extensive and Espressif has a lot of experience in the microcontroller world.

This board is powered by a 32-Bit RISC-V core running at 160MHz, 400kB SRAM, 384kB ROM and 22GPIOs including SPI, UART, I2C, I2S and 12-bit ADC. There is also WiFi, Bluetooth LE and 4MB Flash memory. There are boot and reset buttons along with an RGB LED. There is a micro-USB port that is typically used for programming and to provide power.

img_4370cropped.png?w=1024

Installation

To program most microcontrollers, you write and compile your programs on a host computer with a full operating system like Linux, Windows or MacOS. Then you download the program to the microcontroller to run.

I thought it would be cool to program the C3 from my Starfive Visionfive 2, afterall it runs full Debian Linux. So I followed the instructions for Linux and got quite far, however this is what happened when I went to add the CPU support:

user@starfive:~/esp/esp-idf$ ./install.sh esp32c3
Detecting the Python interpreter
Checking "python3" ...
Python 3.10.9
"python3" has been detected
Checking Python compatibility
Installing ESP-IDF tools
ERROR: Platform Linux-riscv64 appears to be unsupported

It is trying to install a RISC-V cross compiler, but I guess it doesn’t realize it can just use the regular GCC compiler for this host CPU. Hopefully, this gets fixed in the near future.

I then installed the Espressif SDK on this Windows 11 laptop. Espressif provides a Windows installer package that you run and it installs everything you need. This is by far the easiest way I’ve run into to install a GCC cross compiler on a Windows computer. No messing with the Linux subsystem for Windows, everything is done transparently by their installer. Further you can easily run the installed GCC RISC-V compiler tools for any other purposes you may have.

The online Espressif Getting Started Guide is good. The instructions are easy to follow and it didn’t take long to install the SDK, and then compile and execute the “Hello World” example program.

The DevKit version of this board has pins pre-soldered, so is ready to  be plugged into a breadboard right away. All you need to add is a micro-USB cable to connect it to the host computer.

Hello World in Assembly Language

The SDK contains a Hello World program written in C. Let’s instead create a Hello World program written entirely in Assembly Language. We take the example program located at: C:\Espressif\frameworks\esp-idf-v5.0.2\examples\get-started\hello_world. In this we change main\CMakeLists.txt to have the source file hello_world_main.c with hello_world_main.S and then provide the hello_world_main.S file containing:

#
# Risc-V Assembler program to print "Hello World!"
# to the Espressif SDK monitor program through the microUSB.
#
# a0 - address of helloworld string
#

.global app_main      # Provide program starting address to linker

# Setup the parameter to print hello world
# and then call SDK to do it.

app_main:
        la a0, helloworld # load address of helloworld
        call puts              # Call sdk to output the string
        j app_main         # loop forever

.data
helloworld:      .asciz "Hello World!"

Only three Assembly Language instructions to print “Hello World!”. Of course all the work is done by the Espressif SDK’s puts function. But this shows the structure of a minimal program, namely that it has an entry point of app_main, and like most microcontroller programs you want it running in an infinite loop.

CALL isn’t a RISC-V instruction, it is a helper for programmers. If the jump is near (can be reached with a 12-bit offset), then one instruction is output. The “call puts” actually assembles to two instructions:

   auipc ra,0x0
   jalr ra # 8 <app_main+0x8>

This is since it’s a long jump. AUIPC can take a 20-bit immediate which it shifts left 12 bit. JALR takes a 12-bit immediate. When these are added together you can access the whole 32-bit address space. The actual values are filled in by the linker when it resolves all the externals (in this case puts).

We build the program with:

Idf.py build

And then run it with the following:

idf.py -p com4 flash monitor

Resulting in:

runhelloworld.png?w=1024

Summary

Programming using the Espressif ESP32-C3 devkit feels a lot like programming the Raspberry Pi Pico. Both use the CMake build system and both have extensive SDKs. I wonder if Raspberry took a lot of the ideas for their SDK from the Espressif one. There are extensive APIs in the SDK to easily control the onboard devices. Espressif also has a cloud based platform that you can use to develop mobile apps that interact with these boards.

I like that C/C++, Python and Assembly Language are all fully supported. So far I’ve gotten a couple of test programs up and running with little fuss. The documentation is extensive and quite good quality, making any programmer’s job much easier. 

Loading...

Related

ARM’s True RISC ProcessorsOctober 2, 2021In "Microcontrollers"

Introducing Risc-VSeptember 6, 2019In "Business"

Simulating RISC-V on a Raspberry PiApril 1, 2023In "assembly language"


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK