get cmake build with 54h20 not tested on actual hw, probably not running

This commit is contained in:
hathach
2025-10-13 12:41:55 +07:00
parent 87523f2494
commit ee7a7c56db
24 changed files with 487 additions and 137 deletions

View File

@ -0,0 +1,11 @@
set(MCU_VARIANT nrf54h20)
function(update_board TARGET)
# temporarily, 54h20 has multiple sram sections
target_compile_definitions(${TARGET} PUBLIC
CFG_EXAMPLE_VIDEO_READONLY
)
target_sources(${TARGET} PRIVATE
# ${NRFX_PATH}/drivers/src/nrfx_usbreg.c
)
endfunction()

View File

@ -0,0 +1,65 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020, Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
/* metadata:
name: Nordic nRF5340 DK
url: https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF5340-DK
*/
#ifndef BOARD_H_
#define BOARD_H_
#ifdef __cplusplus
extern "C" {
#endif
#define _PINNUM(port, pin) ((port)*32 + (pin))
// LED
#define LED_PIN 28
#define LED_STATE_ON 0
// Button
#define BUTTON_PIN 23
#define BUTTON_STATE_ACTIVE 0
// UART
#define UART_RX_PIN 22
#define UART_TX_PIN 20
// SPI for USB host shield
// Pin is correct but not working probably due to signal incompatible (1.8V 3v3) with MAC3421E !?
//#define MAX3421_SCK_PIN _PINNUM(1, 15)
//#define MAX3421_MOSI_PIN _PINNUM(1, 13)
//#define MAX3421_MISO_PIN _PINNUM(1, 14)
//#define MAX3421_CS_PIN _PINNUM(1, 12)
//#define MAX3421_INTR_PIN _PINNUM(1, 11)
#ifdef __cplusplus
}
#endif
#endif /* BOARD_H_ */

View File

@ -0,0 +1,16 @@
MCU_VARIANT = nrf54h20_application
CFLAGS += -DNRF54H20_XXAA
# enable max3421 host driver for this board
MAX3421_HOST = 1
LD_FILE = hw/mcu/nordic/nrfx/mdk/nrf5340_xxaa_application.ld
SRC_C += hw/mcu/nordic/nrfx/drivers/src/nrfx_usbreg.c
# caused by void SystemStoreFICRNS() (without void) in system_nrf5340_application.c
CFLAGS += -Wno-error=strict-prototypes
# flash using jlink
JLINK_DEVICE = nrf5340_xxaa_app
flash: flash-jlink

View File

