Platform: Refactor generic USART device usage

Add an extra config layer in cmsis_driver_config.h to platform
specifically select the UART device to be used with the required
security domain for TFM core and Non-Secure application separately.
This way the platform independent TFM core UART usage becomes
completely platform agnostic, using a generic CMSIS UART device.

Change-Id: I3e957fcc4df6d041fef2f350c2d7b329a368a220
Signed-off-by: Gabor Kertesz <gabor.kertesz@arm.com>
diff --git a/app/main_ns.c b/app/main_ns.c
index fd40820..94eebc8 100644
--- a/app/main_ns.c
+++ b/app/main_ns.c
@@ -23,10 +23,11 @@
   "test/test_services/tfm_secure_client_service/tfm_secure_client_service_svc.h"
 #endif
 
+#include "target_cfg.h"
 #include "Driver_USART.h"
 
 /* For UART the CMSIS driver is used */
-extern ARM_DRIVER_USART Driver_USART0;
+extern ARM_DRIVER_USART NS_DRIVER_STDIO;
 
 /**
  * \brief Modified table template for user defined SVC functions
@@ -64,19 +65,21 @@
 // ...
 };
 
-/* Struct FILE is implemented in stdio.h. Used to redirect printf to UART0 */
+/* Struct FILE is implemented in stdio.h. Used to redirect printf to
+ * NS_DRIVER_STDIO
+ */
 FILE __stdout;
-/* Redirects armclang printf to UART */
+/* Redirects armclang printf to NS_DRIVER_STDIO */
 int fputc(int ch, FILE *f) {
-    /* Send byte to UART0 */
-    (void)Driver_USART0.Send((const unsigned char *)&ch, 1);
+    /* Send byte to NS_DRIVER_STDIO */
+    (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1);
     /* Return character written */
     return ch;
 }
-/* redirects gcc printf to uart */
+/* redirects gcc printf to NS_DRIVER_STDIO */
 int _write(int fd, char * str, int len)
 {
-    (void)Driver_USART0.Send(str, len);
+    (void)NS_DRIVER_STDIO.Send(str, len);
 
     return len;
 }
@@ -106,8 +109,8 @@
 #endif
 int main(void)
 {
-    (void)Driver_USART0.Initialize(NULL); /* Use UART0 as stdout */
-    Driver_USART0.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
+    (void)NS_DRIVER_STDIO.Initialize(NULL);
+    NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);
 
     status = osKernelInitialize();
 
diff --git a/bl2/ext/mcuboot/bl2_main.c b/bl2/ext/mcuboot/bl2_main.c
index ef08582..9adc072 100644
--- a/bl2/ext/mcuboot/bl2_main.c
+++ b/bl2/ext/mcuboot/bl2_main.c
@@ -80,7 +80,7 @@
     struct boot_rsp rsp;
     int rc;
 
-    uart_init(UART0_CHANNEL);
+    stdio_init();
 
     BOOT_LOG_INF("Starting bootloader");
 
diff --git a/platform/ext/common/uart_stdout.c b/platform/ext/common/uart_stdout.c
index 8075873..401b0b6 100755
--- a/platform/ext/common/uart_stdout.c
+++ b/platform/ext/common/uart_stdout.c
@@ -19,23 +19,20 @@
 #include <assert.h>

 #include <stdio.h>

 #include <string.h>

-#ifdef TARGET_MUSCA_A

-#include "uart_pl011_drv.h"

-#else

-#include "arm_uart_drv.h"

-#endif

 #include "Driver_USART.h"

+#include "target_cfg.h"

 

 #define ASSERT_HIGH(X)  assert(X == ARM_DRIVER_OK)

 

 /* Imports USART driver */

-extern ARM_DRIVER_USART Driver_USART0;

-extern ARM_DRIVER_USART Driver_USART1;

+extern ARM_DRIVER_USART TFM_DRIVER_STDIO;

 

-/* Struct FILE is implemented in stdio.h. Used to redirect printf to UART */

+/* Struct FILE is implemented in stdio.h. Used to redirect printf to

+ * TFM_DRIVER_STDIO

+ */

 FILE __stdout;

 

-/* Redirects printf to UART */

