From 08d28d9ea0919452f2b070546454ea9ef75bc279 Mon Sep 17 00:00:00 2001 From: Benedek Kupper Date: Wed, 4 Dec 2024 22:08:37 +0100 Subject: [PATCH] dongle: set regout0 to provide 3.3V from USB (#361) --- boards/ugl/uhk-80/CMakeLists.txt | 4 +++ boards/ugl/uhk-80/board.c | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 boards/ugl/uhk-80/CMakeLists.txt create mode 100644 boards/ugl/uhk-80/board.c diff --git a/boards/ugl/uhk-80/CMakeLists.txt b/boards/ugl/uhk-80/CMakeLists.txt new file mode 100644 index 00000000..1e446521 --- /dev/null +++ b/boards/ugl/uhk-80/CMakeLists.txt @@ -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() diff --git a/boards/ugl/uhk-80/board.c b/boards/ugl/uhk-80/board.c new file mode 100644 index 00000000..1f8d0c31 --- /dev/null +++ b/boards/ugl/uhk-80/board.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Nordic Semiconductor ASA. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#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