Whitney Knitter
Published © GPL3+

Writing Embedded C Applications for the ZynqberryZero

This project focuses on how to write embedded C applications for the ZynqberryZero using Vitis.

BeginnerFull instructions provided1 hour1,622
Writing Embedded C Applications for the ZynqberryZero

Things used in this project

Hardware components

Trenz Electronic ZynqberryZero
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Vitis Unified Software Platform
AMD Vitis Unified Software Platform

Story

Read more

Schematics

ZynqberryZero Schematic

Code

UART Echo Example

C/C++
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc.  All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/

/*
 * helloworld.c: simple test application
 *
 * This application configures UART 16550 to baud rate 9600.
 * PS7 UART (Zynq) is not initialized by this application, since
 * bootrom/bsp configures it to baud rate 115200
 *
 * ------------------------------------------------
 * | UART TYPE   BAUD RATE                        |
 * ------------------------------------------------
 *   uartns550   9600
 *   uartlite    Configurable only in HW design
 *   ps7_uart    115200 (configured by bootrom/bsp)
 */

#include <stdio.h>
#include "xstatus.h"
#include "platform.h"
#include "xil_types.h"
#include "xil_assert.h"
#include "xuartps_hw.h"
#include "xil_printf.h"
#include "xparameters.h"

#define UART_BASEADDR		XPAR_XUARTPS_0_BASEADDR
#define UART_CLOCK_HZ		XPAR_XUARTPS_0_CLOCK_HZ
#define UART_BUFFER_SIZE	16

#define CHAR_ESC		    0x1b	/* 'ESC' character is used as terminator */
#define CHAR_NULL           0x00
#define CHAR_ENTER          0x0d
#define CHAR_SPACE          0x20

u8 TxBuffer[UART_BUFFER_SIZE];
u8 RxBuffer[UART_BUFFER_SIZE];


int main()
{
    init_platform();

    u8 RXbyte;
    u8 TXbyte;
    int Running = 0;

    u32 CntrlRegister = XUartPs_ReadReg(UART_BASEADDR,XUARTPS_FIFO_OFFSET);

    /* Enable TX and RX for the device */
    XUartPs_WriteReg(UART_BASEADDR, XUARTPS_CR_OFFSET,((CntrlRegister & ~XUARTPS_CR_EN_DIS_MASK) | XUARTPS_CR_TX_EN | XUARTPS_CR_RX_EN));

    while(Running == 0){
        /* Listen for data to come in */
        while (!XUartPs_IsReceiveData(UART_BASEADDR)){

        };

        /* receive */
        RXbyte = XUartPs_ReadReg(UART_BASEADDR,XUARTPS_FIFO_OFFSET);
        TXbyte = RXbyte;

        if (RXbyte == CHAR_ESC){
        	Running = 1;
        }

        /* send */
        XUartPs_WriteReg(UART_BASEADDR,XUARTPS_FIFO_OFFSET,TXbyte);
    }

    xil_printf("Good-bye!\r\n");

    cleanup_platform();
    return 0;
}

Credits

Whitney Knitter

Whitney Knitter

157 projects • 1588 followers
All thoughts/opinions are my own and do not reflect those of any company/entity I currently/previously associate with.

Comments