Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/device/cdc_msc/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ CONFIG_FPU=y
CONFIG_NO_OPTIMIZATIONS=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NRFX_POWER=y
CONFIG_NRFX_UARTE0=y
1 change: 0 additions & 1 deletion examples/device/msc_dual_lun/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ CONFIG_FPU=y
CONFIG_NO_OPTIMIZATIONS=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NRFX_POWER=y
CONFIG_NRFX_UARTE0=y
9 changes: 9 additions & 0 deletions hw/bsp/nrf/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(120);
#define OUTPUTRDY_Msk POWER_USBREGSTATUS_OUTPUTRDY_Msk
#endif

#if CFG_TUSB_OS != OPT_OS_ZEPHYR
static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(0);
#endif

void USBD_IRQHandler(void) {
tud_int_handler(0);
Expand Down Expand Up @@ -163,6 +165,7 @@ void board_init(void) {
irq_enable(DT_INST_IRQN(0));
#endif

#if CFG_TUSB_OS != OPT_OS_ZEPHYR
// UART
nrfx_uarte_config_t uart_cfg = {
.txd_pin = UART_TX_PIN,
Expand All @@ -179,6 +182,7 @@ void board_init(void) {
};

nrfx_uarte_init(&_uart_id, &uart_cfg, NULL);
#endif

//------------- USB -------------//
#if CFG_TUD_ENABLED
Expand Down Expand Up @@ -276,8 +280,13 @@ int board_uart_read(uint8_t* buf, int len) {
}

int board_uart_write(void const* buf, int len) {
#if CFG_TUSB_OS == OPT_OS_ZEPHYR
(void) buf;
return len;
#else
nrfx_err_t err = nrfx_uarte_tx(&_uart_id, (uint8_t const*) buf, (size_t) len ,0);
return (NRFX_SUCCESS == err) ? len : 0;
#endif
}

#if CFG_TUSB_OS == OPT_OS_NONE
Expand Down
4 changes: 3 additions & 1 deletion hw/bsp/nrf/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ function(family_configure_example TARGET RTOS)
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
)

if (NOT RTOS STREQUAL zephyr)
if (RTOS STREQUAL zephyr)
target_include_directories(${TARGET} PUBLIC ${ZEPHYR_HAL_NORDIC_MODULE_DIR}/nrfx/bsp/stable/mdk)
else ()
target_sources(${TARGET} PRIVATE ${STARTUP_FILE_${CMAKE_C_COMPILER_ID}})

if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
Expand Down
47 changes: 27 additions & 20 deletions src/portable/nordic/nrf5x/dcd_nrf5x.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,26 @@
/* Try to detect nrfx version if not configured with CFG_TUD_NRF_NRFX_VERSION
* nrfx v1 and v2 are concurrently developed. There is no NRFX_VERSION only MDK VERSION which is as follows:
* - v3.0.0: 8.53.1 (conflict with v2.11.0), v3.1.0: 8.55.0 ...
* - v2.11.0: 8.53.1, v2.6.0: 8.44.1, v2.5.0: 8.40.2, v2.4.0: 8.37.0, v2.3.0: 8.35.0, v2.2.0: 8.32.1, v2.1.0: 8.30.2, v2.0.0: 8.29.0
* - v2.11.0: 8.53.1, v2.6.0: 8.44.1, v2.5.0: 8.40.2, v2.4.0: 8.37.0, v2.3.0: 8.35.0, v2.2.0: 8.32.1, v2.1.0: 8.30.2,
* v2.0.0: 8.29.0
* - v1.9.0: 8.40.3, v1.8.6: 8.35.0 (conflict with v2.3.0), v1.8.5: 8.32.3, v1.8.4: 8.32.1 (conflict with v2.2.0),
* v1.8.2: 8.32.1 (conflict with v2.2.0), v1.8.1: 8.27.1
* Therefore the check for v1 would be:
* - MDK < 8.29.0 (v2.0), MDK == 8.32.3, 8.40.3
* - in case of conflict User of those version must upgrade to other 1.x version or set CFG_TUD_NRF_NRFX_VERSION
*/
*/
#ifndef CFG_TUD_NRF_NRFX_VERSION
#define _MDK_VERSION (10000*MDK_MAJOR_VERSION + 100*MDK_MINOR_VERSION + MDK_MICRO_VERSION)
#define MDK_VERSION (10000 * MDK_MAJOR_VERSION + 100 * MDK_MINOR_VERSION + MDK_MICRO_VERSION)
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The macro was renamed from _MDK_VERSION to MDK_VERSION, removing the leading underscore. This could potentially conflict with a macro defined by the MDK headers themselves. Consider using a project-specific prefix like TUSB_MDK_VERSION to avoid potential naming collisions with external libraries.

Copilot uses AI. Check for mistakes.

#if _MDK_VERSION < 82900 || _MDK_VERSION == 83203 || _MDK_VERSION == 84003
#if MDK_VERSION < 82900 || MDK_VERSION == 83203 || MDK_VERSION == 84003
// nrfx <= 1.8.1, or 1.8.5 or 1.9.0
#define CFG_TUD_NRF_NRFX_VERSION 1
#else
#elif MDK_VERSION < 85301
#define CFG_TUD_NRF_NRFX_VERSION 2
#elif MDK_VERSION < 87300
#define CFG_TUD_NRF_NRFX_VERSION 3
#else
#define CFG_TUD_NRF_NRFX_VERSION 4
#endif
#endif

Expand Down Expand Up @@ -845,19 +850,19 @@ TU_ATTR_ALWAYS_INLINE static inline bool is_sd_enabled(void) {
#endif

static bool hfclk_running(void) {
#ifdef SOFTDEVICE_PRESENT
if ( is_sd_enabled() ) {
#ifdef SOFTDEVICE_PRESENT
if (is_sd_enabled()) {
uint32_t is_running = 0;
(void) sd_clock_hfclk_is_running(&is_running);
(void)sd_clock_hfclk_is_running(&is_running);
return (is_running ? true : false);
}
#endif
#endif

#if CFG_TUD_NRF_NRFX_VERSION == 1
#if CFG_TUD_NRF_NRFX_VERSION == 1
return nrf_clock_hf_is_running(NRF_CLOCK_HFCLK_HIGH_ACCURACY);
#else
return nrf_clock_hf_is_running(NRF_CLOCK, NRF_CLOCK_HFCLK_HIGH_ACCURACY);
#endif
#else
return nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_HFCLK, NULL);
#endif
}

static void hfclk_enable(void) {
Expand All @@ -867,22 +872,24 @@ static void hfclk_enable(void) {
#else

// already running, nothing to do
if (hfclk_running()) return;
if (hfclk_running()) {
return;
}

#ifdef SOFTDEVICE_PRESENT
if ( is_sd_enabled() ) {
#ifdef SOFTDEVICE_PRESENT
if (is_sd_enabled()) {
(void)sd_clock_hfclk_request();
return;
}
#endif
#endif

#if CFG_TUD_NRF_NRFX_VERSION == 1
#if CFG_TUD_NRF_NRFX_VERSION == 1
nrf_clock_event_clear(NRF_CLOCK_EVENT_HFCLKSTARTED);
nrf_clock_task_trigger(NRF_CLOCK_TASK_HFCLKSTART);
#else
#else
nrf_clock_event_clear(NRF_CLOCK, NRF_CLOCK_EVENT_HFCLKSTARTED);
nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_HFCLKSTART);
#endif
#endif
#endif
}

Expand Down