Platform: Clean up uart_stdout
Details:
- Change the functions used to redirect standard output to UART not to
be declared as weak symbol. These symbols are declared as weak in the
standard library. They are intended to be "overridden" by the
application. And the application in this case is TF-M.
- Remove uart_putc from uart_stdout.h because it should only be used
from uart_stdout.c. All writes to UART should happen through library
functions that are writing to standard out.
- Remove uart_getc as it is not used.
- Add comments
- Fix coding style issues
Change-Id: Ia042cd9104bf1a0f68c028dbe4b6c14e6df05a46
Signed-off-by: Mate Toth-Pal <mate.toth-pal@arm.com>
diff --git a/platform/ext/common/uart_stdout.c b/platform/ext/common/uart_stdout.c
index 401b0b6..75e8b18 100755
--- a/platform/ext/common/uart_stdout.c
+++ b/platform/ext/common/uart_stdout.c
@@ -32,22 +32,40 @@
*/
FILE __stdout;
-/* Redirects printf to TFM_DRIVER_STDIO */
-__attribute__ ((weak)) int fputc(int ch, FILE *f) {
+static void uart_putc(unsigned char c)
+{
+ int32_t ret = ARM_DRIVER_OK;
+
+ ret = TFM_DRIVER_STDIO.Send(&c, 1);
+ ASSERT_HIGH(ret);
+}
+
+/* Redirects printf to TFM_DRIVER_STDIO in case of ARMCLANG*/
+#if defined(__ARMCC_VERSION)
+/* __ARMCC_VERSION is only defined starting from Arm compiler version 6 */
+int fputc(int ch, FILE *f)
+{
/* Send byte to USART */
uart_putc(ch);
/* Return character written */
return ch;
}
-
-int _write(int fd, char * str, int len)
+#elif defined(__GNUC__)
+/* Redirects printf to TFM_DRIVER_STDIO in case of GNUARM */
+int _write(int fd, char *str, int len)
{
- for (int i = 0; i < len; i++) {
+ int i;
+
+ for (i = 0; i < len; i++) {
+ /* Send byte to USART */
uart_putc(str[i]);
}
+
+ /* Return the number of characters written */
return len;
}
+#endif
void stdio_init(void)
{
@@ -59,21 +77,3 @@
ASSERT_HIGH(ret);
}
-void uart_putc(unsigned char c)
-{
- int32_t ret = ARM_DRIVER_OK;
-
- ret = TFM_DRIVER_STDIO.Send(&c, 1);
- ASSERT_HIGH(ret);
-}
-
-unsigned char uart_getc(void)
-{
- unsigned char c = 0;
- int32_t ret = ARM_DRIVER_OK;
-
- ret = TFM_DRIVER_STDIO.Receive(&c, 1);
- ASSERT_HIGH(ret);
-
- return c;
-}