- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to write a mass programmer for production.
The PSoC4/SWD/Cpp-EX Example code provided for erase flash dose not seam to actually be able to clear chip protection.
The code as written in the original example did not erase a protected chip.
I then thinking the chip needed rebooted added a release command before the acquire, No Effect
I then added a erase operation after the writeProtection(), No effect.
I then had it hit the writeProtection() 3 times in a row, Also no effect.
The chip is a CYBLE-014008-00.
The PSoC Programmer software is able to program and erase the protected chip with no issues.
The example code before and after moving it to C++ was/is able to program and erase unlocked chips with no issues. Only the unlocking portion of the example fails.
long c_cypCom::PSoC4_EraseAll()
{
long hr;
//Check chip level protection here. If PROTECTED then move to OPEN by PSoC4_WriteProtection() API.
//Otherwise use PSoC4_EraseAll() - in OPEN/VIRGIN modes.
//TODO do we need to detect no chip and not run any further if none is there??? ppPSoC4_WriteProtection crashes if there is no chip in its default state.
hr = PSoC4_IsChipNotProtected();
if (SUCCEEDED(hr)) //OPEN mode
{
//Erase All - Flash and Protection bits. Still be in OPEN mode.
hr = ppPSoC4_EraseAll(sErrorMsg);
if (!SUCCEEDED(hr))
{
printf("ERROR:%s\n",sErrorMsg.c_str());
return REC_DEVICE_ERASE*-1;
}
}
else
{ //Move to OPEN from PROTECTED. It automatically erases Flash and its Protection bits.
std::vector<byte> flashProt; // do not care in PROTECTED mode
std::vector<byte> chipProt; //move to OPEN
chipProt.push_back(CHIP_PROT_OPEN);// Set as 0x01 value in memory is 1 for the first element of chipProt.
hr = ppPSoC4_WriteProtection(flashProt, chipProt, sErrorMsg);// FAILS TO UNLOCK AND ERASE CHIP
if (!SUCCEEDED(hr))// No errors present here
{
printf("ERROR:%s\n",sErrorMsg.c_str());
return REC_DEVICE_ERASE*-1;
}
//Need to reacquire chip here to boot in OPEN mode.
//ChipLevelProtection is applied only after Reset.
hr = ppDAP_Acquire(sErrorMsg);
if (!SUCCEEDED(hr))
{
printf("ERROR:%s\n",sErrorMsg.c_str());
return REC_DEVICE_ERASE*-1;
}
}
if (!SUCCEEDED(hr)) return REC_DEVICE_ERASE*-1;
return REC_GOOD;
}
I am looking for suggestions.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SOLUTION
The C++ Example code has 2 Lines with typos that causes this issue.
The array index shuld be [2] not 1 for the 2nd parameter
A 3rd line i had already changed in every function in the API that has it. As it can cause a Crash!
bstrError Must be checked to see if it is 0 or null BEFORE using it. Sometimes with a poor connection to the target PSoC4 device commands will return a memory address of 0 causing a crash.
long ppPSoC4_WriteProtection(std::vector<BYTE> flashProtect, std::vector<BYTE> chipProtect, std::string &strError)
{
DISPID dispid=dispID_PSoC4_WriteProtection;
// Set up parameters
DISPPARAMS dispparams;
memset( &dispparams, 0, sizeof( DISPPARAMS ));
dispparams.cArgs = 3;
// Allocate memory for parameters
VARIANTARG* pArg = new VARIANTARG[dispparams.cArgs];
dispparams.rgvarg = pArg;
memset( pArg, 0, sizeof(VARIANT) * dispparams.cArgs);
//Convert hexData into SafeArray
VARIANT varData1, varData2;
ConvertByteVector2SA(chipProtect, &varData1);
ConvertByteVector2SA(flashProtect, &varData2);
//Initialize Parameters
BSTR bstrError=0;
dispparams.rgvarg[0].vt = VT_BSTR | VT_BYREF;
dispparams.rgvarg[0].pbstrVal = &bstrError;
dispparams.rgvarg[1].vt = VT_ARRAY | VT_UI1;
dispparams.rgvarg[1].parray = varData1.parray;
dispparams.rgvarg[2].vt = VT_ARRAY | VT_UI1;//LINE EDITED ORIGINAL dispparams.rgvarg[1].vt = VT_ARRAY | VT_UI1;
dispparams.rgvarg[2].parray = varData2.parray;//LINE EDITED ORIGINAL dispparams.rgvarg[1].parray = varData2.parray;
//Init Result (Return Value)
VARIANTARG vaResult;
VariantInit( &vaResult );
HRESULT hr;
hr = pIDispatch->Invoke(dispid, IID_NULL, GetUserDefaultLCID(), DISPATCH_METHOD,
&dispparams, &vaResult, NULL, NULL);
USES_CONVERSION;
//The following Line has a Potental Crash that has acctualy occured in testing. This shows the fixed version.
if(bstrError != 0) strError = W2A(bstrError);//LINE EDITED ORIGINAL strError = W2A(bstrError);
//Free allocated resources
delete[] pArg;
::SysFreeString(bstrError);
VariantClear(&varData1);
VariantClear(&varData2);
return vaResult.lVal;
}
With the first 2 fixes the chips now erase when protected as expected.
Is there a good place to send this bug report to?
Thanks Srds.