FLASH002 UCB programming, lock/unlock

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
I'm trying to use the FLASH002 app and associated API calls to read/write lock all flash on an XMC4500, and then be able to unlock it at a later time for field upgrades and so forth.

I've used the USBVC001 previously for serial commands for a variety of other functions, and recently implemented a series of FLASH002 related commands so that I can read lock, write lock, unlock, etc. the device via the serial port when needed.

Per the FLASH002 DAVE3 help the process for implementing flash protection is:

1) Program Page0 of the UCB with protection options.
2) Reset the device.
3) Verify password by attempting disabling the protection, attempting
operation on the locked sectors and checking status registers.
4) Program confirmation code into Page2 of UCB.

I've followed these steps and seem to be able to lock the flash on the target using the Flash002_ConfigureProtection() and Flash002_ConfirmProtection(), but am unable to subsequently unlock the same way. Even using the Flash002_DisableSectorWriteProtection() or Flash002_DisableGlobalReadProtection() to temporarily turn off protection does not seem to allow me to write or read (respectively) the flash via JFlashARM or DAVE3 programmer.

Are there some FLASH002 protection / UCB examples available? Failing that, can someone help walk me through what specifically needs to be done to enable and disable UCB flash protection on a target XMC4500 using the FLASH002 app?

Thanks in advance,
Joe Shidle
0 Likes
7 Replies
Not applicable
Hi Joe Shidle,

Our colleague will look into it and update you later, thanks.

Best regards,
Sophia
0 Likes
Not applicable
Thanks for the response, Sophia. Included below are the simple flash protection utilities that I access individually via USBVC001 AT-style commands.

Based on my understanding as outlined above:
1) Issue command to call HandleFlashReadLock() to initiate the locking
2) Reset the target device
3) Issue command to call HandleFlashProtection() to verify and restore the flash protection
4) Issue command to call HandleFlashConfirm() to handle the confirmation code to UCB2


#define FLASH_UCB0 0
#define FLASH_UCB1 1
#define FLASH_UCB2 2
#define FLASH_PWD1 0x00010002
#define FLASH_PWD2 0x00030004
#define FLASH002_PROT_OPEN 0x0000

status_t HandleFlashProtection() {
status_t status = (uint32_t)FLASH002_ERROR;
FLASH002ProtectionFlags_Type protectFlags = FLASH002_PROT_RD_GLOBAL;

status = Flash002_VerifyProtection(FLASH_UCB0, FLASH_PWD1, FLASH_PWD2, protectFlags);

if (status == DAVEApp_SUCCESS) {
SetFlashProtection();
}

status = Flash002_ResumeProtection();

return status;
}

status_t HandleFlashReadLock() {
status_t status = FLASH002_ERROR;
FLASH002ProtectionFlags_Type protectFlags = FLASH002_PROT_RD_GLOBAL;

status = Flash002_ConfigureProtection(FLASH_UCB0, FLASH_PWD1, FLASH_PWD2, protectFlags);

if (status != DAVEApp_SUCCESS) {
lastErrorStatus = ERR_FLASH_READLOCK;
}

return status;
}

status_t HandleFlashUnlock() {
status_t status = FLASH002_ERROR;
FLASH002ProtectionFlags_Type protectFlags = FLASH002_PROT_OPEN;

status = Flash002_ConfigureProtection(FLASH_UCB0, FLASH_PWD1, FLASH_PWD2, protectFlags);

if (status != DAVEApp_SUCCESS) {
lastErrorStatus = ERR_FLASH_UNLOCK;
}

return status;
}

status_t HandleFlashConfirm() {
status_t status = FLASH002_ERROR;

status = Flash002_ConfirmProtection(FLASH_UCB2);

if (status != DAVEApp_SUCCESS) {
lastErrorStatus = ERR_FLASH_CONFIRM;
}

return status;
}

status_t HandleFlashDisableRead() {
status_t status = FLASH002_ERROR;

status = Flash002_DisableGlobalReadProtection(FLASH_PWD1, FLASH_PWD2);

if (status != DAVEApp_SUCCESS) {
lastErrorStatus = ERR_FLASH_DISABLE_READ;
}

return status;
}

status_t HandleFlashDisableWrite() {
status_t status = FLASH002_ERROR;

status = Flash002_DisableSectorWriteProtection(FLASH_UCB0, FLASH_PWD1, FLASH_PWD2);

if (status != DAVEApp_SUCCESS) {
lastErrorStatus = ERR_FLASH_DISABLE_WRITE;
}

return status;
}


Let me know if anything seems amiss. We are on an XMC4500 series AB chip.

Thanks in advance,
Joe Shidle
0 Likes
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
hi,

While investigating your case, you might want to look into this link. There is an attachement on flash protection knowhow.


http://www.infineonforums.com/threads/1015-XMC4500-Tip-of-the-day-Flash-Protection-for-XMC4000-famil...

Best Regards
Travis
0 Likes
Not applicable
Travis;

Thanks for the response. Prior to your post, I had changed my HandleFlashUnlock() as quoted earlier to use the Flash002_EraseUCB() API call from the FLASH002 app but with the same results. Per the recommendation from the API documentation, I do issue a Flash002_DisableSectorWriteProtection() prior to issuing the Flash002_EraseUCB().

But the results are the same, I am able to lock flash protection but unable to turn the flash protection off via Erase. I have verified that the Flash002_EraseUCB() in my FLASH002 API performs the six sequential commands per your PPT but the operation comes back FLASH002_ERROR. I have implemented a command to dump the FSR and after the EraseUCB() fails, the FSR reads 0x02050800.

I've included my updated HandleFlashUnlock() below. Thanks in advance for your help.


status_t HandleFlashUnlock() {
status_t status = FLASH002_ERROR; // assume failure
FLASH002ProtectionFlags_Type protectFlags = FLASH002_PROT_OPEN;

status = Flash002_DisableSectorWriteProtection(FLASH_UCB0, FLASH_PWD1, FLASH_PWD2);
if (status != DAVEApp_SUCCESS) {
lastErrorStatus = ERR_FLASH_DISABLE_WRITE;
return status;
}

status = Flash002_EraseUCB(FLASH_UCB0);
if (status != DAVEApp_SUCCESS) {
lastErrorStatus = ERR_FLASH_UNLOCK;
}

return status;
}
0 Likes
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
Hi,

I am looking at this issue offline with Mike and Robert.

Best Regards
Travis
0 Likes
Not applicable
Hello everyone
I am try to lock internal flash memory in xmc4500 by this program :

status_t status;
uint32_t PW0 = 0x00010002; //first 32 bit of password
uint32_t PW1 = 0x00030004; //second 32 bit of password
uint32_t UserLevel = 0;
FLASH002ProtectionFlags_Type ProtectionFlags;

ProtectionFlags = FLASH002_PROT_RD_GLOBAL;
status = Flash002_ConfigureProtection(UserLevel, PW0, PW1, ProtectionFlags);
status = Flash002_ConfirmProtection(UserLevel);
And then try to unlock global read protection by this program :
status_t status;
uint32_t PW0 = 0x00010002; //first 32 bit of password
uint32_t PW1 = 0x00030004; //second 32 bit of password
status = Flash002_DisableGlobalReadProtection(PW0, PW1);
But after lock chip I can not unlock it. I do not know what happen.
I am use DAVE 3
Can anyone help me about that?
Thanks a lot
Mah
0 Likes
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

Please have a look to the FLASH_PROTECTION XMC4500 example in the XMCLib distribution http://dave.infineon.com/Libraries/XMCLib/XMC_Peripheral_Library_v2.1.18.zip

Regards,
Jesus
0 Likes