Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Difference between revisions of "Zero/dev/libmraa"

< Zero‎ | dev
(Test)
 
(3 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
=== Libmraa on Radxa Zero ===
 
=== Libmraa on Radxa Zero ===
  
This guide describes how to use libmraa on Radxa Zero.
+
This guide describes how to use libmraa on Radxa Zero to access GPIO, SPI, and other peripherals.
 +
 
 
==== Requirement ====
 
==== Requirement ====
* Radxa Zero board
+
 
* The newest image in https://github.com/radxa/radxa-zero-images-released/releases
+
* Radxa Zero  
 +
* You need our latest [https://github.com/radxa/radxa-zero-images-released/releases official image]
  
 
==== Install essential packages ====
 
==== Install essential packages ====
  
Package libmraa is in the Radxa APT focal-stable and buster-stable repositories.
+
Prebuilt libmraa is located in our Radxa APT Focal and Buster repositories.
  
Execute the following commands to add Radxa APT
+
Update your <code>/etc/apt/sources.list.d/apt-radxa-com.list</code> accordingly to enable Radxa APT repository.
  
rock@zero:~$ export DISTRO=focal-testing      # for Focal
+
For Ubuntu Focal:
or
+
rock@zero:~$ export DISTRO=buster-testing      # for Buster
+
rock@zero:~$ echo "deb http://apt.radxa.com/$DISTRO/ ${DISTRO%-*} main" | sudo tee -a /etc/apt/sources.list.d/apt-radxa-com.list
+
  
Get the pub key
+
root@zero:~# cat /etc/apt/sources.list.d/apt-radxa-com.list
 +
deb http://apt.radxa.com/focal-stable/ focal main
 +
deb http://apt.radxa.com/focal-testing/ focal main
  
rock@zero:~$  wget -O -  apt.radxa.com/buster-testing/public.key | sudo apt-key add -
+
For Debian Buster:
  
Install essential packages:
+
root@zero:~# cat /etc/apt/sources.list.d/apt-radxa-com.list
 +
deb http://apt.radxa.com/buster-stable/ buster main
 +
deb http://apt.radxa.com/buster-testing/ buster main
  
rock@zero:~$ sudo apt-get update
+
Install libmraa:
rock@zero:~$ sudo apt-get install -y rockchip-overlay libmraa
+
  
Install compiler:
+
rock@zero:~$ sudo apt update
  rock@zero:~$ sudo apt install -y build-essential
+
rock@zero:~$ sudo apt install libmraa
 +
 
 +
Optionally, install compiler if you want to run some tests:
 +
  rock@zero:~$ sudo apt install build-essential
  
 
==== Enable interface ====
 
==== Enable interface ====
  
See Radxa Zero [[Zero/hardware/gpio | GPIO pintout]]. Radxa Zero has a 40-pin colorful expansion header. Each pin is distinguished by color. mraa define is shown below:   
+
Radxa Zero has a 40-pin color coded expansion header. See Radxa Zero [[Zero/hardware/gpio | GPIO pintout]] for more detail on pin definition.
 +
 
 +
mraa pin definition is configured as follow:   
 +
 
 
23 GPIO:
 
23 GPIO:
 
     PIN03      GPIOA_14
 
     PIN03      GPIOA_14
Line 99: Line 107:
 
     PIN40      PWM'''40'''
 
     PIN40      PWM'''40'''
  
For those Radxa Zero system images released, the configuration file is /boot/uEnv.txt. For more details, follow this guide, [https://wiki.radxa.com/Device-tree-overlays Device tree overlays].
+
Since many peripherals are reusing the same physical pin, all but one has to be disabled to allow proper functionality. While in a normal PC user can easily disable or enable peripherals in their UEFI firmware, currently there is no such universal equivalent in ARM world. Instead, Device tree blobs (dtb) and Device tree overlays (dtbo) are used to inform Linux kernel the existence of external devices. Please refer to [[Device-tree-overlays#Part_Two:_Meson | this guide]] on available dtbo for Radxa Zero and [[Zero/Debian#Common_Hardware_Interfaces.2C_I2C.2C_PWM.2C_SPI.2C_UART.2C_etc | here]] on how to specify the correct dtbo. Please read those carefully or you may get an unbootable system.
  
==== Test ====
+
==== Run libmraa tests ====
  
Package libmraa provides some examples for testing spi, uart, i2c, gpio, etc. We way use the c files in /usr/local/share/mraa/examples/c.
+
After set correct dtbo to use, reboot Radxa Zero for change to take effect. You can now try some examples supplied by libmraa. They can be used to test SPI, UART, I2C, GPIO, and so on.
  
And we copy them to home directory.
+
In this example, we will use the sample files located under '''/usr/local/share/mraa/examples/c'''.
  
rock@zero:~$ cp -av /usr/local/share/mraa/examples/c /home/rock/mraa-examples
+
Let's first copy them to your home directory so we can modify them later:
  
You should pay more attention to the Black Bold words when modifying configuration file /boot/uEnv.txt.
+
rock@zero:~$ cp -av /usr/local/share/mraa/examples/c /home/rock/mraa-examples
About all the overlay list is in [[https://wiki.radxa.com/Zero/Ubuntu here]].
+
  
 
===== GPIO test =====
 
===== GPIO test =====
  
Use '''mraa-gpio tool''' to test
+
Use '''mraa-gpio tool''' to test GPIO:
  
 
  root@rockpis:~# mraa-gpio list
 
  root@rockpis:~# mraa-gpio list
Line 163: Line 170:
 
===== PWM test =====
 
===== PWM test =====
  
Radxa Zero provides 2 PWM, PWM_C and PWMAO_A. It is necessary to enable then at the same time if you need PWM function.
+
Radxa Zero provides 2 PWM devices: PWM_C and PWMAO_A. It is required to enable them at the same time if you want PWM function.
 +
 
 +
First, modify /boot/uEnv.txt overlays option as follows:
  
Firstly, modify the /boot/uEnv.txt file to add the following.
 
 
  rock@zero:~$ cat /boot/uEnv.txt  
 
  rock@zero:~$ cat /boot/uEnv.txt  
 
  verbosity=7
 
  verbosity=7
Line 179: Line 187:
 
  kernelimg=vmlinuz-5.10.69-5-amlogic-gfeede6ac474e
 
  kernelimg=vmlinuz-5.10.69-5-amlogic-gfeede6ac474e
  
Modify the macro PWM in /home/rock/mraa-examples/pwm.c as follows to test PWM_C. To test PWMAO_A, change '''#define PWM 18''' to '''#define PWM 40'''.
+
Reboot to apply the change.
 +
 
 +
Modify the macro PWM in '''/home/rock/mraa-examples/pwm.c''' as follows to test PWM_C. To test PWMAO_A, change '''#define PWM 18''' to '''#define PWM 40'''.
  
 
  '''/* PWM declaration */'''
 
  '''/* PWM declaration */'''
 
  '''#define PWM 18'''
 
  '''#define PWM 18'''
  
Save and compile pwm.c
+
Save and compile pwm.c:
 +
 
 
  rock@zero:~/mraa-examples$ gcc -o pwm pwm.c -lmraa
 
  rock@zero:~/mraa-examples$ gcc -o pwm pwm.c -lmraa
 
  rock@zero:~/mraa-examples$ sudo ./pwm  
 
  rock@zero:~/mraa-examples$ sudo ./pwm  
Line 195: Line 206:
  
 
===== I2C test =====
 
===== I2C test =====
Radxa Zero provides 3 I2C,There are  I2C1 ,I2C3, I2C4.  
+
Radxa Zero provides 3 I2C devices: I2C1, I2C3, and I2C4.  
If you need the I2C function, you can turn on one or more of them.
+
 
 +
Unlike PWM, if you need the I2C function, you can turn them on separately.
 +
 
 +
First, modify /boot/uEnv.txt overlays option as follows:
  
Firstly, modify the /boot/uEnv.txt file to add the following
 
 
  rock@zero:~$ cat /boot/uEnv.txt  
 
  rock@zero:~$ cat /boot/uEnv.txt  
 
  verbosity=7
 
  verbosity=7
Line 212: Line 225:
 
  kernelimg=vmlinuz-5.10.69-5-amlogic-gfeede6ac474e
 
  kernelimg=vmlinuz-5.10.69-5-amlogic-gfeede6ac474e
  
We use MPU6050 test i2c.
+
We use MPU6050 example to test I2C.
Modify the macro MPU6050 in '''/home/rock/mraa-examples/i2c_mpu6050.c''' ,as follows to test I2C1.  
+
Modify the macro MPU6050 in '''/home/rock/mraa-examples/i2c_mpu6050.c''' as follows to test I2C1.  
 
   
 
   
 
   /* mraa header */
 
   /* mraa header */
 
   #include "mraa/i2c.h"
 
   #include "mraa/i2c.h"
 
   '''#define I2C_BUS 0'''
 
   '''#define I2C_BUS 0'''
 
+
 
 
  rock@zero:~/mraa-examples$ gcc -o i2c_mpu6050 i2c_mpu6050.c  -lmraa
 
  rock@zero:~/mraa-examples$ gcc -o i2c_mpu6050 i2c_mpu6050.c  -lmraa
 
  rock@zero:~/mraa-examples$ sudo ./i2c_mpu6050
 
  rock@zero:~/mraa-examples$ sudo ./i2c_mpu6050
Line 237: Line 250:
  
 
===== UART test =====
 
===== UART test =====
Radxa Zero provides 3 UART,There are  '''uart0''' ,'''uart1''', '''uart4'''.
 
If you need the uart function, you can turn on one or more of them.
 
  
Firstly, Disable console and enable '''uart0''' for uart test.modify the '''/boot/uEnv.txt''' file to add the following
+
Radxa Zero provides 3 UART devices: uart0, uart1, and uart'''4'''.
 +
 
 +
Like I2C, you can turn them on separately.
 +
 
 +
First, disable console and enable '''uart0''' for uart test. Pay attention to ovelays and console options in below file:
 +
 
 
  rock@zero:~$ cat /boot/uEnv.txt  
 
  rock@zero:~$ cat /boot/uEnv.txt  
 
  verbosity=7
 
  verbosity=7
Line 255: Line 271:
 
  kernelimg=vmlinuz-5.10.69-5-amlogic-gfeede6ac474e
 
  kernelimg=vmlinuz-5.10.69-5-amlogic-gfeede6ac474e
  
Here set console to NULL value.
+
Here we set console to NULL.
then reboot . use '''ssh''' connect to zero,we must have '''2 windows''',one is for send data,anothor is receiver by serial com.
+
  
send command follow:
+
Reboot to apply the change. While waiting for system to boot up, you can use a jumper wire to short uart0's RX and TX pin, referring to [[Zero/hardware/gpio | this table]] if you don't know which pins you need to connect.
rock@zero:~$ sudo mraa-uart '''dev 0''' baud 1500000 send  radxa
+
  
Another window sets the baud  1500000 and receives the data  
+
In another computer, start 2 SSH sessions, one for sending and one for receiving data via uart0.
  
radxa
+
Let's first start the receiving end, so it can wait for data input:
  
receive command follow:
+
  rock@zero:~$ sudo mraa-uart '''dev 0''' baud 1500000 recv 1000
  rock@zero:~$ sudo mraa-uart '''dev 0''' baud 1500000 recv 1000
+
 
  radxa
+
In another SSH session, run following command to send data:
 +
 
 +
  rock@zero:~$ sudo mraa-uart '''dev 0''' baud 1500000 send radxa
 +
 
 +
You should be able to see <code>radxa</code> shown in your first session.
  
 
===== SPI test =====
 
===== SPI test =====
  
Firstly, modify the '''/boot/uEnv.txt''' file.
+
Change overlays in /boot/uEnv.txt and reboot:
 
  rock@zero:~$ cat /boot/uEnv.txt  
 
  rock@zero:~$ cat /boot/uEnv.txt  
 
  verbosity=7
 
  verbosity=7
Line 287: Line 305:
 
  kernelimg=vmlinuz-5.10.69-5-amlogic-gfeede6ac474e
 
  kernelimg=vmlinuz-5.10.69-5-amlogic-gfeede6ac474e
  
then execute command, sync, followed by '''reboot'''.
+
Create file test-spi.c with following content and build:
 
+
Create file test-spi.c and add the following contents.
+
  
 
  rock@zero:~/mraa-examples$ cat test-spi.c  
 
  rock@zero:~/mraa-examples$ cat test-spi.c  
Line 352: Line 368:
 
  rock@zero:~/mraa-examples$ gcc -o test-spi test-spi.c -lmraa
 
  rock@zero:~/mraa-examples$ gcc -o test-spi test-spi.c -lmraa
  
Then short pin12 and pin18 and run test-spi
+
Then short PIN12 and PIN18 and run test-spi:
  
 
  rock@zero:~/mraa-examples$ sudo ./test-spi  
 
  rock@zero:~/mraa-examples$ sudo ./test-spi  
Line 369: Line 385:
 
==== Development ====
 
==== Development ====
  
More introduction of libmraa can look at [http://iotdk.intel.com/docs/master/mraa/index.html libmraa official website].
+
You can find libmraa's documentation [http://iotdk.intel.com/docs/master/mraa/index.html here].
 
+
==== Troubleshooting ====
+
 
+
* Refer [[RockpiS/getting_started/troubleshooting | Troubleshooting page]]
+
* Post your issue on the forum: https://forum.radxa.com/c/zero
+

Latest revision as of 06:05, 2 December 2021

 Radxa Zero >  Development Guide >  Install Libmraa

Libmraa on Radxa Zero

This guide describes how to use libmraa on Radxa Zero to access GPIO, SPI, and other peripherals.

Requirement

Install essential packages

Prebuilt libmraa is located in our Radxa APT Focal and Buster repositories.

Update your /etc/apt/sources.list.d/apt-radxa-com.list accordingly to enable Radxa APT repository.

For Ubuntu Focal:

root@zero:~# cat /etc/apt/sources.list.d/apt-radxa-com.list 
deb http://apt.radxa.com/focal-stable/ focal main
deb http://apt.radxa.com/focal-testing/ focal main

For Debian Buster:

root@zero:~# cat /etc/apt/sources.list.d/apt-radxa-com.list 
deb http://apt.radxa.com/buster-stable/ buster main
deb http://apt.radxa.com/buster-testing/ buster main

Install libmraa:

rock@zero:~$ sudo apt update
rock@zero:~$ sudo apt install libmraa 

Optionally, install compiler if you want to run some tests:

rock@zero:~$ sudo apt install build-essential

Enable interface

Radxa Zero has a 40-pin color coded expansion header. See Radxa Zero GPIO pintout for more detail on pin definition.

mraa pin definition is configured as follow:

23 GPIO:

   PIN03      GPIOA_14
   PIN05      GPIOA_15
   PIN07      GPIOAO_3
   PIN08      GPIOAO_0
   PIN10      GPIOAO_1
   PIN11      GPIOAO_2
   PIN12      GPIOX_9
   PIN13      GPIOX_11
   PIN16      GPIOX_10
   PIN18      GPIOX_8
   PIN19      GPIOH_4
   PIN21      GPIOH_5
   PIN22      GPIOC_7      //Not supported gpio funtion now
   PIN23      GPIOH_7
   PIN24      GPIOH_6
   PIN27      GPIOAO_3
   PIN28      GPIOAO_2
   PIN32      GPIOAO_4
   PIN35      GPIOAO_8
   PIN36      GPIOH_8
   PIN37      GPIOAO_9
   PIN38      GPIOAO_10
   PIN40      GPIOAO_11

3 I2C:

   PIN23      I2C1_SCL
   PIN24      I2C1_SDA
   PIN13      I2C1_SCL
   PIN16      I2C1_SDA    //these are two i2c-1, only one can be opened when using
   PIN3       I2C3_SDA
   PIN5       I2C3_SCL
   PIN7       I2C4_SDA
   PIN11      I2C4_SCL
   PIN27      I2C4_SDA
   PIN28      I2C4_SCL   ///these are two i2c-4, only one can be opened when using
  

2 SPI: pwm_c

   PIN12      SPI0RX        //must disable i2c1 uart1 pwm_c
   PIN13      SPI0CLK
   PIN16      SPI0CSN
   PIN18      SPI0TX
   PIN19      SPI1TX        //must disable i2c1 uart4
   PIN21      SPI1RX        
   PIN23      SPI1CLK
   PIN24      SPI1CSN

3 UART:

   PIN8       UART0_TX    
   PIN10      UART0_RX
   PIN7       UART1_RX    //must disable i2c4
   PIN11      UART1_TX
   PIN27      UART1_RX
   PIN28      UART1_TX    
   PIN23      UART4_TX    //must disable i2c1 spi1
   PIN24      UART4_RX

2 PWM:

   PIN18      PWM18
   PIN40      PWM40

Since many peripherals are reusing the same physical pin, all but one has to be disabled to allow proper functionality. While in a normal PC user can easily disable or enable peripherals in their UEFI firmware, currently there is no such universal equivalent in ARM world. Instead, Device tree blobs (dtb) and Device tree overlays (dtbo) are used to inform Linux kernel the existence of external devices. Please refer to this guide on available dtbo for Radxa Zero and here on how to specify the correct dtbo. Please read those carefully or you may get an unbootable system.

Run libmraa tests

After set correct dtbo to use, reboot Radxa Zero for change to take effect. You can now try some examples supplied by libmraa. They can be used to test SPI, UART, I2C, GPIO, and so on.

In this example, we will use the sample files located under /usr/local/share/mraa/examples/c.

Let's first copy them to your home directory so we can modify them later:

rock@zero:~$ cp -av /usr/local/share/mraa/examples/c /home/rock/mraa-examples
GPIO test

Use mraa-gpio tool to test GPIO:

root@rockpis:~# mraa-gpio list
01         3V3:  
02          5V: 
03 I2C_EE_M3_S: GPIO I2C  
04          5V: 
05 I2C_EE_M3_S: GPIO I2C  
06         GND: 
07 I2C_AO_M0_S: GPIO I2C  UART 
08 UART_AO_A_T: GPIO UART 
09         GND: 
10 UART_AO_A_R: GPIO UART 
11 I2C_AO_M0_S: GPIO I2C  UART 
12  SPI_A_MISO: GPIO SPI  
13 I2C_EE_M1_S: GPIO I2C  SPI  
14         GND: 
15  SARADC_CH1: 
16 I2C_EE_M1_S: GPIO I2C  SPI  
17         3V3: 
18 SPI_A_MOSI,: GPIO SPI  PWM  
19  SPI_B_MOSI: GPIO SPI  
20         GND: 
21  SPI_B_MISO: GPIO SPI  
22     GPIOC_7: GPIO 
23 I2C_EE_M1_S: GPIO I2C  SPI  UART 
24 UART_EE_C_R: GPIO I2C  SPI  UART 
25         GND: 
26  SARADC_CH2: 
27 I2C_AO_M0_S: GPIO I2C  UART 
28 I2C_AO_M0_S: GPIO I2C  UART 
29          NC: 
30         GND: 
31          NC: 
32    GPIOAO_4: GPIO 
33          NC: 
34         GND: 
35 UART_AO_B_T: GPIO UART 
36     GPIOH_8: GPIO 
37 UART_AO_B_R: GPIO UART 
38   GPIOAO_10: GPIO 
39         GND: 
40     PWMAO_A: GPIO PWM  
root@rockpis:~# mraa-gpio set 40 1           #pin40 pull high
root@rockpis:~# mraa-gpio set 40 0           #pin40 pull low
PWM test

Radxa Zero provides 2 PWM devices: PWM_C and PWMAO_A. It is required to enable them at the same time if you want PWM function.

First, modify /boot/uEnv.txt overlays option as follows:

rock@zero:~$ cat /boot/uEnv.txt 
verbosity=7
console=ttyAML0,115200
overlay_prefix=meson
rootfstype=ext4
fdtfile=amlogic/meson-g12a-radxa-zero.dtb
overlays=meson-g12a-uart-ao-a-on-gpioao-0-gpioao-1 meson-g12a-pwm-c-on-gpiox-8 meson-g12a-pwmao-a-on-gpioao-11
rootuuid=bbe0631f-bbed-4033-8f75-fa5930deceed
initrdsize=0xf1ee3e
kernelversion=5.10.69-5-amlogic-gfeede6ac474e
initrdimg=initrd.img-5.10.69-5-amlogic-gfeede6ac474e
kernelimg=vmlinuz-5.10.69-5-amlogic-gfeede6ac474e

Reboot to apply the change.

Modify the macro PWM in /home/rock/mraa-examples/pwm.c as follows to test PWM_C. To test PWMAO_A, change #define PWM 18 to #define PWM 40.

/* PWM declaration */
#define PWM 18

Save and compile pwm.c:

rock@zero:~/mraa-examples$ gcc -o pwm pwm.c -lmraa
rock@zero:~/mraa-examples$ sudo ./pwm 
PWM value is 0.010015
PWM value is 0.019985
PWM value is 0.030000
PWM value is 0.040014
PWM value is 0.049984
PWM value is 0.059999
I2C test

Radxa Zero provides 3 I2C devices: I2C1, I2C3, and I2C4.

Unlike PWM, if you need the I2C function, you can turn them on separately.

First, modify /boot/uEnv.txt overlays option as follows:

rock@zero:~$ cat /boot/uEnv.txt 
verbosity=7
console=ttyAML0,115200
overlay_prefix=meson
rootfstype=ext4
fdtfile=amlogic/meson-g12a-radxa-zero.dtb
overlays=meson-g12a-uart-ao-a-on-gpioao-0-gpioao-1 meson-g12a-i2c-ee-m1-gpioh-6-gpioh-7
rootuuid=bbe0631f-bbed-4033-8f75-fa5930deceed
initrdsize=0xf1ee3e
kernelversion=5.10.69-5-amlogic-gfeede6ac474e
initrdimg=initrd.img-5.10.69-5-amlogic-gfeede6ac474e
kernelimg=vmlinuz-5.10.69-5-amlogic-gfeede6ac474e

We use MPU6050 example to test I2C. Modify the macro MPU6050 in /home/rock/mraa-examples/i2c_mpu6050.c as follows to test I2C1.

  /* mraa header */
  #include "mraa/i2c.h"
  #define I2C_BUS 0
rock@zero:~/mraa-examples$ gcc -o i2c_mpu6050 i2c_mpu6050.c  -lmraa
rock@zero:~/mraa-examples$ sudo ./i2c_mpu6050
accel: x:0 y:0 z:0
gyro: x:-10 y:1 z:7
  
accel: x:0 y:0 z:0
gyro: x:107 y:-12 z:69
   
accel: x:0 y:0 z:0
gyro: x:6 y:136 z:-50
   
accel: x:0 y:0 z:0
gyro: x:-5 y:48 z:-103
     
accel: x:0 y:0 z:0
gyro: x:3 y:3 z:5
UART test

Radxa Zero provides 3 UART devices: uart0, uart1, and uart4.

Like I2C, you can turn them on separately.

First, disable console and enable uart0 for uart test. Pay attention to ovelays and console options in below file:

rock@zero:~$ cat /boot/uEnv.txt 
verbosity=7
console=ttyAML0,115200
overlay_prefix=meson
rootfstype=ext4
fdtfile=amlogic/meson-g12a-radxa-zero.dtb
overlays=meson-g12a-uart-ao-a-on-gpioao-0-gpioao-1 meson-g12a-uart-ao-b-on-gpioao-2-gpioao-3
console=
rootuuid=bbe0631f-bbed-4033-8f75-fa5930deceed
initrdsize=0xf1ee3e
kernelversion=5.10.69-5-amlogic-gfeede6ac474e
initrdimg=initrd.img-5.10.69-5-amlogic-gfeede6ac474e
kernelimg=vmlinuz-5.10.69-5-amlogic-gfeede6ac474e

Here we set console to NULL.

Reboot to apply the change. While waiting for system to boot up, you can use a jumper wire to short uart0's RX and TX pin, referring to this table if you don't know which pins you need to connect.

In another computer, start 2 SSH sessions, one for sending and one for receiving data via uart0.

Let's first start the receiving end, so it can wait for data input:

rock@zero:~$ sudo mraa-uart dev 0 baud 1500000 recv 1000

In another SSH session, run following command to send data:

rock@zero:~$ sudo mraa-uart dev 0 baud 1500000 send radxa

You should be able to see radxa shown in your first session.

SPI test

Change overlays in /boot/uEnv.txt and reboot:

rock@zero:~$ cat /boot/uEnv.txt 
verbosity=7
console=ttyAML0,115200
overlay_prefix=meson
rootfstype=ext4
fdtfile=amlogic/meson-g12a-radxa-zero.dtb
overlays=meson-g12a-uart-ao-a-on-gpioao-0-gpioao-1 meson-g12a-spi-spidev 
param_spidev_spi_bus=0 
param_spidev_max_freq=10000000
rootuuid=bbe0631f-bbed-4033-8f75-fa5930deceed
initrdsize=0xf1ee3e
kernelversion=5.10.69-5-amlogic-gfeede6ac474e
initrdimg=initrd.img-5.10.69-5-amlogic-gfeede6ac474e
kernelimg=vmlinuz-5.10.69-5-amlogic-gfeede6ac474e

Create file test-spi.c with following content and build:

rock@zero:~/mraa-examples$ cat test-spi.c 
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>

/* mraa header */
#include "mraa/spi.h"

/* SPI declaration */
#define SPI_BUS 0

/* SPI frequency in Hz */
#define SPI_FREQ 10000000
int
main(int argc, char** argv)
{
    mraa_result_t status = MRAA_SUCCESS;
    mraa_spi_context spi;
    int i, j;

    /* initialize mraa for the platform (not needed most of the times) */
    mraa_init();

    //! [Interesting]
    /* initialize SPI bus */
    spi = mraa_spi_init(SPI_BUS);
    if (spi == NULL) {
        fprintf(stderr, "Failed to initialize SPI\n");
        mraa_deinit();
        return EXIT_FAILURE;
    }

    /* set SPI frequency */
    status = mraa_spi_frequency(spi, SPI_FREQ);
    if (status != MRAA_SUCCESS)
        goto err_exit;

    /* set big endian mode */
    status = mraa_spi_lsbmode(spi, 0);
    if (status != MRAA_SUCCESS) {
        goto err_exit;
    }
   
    j = 10;
    while(j) {
  	j--;
        printf("0x%x\n",mraa_spi_write(spi, 0xaa));
    }
err_exit:
    mraa_result_print(status);

    /* stop spi */
    mraa_spi_stop(spi);

    /* deinitialize mraa for the platform (not needed most of the times) */
    mraa_deinit();

     return EXIT_FAILURE;
}
rock@zero:~/mraa-examples$ gcc -o test-spi test-spi.c -lmraa

Then short PIN12 and PIN18 and run test-spi:

rock@zero:~/mraa-examples$ sudo ./test-spi 
0xaa
0xaa
0xaa
0xaa
0xaa
0xaa
0xaa
0xaa
0xaa
0xaa
MRAA: SUCCESS

Development

You can find libmraa's documentation here.