0

I am trying to execute the Chip Erase Lock command (CELCK) on Microchip/Atmel ATSAMD51J20A microcontroller. I am using the following procedure:

  1. Wait for NVMCTRL STATUS.READY bit to set.
  2. Clear NVMCTRL INTFLAG.DONE bit and INTFLAG.PROGE bit if set.
  3. Write to NVMCTRL CTRLB reg the Chip erase Lock command: NVMCTRL_CTRLB_CMD_CELCK (simultaneously with the command execution key NVMCTRL_CTRLB_CMDEX_KEY in the upper byte)
  4. Wait for NVMCTRL STATUS.READY bit to set again.
  5. Check if NVMCTRL INTFLAG.PROGE bit is set to indicate an error.

The problem is that in step 5 the PROGE bit is always set, which indicates that the command resulted in an error or was ignored. I also ran a Chip Erase command with Microchip Studio software and it still works, which shows that Chip Erase Lock command was not successful.

If I repeat the same procedure with other NVMCTRL cmds like Set Security Bit Cmd (using NVMCTRL_CTRLB_CMD_SSB in step 3 instead of NVMCTRL_CTRLB_CMD_CELCK) then it is successful. This makes me believe that the implementation itself is correct.

Are there any special prerequisites for using the CELCK cmd? What can be the possible reasons for the PROGE bit getting set when running the CELCK cmd?

I am using Atmel Start (ASF) generated headers for all the register definitions.

Thanks

(Also posted the same question on Microchip Forum)

theihaq
  • 1
  • 1
  • One of the usual suspect for problems like this is enabled interrupts running in the background. Try a `__asm("CPSID i");` before launching re-programming, see if it changes anything. – Lundin May 31 '23 at 13:04
  • Good point. Although I just tried and in this case it did not solve the problem, but still I will add this to my code as it makes sense to disable interrupts when doing such stuff. – theihaq May 31 '23 at 14:54

0 Answers0