AnsweredAssumed Answered

About ADSP-21584 UART

Question asked by Harley.zhu on Dec 14, 2017
Latest reply on Dec 19, 2017 by Kader.M

Does ADSP_21584 support UART.  I try to use Uart0 to debug output some log message. But I find it can't open.

this is my code.

/*
* uart.h
*
* Created on: 2017年12月14日
* Author: Administrator
*/

#ifndef SRC_SYSTEM_FRAMEWORK_UART_H_
#define SRC_SYSTEM_FRAMEWORK_UART_H_

#include <stdint.h>


/* Baud rate to be used for char echo */
#define BAUD_RATE 115200u

/*
* Macros used in the example
*/

/* Example result definitions */
#define FAILED (-1)
#define PASSED 0

/* Macro for reporting errors */
#define REPORT_ERROR printf

/*
* Processor specific macros
*/

/* UART Device Number to test */
#define UART_DEVICE_NUM 1u

/* default power settings */
#define MHZTOHZ (1000000u)

#if defined(__ADSPSC589_FAMILY__) || defined(__ADSPSC573_FAMILY__)

#define CLKIN (25u * MHZTOHZ)
#define CORE_MAX (450u * MHZTOHZ)
#define SYSCLK_MAX (225u * MHZTOHZ)

#else

#define DF_DEFAULT (0x0)
#define MSEL_DEFAULT (0x10)
#define SSEL_DEFAULT (0x8)
#define CSEL_DEFAULT (0x4)

#define CLKIN (25u * MHZTOHZ)
#define CORE_MAX (500u * MHZTOHZ)
#define SYSCLK_MAX (250u * MHZTOHZ)
#define SCLK_MAX (125u * MHZTOHZ)
#define VCO_MIN (72u * MHZTOHZ)

#endif


int Uart0_Init(void);

int Uart0_SendStr(uint8_t *pData);

#endif /* SRC_SYSTEM_FRAMEWORK_UART_H_ */

 

 

/*
* Uart.c
*
* Created on: 2017年12月14日
* Author: Administrator
*/


#include "Common_macros__extern_definations.h"

#include "uart.h"
#include <drivers/uart/adi_uart.h>

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
/* Rx/Tx Buffer size */
#define BUFFER_SIZE 2

/* UART Handle */
static ADI_UART_HANDLE ghUART;

/* Rx and Tx buffer */
static uint8_t RxBuffer[BUFFER_SIZE];

/* Memory required for operating UART in interrupt mode */
static uint8_t gUARTMemory[ADI_UART_BIDIR_INT_MEMORY_SIZE];

int Uart0_Init(void)
{
/* UART return code */
ADI_UART_RESULT eResult;

/*
* Initialize UART
*/
/* Open UART driver */
eResult = adi_uart_Open(UART_DEVICE_NUM,
ADI_UART_DIR_BIDIRECTION,
gUARTMemory,
ADI_UART_BIDIR_INT_MEMORY_SIZE,
&ghUART);
if (eResult != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not open UART Device 0x%08X\n", eResult);
return FAILED;
}

/* Set the UART Mode */
eResult = adi_uart_SetMode(ghUART, ADI_UART_MODE_UART);
if (eResult != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not set the Mode 0x%08X\n", eResult);
return FAILED;
}

/* Set UART Baud Rate */
eResult = adi_uart_SetBaudRate(ghUART, BAUD_RATE);
if (eResult != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not set the Baud Rate 0x%08X\n", eResult);
return FAILED;
}

/* Set number of stop bits */
eResult = adi_uart_SetNumStopBits(ghUART, ADI_UART_ONE_STOPBIT);
if (eResult != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not set the stop bits 0x%08X\n", eResult);
return FAILED;
}

/* Set number of stop bits */
eResult = adi_uart_SetWordLen(ghUART, ADI_UART_WORDLEN_8BITS);
if (eResult != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not set word length 0x%08X\n", eResult);
return FAILED;
}

return PASSED;

}


int Uart0_SendStr(uint8_t *pData)
{
ADI_UART_RESULT eResult;
/* Write back the character */
eResult = adi_uart_Write(ghUART, pData, sizeof(pData)-1);
if (eResult != ADI_UART_SUCCESS)
{
REPORT_ERROR("Could not do a write 0x%08X\n", eResult);
return FAILED;
}

return PASSED;
}

Outcomes