@ -1,4 +1,5 @@
set(MCU_VARIANT nrf5340_application)
#set(MCU_VARIANT nrf5340_application)
set(MCU_VARIANT nrf5340)
function(update_board TARGET)
target_sources(${TARGET} PRIVATE

View File

@ -1,4 +1,3 @@
CPU_CORE = cortex-m33
MCU_VARIANT = nrf5340_application
CFLAGS += -DNRF5340_XXAA -DNRF5340_XXAA_APPLICATION

View File

@ -45,7 +45,9 @@
#include "nrfx.h"
#include "hal/nrf_gpio.h"
#include "nrfx_gpiote.h"
#if !defined(NRF54H20_XXAA)
#include "nrfx_power.h"
#endif
#include "nrfx_uarte.h"
#include "nrfx_spim.h"
@ -58,21 +60,26 @@
#pragma GCC diagnostic pop
#endif
// There is API changes between nrfx v2 and v3
#if 85301 >= (10000*MDK_MAJOR_VERSION + 100*MDK_MINOR_VERSION + MDK_MICRO_VERSION)
// note MDK 8.53.1 is also used by nrfx v3.0.0, just skip this version and use later 3.x
#define NRFX_VER 2
#else
#define NRFX_VER 3
// example only supports nrfx v3 for code simplicity
#if !(defined(NRFX_CONFIG_API_VER_MAJOR) && NRFX_CONFIG_API_VER_MAJOR >= 3) && \
!(85301 >= (10000*MDK_MAJOR_VERSION + 100*MDK_MINOR_VERSION + MDK_MICRO_VERSION))
#error "Example requires nrfx v3.0.0 or later"
#endif
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
#if defined(NRF54H20_XXAA)
#define USBD_IRQn USBHS_IRQn
void USBHS_IRQHandler(void) {
tusb_int_handler(0, true);
}
#else
void USBD_IRQHandler(void) {
tud_int_handler(0);
}
#endif
/*------------------------------------------------------------------*/
/* MACRO TYPEDEF CONSTANT ENUM
@ -96,39 +103,39 @@ enum {
#define OUTPUTRDY_Msk POWER_USBREGSTATUS_OUTPUTRDY_Msk
#endif
static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(0);
static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(CFG_NRFX_UARTE_INSTANCE_ID);
// tinyusb function that handles power event (detected, ready, removed)
// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled.
extern void tusb_hal_nrf_power_event(uint32_t event);
#if !defined(NRF54H20_XXAA)
// nrf power callback, could be unused if SD is enabled or usb is disabled (board_test example)
TU_ATTR_UNUSED static void power_event_handler(nrfx_power_usb_evt_t event) {
tusb_hal_nrf_power_event((uint32_t) event);
}
#endif
//------------- Host using MAX2341E -------------//
#if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
static void max3421_init(void);
static nrfx_spim_t _spi = NRFX_SPIM_INSTANCE(1);
#if NRFX_VER > 2
static nrfx_gpiote_t _gpiote = NRFX_GPIOTE_INSTANCE(0);
#endif
#endif
//--------------------------------------------------------------------+
//
//--------------------------------------------------------------------+
void board_init(void) {
#if !defined(NRF54H20_XXAA)
// stop LF clock just in case we jump from application without reset
NRF_CLOCK->TASKS_LFCLKSTOP = 1UL;
// Use Internal OSC to compatible with all boards
NRF_CLOCK->LFCLKSRC = LFCLK_SRC_RC;
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
#endif
// LED
nrf_gpio_cfg_output(LED_PIN);
@ -140,6 +147,7 @@ void board_init(void) {
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
#elif CFG_TUSB_OS == OPT_OS_ZEPHYR
#ifdef CONFIG_HAS_HW_NRF_USBREG
// IRQ_CONNECT(USBREGULATOR_IRQn, DT_IRQ(DT_INST(0, nordic_nrf_clock), priority), nrfx_isr, nrfx_usbreg_irq_handler, 0);
@ -153,21 +161,6 @@ void board_init(void) {
#endif
// UART
#if NRFX_VER <= 2
nrfx_uarte_config_t uart_cfg = {
.pseltxd = UART_TX_PIN,
.pselrxd = UART_RX_PIN,
.pselcts = NRF_UARTE_PSEL_DISCONNECTED,
.pselrts = NRF_UARTE_PSEL_DISCONNECTED,
.p_context = NULL,
.baudrate = NRF_UARTE_BAUDRATE_115200, // CFG_BOARD_UART_BAUDRATE
.interrupt_priority = 7,
.hal_cfg = {
.hwfc = NRF_UARTE_HWFC_DISABLED,
.parity = NRF_UARTE_PARITY_EXCLUDED,
}
};
#else
nrfx_uarte_config_t uart_cfg = {
.txd_pin = UART_TX_PIN,
.rxd_pin = UART_RX_PIN,
@ -181,7 +174,6 @@ void board_init(void) {
.parity = NRF_UARTE_PARITY_EXCLUDED,
}
};
#endif
nrfx_uarte_init(&_uart_id, &uart_cfg, NULL);
@ -191,6 +183,7 @@ void board_init(void) {
// 2 is highest for application
NVIC_SetPriority(USBD_IRQn, 2);
#if !defined(NRF54H20_XXAA)
// USB power may already be ready at this time -> no event generated
// We need to invoke the handler based on the status initially
uint32_t usb_reg;
@ -234,6 +227,7 @@ void board_init(void) {
tusb_hal_nrf_power_event(USB_EVT_READY);
}
#endif
#endif
#if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
max3421_init();
@ -255,7 +249,9 @@ uint32_t board_button_read(void) {
size_t board_get_unique_id(uint8_t id[], size_t max_len) {
(void) max_len;
#ifdef NRF5340_XXAA
#if defined(NRF54H20_XXAA)
uintptr_t did_addr = (uintptr_t) NRF_FICR->BLE.ADDR;
#elif defined(NRF5340_XXAA)
uintptr_t did_addr = (uintptr_t) NRF_FICR->INFO.DEVICEID;
#else
uintptr_t did_addr = (uintptr_t) NRF_FICR->DEVICEID;
@ -277,11 +273,7 @@ int board_uart_read(uint8_t* buf, int len) {
}
int board_uart_write(void const* buf, int len) {
nrfx_err_t err = nrfx_uarte_tx(&_uart_id, (uint8_t const*) buf, (size_t) len
#if NRFX_VER > 2
,0
#endif
);
nrfx_err_t err = nrfx_uarte_tx(&_uart_id, (uint8_t const*) buf, (size_t) len ,0);
return (NRFX_SUCCESS == err) ? len : 0;
}
@ -352,18 +344,16 @@ void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info) {
// API: SPI transfer with MAX3421E, must be implemented by application
//--------------------------------------------------------------------+
#if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
#if NRFX_VER <= 2
void max3421_int_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action ) {
if (action != NRF_GPIOTE_POLARITY_HITOLO) return;
#else
void max3421_int_handler(nrfx_gpiote_pin_t pin, nrfx_gpiote_trigger_t action, void* p_context) {
(void) p_context;
if (action != NRFX_GPIOTE_TRIGGER_HITOLO) return;
#endif
if (action != NRFX_GPIOTE_TRIGGER_HITOLO) {
return;
}
if (pin != MAX3421_INTR_PIN) {
return;
}
if (pin != MAX3421_INTR_PIN) return;
tuh_int_handler(1, true);
tusb_int_handler(1, true);
}
static void max3421_init(void) {
@ -378,13 +368,8 @@ static void max3421_init(void) {
.sck_pin = MAX3421_SCK_PIN,
.mosi_pin = MAX3421_MOSI_PIN,
.miso_pin = MAX3421_MISO_PIN,
#if NRFX_VER <= 2
.ss_pin = NRFX_SPIM_PIN_NOT_USED,
.frequency = NRF_SPIM_FREQ_4M,
#else
.ss_pin = NRF_SPIM_PIN_NOT_CONNECTED,
.frequency = 4000000u,
#endif
.ss_active_high = false,
.irq_priority = 3,
.orc = 0xFF,
@ -398,14 +383,6 @@ static void max3421_init(void) {
TU_ASSERT(NRFX_SUCCESS == nrfx_spim_init(&_spi, &cfg, NULL, NULL), );
// max3421e interrupt pin
#if NRFX_VER <= 2
nrfx_gpiote_init(1);
nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
in_config.pull = NRF_GPIO_PIN_PULLUP;
NVIC_SetPriority(GPIOTE_IRQn, 2);
nrfx_gpiote_in_init(MAX3421_INTR_PIN, &in_config, max3421_int_handler);
nrfx_gpiote_trigger_enable(MAX3421_INTR_PIN, true);
#else
nrf_gpio_pin_pull_t intr_pull = NRF_GPIO_PIN_PULLUP;
nrfx_gpiote_trigger_config_t intr_trigger = {
.trigger = NRFX_GPIOTE_TRIGGER_HITOLO,
@ -426,7 +403,6 @@ static void max3421_init(void) {
nrfx_gpiote_input_configure(&_gpiote, MAX3421_INTR_PIN, &intr_config);
nrfx_gpiote_trigger_enable(&_gpiote, MAX3421_INTR_PIN, true);
#endif
}
// API to enable/disable MAX3421 INTR pin interrupt

View File

@ -10,17 +10,21 @@ if (NOT board_cmake_included)
endif ()
# toolchain set up
if (MCU_VARIANT STREQUAL "nrf5340_application")
if (MCU_VARIANT STREQUAL nrf5340 OR MCU_VARIANT STREQUAL nrf54h20)
set(CMAKE_SYSTEM_CPU cortex-m33 CACHE INTERNAL "System Processor")
set(JLINK_DEVICE nrf5340_xxaa_app)
set(JLINK_DEVICE ${MCU_VARIANT}_xxaa_app)
else ()
set(CMAKE_SYSTEM_CPU cortex-m4 CACHE INTERNAL "System Processor")
set(JLINK_DEVICE ${MCU_VARIANT}_xxaa)
endif ()
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
if (MCU_VARIANT STREQUAL "nrf54h20")
set(FAMILY_MCUS NRF54 CACHE INTERNAL "")
else ()
set(FAMILY_MCUS NRF5X CACHE INTERNAL "")
endif ()
set(FAMILY_MCUS NRF5X CACHE INTERNAL "")
set(CMAKE_TOOLCHAIN_FILE ${TOP}/examples/build_system/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
#------------------------------------
# BOARD_TARGET
@ -31,36 +35,46 @@ function(add_board_target BOARD_TARGET)
return()
endif ()
if (MCU_VARIANT STREQUAL "nrf5340_application")
set(MCU_VARIANT_XXAA "nrf5340_xxaa_application")
else ()
set(MCU_VARIANT_XXAA "${MCU_VARIANT}_xxaa")
endif ()
if (NOT DEFINED LD_FILE_GNU)
set(LD_FILE_GNU ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/${MCU_VARIANT_XXAA}.ld)
endif ()
if (NOT DEFINED STARTUP_FILE_${CMAKE_C_COMPILER_ID})
set(STARTUP_FILE_GNU ${NRFX_PATH}/mdk/gcc_startup_${MCU_VARIANT}.S)
set(STARTUP_FILE_Clang ${STARTUP_FILE_GNU})
endif ()
add_library(${BOARD_TARGET} STATIC
${NRFX_PATH}/helpers/nrfx_flag32_allocator.c
${NRFX_PATH}/drivers/src/nrfx_gpiote.c
${NRFX_PATH}/drivers/src/nrfx_power.c
${NRFX_PATH}/drivers/src/nrfx_spim.c
${NRFX_PATH}/drivers/src/nrfx_uarte.c
${NRFX_PATH}/mdk/system_${MCU_VARIANT}.c
${NRFX_PATH}/soc/nrfx_atomic.c
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
)
string(TOUPPER "${MCU_VARIANT_XXAA}" MCU_VARIANT_XXAA_UPPER)
if (MCU_VARIANT STREQUAL nrf54h20)
set(LD_FILE_GNU_DEFAULT ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/${MCU_VARIANT}_xxaa_application.ld)
target_sources(${BOARD_TARGET} PUBLIC
${NRFX_PATH}/mdk/system_nrf54h.c
${NRFX_PATH}/mdk/gcc_startup_${MCU_VARIANT}_application.S
)
elseif (MCU_VARIANT STREQUAL nrf5340)
set(LD_FILE_GNU_DEFAULT ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/${MCU_VARIANT}_xxaa_application.ld)
target_sources(${BOARD_TARGET} PUBLIC
${NRFX_PATH}/mdk/system_${MCU_VARIANT}_application.c
${NRFX_PATH}/mdk/gcc_startup_${MCU_VARIANT}_application.S
)
target_compile_definitions(${BOARD_TARGET} PUBLIC NRF5340_XXAA_APPLICATION)
else()
set(LD_FILE_GNU_DEFAULT ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/linker/${MCU_VARIANT}_xxaa.ld)
target_sources(${BOARD_TARGET} PUBLIC
${NRFX_PATH}/mdk/system_${MCU_VARIANT}.c
${NRFX_PATH}/mdk/gcc_startup_${MCU_VARIANT}.S
)
endif ()
if (NOT DEFINED LD_FILE_GNU)
set(LD_FILE_GNU ${LD_FILE_GNU_DEFAULT})
endif ()
string(TOUPPER ${MCU_VARIANT} MCU_VARIANT_UPPER)
target_compile_definitions(${BOARD_TARGET} PUBLIC
__STARTUP_CLEAR_BSS
CONFIG_GPIO_AS_PINRESET
${MCU_VARIANT_XXAA_UPPER}
${MCU_VARIANT_UPPER}_XXAA
NRF_APPLICATION
)
if (TRACE_ETM STREQUAL "1")
@ -137,13 +151,16 @@ function(family_configure_example TARGET RTOS)
endif ()
# Add TinyUSB target and port source
family_add_tinyusb(${TARGET} OPT_MCU_NRF5X)
family_add_tinyusb(${TARGET} OPT_MCU_${FAMILY_MCUS})
target_sources(${TARGET} PRIVATE
${TOP}/src/portable/nordic/nrf5x/dcd_nrf5x.c
${TOP}/src/portable/synopsys/dwc2/dcd_dwc2.c
${TOP}/src/portable/synopsys/dwc2/hcd_dwc2.c
${TOP}/src/portable/synopsys/dwc2/dwc2_common.c
)
# Flashing
# family_add_bin_hex(${TARGET})
# family_add_bin_hex(${TARGET})
family_flash_jlink(${TARGET})
# family_flash_adafruit_nrfutil(${TARGET})
# family_flash_adafruit_nrfutil(${TARGET})
endfunction()

View File

@ -5,7 +5,15 @@ NRFX_PATH = hw/mcu/nordic/nrfx
include $(TOP)/$(BOARD_PATH)/board.mk
# nRF52 is cortex-m4, nRF53 is cortex-m33
CPU_CORE ?= cortex-m4
ifeq (${MCU_VARIANT},nrf5340_application)
CPU_CORE = cortex-m33
else
ifeq (${MCU_VARIANT},nrf54h20_application)
CPU_CORE = cortex-m33
else
CPU_CORE = cortex-m4
endif
endif
CFLAGS += \
-DCFG_TUSB_MCU=OPT_MCU_NRF5X \

View File

@ -12,9 +12,3 @@ MEMORY
INCLUDE "nrf_common.ld"
/* nrfx v2 linker does not define __tbss_start/end__ __sbss_start/end__*/
__tbss_start__ = __tbss_start;
__tbss_end__ = __tbss_end;
__sbss_start__ = __sbss_start;
__sbss_end__ = __sbss_end;

View File

@ -36,9 +36,3 @@ SECTIONS
} INSERT AFTER .data;
INCLUDE "nrf_common.ld"
/* nrfx v2 linker does not define __tbss_start/end__ __sbss_start/end__*/
__tbss_start__ = __tbss_start;
__tbss_end__ = __tbss_end;
__sbss_start__ = __sbss_start;
__sbss_end__ = __sbss_end;

