Is it possible to configure REGOUT0 at programming time with the nRF Connect SDK?

In my project, I need to set REGOUT0 to 4, to achieve a VDD of 3 volts.  In zephyr/boards/arm/nrf52840dongle_nrf52840/board.c there is an example showing how to do this in code:

/* if the nrf52840dongle_nrf52840 board is powered from USB
	* (high voltage mode), GPIO output voltage is set to 1.8 volts by
	* default and that is not enough to turn the green and blue LEDs on.
	* Increase GPIO voltage to 3.0 volts.
	*/
if ((nrf_power_mainregstatus_get(NRF_POWER) ==
		NRF_POWER_MAINREGSTATUS_HIGH) &&
	((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) ==
		(UICR_REGOUT0_VOUT_DEFAULT << UICR_REGOUT0_VOUT_Pos))) {

	NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
	while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {
		;
	}

	NRF_UICR->REGOUT0 =
		(NRF_UICR->REGOUT0 & ~((uint32_t)UICR_REGOUT0_VOUT_Msk)) |
		(UICR_REGOUT0_VOUT_3V0 << UICR_REGOUT0_VOUT_Pos);

	NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
	while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {
		;
	}

	/* a reset is required for changes to take effect */
	NVIC_SystemReset();
}

This code runs when the chip is powered on and, if REGOUT0 isn't set to 4, it sets it to 4 and then resets the chip.

It is my understanding that it should also be possible to set REGOUT0 (and, indeed, any UICR register) at programming time, so when the code runs it's already set.

For the older nRF SDK, you have documentation showing how to set a UICR register in the hex file and program it onto the device:

https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/uicr_config_example.html

I also found someone setting a UICR register via a linker script on this forum:

 Writing UICR->APPROTECT with linker scripts 

Unfortunately, I haven't been able to get either of these techniques working using the new nRF Connect SDK.  Is this no longer possible with the new SDK, or am I missing something?  Is there an example showing how to achieve this on the new SDK?

I would rather not:

  • Include code to set the register in my project.
  • Use a separate command (like nrfjprog) to set the register.

I'd prefer to just click Flash in the IDE and have it program my code and the register in one click.

Is this possible?

Related