Lab13_RISCV_ICT
Lab13_RISCV_ICT
Lab13_RISCV_ICT
Goal
In this lab, students will become familiar with the ESP32-C3 kit, which is based on the
RISC-V architecture. Students will use RISC-V assembly language to program simple
applications that control the input/output ports of the kit and run simulations using the
Wokwi emulator tool.
Materials
• ESP32-C3 Technical Reference Manual
Preparation
1
Hanoi University of Science and Technology
School of Information and Communications Technology
3. Add a new assembly source file (.S extension). Click the arrow next to the
Library Manager, select New file..., and name the file the same as the source
file (.ino extention) but with the .S extension. For example, if the source file is
sketch.ino, the assembly file should be sketch.S.
4. Edit the assembly source file. Use the following skeleton for the program:
# Define the init function for Wokwi to execute the assembly program
.global init
5. Add the necessary electronic components, connect their pins to the ESP32-C3 kit
pins as per the schematic.
6. Click Start to compile and run the simulation.
Source code:
.global init
init:
li a1, GPIO_ENABLE_REG # Configure GPIO0 as an output pin
li a2, 0x01 # Load mask 0x01 into the GPIO_ENABLE_REG
sw a2, 0(a1)
Source code:
.global init
4
Hanoi University of Science and Technology
School of Information and Communications Technology
init:
li a1, GPIO_ENABLE_REG # Configure GPIO0 as an output pin
li a2, 0x01
sw a2, 0(a1)
main_loop:
li a1, GPIO_OUT_W1TS_REG # Set GPIO0 to high
li a2, 0x01
sw a2, 0(a1)
call delay_asm # Delay
j main_loop # Loop
Circuit Details:
- Pins a, b, c, d, e, f, g of the 7-segment
display are connected to GPIO0,
GPIO1, GPIO2, GPIO3, GPIO4,
GPIO5, GPIO6, respectively. These
GPIO pins must be configured as
output.
Notes:
- GPIO4, GPIO5, GPIO6, and GPIO7
have default functionality for SPI
communication.
- To use them as GPIO output, you need to reconfigure their function using the
IO_MUX_GPIOn_REG registers (n from 4 to 7).
- The IO_MUX_GPIOn_MCU_SEL field (bit 12 – 14) is used to configure the
function for GPIOn pins. If this field is 1, they are input/output pins.
5
Hanoi University of Science and Technology
School of Information and Communications Technology
For Wokwi simulations, configuring GPIO functions is optional. However, for actual
development boards, function configuration is required.
Source code:
.global init
.text
init:
li a1, GPIO_ENABLE_REG
li a2, 0xFF # Output signals on GPIO0 to GPIO7 (set 8 bits)
sw a2, 0(a1) # Configure the bits in GPIO_ENABLE_REG
li a2, 0x1000
li a1, IO_MUX_GPIO4_REG
sw a2, 0(a1)
li a1, IO_MUX_GPIO5_REG
sw a2, 0(a1)
6
Hanoi University of Science and Technology
School of Information and Communications Technology
li a1, IO_MUX_GPIO6_REG
sw a2, 0(a1)
li a1, IO_MUX_GPIO7_REG
sw a2, 0(a1)
# a1 contains the address of the register determining the output logic level of
GPIO pins
li a1, GPIO_OUT_REG
li a2, 0xC0
sw a2, 0(a1) # Output signal to GPIO pins
Circuit Details:
- A button is connected to GPIO0, and an
LED is connected to GPIO1.
- The GPIO_IN_REG register is used to read
the signal input from GPIO pins.
- By default, GPIO pins are configured as
input to receive signals. However, for
GPIOx to receive signals, you must enable input by setting the
IO_MUX_GPIOx_FUN_IE bit in the IO_MUX_GPIOx_REG register
corresponding to GPIOx.
Source code:
.global init
init:
li a1, GPIO_ENABLE_REG # Configure GPIO1 as an output pin
li a2, 0x02
sw a2, 0(a1)
loop:
li a1, GPIO_IN_REG # Read the state of GPIO pins
lw a2, 0(a1)
7
Hanoi University of Science and Technology
School of Information and Communications Technology
Assignment 1
Create a project to implement and test Home Assignment 1. Update the source code to
test with other GPIO pins (GPIO2, GPIO3, GPIO4).
Assignment 2
Create a project to implement and test Home Assignment 2. Update the source code to
test with other GPIO pins (GPIO2, GPIO3, GPIO4) and change the LED blinking time.
Assignment 3
Create a project to implement and test Home Assignment 3. Update the source code to
display different digits (from 0 to 9).
Assignment 4
Create a project to implement and test Home Assignment 4. Update the source code to
use other GPIO pins as signal-receiving pins (GPIO2, GPIO3, GPIO4).
Assignment 5
Create a project to implement a 0 to 9 counter circuit on a 7-segment display.