+/* Redirects printf to TFM_DRIVER_STDIO */

 __attribute__ ((weak)) int fputc(int ch, FILE *f) {

     /* Send byte to USART */

     uart_putc(ch);

@@ -46,69 +43,19 @@
 

 int _write(int fd, char * str, int len)

 {

-    for (int i = 0; i < len; i++)

-    {

+    for (int i = 0; i < len; i++) {

         uart_putc(str[i]);

     }

     return len;

 }

 

-#ifdef TARGET_MUSCA_A

-extern struct uart_pl011_dev_t UART0_DEV_S, UART0_DEV_NS;

-extern struct uart_pl011_dev_t UART1_DEV_S, UART1_DEV_NS;

-#else

-extern struct arm_uart_dev_t ARM_UART0_DEV_S, ARM_UART0_DEV_NS;

-extern struct arm_uart_dev_t ARM_UART1_DEV_S, ARM_UART1_DEV_NS;

-#endif

-

-/* Generic driver to be configured and used */

-ARM_DRIVER_USART *Driver_USART = NULL;

-

-void uart_init(enum uart_channel uchan)

+void stdio_init(void)

 {

     int32_t ret = ARM_DRIVER_OK;

-

-    /* Add a configuration step for the UART channel to use, 0 or 1 */

-    switch(uchan) {

-    case UART0_CHANNEL:

-        /* UART0 is configured as a non-secure peripheral, so it cannot be

-         * accessed using its secure alias. Ideally the driver would

-         * be configured with the right properties, but for simplicity,

-         * use a workaround for now

-         */

-#ifdef TARGET_MUSCA_A

-        memcpy(&UART0_DEV_S, &UART0_DEV_NS, sizeof(struct uart_pl011_dev_t));

-#else

-        memcpy(&ARM_UART0_DEV_S, &ARM_UART0_DEV_NS,

-                                                sizeof(struct arm_uart_dev_t));

-#endif

-        Driver_USART = &Driver_USART0;

-        break;

-    case UART1_CHANNEL:

-#ifndef SECURE_UART1

-        /* If UART1 is configured as a non-secure peripheral, it cannot be

-         * accessed using its secure alias. Ideally the driver would

-         * be configured with the right properties, but for simplicity,

-         * use a workaround for now

-         */

-#ifdef TARGET_MUSCA_A

-        memcpy(&UART1_DEV_S, &UART1_DEV_NS, sizeof(struct uart_pl011_dev_t));

-#else

-        memcpy(&ARM_UART1_DEV_S, &ARM_UART1_DEV_NS,

-                                                sizeof(struct arm_uart_dev_t));

-#endif

-#endif

-        Driver_USART = &Driver_USART1;

-        break;

-    default:

-        ret = ARM_DRIVER_ERROR;

-    }

+    ret = TFM_DRIVER_STDIO.Initialize(NULL);

     ASSERT_HIGH(ret);

 

-    ret = Driver_USART->Initialize(NULL);

-    ASSERT_HIGH(ret);

-

-    ret = Driver_USART->Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);

+    ret = TFM_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200);

     ASSERT_HIGH(ret);

 }

 

@@ -116,7 +63,7 @@
 {

     int32_t ret = ARM_DRIVER_OK;

 

-    ret = Driver_USART->Send(&c, 1);

+    ret = TFM_DRIVER_STDIO.Send(&c, 1);

     ASSERT_HIGH(ret);

 }

 

@@ -125,7 +72,7 @@
     unsigned char c = 0;

     int32_t ret = ARM_DRIVER_OK;

 

-    ret = Driver_USART->Receive(&c, 1);

+    ret = TFM_DRIVER_STDIO.Receive(&c, 1);

     ASSERT_HIGH(ret);

 

     return c;

diff --git a/platform/ext/common/uart_stdout.h b/platform/ext/common/uart_stdout.h
index e9afe03..063ae05 100644
--- a/platform/ext/common/uart_stdout.h
+++ b/platform/ext/common/uart_stdout.h
@@ -1,5 +1,5 @@
 /*

- * Copyright (c) 2017 ARM Limited

+ * Copyright (c) 2017-2018 ARM Limited

  *

  * Licensed under the Apache License, Version 2.0 (the "License");

  * you may not use this file except in compliance with the License.

@@ -30,12 +30,10 @@
 };

 

 /**

- * \brief Initializes the UART.

+ * \brief Initializes the STDIO.

  *

- * \param[in] uchan UART channel

- *                  to use, 0 or 1.

  */

