Issue after enabling Flash Read Protection

Hello,

I have my BLE Gatt Peripheral application working and running.

I am developing a reader that reads BLE credential.

Application is complete. I flash the .hex file and reads the BLE credential from mobile app without power cycling.

I then added Readback protection to my application.

Once i flash this application, i verified Readback is protected (since i added WARM_RESET after enabling APPROTECT), but my BLE credential doesn't read (although reader sees advertisement).

I have to power cycle the reader and then it reads.

I want suggestion to fix this issue. I want to read the BLE credential right after flashing the application without power cycling.

Thanks.

		#ifdef ENABLE_APPROTECT
			//Check if Read Protection is Enabled
			if ((NRF_UICR->APPROTECT & UICR_APPROTECT_PALL_Msk) !=
				(UICR_APPROTECT_PALL_Enabled << UICR_APPROTECT_PALL_Pos)) 
			{
				/* Enable Access Port Protection
				* Access through debugger to CPU registers, mapped-memory and RAM will be disabled
				* To disable protection ERASEALL command must be applied. */

				//Enable HW APPROTECT
				WriteWordNrfNvmcCfg((uint32_t)&NRF_UICR->APPROTECT, 
									((NRF_UICR->APPROTECT & ~((uint32_t)UICR_APPROTECT_PALL_Msk)) | 
									 (UICR_APPROTECT_PALL_Enabled << UICR_APPROTECT_PALL_Pos)));

				//Reset to activate
				sys_reboot(SYS_REBOOT_WARM);
			}
			else
			{
				//Access Port Protection is enabled
				
			}
		#else
			// CTRL-AP ERASEALL command will be applied during Flash / Debug Process which makes Access Port Protection disabled
		#endif //ENABLE_APPROTECT

Parents
  • Jared,

    I am using nRF Connect SDK v2.0.

    This is the Visual Studio Code version

    This is the version of nRF Connect for VS

    This is the J-Link version

    If i program the Application FW using VScode extension FLASH operation, the BLE credential doesnt work (application is running: UART etc)

    I have to power cycle the HW and then everything works.

    But if i flash the same Application FW using Programmer Desktop Application, everything works (without performing power cycle)

  • Hi there,

    I'm a bit unsure how this is related to readback protection. Enabling readback protection by setting ENABLE_APPROTECT will not prevent the application to read from the internal flash. It will however prevent external devices to read internal data because the readback protection disables the debugger interface. 

    Flashing a board from the nRF Connect SDK VScode extension versus flashing it from nRF Connect Programmer app does indeed behave differently. The former will do a pin reset while the latter will do a soft reset. 

    The code snippet you've shared for enabling app protect isn't necessary, there is already a kconfig that can be set in the project kconfig that enables app protect, it's called "NRF_APPROTECT_LOCK". Have you already enabled this in your project, can you double check your build folder and see if it's enabled?

    I'm not sure if this is related directly to readback protection, however your code snippet might be causing the issue here.

    Can you:

    1. Disable NRF_APPROTECT_LOCK if it has already been enabled
    2. Remove the code snippet that you have added that enables readback protection
    3. Enable readback protection trough nRF Command Line Tools by using "nrfjprog --rbp ALL"

    The last step should enable readback protection on your device. Can you see if you're able to reproduce your problem with vs code when you're using this method instead of enabling it with your code from the application.

    regards

    Jared

  • nrfjprog --rbp ALL works fine as well to protect read back.

    After several testing it seems like this issue is not related to ENABLING FLASH protection.

     There seems like a bug in VScode nRF Connect extension for FLASH action
        -> If the fw is flashed using VScode extension, the application runs but the Mobile BLE credential doesn't read, unless reader is power cycled.
        -> If the fw is flashed using Programmer application {inside nRF Connect SDK (Windows Desktop Application)}, the Mobile BLE credential reads right away without needing to power cycle*/
    You did said:
    Flashing a board from the nRF Connect SDK VScode extension versus flashing it from nRF Connect Programmer app does indeed behave differently. The former will do a pin reset while the latter will do a soft reset. 
    Does that makes a difference in performing what application needs to do ?
    Does pin reset halt the application and softreset doesnt ?
    If yes, how can i run the application after i perform FLASH from VScode extension.
  • Hi,

    Yes, most likely this is not related to readback protection. I suspect that it's somewhat related to your code snippet that you shared above. 

    Once i flash this application, i verified Readback is protected (since i added WARM_RESET after enabling APPROTECT), but my BLE credential doesn't read (although reader sees advertisement).

    Can you try to debug your application when you read after the "warm_reset" and see if the program asserts? Do you have any logging on the mobile application or the nRF that would tell something about the state of the program when you try to read the BLE characteristic? Could you capture and share a trace with nRF Sniffer?

    regards

    Jared 

Reply
  • Hi,

    Yes, most likely this is not related to readback protection. I suspect that it's somewhat related to your code snippet that you shared above. 

    Once i flash this application, i verified Readback is protected (since i added WARM_RESET after enabling APPROTECT), but my BLE credential doesn't read (although reader sees advertisement).

    Can you try to debug your application when you read after the "warm_reset" and see if the program asserts? Do you have any logging on the mobile application or the nRF that would tell something about the state of the program when you try to read the BLE characteristic? Could you capture and share a trace with nRF Sniffer?

    regards

    Jared 

Children
  • when i read after the "warm reset" and see if the program asserts? Yes, i cannot read log on RTT since APPLOCK is enabled.

    I have NRF52840 DK as well as Dongle to work with and android app for nRF Sniffer. Can you share me online video tutorial / document that explains how do i use nRF Sniffer to capture BLE logs OTA ?

    Can i use same phone (android) to run NRF SNIFFER APP on which my other BLE credential is being used to read ?

    or can i use nRF Sniffer app on windows PC while using DK / Dongle to capture ?

  • Hi,

    Deep Patel said:
    when i read after the "warm reset" and see if the program asserts? Yes, i cannot read log on RTT since APPLOCK is enabled.

    I see..

    Deep Patel said:

    I have NRF52840 DK as well as Dongle to work with and android app for nRF Sniffer. Can you share me online video tutorial / document that explains how do i use nRF Sniffer to capture BLE logs OTA ?

    Can i use same phone (android) to run NRF SNIFFER APP on which my other BLE credential is being used to read ?

    or can i use nRF Sniffer app on windows PC while using DK / Dongle to capture ?

    You have to use a separate DK or Dongle to sniff packets between two devices. You can not use a device that is already a part of the communication that is going to be sniffed. We have this outdated video that gives you a brief overview of the sniffer, but you should really look at the documentation that explains how to run the sniffer. You can find the documentation here.

    regards

    Jared

Related