[spi] Return error when timer runs out instead of quietly fail

Change-Id: I5567363e9111f0879784707bc681685ddbd0d91e
diff --git a/firmware/src/drivers/bosch_bmi160/bosch_bmi160.c b/firmware/src/drivers/bosch_bmi160/bosch_bmi160.c
index 6e21cb5..33c96a5 100644
--- a/firmware/src/drivers/bosch_bmi160/bosch_bmi160.c
+++ b/firmware/src/drivers/bosch_bmi160/bosch_bmi160.c
@@ -3732,8 +3732,8 @@
             "crcb,e:%d,s:%d", err, (int)GET_STATE());
     bool int1 = gpioGet(T(Int1));
     if (err != 0) {
-        //DEBUG_PRINT_IF(DBG_CHUNKED, "crd retry");
-        INFO_PRINT("crd retry");
+        // TODO: force debug statement for b/29625330, remove it after bug being resolved
+        DEBUG_PRINT_IF(1 || DBG_CHUNKED, "spi err, crd retry");
         // read full fifo length to be safe
         chunkedReadInit(0, FIFO_READ_SIZE);
         return;
diff --git a/firmware/src/spi.c b/firmware/src/spi.c
index fb28d47..afa58a3 100644
--- a/firmware/src/spi.c
+++ b/firmware/src/spi.c
@@ -23,6 +23,14 @@
 #include <spi_priv.h>
 #include <timer.h>
 
+#define INFO_PRINT(fmt, ...) do { \
+        osLog(LOG_INFO, "%s " fmt, "[spi]", ##__VA_ARGS__); \
+    } while (0);
+
+#define ERROR_PRINT(fmt, ...) do { \
+        osLog(LOG_ERROR, "%s " fmt, "[spi] ERROR:", ##__VA_ARGS__); \
+    } while (0);
+
 struct SpiDeviceState {
     struct SpiDevice dev;
 
@@ -109,10 +117,14 @@
     } else {
         size_t i = state->currentBuf++;
 
-        if (state->packets[i].delay > 0)
-            timTimerSet(state->packets[i].delay, 0, 50, spiDelayCallback, state, true);
-        else
+        if (state->packets[i].delay > 0) {
+            if (!timTimerSet(state->packets[i].delay, 0, 50, spiDelayCallback, state, true)) {
+                ERROR_PRINT("Cannot do delayed spi, timer depleted\n");
+                spiMasterDone(state, -ENOMEM); // should be out of timer; out of mem is close enough
+            }
+        } else {
             spiMasterNext(state);
+        }
     }
 }