-void uart_init(enum uart_channel uchan);

+void stdio_init(void);

 

 /**

  * \brief Puts a character in the UART.

diff --git a/platform/ext/readme.md b/platform/ext/readme.md
index a4f81c3..55c9057 100644
--- a/platform/ext/readme.md
+++ b/platform/ext/readme.md
@@ -26,6 +26,18 @@
 This folder contains the headers with CMSIS compliant driver definitions that
 that TF-M project expects a target to provide.
 
+#### target_cfg.h
+
+This file is expected to define the following macros respectively.
+
+ - `TFM_DRIVER_STDIO`
+   This macro should expand to a structure of type `ARM_DRIVER_USART`.
+   TFM redirects its standard input and output to this instance of USART.
+ - `NS_DRIVER_STDIO`
+   This macro should expand to a structure of type `ARM_DRIVER_USART`.
+   Non-Secure application redirects its standard input and output to this
+   instance of USART.
+
 ### target
 
 This folder contains the files for individual target.
diff --git a/platform/ext/target/mps2/an519/cmsis_driver_config.h b/platform/ext/target/mps2/an519/cmsis_driver_config.h
new file mode 100644
index 0000000..cab3b63
--- /dev/null
+++ b/platform/ext/target/mps2/an519/cmsis_driver_config.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CMSIS_DRIVER_CONFIG_H__
+#define __CMSIS_DRIVER_CONFIG_H__
+
+#include "platform_retarget_dev.h"
+#include "RTE_Device.h"
+#include "target_cfg.h"
+
+#ifdef RTE_USART0
+#define UART0_DEV       ARM_UART0_DEV_NS
+#endif
+
+#ifdef RTE_USART1
+#ifdef SECURE_UART1
+#define UART1_DEV       ARM_UART1_DEV_S
+#else
+#define UART1_DEV       ARM_UART1_DEV_NS
+#endif
+#endif
+
+#endif  /* __CMSIS_DRIVER_CONFIG_H__ */
diff --git a/platform/ext/target/mps2/an519/cmsis_drivers/Driver_USART.c b/platform/ext/target/mps2/an519/cmsis_drivers/Driver_USART.c
index 489708e..3b35d0a 100644
--- a/platform/ext/target/mps2/an519/cmsis_drivers/Driver_USART.c
+++ b/platform/ext/target/mps2/an519/cmsis_drivers/Driver_USART.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2017 ARM Limited. All rights reserved.
+ * Copyright (c) 2013-2018 ARM Limited. All rights reserved.
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -19,7 +19,7 @@
 #include "Driver_USART.h"
 
 #include "cmsis.h"
-#include "platform_retarget_dev.h"
+#include "cmsis_driver_config.h"
 #include "RTE_Device.h"
 
 #ifndef ARG_UNUSED
