MLECO-1948: Fix for SysTick init and GNU's stdout

The counter val could have been 0 when read the first time
quickly after the init function. The init function will now
wait for the SysTick counter to start before returning.

Also included are some minor changes to get around  GNU's
file stream implementation being line buffered.

Change-Id: I8d51fef5d85f1261a6a5710608349d7ecc19ad62
diff --git a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/timer_mps3.c b/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/timer_mps3.c
index a72103c..c0c3bdf 100644
--- a/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/timer_mps3.c
+++ b/source/application/hal/platforms/bare-metal/bsp/bsp-packs/mps3/timer_mps3.c
@@ -41,12 +41,11 @@
         .counter_fpga       = MPS3_FPGAIO->COUNTER,
         .counter_systick    = Get_SysTick_Cycle_Count()
     };
-    debug("Timestamp:"
-        "\n\tCounter 1 Hz:   %" PRIu32
-        "\n\tCounter 100 Hz: %" PRIu32
-        "\n\tCounter FPGA:   %" PRIu32
-        "\n\tCounter CPU:    %" PRIu64 "\n",
-        t.counter_1Hz, t.counter_100Hz, t.counter_fpga, t.counter_systick);
+    debug("Timestamp:\n");
+    debug("\tCounter 1 Hz:   %" PRIu32 "\n", t.counter_1Hz);
+    debug("\tCounter 100 Hz: %" PRIu32 "\n", t.counter_100Hz);
+    debug("\tCounter FPGA:   %" PRIu32 "\n", t.counter_fpga);
+    debug("\tCounter CPU:    %" PRIu64 "\n", t.counter_systick);
     return t;
 }
 
diff --git a/source/application/hal/platforms/bare-metal/bsp/cmsis-device/irqs.c b/source/application/hal/platforms/bare-metal/bsp/cmsis-device/irqs.c
index 7c9f4b8..7d8aa06 100644
--- a/source/application/hal/platforms/bare-metal/bsp/cmsis-device/irqs.c
+++ b/source/application/hal/platforms/bare-metal/bsp/cmsis-device/irqs.c
@@ -71,7 +71,8 @@
 
 #define DEFAULT_HANDLER_CALL(type)              \
     do {                                        \
-        printf("\n%s caught by function %s\n",  \
+        printf("\n");                           \
+        printf("%s caught by function %s\n",    \
              type, __FUNCTION__);               \
         DefaultHandler();                       \
     } while (0)
@@ -238,6 +239,11 @@
     /* Enable interrupt again. */
     NVIC_EnableIRQ(SysTick_IRQn);
 
+    /* Wait for SysTick to kick off */
+    while (!err && !SysTick->VAL) {
+        __NOP();
+    }
+
     return err;
 }
 
diff --git a/source/application/main/Mfcc.cc b/source/application/main/Mfcc.cc
index c998ef2..2d697ee 100644
--- a/source/application/main/Mfcc.cc
+++ b/source/application/main/Mfcc.cc
@@ -45,22 +45,17 @@
                         m_useHtkMethod(useHtkMethod)
     {}
 
-    std::string MfccParams::Str() const
+    void MfccParams::Log() const
     {
-        char strC[1024];
-        snprintf(strC, sizeof(strC) - 1, "\n   \
-            \n\t Sampling frequency:         %f\
-            \n\t Number of filter banks:     %" PRIu32 "\
-            \n\t Mel frequency limit (low):  %f\
-            \n\t Mel frequency limit (high): %f\
-            \n\t Number of MFCC features:    %" PRIu32 "\
-            \n\t Frame length:               %" PRIu32 "\
-            \n\t Padded frame length:        %" PRIu32 "\
-            \n\t Using HTK for Mel scale:    %s\n",
-            this->m_samplingFreq, this->m_numFbankBins, this->m_melLoFreq,
-            this->m_melHiFreq, this->m_numMfccFeatures, this->m_frameLen,
-            this->m_frameLenPadded, this->m_useHtkMethod ? "yes" : "no");
-        return std::string{strC};
+        debug("MFCC parameters:\n");
+        debug("\t Sampling frequency:         %f\n", this->m_samplingFreq);
+        debug("\t Number of filter banks:     %" PRIu32 "\n", this->m_numFbankBins);
+        debug("\t Mel frequency limit (low):  %f\n", this->m_melLoFreq);
+        debug("\t Mel frequency limit (high): %f\n", this->m_melHiFreq);
+        debug("\t Number of MFCC features:    %" PRIu32 "\n", this->m_numMfccFeatures);
+        debug("\t Frame length:               %" PRIu32 "\n", this->m_frameLen);
+        debug("\t Padded frame length:        %" PRIu32 "\n", this->m_frameLenPadded);
+        debug("\t Using HTK for Mel scale:    %s\n", this->m_useHtkMethod ? "yes" : "no");
     }
 
     MFCC::MFCC(const MfccParams& params):
