duo-examples
Описание
Milk-V Duo official C/C++ examples
Языки
- C96,8%
- Makefile2%
- Shell1,2%
Milk-V Duo Examples
English | 简体中文
This project provides some examples of developing applications using C/C++ in a Linux environment, which can be run on the device.
Build environment on Ubuntu20.04
You can also use Ubuntu installed in a virtual machine, Ubuntu installed via WSL on Windows, or Ubuntu-based systems using Docker.
-
Install the tools that compile dependencies.
sudo apt-get install wget git make -
Get example source code
git clone https://github.com/milkv-duo/duo-examples.git -
Prepare compilation environment
cd duo-examples source envsetup.shThe first time you source it, the required compilation toolchain will be automatically downloaded. The downloaded directory is named
. The next time the compilation environment is loaded, the directory will be detected. If it already exists, it will not be downloaded again.host-toolsIn the source process, you need to enter the required compilation target as prompted:
Select Product: 1. Duo (CV1800B) 2. Duo256M (SG2002) or DuoS (SG2000)If the target board is Duo, select
, if the target board is Duo256M or DuoS, select1. Since Duo256M and DuoS support both RISCV and ARM architectures, you need to continue to select as prompted:2Select Arch: 1. ARM64 2. RISCV64 Which would you like:If the test program needs to be run on a ARM system, select
, if it is an RISCV system, select1.2In the same terminal, you only need to source it once.
-
Compile testing
Take hello-world as an example, enter the hello-world directory and execute make:
cd hello-world makeAfter the compilation is successful, send the generated
executable program to the Duo device through the network port or the USB-NCM network. For example, the USB-NCM method supported by the default firmware, Duo’s IP is 192.168.42.1, the user name ishelloworld, and the password isrootmilkvscp helloworld root@192.168.42.1:/root/After sending successfully, run ./helloworld in the terminal logged in via ssh or serial port, and it will print
Hello, World![root@milkv]~# ./helloworld Hello, World!At this point, our compilation and development environment is ready for use.
How to create your own project
You can simply copy existing examples and make necessary modifications. For instance, if you need to manipulate a GPIO, you can refer to the example. LED blinking is achieved by controlling the GPIO's voltage level. The current SDK utilizes the WiringX library for GPIO operations, which has been adapted specifically for Duo. You can find the platform initialization and GPIO control methods in the code for reference.
- Create your own project directory called
.my-project - Copy the
andblink.cfiles from theMakefileexample to theblinkdirectory.my-project - Rename
to your desired name, such asblink.c.gpio_test.c - Modify the
by changingMakefiletoTARGET=blink.TARGET=gpio_test - Modify
to implement your own code logic.gpio_test.c - Execute the
command to compile.make - Send the generated
executable program to Duo for execution.gpio_test
Note:
- Creating a new project directory is not mandatory to be placed within the
directory. You can choose any location based on your preference. Before executing theduo-examplescompilation command, it is sufficient to load the compilation environment from themakedirectory (source /PATH/TO/duo-examples/envsetup.sh).duo-examples - Within the terminal where the compilation environment (envsetup.sh) is loaded, avoid compiling Makefile projects for other platforms such as ARM or X86. If you need to compile projects for other platforms, open a new terminal.
Explanation of each example
hello-world
A simple example that doesn't interact with Duo peripherals, only prints the output "Hello, World!" to verify the development environment.
blink
This example demonstrates how to control an LED connected to a GPIO pin. It uses the WiringX library to toggle the GPIO pin's voltage level, resulting in the LED blinking.
The code includes platform initialization and GPIO manipulation methods from the WiringX library.
To test the example, which involves LED blinking, you need to disable the script responsible for the automatic LED blinking on the default firmware of Duo. In the Duo terminal, execute the following command:
mv /mnt/system/blink.sh /mnt/system/blink.sh_backup && sync
This command renames the LED blinking script. After restarting Duo, the LED will no longer blink.
Once you have finished testing the program implemented in C, if you want to restore the LED blinking script, you can rename it back using the following command and then restart Duo:
mv /mnt/system/blink.sh_backup /mnt/system/blink.sh && sync
I2C
| App | Description |
|---|---|
| bmp280_i2c | By connecting the temperature and pressure sensor through the I2C interface, you can read the current temperature and pressure values. |
| vl53l0x_i2c | Read the Time of Flight sensor module to get the measured distance. |
| ssd1306_i2c | Displaying strings on OLED display via I2C interface. |
| adxl345_i2c | Read the acceleration data obtained by through the I2C interface, once every 1 sencond. |
| lcm1602_i2c | Display string on screen via I2C interface. |
| lcm2004_i2c | Display string on screen via I2C interface. |
| tcs34725_i2c | Read the color sensor through the I2C interface and output the obtained data. |
SPI
| App | Description |
|---|---|
| max6675_spi | Connect the K-type thermocouple measurement module through the SPI interface to measure the temperature on the current sensor. |
| rc522_spi | Connect the RFID reading and writing module through the SPI interface, read the card ID and type and output it to the screen. |
AnalogRead (ADC)
This example enables the CV180x 12bit resolution analog-digital converter module, called SARADC. /adc/ has two examples to run the module, first is an sh script and the other one is C source file, which can be easy compiled with TinyCC on Duo board.
The SARADC utilization reference is the CV180x CV181x Peripheral Drive Operation Guide.