View File

@ -12,9 +12,3 @@ MEMORY
}
INCLUDE "nrf_common.ld"
/* nrfx v2 linker does not define __tbss_start/end__ __sbss_start/end__*/
__tbss_start__ = __tbss_start;
__tbss_end__ = __tbss_end;
__sbss_start__ = __sbss_start;
__sbss_end__ = __sbss_end;

View File

@ -13,9 +13,3 @@ MEMORY
INCLUDE "nrf_common.ld"
/* nrfx v2 linker does not define __tbss_start/end__ __sbss_start/end__*/
__tbss_start__ = __tbss_start;
__tbss_end__ = __tbss_end;
__sbss_start__ = __sbss_start;
__sbss_end__ = __sbss_end;

View File

@ -0,0 +1,21 @@
/* Linker script to configure memory regions. */
SEARCH_DIR(.)
/*GROUP(-lgcc -lc) not compatible with clang*/
MEMORY
{
FLASH (rx) : ORIGIN = 0xE0A0000, LENGTH = 0x40000 /* Inside global MRAM0 */
FLASH1 (rx) : ORIGIN = 0x2F840000, LENGTH = 0x4000 /* OTP0 */
EXTFLASH (rx) : ORIGIN = 0x70000000, LENGTH = 0x20000000
RAM (rwx) : ORIGIN = 0x22000000, LENGTH = 0x8000
RAM1 (rwx) : ORIGIN = 0x2F000000, LENGTH = 0x80000 /* RAM00 */
RAM2 (rwx) : ORIGIN = 0x2F080000, LENGTH = 0x60000 /* RAM01 */
RAM3 (rwx) : ORIGIN = 0x2F880000, LENGTH = 0x10000 /* RAM20 */
RAM4 (rwx) : ORIGIN = 0x2F890000, LENGTH = 0x8000 /* RAM21 */
RAM5 (rwx) : ORIGIN = 0x2FC00000, LENGTH = 0x4000 /* RAM30 (low-speed) */
RAM6 (rwx) : ORIGIN = 0x2FC04000, LENGTH = 0x4000 /* RAM31 (low-speed) */
}
INCLUDE "nrf_common.ld"

