How to deploy FreeRTOS on PARASHU & VAJRA with a sample application?

  • Post author:
  • Reading time:11 mins read
  • Post category:RTOS
You are currently viewing How to deploy FreeRTOS on PARASHU & VAJRA with a sample application?

FreeRTOS is an open source, real-time operating system for microcontrollers that makes small, low-power edge devices easy to program, deploy, secure, connect, and manage. This article is a step by step guide to install and cross-compile FreeRTOS with VAJRA and PARASHU. FreeRTOS supports all three SHAKTI SOCs PINAKA(e-class on Arty7 35t) PARASHU(e-class on Arty100t) VAJRA(c-class on Arty7 100t).

Here, we are going to see FreeRTOS running on VAJRA(c-class on Arty7 100t). For Pinaka, Check out this article.

Step 1: Prerequisites

  • shakti-tools installed and PATH exported.
  • Arty7 100T board with either parashu or vajra programmed on it.
  • BMP280 Sensor.
  • Micro USB Cable.
  • Jumper Wires.
  • Bread board

Note: shakti-sdk and shakti-tools are currently a private repository. Please login or sign up to Gitlab and request access here before using it.

Step 2:  Getting FreeRTOS repository

Then clone the FreeRTOS repository to your system.

git clone https://gitlab.com/shaktiproject/software/FreeRTOS.git

Step 3: Running a demo application on FreeRTOS

In this demo, Firstly we are going to deploy FreeRTOS on Arty7 board. Then add a application on that and then execute it. We are going to use BMP280 sensor to read the temperature and pressure from the surrounding environment. Then store that value in internal SPI flash. After that, based on the temperature, further we decide to control Fan and Air conditioner.

3.1 Circuit connection:

  • GPIO0 – Control to AC
  • GPIO7 – Control to Full Fan rotation.
  • GPIO8 – Control to Half Speed Fan rotation.

Connections of the BMP280 sensor:

  • VCC to 3.3V
  • GND to GND
  • SCL to SCL of board
  • SDA to SDA of board
  • CSB to 3.3V
  • SDO to GND

NOTE : The Circuit diagram for parashu is the same as vajra

3.2 Code

Please click here to have a look at the code.

Step 4: Deploying on SHAKTI

4.1.1 Compile and Build

Go to the VAJRA repo and the execute make

$ cd FreeRTOS/FreeRTOS/Demo/shakti/vajra
$ make

For parashu, Goto cd FreeRTOS/FreeRTOS/Demo/shakti/parashu

The output executable is created in <path-to-FreeRTOS>/FreeRTOS/Demo/shakti/vajra or <path-to-FreeRTOS>/FreeRTOS/Demo/shakti/parashu.

freeRtos-c64-100t.elf (vajra) or freeRtos-e32-100t.elf (parashu) is the output executable created.

4.1.2 Execution:

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 .elf. Now, open three terminals, one for each of the following,

  • One terminal for UART terminal display (miniterm)
  • And the last one for OpenOCD.
  • Another for GDB server.

Terminal 1: Firstly, Connect to serial output by using miniterm or gtkterm with the baud rate of 19200.

For instance,

$ sudo miniterm.py /dev/ttyUSB1 19200

Note:

  • “/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 VAJRA,

$ cd FreeRTOS/FreeRTOS/Demo/shakti/bsp/third_party/vajra 
$ sudo $(which openocd) -f ftdi.cfg

For parashu, Goto cd FreeRTOS/FreeRTOS/Demo/shakti/bsp/third_party/parashu


Terminal 3: Now, open either 32-bit or 64-bit RISC-V GDB based on your architecture i.e riscv32-unknown-elf-gdb or riscv64-unknown-elf-gdb respectively from shakti-tools. Load up the .elf file by following the below steps,

.elf file is created in <FreeRTOS/FreeRTOS/Demo/shakti/vajra> or <FreeRTOS/FreeRTOS/Demo/shakti/parashu> as freeRtos-c64-100t.elf (vajra) or freeRtos-e32-100t.elf (parashu)

For vajra,

$ riscv64-unknown-elf-gdb
(gdb) set remotetimeout unlimited
(gdb) target remote localhost:3333
(gdb) file path/to/executable
(gdb) load
(gdb) c

Miniterm Output

Thus we can read the temperature and the pressure values through the sensor with FreeRTOS on VAJRA.

--- Miniterm on /dev/ttyUSB1: 19200,8,N,1 ---
--- Quit: Ctrl+]  |  Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---                  ((                                          
                                    ,(((((
                                *((((((
                           ./(((((((
                       ./((((((((
                    *(((((((((
                .(((((((((((
             ,((((((((((((
           ((((((((((((((
          .((((((((((((((
              *(((((((((((
                   /(((((((
                  *((((((((
                     *(((((((
                       (((((((((
                        ((((((((((
                         (((((((((((((
                         ((((((((((((((
                        ((((((((((((
                      *(((((((((( 
                    (((((((((               
              *(((((((
           *((((((
       .(((((
   ./(((  
SHAKTI PROCESSORS
Booting... vspi1.0

Booting on Vajra! hart 0
Vajra is a SoC build on top of Artix7 100T.
The core belongs to Shakti C class, 64 bit.

Supported ISA: RV64IMACSU.
Processor Arch ID: f.
Device ID 1
extracted device id 2018
No content to boot
FREERTOS starting
Task scheduler started

Control: 80808080; Status: 81818181 I2C Initialization success
Initialization BMP280_STATUS_REGISTER Happened Fine

Temperature Value:31.88 °C
The Pressure Value:100.456 Kpa

Temperature Value:31.50 °C
The Pressure Value:100.454 Kpa

Temperature Value:31.52 °C

 4.1.3 Upload to flash

Steps to generate standalone user application:

The FreeRTOS has an uploader tool that is used to load content (such as ELF) to flash, after building the image.

  • Goto the right directory.
cd FreeRTOS/FreeRTOS/Demo/shakti/vajra
  • The make upload command is used to build and upload the application to the flash automatically.
make upload

Miniterm Output (Upload)

Erasing…
Erase complete.
Writing.......
Write complete.
Please reset.
  • Now press Reset Button on board
--- Miniterm on /dev/ttyUSB1: 19200,8,N,1 ---
--- Quit: Ctrl+]  |  Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---                  ((                                          
                                    ,(((((
                                *((((((
                           ./(((((((
                       ./((((((((
                    *(((((((((
                .(((((((((((
             ,((((((((((((
           ((((((((((((((
          .((((((((((((((
              *(((((((((((
                   /(((((((
                  *((((((((
                     *(((((((
                       (((((((((
                        ((((((((((
                         (((((((((((((
                         ((((((((((((((
                        ((((((((((((
                      *((((((((((
                    (((((((((               
              *(((((((
           *((((((
       .(((((
   ./(((  
SHAKTI PROCESSORS
Booting... vspi1.0
Booting on Vajra! hart 0
Vajra is a SoC build on top of Artix7 100T.
The core belongs to Shakti C class, 64 bit.

Supported ISA: RV64IMACSU.
Processor Arch ID: f.
Device ID 1
extracted device id 2018
................
Control transferred to RAM
FREERTOS starting
Task scheduler started
Control: 80808080; Status: 81818181 I2C Initialization success
Initialization BMP280_STATUS_REGISTER Happened Fine

Temperature Value:31.88 °C
The Pressure Value:100.456 Kpa

Temperature Value:31.50 °C
The Pressure Value:100.454 Kpa