Platform: UART: Align to CMSIS flow

Clarify rationale for busy wait loop and for trying to
POWER_OFF during un-init. For more details on the call flow:

https://www.keil.com/pack/doc/CMSIS_Dev/Driver/html/theoryOperation.html#CallSequence

Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
Change-Id: Id3cc6c4873bb04211588e3ea63369809af2a1741
diff --git a/platform/ext/common/uart_stdout.c b/platform/ext/common/uart_stdout.c
index 24aa38d..6e9277f 100644
--- a/platform/ext/common/uart_stdout.c
+++ b/platform/ext/common/uart_stdout.c
@@ -37,15 +37,17 @@
 {
     int32_t ret;
 
-    /* Add a busy wait before sending. */
-    while (STDIO_DRIVER.GetStatus().tx_busy);
-
     ret = STDIO_DRIVER.Send(str, len);
     if (ret != ARM_DRIVER_OK) {
         return 0;
     }
 
-    /* Add a busy wait after sending. */
+    /* Busy wait after Send(). CMSIS mandates the Send() to be non-blocking,
+     * while TF-M's current implementation expects to block on Send(), i.e.
+     * polling the tx_busy itself in driver code. For this reason the below
+     * busy wait does not have any practical effect, but we keep it in place
+     * for those platforms which might decide to implement IRQ-based UART
+     */
     while (STDIO_DRIVER.GetStatus().tx_busy);
 
     return STDIO_DRIVER.GetTxCount();
@@ -134,6 +136,15 @@
 {
     int32_t ret = ARM_DRIVER_ERROR;
 
+    ret = STDIO_DRIVER.PowerControl(ARM_POWER_OFF);
+    /* FixMe: Still allow this function not to be implemented as in blocking
+     *        mode there is not much that needs to be done when powering off
+     */
+    if ((ret != ARM_DRIVER_OK) && (ret != ARM_DRIVER_ERROR_UNSUPPORTED)) {
+        assert(0);
+        return;
+    }
+
     ret = STDIO_DRIVER.Uninitialize();
     if (ret != ARM_DRIVER_OK) {
         assert(0);