PAC1934 Energy Metering Using Linux® Step 2

Last modified by Microchip on 2023/11/09 09:00

Setup a Linux® Development System

  • This project has been verified to work with the following software versions:

    • VirtualBox - version 6.1.26
    • VirtualBox Extension Pack (Requires license) - version 6.1.26
    • Ubuntu 20.04.3 64-bit LTS ISO Image
    • This guide assumes the host operating system is Windows®. In addition, Virtualization must be enabled in the Host system’s BIOS to use Ubuntu (64-bit) in VirtualBox. Else, you will encounter an error when you try to start the virtual machine.

If you are using a native Linux® host system, proceed to Step 2.2

Install and Configure VirtualBox

Install VirtualBox (and Extension Pack, optional).

Create a virtual machine.

Insert the downloaded Ubuntu ISO image by selecting Choose a disk file…. Please see Figure 1:
Ubuntu Settings

Set up the virtual machine’s network. We will set up (two) adapters: one for connecting the virtual machine to the Internet, the other for connecting to the SOM1-EK.

  • Set up one adapter for connecting to the SOM1-EK. In this step, we will use Adapter 1 for this purpose. Refer to Figure 2 for accessing the Network settings and to see what settings need to be changed.
  • Make sure to select the Ethernet controller available on your device under Name as this will be used to connect to the SOM1-EK directly.
  • Make sure to select Allow All under Promiscuous Mode.
Ubuntu Settings

Figure 2

  • Set up Adapter 2 using most of the same settings used for Adapter 1.
  • However, make sure to select the Wi-Fi® controller available for your device under Name as this will be used to connect your virtual machine to the Internet.

Then, start the virtual machine. It should boot the Ubuntu Installer automatically.

Start Ubuntu Installer

Figure 3

Back to Top


Install Ubuntu

Click Install Ubuntu. Please refer to Figure 4:

Ubuntu Language Screen

Figure 4

 

Follow the step on each page. There is no specific configuration needed.

Wait until the installation has finished.

Ubuntu Welcome Screen

Figure 5

 

Remove ISO image then reboot to Ubuntu.

After installing and booting Ubuntu, we suggest running sudo apt-get update && sudo apt-get upgrade through the terminal to ensure the latest operating system and software versions are installed. Use Ctrl + Alt + T to easily access the terminal.

Back to Top


Install Guest Additions

Guest Additions are very useful since it includes software that optimizes the Linux client operating system and adds other features such as Shared Folder and Auto-Resize Guest Display. This is only required when using VirtualBox. You can learn more about Guest Additions Features at this link: Chapter 4. Guest Additions (virtualbox.org).

Mount the Guest Additions CD Image by clicking Devices > Insert Guest Additions CD Image….

Ubuntu Insert Guest Additions CD Image….

Figure 6

 

After mounting the image, a CD icon on the left side bar should appear. Click Run when a pop-up prompt like the one in Figure 7 appears.

Ubuntu Installation Screen

Figure 7

 

The installer should prompt for a password. After entering the correct user password, Guest Additions should automatically install. Please refer to Figure 8.

Ubuntu Guest Additions Screen

Figure 8

 

Reboot the virtual machine after the installation has finished.

Back to Top


Install Required Utilities

The following applications are required to be installed in Ubuntu for the purposes of this demo:

  • balenaEtcher – An application for flashing image onto SD Cards or USB drives.
  • minicom – A serial terminal application for communicating to the SOM1-EK serial port.

To install balenaEtcher, use the following commands:

$ sudo apt-get install curl -y
$ curl -1sLf https:~~/~~/dl.cloudsmith.io/public/balena/etcher/setup.deb.sh | sudo -E bash
$ sudo apt-get update
$ sudo apt-get install balena-etcher-electron -y(%%)

Adding -y at the end of sudo apt-get install allows us to skip the prompt asking for permission whenever we want to install packages.

balenaEtcher Installation Icon

Figure 9

 

To install minicom, use the command:

$ sudo apt-get install minicom -y


Configure Client Network Interfaces

Configure the Static Network Interface. This network will be used to connect to the SOM1-EK later. Refer to Figure 10 to configure the network interface. After configuring the network interface, reboot the virtual machine.

Configure Client Network Interfaces

Figure 10

The static network interface we need to set up should be the interface that’s not connected to the Internet.

Back to Top


Set Up Shared Folder Access

We will be setting up a shared folder to transfer files between the Windows Host and the Ubuntu virtual machine. This will be used in a later step.

