Flash Protection

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

cross mob
engr815
Level 1
Level 1
5 sign-ins First reply posted First question asked

Hi! I am using XMC4700 Relax Kit with DAVE 4.2.2. I want to turn on the read protection so that U can upload the code again and again when U wanted. Also, please tell me how to verify the read protection?

0 Likes
1 Solution
sujatapatil
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 100 sign-ins

Hi @engr815 ,

As i mentioned earlier enabling flash protection will lock the device and if you need to revert this operation you need external commands like UART . In example project sent before,   this is done  by calling shell_init and you can disable this protection.

Identify com port (XMC board)  in your windows machine and open serial console/hyperterminal/putty . You will see below logs , select disable protection using command  mentioned as below and you will be able to disable flash protection . 

sujatapatil_0-1704364858273.png

void XMC_FLASH_lDisableReadProtectionCommand(uint32_t password_0, uint32_t password_1) - will disable flash protection and get invoked by above command mentioned in shell window.

You can also read README.md in project folder provided for more information.

Please let me know if you need more detail on this.

Thanks

Sujata

 

View solution in original post

0 Likes
4 Replies
lock attach
Attachments are accessible only for community members.
sujatapatil
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 100 sign-ins

Hi @engr815 ,

You need to configure UCB for flash read protection . Please refer section 8.4.8.2Flash Read Protection from user manual for more detail . I am also attaching example code which will enable read protection . 

Enabling Read protection locks the debug interface hence you can verify it .

But please keep in mind ,

If Read protection is required but would require access to PFlash in the future, you should ensure that the code allows executing external commands (via LIN, UART, CAN, and so on) to perform the following PMU sequences:

  • Disable Protection
  • Resume Protection
Thanks
Sujata
0 Likes

Can you explain the code?

What i understood is,

1. In the main function, the peripherals are initialized like IO, UART etc.

2. The UART is initialized in interrupt mode. It is used to send commands on uart so that uC can remove protections or enable protections.

3. Then the following line returns the counter value.
/* Initialize the UCB Program counter */
ucb_program_count = flash_get_ucb_program_count();

4. Then if the counter value exceeds the safe limit, then the code which is burned in the flash is erased.
/* Reset the counter and erase flash sector if invalid count
* value found in flash for counter
*/
if(ucb_program_count > UCB_PROGRAM_MAX_LIMIT)
{
flash_ucb_program_count(0);
ucb_program_count = 0;
}

5. What i didn't understood is the following shell commands. What are they?

/* Initialize shell */
shell_init(shell_cmd_table, initialize_shell);

while(1)
{
/* Process user input */
shell_process_input();
}


Note: If I am missing something please mention that as well and if there is any need for more explanation, please brief that as well. Thank you in advance.

If you could explain the steps how to enable read protection, I would be very grateful to you for this kindness as I have already lost one XMC4700 RelaxKit. I enabled the Read and Write protection without any external commands. 

Also, I am not using registers directly in my code. I am using the DAVE IDE and the provided library, which is generated after adding APIs like Digital IO, ADC, UART etc.

0 Likes

I used the function written in Image 1 shown below.  

/*
 * This API install the global read and sector write protection for the specified user
 */
void XMC_FLASH_InstallProtection(uint8_t user,
                                 uint32_t protection_mask,
                             uint32_t password_0,
                                 uint32_t password_1)
{
  uint32_t idx;
  
  XMC_ASSERT(" XMC_FLASH_ConfigureProtection: User level out of range", (user < 3U))
 
  XMC_FLASH_lEnterPageModeCommand();
 
  XMC_FLASH_lLoadPageCommand(protection_mask, 0UL);
  XMC_FLASH_lLoadPageCommand(protection_mask, 0UL);
  XMC_FLASH_lLoadPageCommand(password_0, password_1);
  XMC_FLASH_lLoadPageCommand(password_0, password_1);
  
  for (idx = 0U; idx < (XMC_FLASH_WORDS_PER_PAGE - XMC_FLASH_PROTECTION_CONFIGURATION_WORDS); idx += 2U)
  {
    XMC_FLASH_lLoadPageCommand(0UL, 0UL);
  }
 
  XMC_FLASH_lWriteUCBPageCommand((uint32_t *)((uint32_t)XMC_FLASH_UCB0 + (user * XMC_FLASH_BYTES_PER_UCB)));
 
  /* wait until the operation is completed */
  while ((FLASH0->FSR & (uint32_t)FLASH_FSR_PBUSY_Msk) != 0U){}
}

Image 1.png

It locked the sectors forever and i am unable to reprogram the XMC4700.

Later i came to another function which is shown below.
void XMC_FLASH_lDisableReadProtectionCommand(uint32_t password_0, uint32_t password_1)

Image 2.png

Now i want to ask you that do you have any knowladge about these functions?
If yes please guide me.

Also i want to confirm that if i use first function then after that, if on button press i use the 2nd function to temporarily disable the read and write protection then can i be able to reprogram the XMC?

0 Likes
sujatapatil
Moderator
Moderator
Moderator
50 solutions authored 10 likes received 100 sign-ins

Hi @engr815 ,

As i mentioned earlier enabling flash protection will lock the device and if you need to revert this operation you need external commands like UART . In example project sent before,   this is done  by calling shell_init and you can disable this protection.

Identify com port (XMC board)  in your windows machine and open serial console/hyperterminal/putty . You will see below logs , select disable protection using command  mentioned as below and you will be able to disable flash protection . 

sujatapatil_0-1704364858273.png

void XMC_FLASH_lDisableReadProtectionCommand(uint32_t password_0, uint32_t password_1) - will disable flash protection and get invoked by above command mentioned in shell window.

You can also read README.md in project folder provided for more information.

Please let me know if you need more detail on this.

Thanks

Sujata

 

0 Likes