Step 4: Application-Specific Configuration

Step 4.1: Download and Extract Project Files

Download the example files from pac1934-linux.zip to your virtual machine and extract the files into <your unzip folder>.

Picture51a.png
Figure 1
  • We leave it up to you to decide where to place <your unzip folder>. Make sure it can be easily accessed from your home folder in ~/. For this tutorial, we will assume that the project files are in ~/project/pac1934-linux
  • There are many ways to place the project files into your virtual machine. With Guest Additions installed, you can also use VirtualBox’s Drag and Drop feature if you downloaded pac1934-linux.zip on your host system. You can enable these options as shown in the screenshot below
Picture52.png
Figure 2

Step 4.2: Add PAC193x and spidev Linux® Drivers

1. Navigate to the extracted Project Files Directory:

$ cd ~/project/pac1934-linux

2. Copy the PAC193x driver source to the Linux® Kernel Source directory of Buildroot:

$ cp pac193x.c ~/project/my_external_tree/build/linux-linux4sam-2021.04/drivers/iio/adc

3. Edit linux-linux4sam-2021.04/drivers/iio/adc/Makefile:

$ nano ~/project/my_external_tree/build/linux-linux4sam-2021.04/drivers/iio/adc/Makefile

Add the following to the bottom of the file:

obj-$(CONFIG_PAC193x) += pac193x.o
Picture53.png
Figure 3

After editing in Nano, use Ctrl + X then Y and Enter.

4. Edit linux-linux4sam-2021.04/drivers/iio/adc/Kconfig:

$ nano ~/project/my_external_tree/build/linux-linux4sam-2021.04/drivers/iio/adc/Kconfig

Add the following to the bottom of the file just before endmenu:

config PAC193x
tristate "PAC193x Driver"

In Nano, using the Page Down button can help scroll down the file. Ensure that the second line of text is properly indented as shown in Figure 4.

Picture54.png
Figure 4

5. Navigate to my_external_tree directory and run make linux-menuconfig to add the PAC193x and spidev drivers.

$ cd ~/project/my_external_tree/
$ make linux-menuconfig

Device Drivers > Industrial I/O support > Analog to digital converters

  • <*> PAC193x Driver

Device Drivers > SPI support

  • <*> User mode Serial Peripheral Interface (SPI) device driver support
Picture55.png
Figure 5
Picture56.png
Figure 6

Press Space twice to include the driver as a static module within the kernel. This is indicated by <*>. If we include the driver as a module (indicated by <M>), the resulting *.ko file will be included in the root filesystem (rootfs) of the target device.

6. Exit then save the configuration.

Step 4.3: Configure the Device Tree

1. Add the PAC1934 Click board™ and the OLED W Click to the device tree by editing the device tree source (*.dts) file using the following command:

$ nano ~/project/my_external_tree/build/linux-linux4sam-2021.04/arch/arm/boot/dts/at91-sama5d27_som1_ek.dts

2. Navigate to the flx1 node using Ctrl + W then add the following under the i2c3 node:

pac1934@10 {
    compatible = "microchip,pac1934";
    reg = <0x10>;
    samp-rate = <64>;
    status = "okay";

    ch1: channel@0 {
        uohms-shunt-res = <4000>; /* shunt resistor is 4 mOhm */
        rail-name = "R1";
        channel_enabled;
        channel_index = <1>;
    };

    ch2: channel@1 {
        uohms-shunt-res = <4000>; /* shunt resistor is 4 mOhm */
        rail-name = "R2";
        channel_enabled;
        channel_index = <2>;
    };

    ch3: channel@2 {
        uohms-shunt-res = <4000>; /* shunt resistor is 4 mOhm */
        rail-name = "R3";
        channel_enabled;
        channel_index = <3>;
    };

    ch4: channel@3 {
        uohms-shunt-res = <4000>; /* shunt resistor is 4 mOhm */
        rail-name = "R4";
        channel_enabled;
        channel_index = <4>;
    };
};
step4_dts_pac1934.png
Figure 7

We add the PAC1934 Click board under flx1 and i2c3 since the Inter-Integrated Circuit (I2C) pins of mikroBUS™ 1 (PA23 and PA24) are mapped to the FLEXCOM1 peripheral of the SAMA5D27 microprocessor (MPU). To double-check, you may refer to the SAMA5D2 Series datasheet to find the pinouts and the memory location of FLEXCOM1, which should match the address specified in the device tree, and Table 4-24 of the "SAMA5D27 SOM1 Kit1 User's Guide" for the pin assignments of the mikroBUSTM 1 interface.

3. Navigate to the spi6 node using Ctrl +​ W then add the following within the node and as shown on Figure 8:

cs-gpios = <&pioA PIN_PD0 GPIO_ACTIVE_LOW>, <&pioA PIN_PC31 GPIO_ACTIVE_LOW>;
#address-cells = <1>;
#size-cells = <0>;

    spidev@1 {
        reg = <1>;
        compatible ="atmel,at91rm9200-spidev";
        spi-max-frequency = <1000000>;
        status = "okay";
    };
