Menu Close

Achieving Linux PS Uart and PL Uart in App

This article talks about how to implement Linux PS Uart and PL Uart by writing an executable application.

For related subjects, please refer to the SOC Table of Contents.

 

Create a new folder for the new PetaLinux project.

Use the following commands to create a new PetaLinux project within the folder that was just created.

sptl
petalinux-create -t project --template zynq -n appdevtest

Use the cd command to go into the project folder to make some modifications. Make sure to use the corresponding .sdk file.

cd appdevtest
petalinux-config --get-hw-description ~/petalinux_app_dev_tests/FII_7030_APP.sdk/

The settings page should open up.

Select Linux Components Selection.

Select First Stage Bootloader as well as Auto update ps_init.

Next, go into Subsystem AUTO Hardware Settings.

Go into Serial Settings.

Select Primary stdin/stdout and set it as ps7_uart_0.

Save and exit after modifying the settings.

Next, we will configure the Linux kernel.

petalinux-config -c kernel

We don’t need to make any changes in the graphical interface, we can directly save and exit.

Next, we can use the following command to compile the entire project.

petalinux-build

Use the following command to create the boot file.

petalinux-package --boot --fsbl --fpga --u-boot --force

Copy BOOT.BIN and image.ub to the BOOT partition of the SD card, and extract roots.cpio to the rootfs partition.

Next, we will create a folder for the app to be developed. We will name it appdevtest_app.

Create a new .c file in the folder we just created. We will name it as appdevtestapp.c.

App code download: appdevtestapp

The app’s code is as follows:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h> /* File Control Definitions */
#include <termios.h> /* POSIX Terminal Control Definitions */
#include <unistd.h> /* UNIX Standard Definitions */ 
#include <errno.h> /* ERROR Number Definitions */
#include <string.h>

int main()
{
    int fid;
    char resultstr[] = "\nMessage recieved is: \n";

    printf("App has started running \n");
    printf("\n");

    fid = open("/dev/ttyPS0", O_WRONLY);

    char string1[100];

    printf("Enter a message to be sent to ttyPS0: ");
    fgets(string1, 100, stdin);

    write(fid, resultstr, strlen(resultstr));
    write(fid, string1, strlen(string1));
    close(fid);

    printf("\n");


    fid = open("/dev/ttyUL1", O_WRONLY);

    char string2[100];

    printf("Enter a message to be sent to ttyUL1: ");
    fgets(string2, 100, stdin);
    write(fid, resultstr, strlen(resultstr));
    write(fid, string2, strlen(string2));
    close(fid);

    printf("\n");
    printf("App has finished running \n");

    return 0;
}

Next, we will execute the following command to create a .o file from the file we just created and modified.

arm-linux-gnueabihf-gcc appdevtestapp.c -o appdevtestapp.o

We will also copy this file to the SD card. For simplicity, we will put it in the BOOT partition.

Now we can plug the SD card into the development board and boot it up. Make sure that your device is connected to both the ARM_UART and the RISC_V JTAG ports on the development board. Next, execute the following command to mount the two partitions on the SD card.

cd /mnt
mkdir sd1
mkdir sd2
mount /dev/mmcblk0p1 /mnt/sd1
mount /dev/mmcblk0p2 /mnt/sd2

Next, we will go into the directory of the .o file, which should be /mnt/sd1 on the BOOT partition.

We can then execute the following command to execute the program/app.

./appdevtestapp.o

We can see that the corresponding messages are being output from the corresponding ports.


		
Posted in Textbook and Training Project

Related Articles

Leave a Reply

Your email address will not be published.

Leave the field below empty!