Use the same exact application binary you used for testing the original pin-based version. Don't change too many things at once.
How do you place initial 0xEB value in the USERROW31?
Ok, I actually don't get the logic here. If USERROW31 is 0xEB, then you are requesting to run the application. But how would 0xEB get there in a first place?
Assuming USERROW31 is 0xff by default, the code should be something like:
static bool is_bootloader_requested(void)
{
if (USERROW.USERROW31 == 0xFF)
{
/* Clear boot request*/
USERROW.USERROW31 = 0xEB; // Any non-0xFF value
_PROTECTED_WRITE_SPM(NVMCTRL.CTRLA, NVMCTRL_CMD_PAGEERASEWRITE_gc);
while(NVMCTRL.STATUS & NVMCTRL_EEBUSY_bm);
return true;
}
return false;
}
This will request the BL and simultaneously clear the flag.
And then to enter the bootloader, you write 0xff from the application.
Ok, I see where the issue is. You incorrectly copied the code from the appnote. And your comment "this will enter boot mode" is not correct. "Return false" will run the application.