This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52832 debug mode

Hi, I am using nrf52832_xxaa with SDK v11.0.I have the requirement to disable the debug at the start of the program.(Also to enable it if required in the future).

I use the following code at the start of the main function to write into the APPROTECT register to disable the debug mode.The softdevice is disabled.

        uint8_t retry = 10;          /// retry count
        if( ( NRF_UICR->APPROTECT & 0xFF ) == 0xFF )
        {
    
            NRF_NVMC->CONFIG = ( NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos );
            do
            {
                if( ( --retry ) == 0 )
                {
                    NVIC_SystemReset();
                }
            }
            while( NRF_NVMC->READY == NVMC_READY_READY_Busy );
    
            NRF_UICR->APPROTECT = 0;
    
            retry = 10;
            NRF_NVMC->CONFIG = ( NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos );
            do
            {
                if( ( --retry ) == 0 )
                {
                    break;
                }
            }
            while( NRF_NVMC->READY == NVMC_READY_READY_Busy );
            NVIC_SystemReset();
        }

Is it the proper way to disable the debug mode? Or is there any other method?

Do we need need to configure clock or need to enable softdevice before applying changes?

What are the other parameters to be considered when disabling debug mode?

Parents
  • If you don't have Soft Device running then this is the way to write to NVMC (including UICR). If you have Soft Device running then you need to use SD API for flash access. It's not necessary to disable SD just because of this operation. The main problem is: the fact that APPROTECT blocks most of SWD debugging interface except "recovery" procedure is irreversible unless you wipe the whole chip. So there is actually no way you would revert this later from your FW. There would be wild scenario of trying to erase UICR from within the FW and do reset which would be basically "suicide" from the FWs point of view. However even if this is possible it is useless: you would need to attach SWD debugger to program the chip again so why erasing it from within when the debugger can do it any time...

  • Actually, on nRF52 series, it's possible to erase UICR without erasing the chip. Check ERASEUICR register in NVMC.

Reply Children
No Data
Related