+/* Busy-loop block implementation. Each iteration will take 3 CPU cycles.
+ * Of course, when interrupts are enabled, the exact delay time will be
+ * uncertain.
+ *
+ * Example: for a standard STM32x config board (8MHz) the maximum delay is
+ * 0xFFFF * (1/8,000,000) * 3 = 24.58ms
+ * */
+static void __block(uint16_t count) {
+
+ asm volatile("b1: subs %0, %1, #1" "\n\t"
+ "bne b1" : "=r" (count) : "r" (count));
+}
+
+/* Delay us microsecond
+ * Note: delay includes setup time (about 4 clockcycles), so is quite
+ * inaccurate */
+void _block(uint16_t us) {
+
+ uint16_t count = (us/3) * CLKSPEED_MHZ; // x cycles
+ __block(count);
+
+}
+