For this step, we will refer to your shared folder as <your shared folder>.
We can set up shared folders without having to shut down the virtual machine beforehand.

In your Host system, open the Oracle® VirtualBox window, select the virtual machine from the left-hand side of the screen, and navigate to Settings > Shared folders. Your window should appear as shown in Figure 11.

Set Up Shared Folder Access

Figure 11

 

Click the + icon on the right side of the window to open the menu shown in Figure 12:

Select Shared Folder

Figure 12

 

On Folder Path, click on the dropdown menu icon, select Other…, and navigate to the location of a folder you would want to access from the virtual machine.

We will leave it up to you to decide where to place the shared folder in your Host system. We suggest placing it somewhere accessible like the Desktop for the purposes of this tutorial.

Tick Auto-mount and Make Permanent then click OK. Your shared folder should appear under Machine Folders.

Make Permanent makes sure that the shared folder remains mounted even after shutting down the virtual machine so we can still access it the next time we open the virtual machine.

Click OK again. The shared folder should now mount in the virtual machine as shown in Figure 13, with the name displayed as sf_<your shared folder>.

Virtual Machine Shared Folders

Figure 13

 

Back to Top


Install Buildroot Dependencies

The System Requirements chapter of the Buildroot user manual specifies the required packages that must be installed in your host system.

To install optional packages, we can append the package name to the command.

  • Install the required dependencies using the following command:

​$ sudo apt-get install sed make binutils build-essential gcc g++ bash patch gzip bzip2 perl tar cpio unzip rsync file bc git python3 python libncurses5-dev -y

​We install the optional git, python, and libncurses5-devjpackages here since we’ll need these later in the project.

Back to Top


Create a Project Directory

It is good practice to create a project directory to place source code and specific configurations for a given Buildroot project.

For this tutorial, we will name our project directory as the project.

$ mkdir project

Change the directory to the project directory by using the following command:

$ cd ~~/project

​You can use the Tab key to auto-complete file/folder names when using the cd command. For example, you can type "cd ~/pro" and then press Tab to autocomplete the folder name. Note that in some instances, pressing Tab may list files/folders with similar names, so you will need to type more characters so the specific name required can be autocompleted.

Back to Top


Clone Buildroot

​For SAM devices, we can clone buildroot-at91 repository in Linux4SAM Official GitHub. buildroot-at91 is a fork of Buildroot with a minimal number of patches, only the ones which have not hit the mainline yet.

  • Clone Buildroot-at91 using the following command:

​$ git clone https:~/~/github.com/linux4sam/buildroot-at91

Back to Top


Clone Buildroot-External-Microchip

​For SAM devices, we can also clone the buildroot-external-microchip repository. The Microchip-maintained external tree provides additional packages and defconfigs dedicated for our SAM MPU device demos which may not hit the mainline.

Clone Buildroot-External-Microchip using the following command:

$(% style="background-color:inherit; color:inherit; font-family:Menlo,Monaco,Consolas,~"Courier New~",monospace; font-size:inherit; white-space:pre" %)git clone https:~/~/github.com/linux4microchip/buildroot-external-microchip.git

Back to Top


Checkout Repository Versions

​This project has been verified to work with the linux4sam-2021.04 release tag of buildroot-at91 and the Microchip Buildroot external.

  • Change directory to the Buildroot-at91 directory:

    cd buildroot-at91

To get the available repository versions, use the following command:

$ git tag

To find a specific version, use the grep command:

$ git tag | grep <version>

You may sometimes find that using git tag results in a similar screen shown in Figure 14 where a colon is displayed at the bottom of the terminal. When this happens, you can use the up and down arrow keys to navigate the versions available. To exit this menu, simply press Q.

git tag command

Figure 14

Checking out a remote branch to a new local branch may help users track their changes on the new local branch.

  • Checkout the linux4sam-2021.04 release tag of Buildroot-at91 using the following command:

$ git checkout linux4sam-2021.04 -b buildroot-linux4sam-2021.04

Change directory to the Microchip Buildroot external directory:

cd ../buildroot-external-microchip

Checkout the linux4sam-2021.04 release tag using the following command:

$ git checkout linux4sam-2021.04 -b buildroot-external-linux4sam-2021.04

To verify the currently checked out versions, use the following command within each repository’s respective directory:

$ git status

The output of git status, when run in both directories, should look like the following:

  • For Buildroot-at91/ directory
git status output

Figure 15

  • For Buildroot-external-microchip/ directory
git status output

Figure 16

Back to Top