   return D;
 }
 
+// Tell the CPLD to return control of the flash to the host machine
 void flash_unlock() {
   // Reset allowing_arm_access to 1 in the CPLD
   digitalWrite(CPLD_SS_PIN, LOW);

  digitalWrite(CPLD_SS_PIN, HIGH);
}

void setup() {
  // Set pin directions for CPLD JTAG.
  pinMode(TDO_PIN, INPUT);

      }
      case 'I': {
        Serial.println("IDENTIFY FLASH");

        flash_write(0x55, 0x00980098L);  // Enter CFI mode

        Serial.print("Device size: 2^");
        Serial.print(flash_read(0x27) & 0xffff);
        Serial.println(" bytes");

        for (uint32_t cfi_addr = 0x10; cfi_addr <= 0x50; ++cfi_addr) {
          Serial.print("CFI 0x");
          Serial.print(cfi_addr, HEX);
          Serial.print(": ");
          Serial.println(flash_read(cfi_addr), HEX);
        }

        flash_write(0x00, 0xf0);  // Exit CFI mode
        flash_unlock();  // Allow host access again

        break;
      }
      case 'P': {
        chip_end = chip_size();
        Serial.print("Program whole chip.  Size = ");
        Serial.println(chip_end * 2);  // Because we actually have double this
        program_range(0, chip_end);
        flash_unlock();
        reset();
        break;
      }
      case 'Z': {
