The name 3 files 10 cents RISC-V takes some explanation. Embeetle IDE provides this sample demo program for development boards with the CH32V003F4P6 processor - the 10cent computer.
RISC-V means reduced instruction set computer version 5. ATmega chips in Arduino boards are an earlier reduced instruction set device. Details on the code and the circuit used are in the Embeetle IDE blog posting 3 Files 10 Cents RISC-V.
ObjectiveC programming language can be complicated. New generations of processors add complexity and new features. We are going to run our code on the WCH EVT board
This project uses a minimal 3 source files of code for blinky. It is more human readable by having less code to read. We will scroll through and see how this code is laid out.
Programming ConnectionsLike our earlier project. We need to connect 3.3volt power, ground and SDI programming pin to a WCH-LinkE programmer dongle. A jumper wire needs to connect pin PD0 to LED1 to blink our built in light.
Later, we will add Tx and Rx jumpers for the serial port USART connection to the LinkE programmer. Your board may look quite different but still have the same pins.
Install Embeetle IDEEmbeetle is an Interactive Development Environment IDE providing the tools to work with C/C++ code, compilers and flash programmers. The website provides manuals, tutorials and support for the studio.
Install and run Embeetle following Program RISC-V with Embeetle IDE or Program Arduino with Embeetle. If you do not have a board you can still compile the code in this project.
Create New ProjectCreate a New Project from the Embeetle Home panel. We are going to download a software example from the Embeetle website along with the programming tools needed for our board.
Bare metal is programming at the zero and one machine code level. There is no operating system in our development board. Embeetle will generate an executable binary elf file that will be uploaded through our programmer circuit.
Select sample project ch32v003f4p6-evt-r0-1v1-baremetal for the WCH board.
Watch where your code downloads are going. You can look at source code, makefiles and pdf documents. Files and are organized around established industry procedures. Our final product are the executables in the build folder.
Files will be downloaded onto your computer. The first time you run a program for a processor type you may be prompted to install build tools taking over a GigaByte of space.
PanelTake a moment to explore the opening panel. Move the dividers, hover over and click on things. Tutorials at the website provide explanations.
In Filetree click Source then main.c., registers.h and startup.S. Our project uses three source module files: main.c, registers.h and startup.S.
Back to the main.c file tab. Arduino code is the same language as this but different. You may be used to Arduino sketches that do all the code in one source sketch.
C/C++ is built around modularity. #include <stdio.h> is an instruction to the compiler to include code from a standard IO library in a known location. #include "registers.h" means include code locally from the file registers.h in our project folder.
Scrolling down we see functions that will be called to initialize our GPIO general purpose input output circuit. Comments give explanations.
Scroll to the bottom and look at the main function. int main(void) is a mathematical calculation performed by the processor, it points the program counter to the current instruction.
Our code initializes pin PD0 to be a GPIO general purpose input and output circuit. Pin PC0 is set up as an interrupt for the serial port along with the Tx/Rx pins for the USART universal serial asynchronous receiver transmitter serial transmitter.
registers.hA definitions file mapping out the CH32V003F4P6 processor pin by pin, function by function. Change boards and we need a different registers.h file mapping out a different chip.
This may be new to you. It is in assembly language for the Risc-V ISA instruction set architecture. Specifically, it is RV32EC which is Risc-V 32 bit language for Embedded processors, compressed instruction set.
Scroll down to line 130 to see la load address, addi add immediate commands. We will not be editing this file.
Click CleanA simple script erases old build files to start fresh. Optional step, not necessary.
The compiler takes each of the C code source modules and builds temporary object modules. On a final pass it assembles all of the code into a binary or hexadecimal program for upload. Scroll through the messages and see how much you understand.
In Filetree open the build folder. We have built three output files that could be uploaded to our board, a bin file, an elf file and a hex file.
Scroll through the build message and look for the instruction set used to compile our output. Specifically, it is RV32EC which is Risc-V32 bit language for Embedded processors, Compressed instruction set.
Click FlashNow, Embeetle takes the elf version of the binary machine code executable program and uploads it to the flash memory of the board.
All going well, board connected with led pin jumpered to GPIO. We expect the lamp on the board to blink.
Scroll through the output text from the Flash operation. Our flash upload was performed by a software called OpenOCD. The elf version of our program works with OpenOCD to provide on-chip-debugging features to see inside a running chip.
Certain ARM and RISC chips can do this. Look at the Dashboard features showing Probe Device and Transport Protocol. These show settings, not presence of device.
USART Serial CircuitArduino boards contain a serial port built-in. These WCH devboards need us to add three jumper wires to connect the serial port on our programmer to PD5, PD6 and Reset pins of our board.
Click the Serial icon in Embeetle and a panel should open. Select Baudrate of 115200 bps, com port for the dongle and Connect. We could use hyperterminal or other serial emulator.
The comm port of the computer connects to the USART in the LinkE dongle and is enabled when the driver loads. Use Windows device manager to check the driver and assigned comm port.
The reset connection lead may be optional. Try it both ways and leave a comment.
Comments
Please log in or sign up to comment.