Platform: Unify NS and secure UART STDOUT implementation

The uart_stdout implementations are actually identical for
Non-secure and Secure. The only difference is the actual
underlying stdio driver.
This patch unifies the implementations to one file, using
Macro to distinguish different drivers.

The patch also removes the unused enum uart_channel.

Change-Id: Ice89127cc98bd185947ce8de7af5190bd5bd69dc
Signed-off-by: Kevin Peng <kevin.peng@arm.com>
This commit is contained in:
Kevin Peng 2020-05-29 10:28:26 +08:00 committed by Ken Liu
parent 738a4b0118
commit 524e3ececa
5 changed files with 25 additions and 82 deletions

View File

@ -167,7 +167,7 @@ set(BUILD_TARGET_CFG Off)
set(BUILD_TARGET_HARDWARE_KEYS Off)
set(BUILD_TARGET_NV_COUNTERS Off)
set(BUILD_CMSIS_DRIVERS On)
set(BUILD_UART_STDOUT Off)
set(BUILD_UART_STDOUT On)
set(BUILD_FLASH Off)
if(CORE_TEST_POSITIVE)
set(BUILD_PLAT_TEST On)

View File

@ -26,6 +26,7 @@
#endif
#include "log/tfm_assert.h"
#include "log/tfm_log.h"
#include "uart_stdout.h"
/**
* \brief Modified table template for user defined SVC functions
@ -106,24 +107,6 @@ static void tfm_ns_multi_core_boot(void)
}
#endif
/* For UART the CMSIS driver is used */
extern ARM_DRIVER_USART NS_DRIVER_STDIO;
int stdio_output_string(const unsigned char *str, uint32_t len)
{
int32_t ret;
ret = NS_DRIVER_STDIO.Send(str, len);
if (ret != ARM_DRIVER_OK) {
return 0;
}
/* Add a busy wait after sending. */
while (NS_DRIVER_STDIO.GetStatus().tx_busy)
;
return NS_DRIVER_STDIO.GetTxCount();
}
/**
* \brief Platform peripherals and devices initialization.
* Can be overridden for platform specific initialization.
@ -132,19 +115,7 @@ int stdio_output_string(const unsigned char *str, uint32_t len)
*/
__WEAK int32_t tfm_ns_platform_init(void)
{
int32_t ret;
ret = NS_DRIVER_STDIO.Initialize(NULL);
TFM_ASSERT(ret == ARM_DRIVER_OK);
ret = NS_DRIVER_STDIO.PowerControl(ARM_POWER_FULL);
TFM_ASSERT(ret == ARM_DRIVER_OK);
ret = NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS,
DEFAULT_UART_BAUDRATE);
TFM_ASSERT(ret == ARM_DRIVER_OK);
(void)NS_DRIVER_STDIO.Control(ARM_USART_CONTROL_TX, 1);
stdio_init();
return ARM_DRIVER_OK;
}
@ -157,12 +128,7 @@ __WEAK int32_t tfm_ns_platform_init(void)
*/
__WEAK int32_t tfm_ns_platform_uninit(void)
{
int32_t ret;
(void)NS_DRIVER_STDIO.PowerControl(ARM_POWER_OFF);
ret = NS_DRIVER_STDIO.Uninitialize();
TFM_ASSERT(ret == ARM_DRIVER_OK);
stdio_uninit();
return ARM_DRIVER_OK;
}

View File

@ -1,18 +0,0 @@
/*
* Copyright (c) 2019, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef __UART_STDOUT_H__
#define __UART_STDOUT_H__
#include <stdint.h>
/**
* \brief Output buffer by STDIO.
*/
int stdio_output_string(const unsigned char *str, uint32_t len);
#endif /* __UART_STDOUT_H__ */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2019 ARM Limited
* Copyright (c) 2017-2020 ARM Limited
*
* Licensed under the Apace License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,7 +18,6 @@
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include "Driver_USART.h"
#include "target_cfg.h"
#include "device_cfg.h"
@ -26,26 +25,32 @@
#define ASSERT_HIGH(X) assert(X == ARM_DRIVER_OK)
/* Imports USART driver */
#if DOMAIN_NS == 1U
extern ARM_DRIVER_USART NS_DRIVER_STDIO;
#define STDIO_DRIVER NS_DRIVER_STDIO
#else
extern ARM_DRIVER_USART TFM_DRIVER_STDIO;
#define STDIO_DRIVER TFM_DRIVER_STDIO
#endif
int stdio_output_string(const unsigned char *str, uint32_t len)
{
int32_t ret;
ret = TFM_DRIVER_STDIO.Send(str, len);
ret = STDIO_DRIVER.Send(str, len);
if (ret != ARM_DRIVER_OK) {
return 0;
}
/* Add a busy wait after sending. */
while (TFM_DRIVER_STDIO.GetStatus().tx_busy);
while (STDIO_DRIVER.GetStatus().tx_busy);
return TFM_DRIVER_STDIO.GetTxCount();
return STDIO_DRIVER.GetTxCount();
}
/* Redirects printf to TFM_DRIVER_STDIO in case of ARMCLANG*/
/* Redirects printf to STDIO_DRIVER in case of ARMCLANG*/
#if defined(__ARMCC_VERSION)
/* Struct FILE is implemented in stdio.h. Used to redirect printf to
* TFM_DRIVER_STDIO
* STDIO_DRIVER
*/
FILE __stdout;
/* __ARMCC_VERSION is only defined starting from Arm compiler version 6 */
@ -60,7 +65,7 @@ int fputc(int ch, FILE *f)
return ch;
}
#elif defined(__GNUC__)
/* Redirects printf to TFM_DRIVER_STDIO in case of GNUARM */
/* Redirects printf to STDIO_DRIVER in case of GNUARM */
int _write(int fd, char *str, int len)
{
(void)fd;
@ -82,25 +87,25 @@ int putchar(int ch)
void stdio_init(void)
{
int32_t ret;
ret = TFM_DRIVER_STDIO.Initialize(NULL);
ret = STDIO_DRIVER.Initialize(NULL);
ASSERT_HIGH(ret);
ret = TFM_DRIVER_STDIO.PowerControl(ARM_POWER_FULL);
ret = STDIO_DRIVER.PowerControl(ARM_POWER_FULL);
ASSERT_HIGH(ret);
ret = TFM_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS,
DEFAULT_UART_BAUDRATE);
ret = STDIO_DRIVER.Control(ARM_USART_MODE_ASYNCHRONOUS,
DEFAULT_UART_BAUDRATE);
ASSERT_HIGH(ret);
(void)TFM_DRIVER_STDIO.Control(ARM_USART_CONTROL_TX, 1);
(void)STDIO_DRIVER.Control(ARM_USART_CONTROL_TX, 1);
}
void stdio_uninit(void)
{
int32_t ret;
(void)TFM_DRIVER_STDIO.PowerControl(ARM_POWER_OFF);
(void)STDIO_DRIVER.PowerControl(ARM_POWER_OFF);
ret = TFM_DRIVER_STDIO.Uninitialize();
ret = STDIO_DRIVER.Uninitialize();
ASSERT_HIGH(ret);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2019 ARM Limited
* Copyright (c) 2017-2020 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,16 +19,6 @@
#include <stdint.h>
/**
* \brief UART channels that
* can be used from TFM
*/
enum uart_channel {
UART0_CHANNEL = 0,
UART1_CHANNEL,
UART_INVALID
};
/**
* \brief Initializes the STDIO.
*