コード例 #1
0
        public bool AcquireAndEraseSFlash()
        {
            int    hr       = S_OK;
            string strError = "";

            if (!InitializeProgrammer())
            {
                return(false);
            }

            //-1-. Acquire part (it automatically sets IMO to 48 MHz to enable Flash Updates)
            hr = Programmer.DAP_Acquire(out strError);
            if (!IsSuccess(hr))
            {
                Log.PrintLog(this, strError, LogDetailLevel.LogRelevant);
                return(false);
            }

            //-2-. Check if this is PSoC4-BLE family
            byte[] siliconID;
            hr = Programmer.PSoC4_GetSiliconID(out siliconID, out strError);
            if (!IsSuccess(hr))
            {
                Log.PrintLog(this, strError, LogDetailLevel.LogRelevant);
                return(false);
            }

            if (siliconID[3] == 0x9E) //check Family ID field for "BLE" and "BLE256K"
            {
                ble_Family = BLE_FAMILY.BLE_128K;
            }
            else if ((siliconID[3] == 0xA3) || (siliconID[3] == 0xAA) || (siliconID[3] == 0xAE)) //BLE-256, BLE-256-DMA, BLEvII
            {
                ble_Family = BLE_FAMILY.BLE_256K;
            }
            else
            {
                strError = "Detected target is not from PSoC4-BLE family. Please connect correct device.";
                return(false);
            }

            //-3-. Move Chip into OPEN state (if in PROTECTED state now). User SFLASH rows can be updated only in OPEN state.
            TestStatusUpdate(MTKTestMessageType.Information, "Erasing...");
            hr = PSoC4_EraseAll();
            if (!IsSuccess(hr))
            {
                Log.PrintLog(this, "Unable to erase chip.", LogDetailLevel.LogRelevant);
                return(false);
            }

            return(true);
        }