View File

@ -1,46 +1,111 @@
/*
* Copyright (c) 2019 - 2025, Nordic Semiconductor ASA
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef NRFX_CONFIG_H__
#define NRFX_CONFIG_H__
#define NRFX_POWER_ENABLED 1
#define NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY 7
#define NRFX_CLOCK_ENABLED 0
#define NRFX_GPIOTE_ENABLED 1
#define NRFX_GPIOTE0_ENABLED 1
#define NRFX_UARTE_ENABLED 1
#define NRFX_UARTE0_ENABLED 1
#define NRFX_SPIM_ENABLED 1
#define NRFX_SPIM1_ENABLED 1 // use SPI1 since nrf5340 share uart with spi
#define NRFX_PRS_ENABLED 0
#define NRFX_USBREG_ENABLED 1
#include "nrfx_config_common.h"
#if defined(NRF51)
#include <templates/nrfx_config_nrf51.h>
#include <templates/nrfx_config_nrf51.h>
#elif defined(NRF52805_XXAA)
#include <templates/nrfx_config_nrf52805.h>
#include <templates/nrfx_config_nrf52805.h>
#elif defined(NRF52810_XXAA)
#include <templates/nrfx_config_nrf52810.h>
#include <templates/nrfx_config_nrf52810.h>
#elif defined(NRF52811_XXAA)
#include <templates/nrfx_config_nrf52811.h>
#include <templates/nrfx_config_nrf52811.h>
#elif defined(NRF52820_XXAA)
#include <templates/nrfx_config_nrf52820.h>
#include <templates/nrfx_config_nrf52820.h>
#elif defined(NRF52832_XXAA) || defined (NRF52832_XXAB)
#include <templates/nrfx_config_nrf52832.h>
#include <templates/nrfx_config_nrf52832.h>
#elif defined(NRF52833_XXAA)
#include <templates/nrfx_config_nrf52833.h>
#include <templates/nrfx_config_nrf52833.h>
#elif defined(NRF52840_XXAA)
#include <templates/nrfx_config_nrf52840.h>
#include <templates/nrfx_config_nrf52840.h>
#elif defined(NRF5340_XXAA_APPLICATION)
#include <templates/nrfx_config_nrf5340_application.h>
#include <templates/nrfx_config_nrf5340_application.h>
#elif defined(NRF5340_XXAA_NETWORK)
#include <templates/nrfx_config_nrf5340_network.h>
#elif defined(NRF54H20_XXAA) && defined(NRF_APPLICATION)
#include <templates/nrfx_config_nrf54h20_application.h>
#elif defined(NRF54H20_XXAA) && defined(NRF_RADIOCORE)
#include <templates/nrfx_config_nrf54h20_radiocore.h>
#elif defined(NRF54H20_XXAA) && defined(NRF_PPR)
#include <templates/nrfx_config_nrf54h20_ppr.h>
#elif defined(NRF54H20_XXAA) && defined(NRF_FLPR)
#include <templates/nrfx_config_nrf54h20_flpr.h>
#elif defined(NRF54L05_XXAA) && defined(NRF_APPLICATION)
#include <templates/nrfx_config_nrf54l05_application.h>
#elif defined(NRF54L05_XXAA) && defined(NRF_FLPR)
#include <templates/nrfx_config_nrf54l05_flpr.h>
#elif defined(NRF54L10_XXAA) && defined(NRF_APPLICATION)
#include <templates/nrfx_config_nrf54l10_application.h>
#elif defined(NRF54L10_XXAA) && defined(NRF_FLPR)
#include <templates/nrfx_config_nrf54l10_flpr.h>
#elif defined(NRF54L15_XXAA) && defined(NRF_APPLICATION)
#include <templates/nrfx_config_nrf54l15_application.h>
#elif defined(NRF54L15_XXAA) && defined(NRF_FLPR)
#include <templates/nrfx_config_nrf54l15_flpr.h>
#elif defined(NRF54LM20A_ENGA_XXAA) && defined(NRF_APPLICATION)
#include <templates/nrfx_config_nrf54lm20a_enga_application.h>
#elif defined(NRF54LM20A_ENGA_XXAA) && defined(NRF_FLPR)
#include <templates/nrfx_config_nrf54lm20a_enga_flpr.h>
#elif defined(NRF54LS05B_ENGA_XXAA) && defined(NRF_APPLICATION)
#include <templates/nrfx_config_nrf54ls05b_application.h>
#elif defined(NRF54LV10A_ENGA_XXAA) && defined(NRF_APPLICATION)
#include <templates/nrfx_config_nrf54lv10a_enga_application.h>
#elif defined(NRF54LV10A_ENGA_XXAA) && defined(NRF_FLPR)
#include <templates/nrfx_config_nrf54lv10a_enga_flpr.h>
#elif defined(NRF7120_ENGA_XXAA) && defined(NRF_APPLICATION)
#include <templates/nrfx_config_nrf7120_application.h>
#elif defined(NRF7120_ENGA_XXAA) && defined(NRF_FLPR)
#include <templates/nrfx_config_nrf7120_flpr.h>
#elif defined(NRF7120_ENGA_XXAA) && defined(NRF_LMAC)
#include <templates/nrfx_config_nrf7120_lmac.h>
#elif defined(NRF7120_ENGA_XXAA) && defined(NRF_UMAC)
#include <templates/nrfx_config_nrf7120_umac.h>
#elif defined(NRF9120_XXAA) || defined(NRF9160_XXAA)
#include <templates/nrfx_config_nrf91.h>
#elif defined(NRF9230_ENGB_XXAA) && defined(NRF_APPLICATION)
#include <templates/nrfx_config_nrf9230_engb_application.h>
#elif defined(NRF9230_ENGB_XXAA) && defined(NRF_RADIOCORE)
#include <templates/nrfx_config_nrf9230_engb_radiocore.h>
#elif defined(NRF9230_ENGB_XXAA) && defined(NRF_PPR)
#include <templates/nrfx_config_nrf9230_engb_ppr.h>
#elif defined(NRF9230_ENGB_XXAA) && defined(NRF_FLPR)
#include <templates/nrfx_config_nrf9230_engb_flpr.h>
#else
#error "Unknown device."
#include "nrfx_config_ext.h"
#endif
#endif // NRFX_CONFIG_H__

View File

@ -0,0 +1,86 @@
/*
* Copyright (c) 2022 - 2025, Nordic Semiconductor ASA
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef NRFX_CONFIG_COMMON_H__
#define NRFX_CONFIG_COMMON_H__
#ifndef NRFX_CONFIG_H__
#error "This file should not be included directly. Include nrfx_config.h instead."
#endif
/** @brief Symbol specifying major version of the nrfx API to be used. */
#ifndef NRFX_CONFIG_API_VER_MAJOR
#define NRFX_CONFIG_API_VER_MAJOR 3
#endif
/** @brief Symbol specifying minor version of the nrfx API to be used. */
#ifndef NRFX_CONFIG_API_VER_MINOR
#define NRFX_CONFIG_API_VER_MINOR 12
#endif
/** @brief Symbol specifying micro version of the nrfx API to be used. */
#ifndef NRFX_CONFIG_API_VER_MICRO
#define NRFX_CONFIG_API_VER_MICRO 0
#endif
//--------------------------------------------------------------------+
//
//--------------------------------------------------------------------+
#define NRFX_CLOCK_ENABLED 0
#define NRFX_UARTE_ENABLED 1
#if defined(NRF54H20_XXAA)
#define NRFX_UARTE120_ENABLED 1
#define CFG_NRFX_UARTE_INSTANCE_ID 120
#else
#define NRFX_POWER_ENABLED 1
#define NRFX_POWER_DEFAULT_CONFIG_IRQ_PRIORITY 7
#define NRFX_UARTE0_ENABLED 1
#define CFG_NRFX_UARTE_INSTANCE_ID 0
#define NRFX_GPIOTE_ENABLED 1
#define NRFX_GPIOTE0_ENABLED 1
#define NRFX_SPIM_ENABLED 1
#define NRFX_SPIM1_ENABLED 1 // use SPI1 since nrf5340 share uart with spi
#endif
#define NRFX_PRS_ENABLED 0
#define NRFX_USBREG_ENABLED 1
#define NRF_STATIC_INLINE static inline
#endif /* NRFX_CONFIG_COMMON_H__ */

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2023 - 2025, Nordic Semiconductor ASA
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef NRFX_CONFIG_EXT_H__
#define NRFX_CONFIG_EXT_H__
#error "Unknown device."
#endif // NRFX_CONFIG_EXT_H__

