Interrupts are Asynchronous events i.e unexpected events generated by an external source (external to the core). The Processor services the interrupts through Interrupt Service Routines (ISR). In RISC-V, Interrupts are classified into Timer, Software and External interrupts. The External interrupts are also called Global interrupts. These interrupts are handled by a module called Platform Level Interrupt Controller (PLIC). In this blog, we will see a button-led example using PLIC.
When the button is pressed, the external interrupt is generated. Then the LED glows as a result.
Learn more about Platform Level Interrupt Controller from our detailed manual.
Step 1: What You Will Need
For this you will need:-
- A Button
- A LED
- Arty7 35t/100T board with either
pinaka, parashu or vajraprogrammed on it.
- shakti-sdk and shakti-tools installed or Platform IO installed and ready
- Micro USB Cable.
- Jumper Wires.
Step 2: The Circuit
We will use the GPIO 0 ports for getting interrupt
Buttonone leg to 3.3V (VCC).
Buttonone leg to GPIO 0
- LED -ve to GND
- LED +ve to GPIO1
Here we use Arty100t for instance. Also, the connections are the same in Arty35t boards. For better clarity, Check the device pin mapping for
pinaka, parashu and vajra.
Step 3: Code
Please click here to have a look at the code. When the button is pressed, the interrupt occurs. Then the LED glows.
Code can be compiled and run using the following ways,
- Using terminal on a system with shakti-sdk and shakti-tools installed (Manual method).
- Using Platform IO IDE.
Step 4.1: Manual Method
4.1.1 Compile and build
- Move to
- Compile using
make software PROGRAM=? TARGET=?. Type
make list_applnsto list all the applications available in the SDK. Target can be either
parashu, pinaka or vajra.
For instance, Use target as
make software PROGRAM= interrupt_demo TARGET=parashu
Once the application is built, the executable is generated in the output folder. The executable is in
ELF file format and they have the extension
.shakti. Now, open three terminals, one for each of the following,
- One terminal for UART terminal display
- Another for
- And the last one for
Terminal 1: Firstly, Connect to serial output by using miniterm or gtkterm with the baud rate of 19200.
$ sudo miniterm.py /dev/ttyUSB1 19200
- “/dev/ttyUSB1” – ttyUSB means “USB serial port adapter”
- The “1” (“0” or “1” or “2”“here means the USB device number on your system. Please connect the FPGA board to that USB device number.
Terminal 2: After that, Connect to the FPGA board by using the OpenOCD provided by shakti-tools and its respective configuration file. (Read how OpenOCD and RISC-V GDB work together to establish a connection between our PC and the Microprocessor)
For instance, if we use parashu,
$ cd shakti-sdk $ cd ./bsp/third_party/parashu $ sudo $(which openocd) -f ftdi.cfg
For pinaka and vajra, Goto
Terminal 3: Now, open either 32-bit or 64-bit RISC-V GDB based on your architecture i.e
riscv64-unknown-elf-gdb respectively from shakti-tools.
The output executable is created in
Load up the
.shakti file by following the below steps,
(gdb) set remotetimeout unlimited (gdb) target remote localhost:3333 (gdb) file path/to/executable (gdb) load (gdb) c
4.1.3 Upload to flash
Steps to generate standalone user application:
The SHAKTI-SDK has a uploader tool that is used to load a content (such as ELF) to flash, after building the image.
- Goto the right directory.
- The make upload command is used to build and upload the application to the flash automatically.
make upload PROGRAM= interrupt_demo TARGET=parashu
PROGRAM is the new bare metal user application that is created. Type
make list_applns to list all the applications available in the SDK.
Step 4.2: Using Platform IO
We can use IDE’s like Platform IO to compile, build, run, upload and debug. Please read the article on Platform IO on SHAKTI to understand the steps.
Akshaya currently works at the RISE labs. Her favorite subjects are Web designing and Microprocessors. She loves learning about new things and writing about them!