8 Replies Latest reply on Dec 28, 2016 7:35 AM by vasilyvs_1494681

    What is the correct C# code to this?

    aegea.liang

      Hi,

         

      I can program a hex file with a MiniProg3 and its GUI application as attached picture shows.

         

      Then I followed the sample code in "C:\Program Files (x86)\Cypress\Programmer\Examples\Programming\PSoC3_5\SWD\C_Sharp", if I run this sample code directly without any changes, the prompt tells me:

         

      "Failed! PSoC device is not acquired! Check connection of the chip to the programmer"

         

       

         

      So I change the code with the settings on the GUI application, Below is the code of setting part in ProgramAll() function:

         

      Mainly I have many issues on:

         

      1. The prompt tells me "Failed! Device is not in ISSP mode"

         

      2. CheckHexAndDeviceCompatibility() function could not pass.

         

      3. EraseAll() function is unable to run.

         

      4. Sometime I change the "Power" mode to "Power Cycle", sometimes I change the function from xxx() to PsoC3_xxx() if I found there is one, but it still could not work. Anyone know what's wrong there? Thanks!

         

       

         

       

         

      Code:

         

       

         

      if (pp == null) return -1;

         

      string filePath = "E:/Projects/X2/CRTS-XRAY-XPS-Bootloader-v3.2.hex";

         

      int hr;

         

      //Port Initialization

         

      //Setup Power - "5.0V" and internal

         

      hr = pp.SetPowerVoltage("0.5", out m_sLastError);

         

      if (!SUCCEEDED(hr)) return hr;

         

      hr = pp.PowerOn(out m_sLastError);

         

      if (!SUCCEEDED(hr)) return hr;

         

      //Set protocol, connector and frequency

         

      hr = pp.SetProtocol(enumInterfaces.SWD, out m_sLastError); //SWD-protocol

         

      if (!SUCCEEDED(hr)) return hr;

         

      hr = pp.SetProtocolConnector(0, out m_sLastError); //5-pin connector

         

      if (!SUCCEEDED(hr)) return hr;

         

      hr = pp.PSoC3_SetProtocolClock(enumFrequencies.FREQ_01_6, out m_sLastError); //3.0 MHz clock on SWD bus

         

      // Set Hex File

         

      int hexImageSize;

         

      hr = pp.HEX_ReadFile(filePath, out hexImageSize, out m_sLastError);

         

      if (!SUCCEEDED(hr)) return hr;

         

      //Set Acquire Mode

         

      pp.SetAcquireMode("Power", out m_sLastError);

         

      //The "Programming Flow" proper

         

      //Acquire Device

         

      //hr = pp.DAP_Acquire(out m_sLastError);

         

      hr = pp.DAP_Acquire(out m_sLastError);

         

      if (!SUCCEEDED(hr)) return hr;

         

      //Check Hex File and Device compatibility

         

      //bool fCompatibility;

         

      //hr = CheckHexAndDeviceCompatibility(out fCompatibility);

         

      //if (!SUCCEEDED(hr)) return hr;

         

      //if (!fCompatibility)

         

      //{

         

      // m_sLastError = "The Hex file does not match the acquired device, please connect the appropriate device";

         

      // return -1;

         

      //}

         

      //Erase All

         

      hr = pp.EraseAll(out m_sLastError);

         

      if (!SUCCEEDED(hr)) return hr;