View File

@ -137,6 +137,12 @@
// 8 CBI + 1 ISO
#define TUP_DCD_ENDPOINT_MAX 9
#elif TU_CHECK_MCU(OPT_MCU_NRF54)
#define TUP_USBIP_DWC2
#define TUP_USBIP_DWC2_NRF
#define TUP_DCD_ENDPOINT_MAX 16
#define CFG_TUH_DWC2_DMA_ENABLE_DEFAULT 0
//--------------------------------------------------------------------+
// Microchip
//--------------------------------------------------------------------+

View File

@ -51,6 +51,8 @@
#include "dwc2_xmc.h"
#elif defined(TUP_USBIP_DWC2_AT32)
#include "dwc2_at32.h"
#elif defined(TUP_USBIP_DWC2_NRF)
#include "dwc2_nrf.h"
#else
#error "Unsupported MCUs"
#endif

View File

@ -0,0 +1,61 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2025 Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
#ifndef TUSB_DWC2_NRF_H
#define TUSB_DWC2_NRF_H
#include "nrf.h"
#define DWC2_EP_MAX 16
static const dwc2_controller_t _dwc2_controller[] = {
{ .reg_base = NRF_USBHSCORE0_NS_BASE, .irqnum = USBHS_IRQn, .ep_count = 16, .ep_fifo_size = 12288 },
};
TU_ATTR_ALWAYS_INLINE static inline void dwc2_int_set(uint8_t rhport, tusb_role_t role, bool enabled) {
(void) rhport;
(void) role;
(void) enabled;
}
#define dwc2_dcd_int_enable(_rhport) dwc2_int_set(_rhport, TUSB_ROLE_DEVICE, true)
#define dwc2_dcd_int_disable(_rhport) dwc2_int_set(_rhport, TUSB_ROLE_DEVICE, false)
TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) {
}
// MCU specific PHY init, called BEFORE core reset
TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
(void)dwc2;
(void)hs_phy_type;
}
// MCU specific PHY update, it is called AFTER init() and core reset
TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_update(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
(void)dwc2;
(void)hs_phy_type;
}
#endif

View File

@ -62,7 +62,8 @@
#define OPT_MCU_LPC55XX OPT_MCU_LPC55
// NRF
#define OPT_MCU_NRF5X 100 ///< Nordic nRF5x series
#define OPT_MCU_NRF5X 100 ///< Nordic nRF 52,53 series
#define OPT_MCU_NRF54 101 ///< Nordic nRF54 series
// SAM
#define OPT_MCU_SAMD21 200 ///< MicroChip SAMD21

View File

@ -47,7 +47,7 @@ deps_optional = {
'b93e856211060ae825216c6a1d6aa347ec758843',
'mm32'],
'hw/mcu/nordic/nrfx': ['https://github.com/NordicSemiconductor/nrfx.git',
'7c47cc0a56ce44658e6da2458e86cd8783ccc4a2',
'11f57e578c7feea13f21c79ea0efab2630ac68c7',
'nrf'],
'hw/mcu/nuvoton': ['https://github.com/majbthrd/nuc_driver.git',
'2204191ec76283371419fbcec207da02e1bc22fa',