Getting Write verify failed every time when try to debug or write without erase.

Hi,

We are working with nRF5340 with SDK v2.5.2.

Each time we try to program the board, we get below error.

[ #################### ]  12.131s | Erase file - Done erasing                                                          
[ #################### ]   1.269s | Program file - Done programming                                                    
[ #################### ]   1.299s | Verify file - Done verifying                                                       
[ #################### ]  14.504s | Erase file - Done erasing                                                          
[ #################### ]   2.654s | Program file - Done programming                                                    
[error] [ Client] - Encountered error -160: Command verify_file executed for 2719 milliseconds with result -160        
[error] [  nRF53] - Failed while performing 'Verify' operation on target address 0x00FF8128.                           
-160: Data does not match in address range [0x00FF8128 - 0x00FF8177] (APP UICR)
Expected byte value 0xFF but read 0xFC at address 0x00FF8150.
[error] [  nRF53] - Failed while verifying device. -160: Data does not match in address range [0x00FF8128 - 0x00FF8177] (APP UICR)
Expected byte value 0xFF but read 0xFC at address 0x00FF8150.
[error] [ Worker] - Data does not match in address range [0x00FF8128 - 0x00FF8177] (APP UICR)
Expected byte value 0xFF but read 0xFC at address 0x00FF8150.
ERROR: Write verify failed.
NOTE: For additional output, try running again with logging enabled (--log).
NOTE: Any generated log error messages will be displayed.
FATAL ERROR: command exited with status 25: nrfjprog --program 'd:\project\..\build\zephyr\GENERATED_CP_APPLICATION_merged_domains.hex' --sectorerase --verify -f NRF53 --coprocessor CP_APPLICATION --snr 960130361

We do not see this error if we try Erase and Flash option from VS Code. We observe the same issue even with the nRF5340DK board.

This is very annoying us as we cannot debug or program without erasing. Please help us solving the issue.

We are using VS Code with NRF Connect extensions. SDK v2.5.2.

Parents
  • Any update on this?

    Please let me know if any additional information is needed.

    Thank you in advance

  • Hello,

    Are you using a watchdog timer in your code by change?

    Best regards,

    Michal

  • Hi Jithin,

    I got back to your ticket quite late today, and I will need to give you a proper reply after the weekend.

    Thank you for your continued patience with this, and I apologize for the delays.

    Best regards,

    Maria

  • Hi Jithin,

    The TF-M: PSA template is a sample which has NSIB enabled by default. Do you get the same UICR error when flashing that sample to your board? If the sample flashes successfully without erasing, then please ensure that your project configures the NSIB like the PSA template sample does.

    Best,

    Maria

  • The TF-M: PSA template is a sample which has NSIB enabled by default. Do you get the same UICR error when flashing that sample to your board? If the sample flashes successfully without erasing, then please ensure that your project configures the NSIB like the PSA template sample does.

    --> Maria, first time I can flash the code without any issue.

    Later if I try to debug/flash without erase, I see below error.

    -- west flash: using runner nrfjprog
    -- runners.nrfjprog: Flashing file: d:\work\nrf\app\tfm_psa_template\build\zephyr\merged.hex
    [error] [ Worker] - Can't read memory descriptors, ap-protection is enabled.
    [error] [ Client] - Encountered error -90: Command read_memory_descriptors executed for 15 milliseconds with result -90
    [error] [ Client] - Encountered error -90: Command erase_file executed for 188 milliseconds with result -90
    [error] [  nRF53] - Failed while detecting device memory block protection status!                                      
    [error] [  nRF53] - Failed while erasing device. -90: Access protection is enabled, can't read block protection state.
    [error] [ Worker] - Access protection is enabled, can't read block protection state.
    ERROR: The operation attempted is unavailable due to readback protection in
    ERROR: your device. Please use --recover to unlock the device.
    NOTE: For additional output, try running again with logging enabled (--log).
    NOTE: Any generated log error messages will be displayed.
    ERROR: runners.nrfjprog: Flashing failed because the target must be recovered.
      To fix, run "west flash --recover" instead.
      Note: your target is an nRF53; all flash memory for both the network and application cores will be erased prior to reflashing.
    FATAL ERROR: command exited with status 24: nrfjprog --program 'd:\work\nrf\app\tfm_psa_template\build\zephyr\merged.hex' --sectorerase --verify -f NRF53 --coprocessor CP_APPLICATION --snr 1050014096

    I see, first we need to program provisioning bin first and then we need to program PSA template to run properly, and I did the same. First time it worked well.

    Please let me know if I am doing anything wrong.

    I am using SDK v2.6.0

  • Hi Jithin,

    This error is expected. The PSA template sample is only meant to be programmed to the board once, and then the next firmware updates are done with DFU, not by flashing. See the Firmware update section for the sample for details.

    Best regards,

    Maria

  • Hi Maria,

    We did some research on the issue.

    We found that we are getting the issue when we enable DFU target.

    Let me explain,

    First, we build TFM_secure_peripheral example using SDK v2.2.0 as we found no debug issue from this SDK.
    The build works well no error found when we try to debug.
    Later, we updated the SDK to 2.6.0 and made all the necessary changes. No issues with the debug.
    The only difference from the TFM sample application to ours is DFU enabled.
    So, we enabled the DFU target by adding below configuration into the prj.conf file.

    CONFIG_BUILD_WITH_TFM=y
    CONFIG_TFM_PROFILE_TYPE_NOT_SET=y
    CONFIG_TFM_IPC=y
    CONFIG_NRF_TIMER1_SECURE=y
    CONFIG_NRF_SPIM3_SECURE=y
    CONFIG_NRF_GPIOTE0_SECURE=y
    CONFIG_TFM_ISOLATION_LEVEL=1
    
    # Added DFU functionality-------------------------------
    # Setup secure bootloader
    # Flash configurations
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    
    # Enable MCUboot and secure bootloader for sgining the image
    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_SECURE_BOOT=y
    CONFIG_SB_SIGNING_KEY_FILE="key.pem"
    
    # Enable DFU target
    CONFIG_DFU_TARGET=y
    CONFIG_IMG_MANAGER=y
    CONFIG_DFU_TARGET_MCUBOOT=y
    CONFIG_DFU_TARGET_STREAM=y
    CONFIG_STREAM_FLASH_ERASE=y
    CONFIG_STREAM_FLASH=y
    # Do not add any config below this line as below are added from kconfig
    CONFIG_B0_MIN_PARTITION_SIZE=y
    CONFIG_NRF53_UPGRADE_NETWORK_CORE=n

    Flash the code, works well. NOW, we try to debug we get the error.

    To confirm, we disabled the DFU in our project and debug works without need for the sector erase.

    Can you please look into this.

    Please let me know we are configuring anything wrong or any additional info needed.

    Thank you in advance.

Reply
  • Hi Maria,

    We did some research on the issue.

    We found that we are getting the issue when we enable DFU target.

    Let me explain,

    First, we build TFM_secure_peripheral example using SDK v2.2.0 as we found no debug issue from this SDK.
    The build works well no error found when we try to debug.
    Later, we updated the SDK to 2.6.0 and made all the necessary changes. No issues with the debug.
    The only difference from the TFM sample application to ours is DFU enabled.
    So, we enabled the DFU target by adding below configuration into the prj.conf file.

    CONFIG_BUILD_WITH_TFM=y
    CONFIG_TFM_PROFILE_TYPE_NOT_SET=y
    CONFIG_TFM_IPC=y
    CONFIG_NRF_TIMER1_SECURE=y
    CONFIG_NRF_SPIM3_SECURE=y
    CONFIG_NRF_GPIOTE0_SECURE=y
    CONFIG_TFM_ISOLATION_LEVEL=1
    
    # Added DFU functionality-------------------------------
    # Setup secure bootloader
    # Flash configurations
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    
    # Enable MCUboot and secure bootloader for sgining the image
    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_SECURE_BOOT=y
    CONFIG_SB_SIGNING_KEY_FILE="key.pem"
    
    # Enable DFU target
    CONFIG_DFU_TARGET=y
    CONFIG_IMG_MANAGER=y
    CONFIG_DFU_TARGET_MCUBOOT=y
    CONFIG_DFU_TARGET_STREAM=y
    CONFIG_STREAM_FLASH_ERASE=y
    CONFIG_STREAM_FLASH=y
    # Do not add any config below this line as below are added from kconfig
    CONFIG_B0_MIN_PARTITION_SIZE=y
    CONFIG_NRF53_UPGRADE_NETWORK_CORE=n

    Flash the code, works well. NOW, we try to debug we get the error.

    To confirm, we disabled the DFU in our project and debug works without need for the sector erase.

    Can you please look into this.

    Please let me know we are configuring anything wrong or any additional info needed.

    Thank you in advance.

Children
  • Hi Maria,

    Any update on this?

    We get the same error if we build the project from SDK v2.5.0 or greater.

    Let me explain our observations.

    1. Create a new sample (TF-M secure peripheral) from the SDK v2.5.0 or greater.
    2. Build and program, works well.
    3. Try debug after programming, works well.
    4. Enable DFU using below config
      # Added DFU functionality-------------------------------
      # Setup secure bootloader
      # Flash configurations
      CONFIG_FLASH=y
      CONFIG_FLASH_PAGE_LAYOUT=y
      CONFIG_FLASH_MAP=y
      
      # Enable MCUboot and secure bootloader for sgining the image
      CONFIG_BOOTLOADER_MCUBOOT=y
      CONFIG_SECURE_BOOT=y
      CONFIG_SB_SIGNING_KEY_FILE="key.pem"
      
      # Enable DFU target
      CONFIG_DFU_TARGET=y
      CONFIG_IMG_MANAGER=y
      CONFIG_DFU_TARGET_MCUBOOT=y
      CONFIG_DFU_TARGET_STREAM=y
      CONFIG_STREAM_FLASH_ERASE=y
      CONFIG_STREAM_FLASH=y
      # Do not add any config below this line as below are added from kconfig
      CONFIG_B0_MIN_PARTITION_SIZE=y
      CONFIG_NRF53_UPGRADE_NETWORK_CORE=n
    5. Build and program, works well.
    6. Try debug after programming, we get the error.

    Please help us to solve the issue ASAP. Please let me know if any additional information required.

  • Hi Jithin,

    Apologies for the wait.

    I assume that you are using the VS Code extension for debugging. When selecting the Debug action, your board will be flashed first before starting the debugging session. After programming your project, APPROTECT will be enabled on reset, which is I suspect is the cause for the error when debugging. To circumvent this you have two possibilities:

    1. Select the option "Attach Debugger to Target" which is available when hovering over the Debug action and clicking the three dots.

    2. Add "flash": false to the Launch Configuration for your project, for example
      {
      	"version": "0.2.0",
      	"configurations": [
      		{
      			"type": "nrf-connect",
      			"request": "launch",
      			"name": "Launch tfm_secure_peripheral\\build",
      			"config": "${workspaceFolder}/build",
      			"runToEntryPoint": "main",
                  "flash": false
      		}
      	]
      }

    Best regards,

    Maria

  • Hi Maria,

    Thanks for the suggestion, option #2 worked for me.

    I assume the above option works as debug without flash.

    I need to flash the changes.

    Is there any option to combine 2 tasks say first, program the code and then perform the debug task?

    If so, please guide me to configure the task.

  • Hi Maria,

    I modified launch.json and created tasks to flash the build to the board by ignoring verify status.

    Now I can flash and debug the changes.

    Yet I see the warning that verification failed and since I am ignoring the write verification, I am able to debug, I think this is not the actual solution but for the time being I can flash and debug the latest build without any need of the sector erase.

    Thank you.

    Please let me know if we have any complete solution.

Related