Esempio n. 1
0
//! Print bdm option structure to log file
//!
//! @param options - options to report
//!
void printBdmOptions(const USBDM_ExtendedOptions_t *options) {
   print("========================================\n"
         "autoReconnect         => %s\n"
         "bdmClockSource        => %s\n"
         "cycleVddOnConnect     => %s\n"
         "cycleVddOnReset       => %s\n"
         "guessSpeed            => %s\n"
         "interfaceFrequency    => %d kHz\n"
         "leaveTargetPowered    => %s\n"
         "maskInterrupts        => %s\n"
         "powerOffDuration      => %d ms\n"
         "powerRecoveryInterval => %d ms\n"
         "resetDuration         => %d ms\n"
         "resetReleaseInterval  => %d ms\n"
         "resetRecoveryInterval => %d ms\n"
         "size                  => %d\n"
         "targetType            => %s\n"
         "targetVdd             => %s\n"
         "usePSTSignals         => %s\n"
         "useResetSignal        => %s\n"
         "========================================\n",
         getAutoConnectName(options->autoReconnect),
         getClockSelectName(options->bdmClockSource),
         options->cycleVddOnConnect?"T":"F",
         options->cycleVddOnReset?"T":"F",
         options->guessSpeed?"T":"F",
         options->interfaceFrequency,
         options->leaveTargetPowered?"T":"F",
         options->maskInterrupts?"T":"F",
         options->powerOffDuration,
         options->powerOnRecoveryInterval,
         options->resetDuration,
         options->resetReleaseInterval,
         options->resetRecoveryInterval,
         options->size,
         getTargetTypeName(options->targetType),
         getVoltageSelectName(options->targetVdd),
         options->usePSTSignals?"T":"F",
         options->useResetSignal?"T":"F"
         );
}
USBDM_ErrorCode usbdmInit(TargetType_t targetType = T_CFV1) {
   unsigned int deviceCount;
   unsigned int deviceNum;
   USBDM_ErrorCode rc = USBDM_Init();
   if (rc != BDM_RC_OK) {
      return rc;
   }
   rc = USBDM_FindDevices(&deviceCount);
   print( "usbdmInit(): Usb initialised, found %d device(s)\n", deviceCount);
   print("After USBDM_FindDevices, Time = %f\n", progressTimer->elapsedTime());
   if (rc != BDM_RC_OK) {
      return rc;
   }
   deviceNum  = 0;
   rc = USBDM_Open(deviceNum);
   if (rc != BDM_RC_OK) {
      print( "usbdmInit(): Failed to open %s, device #%d\n", getTargetTypeName(targetType), deviceNum);
      return rc;
   }
   print( "usbdmInit(): Opened %s, device #%d\n", getTargetTypeName(targetType), deviceNum);
   print("After USBDM_Open, Time = %f\n", progressTimer->elapsedTime());
   // Set up sensible default since we can't change this (at the moment)
   USBDM_ExtendedOptions_t bdmOptions = {sizeof(USBDM_ExtendedOptions_t), TARGET_TYPE};
   USBDM_GetDefaultExtendedOptions(&bdmOptions);
   bdmOptions.targetVdd                  = BDM_TARGET_VDD_3V3; // BDM_TARGET_VDD_NONE;
   bdmOptions.autoReconnect              = AUTOCONNECT_ALWAYS; // Aggressively auto-connect
   bdmOptions.guessSpeed                 = FALSE;
   bdmOptions.cycleVddOnConnect          = FALSE;
   bdmOptions.cycleVddOnReset            = FALSE;
   bdmOptions.leaveTargetPowered         = FALSE;
   bdmOptions.bdmClockSource             = CS_DEFAULT;
   bdmOptions.useResetSignal             = FALSE;
   bdmOptions.usePSTSignals              = FALSE;
   bdmOptions.interfaceFrequency         = 1000; // 1MHz
   bdmOptions.powerOnRecoveryInterval    = 100;
   bdmOptions.resetDuration              = 100;
   bdmOptions.resetReleaseInterval       = 100;
   bdmOptions.resetRecoveryInterval      = 100;
   rc = USBDM_SetExtendedOptions(&bdmOptions);
   if (rc != BDM_RC_OK) {
      print( "usbdmInit(): USBDM_SetExtendedOptions() failed\n");
      return rc;
   }
   print("After USBDM_SetExtendedOptions, Time = %f\n", progressTimer->elapsedTime());
   rc = USBDM_SetTargetType(targetType);
   if (rc != BDM_RC_OK) {
      print( "usbdmInit(): USBDM_SetTargetType() failed\n");
      return rc;
   }
   print("After USBDM_SetTargetType, Time = %f\n", progressTimer->elapsedTime());
   USBDM_TargetReset((TargetMode_t)(RESET_DEFAULT|RESET_SPECIAL));
   print("After USBDM_TargetReset, Time = %f\n", progressTimer->elapsedTime());
   if (USBDM_Connect() != BDM_RC_OK) {
      print( "usbdmInit(): Connecting failed - retry\n");
      USBDM_TargetReset((TargetMode_t)(RESET_DEFAULT|RESET_SPECIAL));
      rc = USBDM_Connect();
      if (rc != BDM_RC_OK) {
         print( "targetConnect(): USBDM_SetTargetType() failed\n");
         return rc;
      }
   }
   print("After targetConnect, Time = %f\n", progressTimer->elapsedTime());
   return BDM_RC_OK;
}