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

Parents
  • Hi,

    There are two aspects here. Firstly, CONFIG_GPIO_AS_PINRESET is deprecated, and you need to configure this in the device tree with  gpio-as-nreset. So if you have your custom board files, don't add it. If you are using DK board files (which as it), make an app.overlay file or similar with this:

    &uicr {
            /delete-property/ gpio-as-nreset;
        };
    

    With this, the firmware itself will not configure the pin as reset, and you can use it as a GPIO.

    The next is programming. By default, pin reset will be enabled when programming with west. You can avoid this with the "--softreset" option to west flash. This is also used by nRF Connect for VS Code, and to make vs code use soft reset you can add a softreset config as explained here. Note that you need to provide a path to a specific application, and this config only applies to that application (to use on multiple applications you need to specify it separately for each of the apps you need to use). (I have asked the team to make this a generic configuration and they are looking into that.)

  • Hi,

    I've been trying to modify the UICR node on an overlay file, but upon reviewing the nRF52840dk original device tree file, I could not locate the "gpio-as-nreset" property, so I get an error when I try to remove it. I am using SDK v2.3.0 version, could this be the problem?

    I managed to softreset the device with west flash too.

    Thanks a lot,

    Candela

  • Hi Candela,

    Ah, sorry. On 2.3.0 CONFIG_GPIO_AS_PINRESET is what you should use, so you can ignore my comment about the devicetree as that is only relevant for 2.5.0 and later.

    Do you get it to work with VS Code as well as west flash now? For reference, this is what I tested with that worked for me:

            "nrf-connect.applicationOptions": {
                "/home/eith/ncs/v2.5.0/zephyr/samples/basic/blinky": {
                  "flash": {
                    "softreset": true,
                    "skipBuild": false
                  }
                }
              }

  • Hi Einar,

    I am currently using v2.7.0 with NRF52840 DK.  I want to use p0.18 as a chip select pin for SPI.  Per your answer above, I've modified the device tree overlay to match your UICR redefinition.

    Upon booting, I still get this assertion:

    ASSERTION FAIL [(cfg->port_pin_mask & (gpio_port_pins_t)(1UL << (pin))) != 0U] @ WEST_TOPDIR/zephyr/include/zephyr/drivers/gpio.h:1005
    Unsupported pin

    Here are my overlay definitions:

    &pinctrl {
    spi2_default: spi2_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 19)>,
                    <NRF_PSEL(SPIM_MOSI, 0, 23)>,
                    <NRF_PSEL(SPIM_MISO, 1, 00)>;
            };
        };
    };
    spi2: &spi2 {
        compatible = "nordic,nrf-spi";
        status = "okay";
        pinctrl-0 = <&spi2_default>;
        pinctrl-1 = <&spi2_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
    };

    &uicr {
        /delete-property/ gpio-as-nreset;
    };
    I've also tried without the uicr redefinition and also tried CONFIG_GPIO_AS_PINRESET in the proj.conf but it shows deprecrated.
Reply
  • Hi Einar,

    I am currently using v2.7.0 with NRF52840 DK.  I want to use p0.18 as a chip select pin for SPI.  Per your answer above, I've modified the device tree overlay to match your UICR redefinition.

    Upon booting, I still get this assertion:

    ASSERTION FAIL [(cfg->port_pin_mask & (gpio_port_pins_t)(1UL << (pin))) != 0U] @ WEST_TOPDIR/zephyr/include/zephyr/drivers/gpio.h:1005
    Unsupported pin

    Here are my overlay definitions:

    &pinctrl {
    spi2_default: spi2_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 19)>,
                    <NRF_PSEL(SPIM_MOSI, 0, 23)>,
                    <NRF_PSEL(SPIM_MISO, 1, 00)>;
            };
        };
    };
    spi2: &spi2 {
        compatible = "nordic,nrf-spi";
        status = "okay";
        pinctrl-0 = <&spi2_default>;
        pinctrl-1 = <&spi2_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
    };

    &uicr {
        /delete-property/ gpio-as-nreset;
    };
    I've also tried without the uicr redefinition and also tried CONFIG_GPIO_AS_PINRESET in the proj.conf but it shows deprecrated.
Children
No Data
Related