fix build with zephyr with latest nrfx v4

This commit is contained in:
hathach
2025-11-28 12:55:56 +07:00
parent 1618c58dc4
commit 7d012b014e
5 changed files with 39 additions and 23 deletions

View File

@ -3,4 +3,3 @@ CONFIG_FPU=y
CONFIG_NO_OPTIMIZATIONS=y CONFIG_NO_OPTIMIZATIONS=y
CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NRFX_POWER=y CONFIG_NRFX_POWER=y
CONFIG_NRFX_UARTE0=y

View File

@ -3,4 +3,3 @@ CONFIG_FPU=y
CONFIG_NO_OPTIMIZATIONS=y CONFIG_NO_OPTIMIZATIONS=y
CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_NRFX_POWER=y CONFIG_NRFX_POWER=y
CONFIG_NRFX_UARTE0=y

View File

@ -100,7 +100,9 @@ static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(120);
#define OUTPUTRDY_Msk POWER_USBREGSTATUS_OUTPUTRDY_Msk #define OUTPUTRDY_Msk POWER_USBREGSTATUS_OUTPUTRDY_Msk
#endif #endif
#if CFG_TUSB_OS != OPT_OS_ZEPHYR
static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(0); static nrfx_uarte_t _uart_id = NRFX_UARTE_INSTANCE(0);
#endif
void USBD_IRQHandler(void) { void USBD_IRQHandler(void) {
tud_int_handler(0); tud_int_handler(0);
@ -163,6 +165,7 @@ void board_init(void) {
irq_enable(DT_INST_IRQN(0)); irq_enable(DT_INST_IRQN(0));
#endif #endif
#if CFG_TUSB_OS != OPT_OS_ZEPHYR
// UART // UART
nrfx_uarte_config_t uart_cfg = { nrfx_uarte_config_t uart_cfg = {
.txd_pin = UART_TX_PIN, .txd_pin = UART_TX_PIN,
@ -179,6 +182,7 @@ void board_init(void) {
}; };
nrfx_uarte_init(&_uart_id, &uart_cfg, NULL); nrfx_uarte_init(&_uart_id, &uart_cfg, NULL);
#endif
//------------- USB -------------// //------------- USB -------------//
#if CFG_TUD_ENABLED #if CFG_TUD_ENABLED
@ -276,8 +280,13 @@ int board_uart_read(uint8_t* buf, int len) {
} }
int board_uart_write(void const* 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); nrfx_err_t err = nrfx_uarte_tx(&_uart_id, (uint8_t const*) buf, (size_t) len ,0);
return (NRFX_SUCCESS == err) ? len : 0; return (NRFX_SUCCESS == err) ? len : 0;
#endif
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE

View File

@ -127,7 +127,9 @@ function(family_configure_example TARGET RTOS)
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD} ${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}}) target_sources(${TARGET} PRIVATE ${STARTUP_FILE_${CMAKE_C_COMPILER_ID}})
if (CMAKE_C_COMPILER_ID STREQUAL "GNU") if (CMAKE_C_COMPILER_ID STREQUAL "GNU")

View File

@ -59,21 +59,26 @@
/* Try to detect nrfx version if not configured with CFG_TUD_NRF_NRFX_VERSION /* 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: * 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 ... * - 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.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 * v1.8.2: 8.32.1 (conflict with v2.2.0), v1.8.1: 8.27.1
* Therefore the check for v1 would be: * Therefore the check for v1 would be:
* - MDK < 8.29.0 (v2.0), MDK == 8.32.3, 8.40.3 * - 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 * - 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 #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)
#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 // nrfx <= 1.8.1, or 1.8.5 or 1.9.0
#define CFG_TUD_NRF_NRFX_VERSION 1 #define CFG_TUD_NRF_NRFX_VERSION 1
#else #elif MDK_VERSION < 85301
#define CFG_TUD_NRF_NRFX_VERSION 2 #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
#endif #endif
@ -845,19 +850,19 @@ TU_ATTR_ALWAYS_INLINE static inline bool is_sd_enabled(void) {
#endif #endif
static bool hfclk_running(void) { static bool hfclk_running(void) {
#ifdef SOFTDEVICE_PRESENT #ifdef SOFTDEVICE_PRESENT
if ( is_sd_enabled() ) { if (is_sd_enabled()) {
uint32_t is_running = 0; 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); 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); return nrf_clock_hf_is_running(NRF_CLOCK_HFCLK_HIGH_ACCURACY);
#else #else
return nrf_clock_hf_is_running(NRF_CLOCK, NRF_CLOCK_HFCLK_HIGH_ACCURACY); return nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_HFCLK, NULL);
#endif #endif
} }
static void hfclk_enable(void) { static void hfclk_enable(void) {
@ -867,22 +872,24 @@ static void hfclk_enable(void) {
#else #else
// already running, nothing to do // already running, nothing to do
if (hfclk_running()) return; if (hfclk_running()) {
return;
}
#ifdef SOFTDEVICE_PRESENT #ifdef SOFTDEVICE_PRESENT
if ( is_sd_enabled() ) { if (is_sd_enabled()) {
(void)sd_clock_hfclk_request(); (void)sd_clock_hfclk_request();
return; 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_event_clear(NRF_CLOCK_EVENT_HFCLKSTARTED);
nrf_clock_task_trigger(NRF_CLOCK_TASK_HFCLKSTART); nrf_clock_task_trigger(NRF_CLOCK_TASK_HFCLKSTART);
#else #else
nrf_clock_event_clear(NRF_CLOCK, NRF_CLOCK_EVENT_HFCLKSTARTED); nrf_clock_event_clear(NRF_CLOCK, NRF_CLOCK_EVENT_HFCLKSTARTED);
nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_HFCLKSTART); nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_HFCLKSTART);
#endif #endif
#endif #endif
} }