Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
dongle: set regout0 to provide 3.3V from USB (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
benedekkupper committed Dec 16, 2024
1 parent f2ecd6b commit 08d28d9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions boards/ugl/uhk-80/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
zephyr_library()
if(CONFIG_DEVICE_ID) # don't add it to bootloader image as well
zephyr_library_sources(board.c)
endif()
45 changes: 45 additions & 0 deletions boards/ugl/uhk-80/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2018 Nordic Semiconductor ASA.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/init.h>
#include <hal/nrf_power.h>

#ifdef CONFIG_BOARD_UHK_DONGLE_NRF52840
static int board_uhk_dongle_nrf52840_init(void)
{
/* 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.3 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_3V3 << 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();
}

return 0;
}

SYS_INIT(board_uhk_dongle_nrf52840_init, PRE_KERNEL_1,
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
#endif

0 comments on commit 08d28d9

Please sign in to comment.