Picture58.png
Figure 8

4. Navigate to the leds node and change its status to “disabled”.

Picture59.png
Figure 9

The blue heartbeat LED conflicts with the D/C pin of the OLED W Click, both of which use PA31. For this project, we will disable the heartbeat LED.

5. Save the changes made to the file using Ctrl + X then Y and Enter.

Step 4.4: Modify the spidev Driver

1. Navigate back to the my_external_tree directory and modify spidev.c using the following command:

$ cd ~/project/my_external_tree
$ nano build/linux-linux4sam-2021.04/drivers/spi/spidev.c

2. Navigate to the spidev_dt_ids struct and add the following as another struct member:

{ .compatible = "atmel,at91rm9200-spidev" },

The structure should appear as seen in Figure 10:

Picture60.png
Figure 10

spidev.c does not list atmel,at91rm9200-spidev as a compatible device-tree node, hence why we need to do this to make sure the spidev driver is loaded for the OLED W Click. Refer to AN3253 for additional details.

3. Save the changes made to the file using Ctrl + X then Y and Enter.

Step 4.5: Rebuild the Image

1. Rebuild the Linux kernel to implement the changes made to the spidev driver:

$ make linux-rebuild

2. Rebuild the modified device tree using the following command:

$ make dt-overlay-at91-rebuild

3. Rebuild the SD card image using make:

$ make

4. Navigate back to the my_external_tree/images directory using the following command to find sdcard.img:

$ cd ~/project/my_external_tree/images

Your screen should appear as shown in Figure 11:

Picture61.png
Figure 11

Step 4.6: Flash the Image to the SD Card Using balenaEtcher

The sdcard.img, mentioned on the previous step, contains the Linux distribution built by Buildroot. There are many ways to burn this image to an SD card. On this tutorial, we will be using balenaEtcher.

We can either run balenaEtcher in our Ubuntu virtual machine if the SD card shows up from there or copy the image to the Windows Host then run balenaEtcher from there.

Go to Step 4.6.1a if you opt to flash the SD card through the Ubuntu virtual machine. Otherwise, go to Step 4.6.1b if you would like to do so through the Windows® host system.

Step 4.6.1a – From Ubuntu Virtual Machine Using a USB SD Card Reader

The VirtualBox Extension Pack (license needed) is required to attach USB 2.0 and USB 3.0 devices to the virtual machine.

Some of the steps below may also apply if you are running Ubuntu natively (i.e., not using a virtual machine).

1. Open balenaEtcher from the Applications menu.

Picture62.png
Figure 12

2. Connect a USB 2.0 SD card reader to the computer.

3. Attach the USB 2.0 SD card reader to the virtual machine by following the steps below:

  1. Right-click the USB icon in the VirtualBox Status Bar as shown on Figure 13.
  2. Click the USB card reader.
  3. If the USB Card Reader mounted successfully, a checkmark should appear beside its name as seen on Figure 13.

On this specific system, the USB card reader shows up as “USB Storage.” This varies with the manufacturer. To determine the correct USB device, try disconnecting then checking this list and reconnecting the device again.

Picture63.png
Figure 13

4. In Etcher, click Flash from file.

Picture64.png
Figure 14

5. Navigate to Home>project>my_external_tree>images as shown in Figure 15 to find sdcard.img.

Picture65.png
Figure 15

6. Click Select target. Verify that the selected target is the correct target by checking size and location. Your screen may look like Figure 16. Click Select (1).

Picture66.png
Figure 16

7. Click Flash!. It should prompt for a password.
8. A successful flash is shown on Figure 17:

Picture67.png
Figure 17

9. Remove the SD card from the USB card reader. Proceed to Step 4.6.2.

Step 4.6.1b – From Windows Host

  • To flash the SD card from the Windows host system, we will use the shared folder that we set up in Step 2.1.6 to transfer files between the virtual machine and the host.
  • Download and install balenaEtcher on the Windows host system before proceeding to these steps.

For this step, we will refer to your shared folder as <your shared folder>.

1. Navigate to the my_external_tree/images directory:

$ cd ~/project/my_external_tree/images

2. Copy sdcard.img to <your shared folder> which should be mounted within /media/:

$ cp sdcard.img /media/<your shared folder>

3. Launch balenaEtcher on the Windows host system as Administrator.

4. In Etcher, click Flash from file.

Picture68.png
Figure 18

5. Navigate to the location of <your shared folder> to find and select sdcard.img.

6. Click Select target and choose the SD card plugged in to the system. Verify that the selected target is correct by checking its size and location. Click Select (1) afterwards.

Picture69.png
Figure 19

7. Click Flash!. Depending on the configurations of your system, you may be prompted to enter your password.

8. A successful flash is shown in Figure 20. After flashing succeeds, you can proceed with removing the SD card from your PC.

Picture70.png
Figure 20

