Hi,
I am working to test PS-UART1 in ZynqMP (UltraZed Som). I am running UART polled mode example to test PS-UART 1.
When I run this example application via JTAG from SDK Debugger, it runs successfully. UART Self Test and UART Internal Loopback Passes Successfully.
After that I generate a petalinux build to boot image from SD-Card in Ultrazed-Som. Then I run same application via following commands,
echo UARTSelfTest.elf > /sys/class/remoteproc/remoteproc0/firmware
echo start > /sys/class/remoteproc/remoteproc0/state
-In this case, the PS-UART1 goes to reset state when the following function is called in the application XUartPs_SetBaudRate(InstancePtr, BaudRate).
The code for PS-UART Self Test is attached here.
/******************************************************************************
*
* Copyright (C) 2010 - 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.
*
* 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.
*
******************************************************************************/
/****************************************************************************/
/**
*
* @file xuartps_polled_example.c
*
* This file contains an example using the XUartPs driver in polled mode.
*
* This function sends data and expects to receive the data thru the device
* using the local loopback mode.
*
* @note
* If the device does not work properly, the example may hang.
*
* MODIFICATION HISTORY:
* <pre>
* Ver Who Date Changes
* ----- ------ -------- -----------------------------------------------
* 1.00a drg/jz 01/13/10 First Release
* 1.03a sg 07/16/12 Modified the device ID to use the first Device Id
* Removed the printf at the start of the main
* </pre>
******************************************************************************/
/***************************** Include Files *********************************/
#include "xparameters.h"
#include "xuartps.h"
#include "xil_printf.h"
/************************** Constant Definitions *****************************/
/*
* The following constants map to the XPAR parameters created in the
* xparameters.h file. They are defined here such that a user can easily
* change all the needed parameters in one place.
*/
#define UART_DEVICE_ID XPAR_XUARTPS_1_DEVICE_ID
/*
* The following constant controls the length of the buffers to be sent
* and received with the device, this constant must be 32 bytes or less since
* only as much as FIFO size data can be sent or received in polled mode.
*/
#define TEST_BUFFER_SIZE 32
/**************************** Type Definitions *******************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
int UartPsPolledExample(u16 DeviceId);
/************************** Variable Definitions *****************************/
XUartPs Uart_PS; /* Instance of the UART Device */
/*
* The following buffers are used in this example to send and receive data
* with the UART.
*/
static u8 SendBuffer[TEST_BUFFER_SIZE]; /* Buffer for Transmitting Data */
static u8 RecvBuffer[TEST_BUFFER_SIZE]; /* Buffer for Receiving Data */
/*****************************************************************************/
/**
*
* Main function to call the Uart Polled mode example.
*
* @param None
*
* @return XST_SUCCESS if succesful, otherwise XST_FAILURE
*
* @note None
*
******************************************************************************/
#ifndef TESTAPP_GEN
int main(void)
{
int Status;
usleep(5000);
xil_printf("Hello World\r\n");
Status = UartPsPolledExample(UART_DEVICE_ID);
if (Status != XST_SUCCESS)
{
xil_printf("UART Polled Mode Example Test Failed\r\n");
return XST_FAILURE;
}
u32* uart_pll = 0xff5e0020;
// Release UART from reset state by clearing TXRST and RXRST bits
u32 control_reg_value = *uart_pll;
xil_printf("IO PLL Control Register = %x \r\n",control_reg_value);
xil_printf("Successfully ran UART Polled Mode Example Test\r\n");
return XST_SUCCESS;
}
#endif
/*****************************************************************************/
/**
*
* This function does a minimal test on the XUartPs device in polled mode.
*
* This function sends data and expects to receive the data thru the UART
* using the local loopback mode.
*
*
* @param DeviceId is the unique device id from hardware build.
*
* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful
*
* @note
* This function polls the UART, it may hang if the hardware is not
* working correctly.
*
****************************************************************************/
int UartPsPolledExample(u16 DeviceId)
{
int Status;
XUartPs_Config *Config;
unsigned int SentCount;
unsigned int ReceivedCount;
u16 Index;
u32 LoopCount = 0;
/*
* Initialize the UART driver so that it's ready to use.
* Look up the configuration in the config table, then initialize it.
*/
// Address of the UART PS control register
u32* uart_cr = (volatile u32*)(XPAR_PSU_UART_1_BASEADDR + XUARTPS_CR_OFFSET);
// Release UART from reset state by clearing TXRST and RXRST bits
u32 control_reg_value = *uart_cr;
xil_printf("UART Control Register Before LookUp = %x \r\n",control_reg_value);
Config = XUartPs_LookupConfig(DeviceId);
if (NULL == Config)
{
xil_printf("UART PS Lookup Config Failed\r\n");
return XST_FAILURE;
}
else
{
xil_printf("UART PS Lookup Config Success\r\n");
}
// Release UART from reset state by clearing TXRST and RXRST bits
control_reg_value = *uart_cr;
xil_printf("UART Control Register After Lookup = %x \r\n",control_reg_value);
Status = XUartPs_CfgInitialize(&Uart_PS, Config, Config->BaseAddress);
if (Status != XST_SUCCESS)
{
xil_printf("UART PS CFG Init Failed\r\n");
return XST_FAILURE;
}
{
xil_printf("UART PS CFG Init Success\r\n");
}
control_reg_value = *uart_cr;
xil_printf("UART Control Register After INIT = %x \r\n",control_reg_value);
/*
xil_printf("UART PS Before Reset\r\n");
XUartPs_ResetHw(XPAR_PSU_UART_1_BASEADDR);
xil_printf("UART PS After Reset\r\n");
usleep(5000);
*/
/* Check hardware build. */
Status = XUartPs_SelfTest(&Uart_PS);
if (Status != XST_SUCCESS)
{
xil_printf("UART PS Self Test Failed\r\n");
return XST_FAILURE;
}
else
{
xil_printf("UART PS Self Test Success\r\n");
}
/* Use local loopback mode. */
XUartPs_SetOperMode(&Uart_PS, XUARTPS_OPER_MODE_LOCAL_LOOP);
/*
* Initialize the send buffer bytes with a pattern and zero out
* the receive buffer.
*/
for (Index = 0; Index < TEST_BUFFER_SIZE; Index++)
{
SendBuffer[Index] = '0' + Index;
RecvBuffer[Index] = 0;
}
/* Block sending the buffer. */
SentCount = XUartPs_Send(&Uart_PS, SendBuffer, TEST_BUFFER_SIZE);
if (SentCount != TEST_BUFFER_SIZE)
{
xil_printf("UART PS Data Sent Failed\r\n");
return XST_FAILURE;
}
else
{
xil_printf("Sent Count = %d\r\n",SentCount);
}
/*
* Wait while the UART is sending the data so that we are guaranteed
* to get the data the 1st time we call receive, otherwise this function
* may enter receive before the data has arrived
*/
while (XUartPs_IsSending(&Uart_PS))
{
LoopCount++;
}
xil_printf("Data Sent Completed\r\n");
/* Block receiving the buffer. */
ReceivedCount = 0;
while (ReceivedCount < TEST_BUFFER_SIZE)
{
ReceivedCount +=
XUartPs_Recv(&Uart_PS, &RecvBuffer[ReceivedCount],
(TEST_BUFFER_SIZE - ReceivedCount));
}
xil_printf("Received Count = %d\r\n",ReceivedCount);
/*
* Check the receive buffer against the send buffer and verify the
* data was correctly received
*/
for (Index = 0; Index < TEST_BUFFER_SIZE; Index++)
{
xil_printf("Send Data = %d\r\n",SendBuffer[Index]);
xil_printf("Received Data = %d\r\n",RecvBuffer[Index]);
if (SendBuffer[Index] != RecvBuffer[Index])
{
return XST_FAILURE;
}
else
{
xil_printf("Data Matched Success\r\n");
}
}
xil_printf("Internal Loopback Tested Successfully\r\n");
/* Restore to normal mode. */
XUartPs_SetOperMode(&Uart_PS, XUARTPS_OPER_MODE_NORMAL);
return XST_SUCCESS;
}

