Use RESET pin as GPIO - nRF52840

Hi all,

I am developing an application for a custom board using the nRF52840. I need to use the reset pin (P0.18) as a regular GPIO, configured as an input with an associated interrupt. However, I am unable to set this pin as a GPIO. The steps I have followed are based on this thread.

My setup:

- First, I try to run the application on nRF52840dk

- I am using the Visual Studio nRF Connect extension, with version v2.3.0 for both toolchain and SDK to build the application.

- I flash the board using the following commands on a powershell terminal

nrfjprog -e
west flash --softreset

Code configuration:

- I added CONFIG_GPIO_AS_PINRESET=n on prj.conf file

- Then, I added the following code before configuring the pin to turn on the disconnect flag on the PSELRESET registers

#ifdef CONFIG_GPIO_AS_PINRESET
    if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Disconnected << UICR_PSELRESET_CONNECT_Pos)) || 
          ((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Disconnected << UICR_PSELRESET_CONNECT_Pos))){
      NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
      while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
      NRF_UICR->PSELRESET[0] = 18 | (1 << 31);
      while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
      NRF_UICR->PSELRESET[1] = 18 | (1 << 31);
      while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
      NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
      while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
      // UICR changes require a reset to be effective
      NVIC_SystemReset();  
    }
#endif

Results:

After setting these configurations, I get CONFIG_GPIO_AS_PINRESET is not set after building the application, and I get a HARD FAULT debug event when the pin configuration is set.

How can I solve this problem?

Candela

  • Hi,

    The only way to make it works for me is to launch the command at first use of my custom board:

    nrfjprog --eraseuicr


    Before using Flash command (with softreset) from VS Code action.

  • Hi,

    Yes, if the board was previously programmed in a way that enabled pin reset, you will have to earse the UICR, as that is persistent. That can be done like you do, or more generall with "nrfjprog --recover" (which will also work if AP protect is enabled). 

  • My nrf52840dk_nrf52840.dts file had the following:

    &gpio0 {
        status = "okay";
        gpio-reserved-ranges = <0 2>, <6 1>, <8 3>, <17 7>;
        gpio-line-names = "XL1", "XL2", "AREF", "A0", "A1", "RTS", "TXD",
            "CTS", "RXD", "NFC1", "NFC2", "BUTTON1", "BUTTON2", "LED1",
            "LED2", "LED3", "LED4", "QSPI CS", "RESET", "QSPI CLK",
            "QSPI DIO0", "QSPI DIO1", "QSPI DIO2", "QSPI DIO3","BUTTON3",
            "BUTTON4", "SDA", "SCL", "A2", "A3", "A4", "A5";
    };
    I verified UICR was cleared and it kept asserting.  The gpio-reserved-ranges was what caused the assertion.  Commenting that line out allowed me to move forward.  Putting this here in case someone else runs into the same issue.
    Thanks!
Related