@@ -211,11 +211,7 @@
 #if (RTE_USART0)
 /* USART0 Driver wrapper functions */
 static UARTx_Resources USART0_DEV = {
-#if (__DOMAIN_NS == 1)
-    .dev = &ARM_UART0_DEV_NS,
-#else
-    .dev = &ARM_UART0_DEV_S,
-#endif
+    .dev = &UART0_DEV,
     .tx_nbr_bytes = 0,
     .rx_nbr_bytes = 0,
     .cb_event = NULL,
@@ -313,11 +309,7 @@
 #if (RTE_USART1)
 /* USART1 Driver wrapper functions */
 static UARTx_Resources USART1_DEV = {
-#if (__DOMAIN_NS == 1)
-    .dev = &ARM_UART1_DEV_NS,
-#else
-    .dev = &ARM_UART1_DEV_S,
-#endif
+    .dev = &UART1_DEV,
     .tx_nbr_bytes = 0,
     .rx_nbr_bytes = 0,
     .cb_event = NULL,
@@ -415,11 +407,7 @@
 #if (RTE_USART2)
 /* USART2 Driver wrapper functions */
 static UARTx_Resources USART2_DEV = {
-#if (__DOMAIN_NS == 1)
-    .dev = &ARM_UART2_DEV_NS,
-#else
-    .dev = &ARM_UART2_DEV_S,
-#endif
+    .dev = &UART2_DEV,
     .tx_nbr_bytes = 0,
     .rx_nbr_bytes = 0,
     .cb_event = NULL,
@@ -517,11 +505,7 @@
 #if (RTE_USART3)
 /* USART3 Driver wrapper functions */
 static UARTx_Resources USART3_DEV = {
-#if (__DOMAIN_NS == 1)
-    .dev = &ARM_UART3_DEV_NS,
-#else
-    .dev = &ARM_UART3_DEV_S,
-#endif
+    .dev = &UART3_DEV,
     .tx_nbr_bytes = 0,
     .rx_nbr_bytes = 0,
     .cb_event = NULL,
@@ -619,11 +603,7 @@
 #if (RTE_USART4)
 /* USART4 Driver wrapper functions */
 static UARTx_Resources USART4_DEV = {
-#if (__DOMAIN_NS == 1)
-    .dev = &ARM_UART4_DEV_NS,
-#else
-    .dev = &ARM_UART4_DEV_S,
-#endif
+    .dev = &UART4_DEV,
     .tx_nbr_bytes = 0,
     .rx_nbr_bytes = 0,
     .cb_event = NULL,
diff --git a/platform/ext/target/mps2/an519/target_cfg.h b/platform/ext/target/mps2/an519/target_cfg.h
index c9c3cf1..6430113 100644
--- a/platform/ext/target/mps2/an519/target_cfg.h
+++ b/platform/ext/target/mps2/an519/target_cfg.h
@@ -17,8 +17,13 @@
 #ifndef __SSE200_TARGET_CFG_H__
 #define __SSE200_TARGET_CFG_H__
 
+#include "arm_uart_drv.h"
+#include "platform/ext/common/uart_stdout.h"
 #include "tfm_peripherals_def.h"
 
+#define TFM_DRIVER_STDIO    Driver_USART0
+#define NS_DRIVER_STDIO     Driver_USART0
+
 /**
  * \brief Defines the word offsets of Slave Peripheral Protection Controller
  *        Registers
diff --git a/platform/ext/target/mps2/an521/cmsis_driver_config.h b/platform/ext/target/mps2/an521/cmsis_driver_config.h
new file mode 100644
index 0000000..cab3b63
--- /dev/null
+++ b/platform/ext/target/mps2/an521/cmsis_driver_config.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CMSIS_DRIVER_CONFIG_H__
+#define __CMSIS_DRIVER_CONFIG_H__
+
+#include "platform_retarget_dev.h"
+#include "RTE_Device.h"
+#include "target_cfg.h"
+
+#ifdef RTE_USART0
+#define UART0_DEV       ARM_UART0_DEV_NS
+#endif
+
+#ifdef RTE_USART1
+#ifdef SECURE_UART1
+#define UART1_DEV       ARM_UART1_DEV_S
+#else
+#define UART1_DEV       ARM_UART1_DEV_NS
+#endif
+#endif
+
+#endif  /* __CMSIS_DRIVER_CONFIG_H__ */
diff --git a/platform/ext/target/mps2/an521/cmsis_drivers/Driver_USART.c b/platform/ext/target/mps2/an521/cmsis_drivers/Driver_USART.c
index 489708e..3b35d0a 100644
--- a/platform/ext/target/mps2/an521/cmsis_drivers/Driver_USART.c
+++ b/platform/ext/target/mps2/an521/cmsis_drivers/Driver_USART.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2017 ARM Limited. All rights reserved.
+ * Copyright (c) 2013-2018 ARM Limited. All rights reserved.
  *
  * SPDX-License-Identifier: Apache-2.0
  *
@@ -19,7 +19,7 @@
 #include "Driver_USART.h"
 
 #include "cmsis.h"
-#include "platform_retarget_dev.h"
+#include "cmsis_driver_config.h"
 #include "RTE_Device.h"
 
 #ifndef ARG_UNUSED
@@ -211,11 +211,7 @@
 #if (RTE_USART0)
 /* USART0 Driver wrapper functions */
 static UARTx_Resources USART0_DEV = {
-#if (__DOMAIN_NS == 1)
-    .dev = &ARM_UART0_DEV_NS,
-#else
-    .dev = &ARM_UART0_DEV_S,
-#endif
+    .dev = &UART0_DEV,
     .tx_nbr_bytes = 0,
     .rx_nbr_bytes = 0,
     .cb_event = NULL,
@@ -313,11 +309,7 @@
 #if (RTE_USART1)
 /* USART1 Driver wrapper functions */
 static UARTx_Resources USART1_DEV = {
-#if (__DOMAIN_NS == 1)
-    .dev = &ARM_UART1_DEV_NS,
-#else
-    .dev = &ARM_UART1_DEV_S,
-#endif
+    .dev = &UART1_DEV,
     .tx_nbr_bytes = 0,
     .rx_nbr_bytes = 0,
     .cb_event = NULL,
@@ -415,11 +407,7 @@
 #if (RTE_USART2)
 /* USART2 Driver wrapper functions */
 static UARTx_Resources USART2_DEV = {
-#if (__DOMAIN_NS == 1)
-    .dev = &ARM_UART2_DEV_NS,
-#else
-    .dev = &ARM_UART2_DEV_S,
-#endif
+    .dev = &UART2_DEV,
     .tx_nbr_bytes = 0,
     .rx_nbr_bytes = 0,
     .cb_event = NULL,
@@ -517,11 +505,7 @@
 #if (RTE_USART3)
 /* USART3 Driver wrapper functions */
 static UARTx_Resources USART3_DEV = {
-#if (__DOMAIN_NS == 1)
-    .dev = &ARM_UART3_DEV_NS,
-#else
-    .dev = &ARM_UART3_DEV_S,
-#endif
+    .dev = &UART3_DEV,
     .tx_nbr_bytes = 0,
     .rx_nbr_bytes = 0,
     .cb_event = NULL,
@@ -619,11 +603,7 @@
 #if (RTE_USART4)
 /* USART4 Driver wrapper functions */
 static UARTx_Resources USART4_DEV = {
-#if (__DOMAIN_NS == 1)
-    .dev = &ARM_UART4_DEV_NS,
-#else
-    .dev = &ARM_UART4_DEV_S,
-#endif
+    .dev = &UART4_DEV,
     .tx_nbr_bytes = 0,
     .rx_nbr_bytes = 0,
     .cb_event = NULL,
diff --git a/platform/ext/target/mps2/an521/target_cfg.h b/platform/ext/target/mps2/an521/target_cfg.h
index c9c3cf1..6430113 100644
--- a/platform/ext/target/mps2/an521/target_cfg.h
+++ b/platform/ext/target/mps2/an521/target_cfg.h
@@ -17,8 +17,13 @@
 #ifndef __SSE200_TARGET_CFG_H__
 #define __SSE200_TARGET_CFG_H__
 
+#include "arm_uart_drv.h"
+#include "platform/ext/common/uart_stdout.h"
 #include "tfm_peripherals_def.h"
 
+#define TFM_DRIVER_STDIO    Driver_USART0
+#define NS_DRIVER_STDIO     Driver_USART0
+
 /**
  * \brief Defines the word offsets of Slave Peripheral Protection Controller
  *        Registers
diff --git a/platform/ext/target/musca_a/CMSIS_Driver/Config/cmsis_driver_config.h b/platform/ext/target/musca_a/CMSIS_Driver/Config/cmsis_driver_config.h
new file mode 100644
index 0000000..d343cbf
--- /dev/null
+++ b/platform/ext/target/musca_a/CMSIS_Driver/Config/cmsis_driver_config.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2018 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CMSIS_DRIVER_CONFIG_H__
+#define __CMSIS_DRIVER_CONFIG_H__
+
+#include "platform_retarget_dev.h"
+#include "RTE_Device.h"
+#include "target_cfg.h"
+
+#ifdef RTE_USART0
+#define UART0_DEV           UART0_DEV_NS
+#define ARM_SCC_DEV         ARM_SCC_DEV_NS /* only UART0 requires SCC */
+#endif
+
+#ifdef RTE_USART1
+#define UART1_DEV           UART1_DEV_NS
+#endif
+
+#endif  /* __CMSIS_DRIVER_CONFIG_H__ */
diff --git a/platform/ext/target/musca_a/CMSIS_Driver/Driver_USART.c b/platform/ext/target/musca_a/CMSIS_Driver/Driver_USART.c
index 90a25e6..0a17875 100755
--- a/platform/ext/target/musca_a/CMSIS_Driver/Driver_USART.c
+++ b/platform/ext/target/musca_a/CMSIS_Driver/Driver_USART.c
@@ -19,7 +19,7 @@
 #include "Driver_USART.h"
 
 #include "cmsis.h"
-#include "platform_retarget_dev.h"
+#include "cmsis_driver_config.h"
 #include "RTE_Device.h"
 
 #ifndef ARG_UNUSED
@@ -214,11 +214,7 @@
 #if (RTE_USART0)
 /* USART0 Driver wrapper functions */
 static UARTx_Resources USART0_DEV = {
-#if (__DOMAIN_NS == 1)
-    .dev = &UART0_DEV_NS,
-#else
-    .dev = &UART0_DEV_S,
-#endif
+    .dev = &UART0_DEV,
     .tx_nbr_bytes = 0,
     .rx_nbr_bytes = 0,
     .cb_event = NULL,
@@ -228,13 +224,8 @@
 {
     USART0_DEV.cb_event = cb_event;
 
-#if (__DOMAIN_NS == 1)
-    arm_scc_set_alt_func(&ARM_SCC_DEV_NS, GPIO_ALTFUNC_1, 1<<AHB_GPIO0_0);
-    arm_scc_set_alt_func(&ARM_SCC_DEV_NS, GPIO_ALTFUNC_1, 1<<AHB_GPIO0_1);
-#else
-    arm_scc_set_alt_func(&ARM_SCC_DEV_S, GPIO_ALTFUNC_1, 1<<AHB_GPIO0_0);
-    arm_scc_set_alt_func(&ARM_SCC_DEV_S, GPIO_ALTFUNC_1, 1<<AHB_GPIO0_1);
-#endif
+    arm_scc_set_alt_func(&ARM_SCC_DEV, GPIO_ALTFUNC_1, 1<<AHB_GPIO0_0);
+    arm_scc_set_alt_func(&ARM_SCC_DEV, GPIO_ALTFUNC_1, 1<<AHB_GPIO0_1);
 
     return ARM_USARTx_Initialize(&USART0_DEV);
 }
@@ -324,11 +315,7 @@
 #if (RTE_USART1)
 /* USART1 Driver wrapper functions */
 static UARTx_Resources USART1_DEV = {
-#if (__DOMAIN_NS == 1)
-    .dev = &UART1_DEV_NS,
-#else
-    .dev = &UART1_DEV_S,
-#endif
+    .dev = &UART1_DEV,
     .tx_nbr_bytes = 0,
     .rx_nbr_bytes = 0,
     .cb_event = NULL,
diff --git a/platform/ext/target/musca_a/target_cfg.h b/platform/ext/target/musca_a/target_cfg.h
index 25bdeaf..a0d6560 100755
--- a/platform/ext/target/musca_a/target_cfg.h
+++ b/platform/ext/target/musca_a/target_cfg.h
@@ -17,7 +17,12 @@
 #ifndef __TARGET_CFG_H__
 #define __TARGET_CFG_H__
 
+#include "platform/ext/common/uart_stdout.h"
 #include "tfm_peripherals_def.h"
+#include "uart_pl011_drv.h"
+
+#define TFM_DRIVER_STDIO    Driver_USART1
+#define NS_DRIVER_STDIO     Driver_USART1
 
 enum ppc_bank_e
 {
diff --git a/secure_fw/core/tfm_core.c b/secure_fw/core/tfm_core.c
index c21db00..0cb5afc 100644
--- a/secure_fw/core/tfm_core.c
+++ b/secure_fw/core/tfm_core.c
@@ -122,7 +122,7 @@
 
     __enable_irq();
 
-    uart_init(UART0_CHANNEL);
+    stdio_init();
     LOG_MSG("Secure image initializing!");
 
 #ifdef TFM_CORE_DEBUG