@@ -84,7 +79,7 @@
         }
 
         math::MathUtils::FftInitF32(this->m_params.m_frameLenPadded, this->m_fftInstance);
-        debug("Instantiated MFCC object: %s\n", this->m_params.Str().c_str());
+        this->m_params.Log();
     }
 
     void MFCC::Init()
diff --git a/source/application/main/include/Mfcc.hpp b/source/application/main/include/Mfcc.hpp
index 6b11ebb..86330ca 100644
--- a/source/application/main/include/Mfcc.hpp
+++ b/source/application/main/include/Mfcc.hpp
@@ -51,8 +51,8 @@
 
         ~MfccParams() = default;
 
-        /** @brief  String representation of parameters */
-        std::string Str() const;
+        /** @brief  Log parameters */
+        void Log() const;
     };
 
     /**
diff --git a/source/use_case/ad/src/MainLoop.cc b/source/use_case/ad/src/MainLoop.cc
index 6a7cbe0..6431509 100644
--- a/source/use_case/ad/src/MainLoop.cc
+++ b/source/use_case/ad/src/MainLoop.cc
@@ -31,7 +31,8 @@
 
 static void DisplayMenu()
 {
-    printf("\n\nUser input required\n");
+    printf("\n");
+    printf("User input required\n");
     printf("Enter option number from:\n\n");
     printf("  %u. Classify next audio signal\n", MENU_OPT_RUN_INF_NEXT);
     printf("  %u. Classify audio signal at chosen index\n", MENU_OPT_RUN_INF_CHOSEN);
diff --git a/source/use_case/asr/src/MainLoop.cc b/source/use_case/asr/src/MainLoop.cc
index 9950541..24b6fcd 100644
--- a/source/use_case/asr/src/MainLoop.cc
+++ b/source/use_case/asr/src/MainLoop.cc
@@ -35,7 +35,8 @@
 
 static void DisplayMenu()
 {
-    printf("\n\nUser input required\n");
+    printf("\n\n");
+    printf("User input required\n");
     printf("Enter option number from:\n\n");
     printf("  %u. Classify next audio clip\n", MENU_OPT_RUN_INF_NEXT);
     printf("  %u. Classify audio clip at chosen index\n", MENU_OPT_RUN_INF_CHOSEN);
diff --git a/source/use_case/img_class/src/MainLoop.cc b/source/use_case/img_class/src/MainLoop.cc
index 66d7064..255f8e0 100644
--- a/source/use_case/img_class/src/MainLoop.cc
+++ b/source/use_case/img_class/src/MainLoop.cc
@@ -35,7 +35,8 @@
 
 static void DisplayMenu()
 {
-    printf("\n\nUser input required\n");
+    printf("\n\n");
+    printf("User input required\n");
     printf("Enter option number from:\n\n");
     printf("  %u. Classify next image\n", MENU_OPT_RUN_INF_NEXT);
     printf("  %u. Classify image at chosen index\n", MENU_OPT_RUN_INF_CHOSEN);
diff --git a/source/use_case/kws/src/MainLoop.cc b/source/use_case/kws/src/MainLoop.cc
index f971c30..48cdad4 100644
--- a/source/use_case/kws/src/MainLoop.cc
+++ b/source/use_case/kws/src/MainLoop.cc
@@ -35,7 +35,8 @@
 
 static void DisplayMenu()
 {
-    printf("\n\nUser input required\n");
+    printf("\n\n");
+    printf("User input required\n");
     printf("Enter option number from:\n\n");
     printf("  %u. Classify next audio clip\n", MENU_OPT_RUN_INF_NEXT);
     printf("  %u. Classify audio clip at chosen index\n", MENU_OPT_RUN_INF_CHOSEN);
diff --git a/source/use_case/kws_asr/src/MainLoop.cc b/source/use_case/kws_asr/src/MainLoop.cc
index 631b7c1..3a69315 100644
--- a/source/use_case/kws_asr/src/MainLoop.cc
+++ b/source/use_case/kws_asr/src/MainLoop.cc
@@ -40,7 +40,8 @@
 
 static void DisplayMenu()
 {
-    printf("\n\nUser input required\n");
+    printf("\n\n");
+    printf("User input required\n");
     printf("Enter option number from:\n\n");
     printf("  %u. Classify next audio clip\n", MENU_OPT_RUN_INF_NEXT);
     printf("  %u. Classify audio clip at chosen index\n", MENU_OPT_RUN_INF_CHOSEN);