Skip to content

fix build with zephyr with latest nrfx v4#3376

Merged
hathach merged 1 commit intomasterfrom
fix-zephyr-build
Nov 28, 2025
Merged

fix build with zephyr with latest nrfx v4#3376
hathach merged 1 commit intomasterfrom
fix-zephyr-build

Conversation

@hathach
Copy link
Owner

@hathach hathach commented Nov 28, 2025

No description provided.

Copilot AI review requested due to automatic review settings November 28, 2025 05:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes build compatibility with Zephyr RTOS when using the latest nrfx v4 by adding proper version detection and conditional compilation for Zephyr-specific configurations.

Key changes:

  • Extended nrfx version detection to support v3 and v4 based on MDK version ranges
  • Updated clock API calls to use the new nrf_clock_is_running() function for nrfx v2+
  • Added Zephyr-specific conditional compilation to exclude UART initialization that conflicts with Zephyr's drivers

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/portable/nordic/nrf5x/dcd_nrf5x.c Added nrfx v3/v4 detection logic and updated clock API calls to use newer functions
hw/bsp/nrf/family.cmake Added MDK header include path for Zephyr builds
hw/bsp/nrf/family.c Wrapped UART initialization code with Zephyr guards to prevent conflicts
examples/device/cdc_msc/prj.conf Removed UART0 configuration that conflicts with Zephyr's driver handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

*/
#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.
Comment on lines 864 to 865
nrf_clock_hfclk_t active_clk_src;
return nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_HFCLK, &active_clk_src);
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.

The variable active_clk_src is declared but its value is never used after the function call. Consider using NULL as the third parameter if the API supports it, or add a comment explaining why the output parameter is intentionally unused.

Suggested change
nrf_clock_hfclk_t active_clk_src;
return nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_HFCLK, &active_clk_src);
// Output parameter unused; pass NULL
return nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_HFCLK, NULL);

Copilot uses AI. Check for mistakes.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 861 to 865
#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
nrf_clock_hfclk_t active_clk_src;
return nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_HFCLK, &active_clk_src);

Choose a reason for hiding this comment

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

P1 Badge Preserve clock API for nrfx v2/v3 builds

When CFG_TUD_NRF_NRFX_VERSION resolves to 2 or 3 (MDK 8.44–8.53 per the version table), hfclk_running now calls nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_HFCLK, …) for all versions greater than 1. That helper only exists in nrfx v4, while the v2/v3 HALs still expose nrf_clock_hf_is_running, so building against the common nrfx v2/v3 SDKs will fail to link. Please keep the old nrf_clock_hf_is_running path for versions below v4 and use nrf_clock_is_running only when CFG_TUD_NRF_NRFX_VERSION is 4.

Useful? React with 👍 / 👎.

@sonarqubecloud
Copy link

@hathach hathach merged commit 583fe84 into master Nov 28, 2025
197 of 200 checks passed
@hathach hathach deleted the fix-zephyr-build branch November 28, 2025 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant