In a previous project I covered Getting Started with the Arduino core on a MILK-V Duo. If you are not familiar with preparing the SDcard boot loader I recommend you check out this project.  This same bootloader will be used in this example.

The assumptions in the is project are that you are using a Debian based Linux PC and have established SSH communication with your Milk-V Duo development board.

The WorkFlow starts with using your Linux PC for writing a 'C' source file using your favourite editor (I like geany) and then running a make script to cross compile it to produce a Linux executable for the Milk-V Duo.  This executable will then be uploaded and run on the Duo.

If you do much source code development on you PC the necessary tools are probably already installed on your system.  If not, you may wish to refer to this README.

At this point I make the assumption that we are running in a Linux terminal. ( crtl-alt T ).

To get started you will need to download the duo examples into a directory of your choosing.  Change to this directory and enter:

git clone https://github.com/milkv-duo/duo-examples.git

 this will create a duo-examples directory with example projects such as adc, blink and i2c.

SO, let's start with the blink program.  'cd' into the 'blink' project directory. If this is the first time you are compiling this project you will need to setup the environment by running the envsetup.sh script.

source ../envsetup.sh

At this point we will modify the existing blink.c program to work with both 64Meg and 256Meg versions, as well as changing the blink sequence by changing the sleep() parameters.  For example, change line 28 to sleep( 2 ) to make the LED stay ON longer than it is OFF.  The sleep parameter is in whole seconds.

We will change line 46 to read:

    if(wiringXSetup("duo", NULL) == -1) {

 where the parameter "duo" will work for most versions of the boot card.  There is a complete copy of this modified blink.c in the Files section.

You should note that there is a file named 'Makefile' in the directory.  This contains the instruction for compiling and linking your 'C' program. To compile simply type:

make

after some whizzing and whirring you should have a file named blink. If this your first time compiling for the milk-v the toolchain will be automatically downloaded, which can take longer.

We can then proceed to upload this file using SCP:

scp blink root@milkv:/root

 we will be prompted for the password which is milkv.

Connect to the MILKV using SSH (I recommmend Putty)...  and enter:

./blink

Assuming that the automatic startup blink script has been disabled as in previous projects you should see the blue LED blinking with the timing that you set with the sleep commands, together with serial output telling us what is happening.

In lines 24-44 I have shown how to determine some details on the SDcard BootLoader in use. These will be printed on the console when the program starts.

So, in conclusion, we have discovered how to setup wiringX and use it's digitalWrite and pinMode routines to manipulate a GPIO pin, as well as using printf to print messages to the serial port.