Step 4.6.2 – Booting the SD Card to ATSAMA5D27-SOM1-EK Evaluation Board

  • For this step, we will use minicom to see the boot process of the target device
  • In case you encounter issues with mounting the virtual COM port to the virtual machine, you may opt to use your preferred serial terminal software. You may check the terminal configuration on this step and skip to Step 4.7 if you are using a different serial terminal software
Picture71.png
Figure 21

3. Configure minicom to talk to the target device using the following command:

$ sudo minicom -s

4. Navigate to Serial port setup, press Enter, and change the serial device to /dev/ttyACM0 by pressing A first. The settings should look like Figure 22:

Picture72.png
Figure 22

The name of the COM port will usually be “ttyACM0.” Sometimes the name may be different, like when there are other virtual COM ports connected to your system. If so, we suggest using dmesg to determine the COM port name on your system after connecting the Segger J-Link Virtual COM port to the computer and mounting it to the virtual machine. The name usually starts with "tty." An example is shown in Figure 23:

Picture73.png
Figure 23

5. After changing the serial device, press Enter, select Exit, then press Enter again. You should now be in the minicom terminal as shown in Figure 24:

Picture74.png
Figure 24

6. On the SOM1-EK (J12), hold the NRST button, insert the SD card to the SD card adapter, insert the adapter to J12, then let go of NRST. The board will now start booting and you will see some output on minicom as shown in Figure 25:

Picture75.png
Figure 25

7. After the boot process completes, you will be greeted by the system banner set in the system configurations mentioned in Step 3.3.4. There will also be a prompt to enter your credentials as shown in Figure 26. Log in using the credentials configured in Step 3.3.4.

Picture76.png
Figure 26

Step 4.7: Verify That Drivers Have Been Loaded

Starting at this step, the commands preceded by # are executed on the SOM1-EK, while commands preceded by $ are executed in Ubuntu

We will now verify that the PAC193x and spidev drivers have been loaded.

1

Verify PAC193x Driver

1. Use dmesg to verify that the PAC193x driver has been loaded. A message like the one shown in Figure 27 will appear:

# dmesg | grep pac193x

Picture77.png
Figure 27

2. To further verify that the PAC193x driver has been loaded, we can check sysfs to see if the driver has exposed kernel information from the PAC1934 to user space.

# ls /sys/bus/iio/devices/

Picture78.png
Figure 28

3. The PAC1934 will typically be located within iio:device1, so we will display its contents using the following command:

# ls /sys/bus/iio/devices/iio\:device1/

Picture79.png
Figure 29

4. To verify that this is the PAC1934 sysfs interface, use the following command:

# cat /sys/bus/iio/devices/iio\:device1/name

Picture80.png
Figure 30

2

Verify spidev Driver

1. To verify the spidev driver has been loaded, we can also check the exposed sysfs interface using the following command:

# ls /sys/bus/spi/devices/spi1.1/spidev

Picture81.png
Figure 31

2. We can also check the /dev directory to see if the OLED W Click is recognized as an SPI device.

# ls /dev | grep spi

Picture82.png
Figure 32

Step 4.8: Verify Device Tree Changes

We will check the contents of the proc filesystem (procfs) to verify that the device tree changes took effect.

procfs is a special filesystem in Unix-like operating systems that presents information about processes and other system information in a file-like structure.

1. Navigate to the Advanced Peripheral Bus (apb) within the device tree using the following command:

# cd /proc/device-tree/ahb/apb

2. Use the following commands to verify the SPI changes for the OLED W Click:

# ls flexcom@fc018000/spi@400/
# cat flexcom@fc018000/spi@400/name
# cat flexcom@fc018000/spi@400/status

Picture83.png
Figure 33

You may notice that the device tree node flexcom@fc018000 is the same node we modified in Step 4.3 to add the mikroBUS™ 2 SPI pins to the device tree.

3. Use the following commands to verify the I2C changes for the PAC1934:

# ls flexcom@f8038000/i2c@600/
# cat flexcom@f8038000/i2c@600/name
# cat flexcom@f8038000/i2c@600/status

Picture84.png
Figure 34

Step 4.9: Configure Network Interface for Deploying the Application

1. Edit /etc/network/interfaces:

# nano /etc/network/interfaces

2. Delete all the contents of the file and replace it with the following:

auto eth0
iface eth0 inet static
address 192.168.1.5
netmask 255.255.255.0

Your screen should appear as shown in Figure 35.
Picture85.png
Figure 35

3. Save and exit by using Ctrl + X.
4. Restart the network interface using the following commands:

# ifdown -a
# ifup -a

ifdown means disable network interface; ifup means enable network interface

Picture86.png
Figure 36

5. Confirm that the network interface is using the static IP addressifconfig. The output should look like the screenshot below:

Picture87.png
Figure 37

6. Enable ssh login to root using a password on the SOM1-EK by executing the following commands:

# echo ‘PasswordAuthentication yes’ » /etc/ssh/sshd_config
# echo ‘PermitRootLogin yes’ » /etc/ssh/sshd_config


© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.