     return 0;
 }
 
+// wait for an ACK reply, else print an error message and halt
 static void wantAck () {
     uint8_t b = 0;
+    // wait a bit longer than normal getReply() timeouts, if needed
     for (int i = 0; i < 5; ++i) {
         b = getReply();
         if (b == 0) {
-            Serial.print('.');
+            Serial.print('.'); // each retry prints a dot
             continue;
         }
         if (b != ACK)
             break;
-        check = 0;
+        check = 0; // the global checksum is always cleared after an ACK
         return;
     }
     Serial.print(" FAILED - got 0x");
     Serial.println(b, HEX);
-    while (true)
-        ; // halt
-}
-
+    while (true) ; // halt
+}
+
+// send a byte to the target and update the global checkum value
 static void sendByte (uint8_t b) {
     check ^= b;
     Target.write(b);
 }
 
+// send a command and wait for the coorresponding ACK
 static void sendCmd (uint8_t cmd) {
     Serial.flush();
     sendByte(cmd);

#endif
}

void setup () {
    Serial.begin(115200);
    Serial.print("[stm32f1init] ");

    wantAck();
}

// special infinite loop to trigger target autobaud and wait for ACK or NAK
static void connectToTarget () {
#ifdef __AVR_ATmega328P__   // use a modified SoftwareSerial implementation
    Target.begin(9600);
