Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / firmware / qorvo-uwb / CMakeLists.txt
CMakeLists.txt201 lines · 8.2 KiBRaw
| 1 | # Zephyr module wrapping the licensed Qorvo DW3_QM33 SDK. |
| 2 | # |
| 3 | # The SDK is NOT vendored in this repo — it ships under a Qorvo licence. Point |
| 4 | # QORVO_SDK_DIR at an extracted copy (see README.md). Only the glue lives here: |
| 5 | # a Zephyr SPI backend and the platform instance definitions, because the versions |
| 6 | # the SDK ships are respectively a stub and written against an older Zephyr API. |
| 7 | |
| 8 | if(NOT CONFIG_QORVO_UWB) |
| 9 | return() |
| 10 | endif() |
| 11 | |
| 12 | if(NOT QORVO_SDK_DIR) |
| 13 | set(QORVO_SDK_DIR "$ENV{QORVO_SDK_DIR}") |
| 14 | endif() |
| 15 | if(NOT QORVO_SDK_DIR OR NOT EXISTS "${QORVO_SDK_DIR}/Libs/uwb-stack") |
| 16 | message(FATAL_ERROR |
| 17 | "CONFIG_QORVO_UWB=y but the Qorvo SDK was not found.\n" |
| 18 | "Set -DQORVO_SDK_DIR=<path> or the QORVO_SDK_DIR environment variable to an\n" |
| 19 | "extracted DW3_QM33_SDK (the directory containing Libs/uwb-stack).\n" |
| 20 | "Got: '${QORVO_SDK_DIR}'\n" |
| 21 | "See firmware/qorvo-uwb/README.md.") |
| 22 | endif() |
| 23 | |
| 24 | set(UWB_STACK "${QORVO_SDK_DIR}/Libs/uwb-stack") |
| 25 | set(QOSAL "${UWB_STACK}/libs/qosal") |
| 26 | set(QHAL "${UWB_STACK}/libs/qhal") |
| 27 | set(QMATH "${UWB_STACK}/libs/qmath") |
| 28 | set(QPLATFORM "${UWB_STACK}/libs/qplatform") |
| 29 | |
| 30 | # The driver ships in the Drivers package, which extracts alongside the SDK zip |
| 31 | # rather than inside it, so allow it to be pointed at separately. |
| 32 | if(NOT QORVO_DRIVER_DIR) |
| 33 | set(QORVO_DRIVER_DIR "$ENV{QORVO_DRIVER_DIR}") |
| 34 | endif() |
| 35 | if(NOT QORVO_DRIVER_DIR) |
| 36 | set(QORVO_DRIVER_DIR "${QORVO_SDK_DIR}/Libs/dwt_uwb_driver") |
| 37 | endif() |
| 38 | if(NOT EXISTS "${QORVO_DRIVER_DIR}/deca_device_api.h") |
| 39 | message(FATAL_ERROR |
| 40 | "DW3xxx driver not found at '${QORVO_DRIVER_DIR}'. Set -DQORVO_DRIVER_DIR=<path>\n" |
| 41 | "to the dwt_uwb_driver directory (it contains deca_device_api.h).") |
| 42 | endif() |
| 43 | |
| 44 | # Prebuilt FiRa bundle. nRF52833 is a Cortex-M4 with no FPU, hence soft_floating; |
| 45 | # picking the hard-float archive links but faults at the first float call. |
| 46 | file(GLOB FIRA_LIB |
| 47 | "${QORVO_SDK_DIR}/Libs/uwbstack_libs/delivery/fira/Release/lib/arm-cortex-m4-soft_floating/uwbstack_bundle/libuwbstack_bundle_fira_*.a") |
| 48 | if(NOT FIRA_LIB) |
| 49 | message(FATAL_ERROR "No arm-cortex-m4-soft_floating uwbstack bundle under ${QORVO_SDK_DIR}") |
| 50 | endif() |
| 51 | list(GET FIRA_LIB 0 FIRA_LIB) |
| 52 | message(STATUS "Qorvo FiRa bundle: ${FIRA_LIB}") |
| 53 | |
| 54 | set(FIRA_INC |
| 55 | "${QORVO_SDK_DIR}/Libs/uwbstack_libs/delivery/fira/Release/include/uwbstack_bundle") |
| 56 | |
| 57 | zephyr_include_directories( |
| 58 | ${FIRA_INC} |
| 59 | ${CMAKE_CURRENT_LIST_DIR}/include |
| 60 | ${QOSAL}/include |
| 61 | ${QOSAL}/include/zephyr |
| 62 | ${QHAL}/include |
| 63 | ${QMATH}/include |
| 64 | ${QPLATFORM}/include |
| 65 | ${QORVO_DRIVER_DIR} |
| 66 | |
| 67 | # Qorvo's headers predate the <zephyr/...> include prefix (Zephyr 3.0) and still write |
| 68 | # <kernel.h>, <device.h>, <logging/log.h>. These have to be global rather than scoped |
| 69 | # to this library because the FindFamily firmware includes uwbmac/fira_helper.h, which |
| 70 | # pulls the qosal headers in. include-compat/ supplies the two headers that were |
| 71 | # removed outright rather than renamed. |
| 72 | ${ZEPHYR_BASE}/include/zephyr |
| 73 | ${CMAKE_CURRENT_LIST_DIR}/include-compat |
| 74 | ) |
| 75 | |
| 76 | zephyr_library_named(qorvo_uwb) |
| 77 | |
| 78 | zephyr_library_sources( |
| 79 | # Our glue. Three of the SDK's Zephyr backends are unusable as shipped: |
| 80 | # - qhal/src/zephyr/qspi.c returns QERR_ENOTSUP from every function (a placeholder). |
| 81 | # - qhal/src/zephyr/qtimer.c likewise, which alone makes llhw_init fail with EIO. |
| 82 | # - qhal/src/zephyr/qgpio.c redefines gpio_is_ready_dt/gpio_add_callback_dt, which |
| 83 | # Zephyr has since added itself. |
| 84 | src/qspi_zephyr.c |
| 85 | src/qtimer_zephyr.c |
| 86 | src/qgpio_zephyr.c |
| 87 | # - qplatform/qm33_qhal_zephyr/qplatform.c dereferences spi_config.cs as a pointer |
| 88 | # (by value since Zephyr 3.5) and hard-requires a "dw35720" node label. |
| 89 | # - qhal/src/qm33/qpwr.c and qhal/src/qrtc.c likewise, or route through |
| 90 | # persistent_time, which only has an nrfx implementation. |
| 91 | # mcps_crypto_psa.c replaces Src/UWB/mcps_crypto.c so the image has one crypto |
| 92 | # provider rather than PSA plus Nordic's nrf_crypto. |
| 93 | src/qspi_zephyr.c |
| 94 | src/qgpio_zephyr.c |
| 95 | src/qplatform_zephyr.c |
| 96 | src/qhal_extras_zephyr.c |
| 97 | src/l1_config_storage_zephyr.c |
| 98 | src/qmalloc_zephyr.c |
| 99 | src/qthread_zephyr.c |
| 100 | src/mcps_crypto_psa.c |
| 101 | |
| 102 | # qosal — Zephyr OS abstraction. |
| 103 | ${QOSAL}/src/qerr_common.c |
| 104 | ${QOSAL}/src/qmalloc.c |
| 105 | ${QOSAL}/src/zephyr/qerr.c |
| 106 | ${QOSAL}/src/zephyr/qirq.c |
| 107 | ${QOSAL}/src/zephyr/qlog.c |
| 108 | ${QOSAL}/src/zephyr/qmsg_queue.c |
| 109 | ${QOSAL}/src/zephyr/qmutex.c |
| 110 | ${QOSAL}/src/zephyr/qos.c |
| 111 | ${QOSAL}/src/zephyr/qpm.c |
| 112 | ${QOSAL}/src/zephyr/qprofiling.c |
| 113 | ${QOSAL}/src/zephyr/qrand.c |
| 114 | ${QOSAL}/src/zephyr/qsemaphore.c |
| 115 | ${QOSAL}/src/zephyr/qsignal.c |
| 116 | ${QOSAL}/src/zephyr/qtime.c |
| 117 | ${QOSAL}/src/zephyr/qtracing.c |
| 118 | ${QOSAL}/src/zephyr/qworkqueue.c |
| 119 | |
| 120 | # qhal — Zephyr hardware abstraction (qspi.c, qgpio.c and qtimer.c replaced above). |
| 121 | # OTP access, needed to read this module's factory calibration. |
| 122 | ${QHAL}/src/qm33/qotp.c |
| 123 | |
| 124 | ${QMATH}/src/qmath.c |
| 125 | |
| 126 | # qplatform — ties the driver to qhal. |
| 127 | ${QPLATFORM}/qm33_qhal_common/src/qplatform.c |
| 128 | ${QPLATFORM}/qm33_qhal_common/src/qplatform_deca_impl.c |
| 129 | |
| 130 | # DW3xxx driver, DW3000 family (the DWM3001C carries a DW3110). |
| 131 | ${QORVO_DRIVER_DIR}/deca_compat.c |
| 132 | ${QORVO_DRIVER_DIR}/deca_interface.c |
| 133 | ${QORVO_DRIVER_DIR}/deca_rsl.c |
| 134 | ${QORVO_DRIVER_DIR}/dw3000/dw3000_device.c |
| 135 | |
| 136 | # Board calibration. l1_config_init() needs a reset_to_default hook that loads this |
| 137 | # module's factory calibration — antenna delays, crystal trim, TX power — out of the |
| 138 | # DW3110's OTP. Reusing the vendor's DWM3001CDK implementation rather than |
| 139 | # reimplementing it, since those values are what make ranging accurate. |
| 140 | ${QORVO_SDK_DIR}/Src/Boards/Src/Common/helper_platform_l1_config.c |
| 141 | ${QORVO_SDK_DIR}/Src/Boards/Src/DWM3001CDK/platform_l1_config.c |
| 142 | ) |
| 143 | |
| 144 | zephyr_library_include_directories( |
| 145 | ${QPLATFORM}/qm33_qhal_common/include |
| 146 | ${CMAKE_CURRENT_LIST_DIR}/src |
| 147 | ${QORVO_DRIVER_DIR}/dw3000 |
| 148 | ${QORVO_SDK_DIR}/Src/Boards/Src/Common |
| 149 | ${QORVO_SDK_DIR}/Src/Boards/Src/Common_OTP |
| 150 | ${QORVO_SDK_DIR}/Src/Boards/Inc |
| 151 | ) |
| 152 | |
| 153 | zephyr_library_compile_definitions( |
| 154 | CONFIG_DW3000=1 |
| 155 | # Selects the idle-timer configuration in qm33_qhal_common/qplatform.c, which |
| 156 | # #errors without a platform. The nRF branch is right for nRF52833; Zephyr owns |
| 157 | # the timer instance via qhal's qtimer, so the "RTC1 is FreeRTOS" comment there |
| 158 | # does not apply to us. |
| 159 | CONFIG_QPLATFORM_IMPL_NRF=1 |
| 160 | CONFIG_UWB_SPI_INSTANCE=3 |
| 161 | CONFIG_UWB_SPI_FRAME_SIZE=8 |
| 162 | CONFIG_SPI_UWB_IRQ_PRIORITY=3 |
| 163 | CONFIG_SPI_UWB_SLOW_RATE_FREQ=${CONFIG_QORVO_UWB_SPI_FREQ_SLOW_HZ} |
| 164 | CONFIG_SPI_UWB_FAST_RATE_FREQ=${CONFIG_QORVO_UWB_SPI_FREQ_FAST_HZ} |
| 165 | CONFIG_QLOG_LEVEL=${CONFIG_QORVO_UWB_QLOG_LEVEL} |
| 166 | # Number of GPIO callback slots in our qgpio backend's static table; the stack only |
| 167 | # registers one, on the transceiver IRQ. |
| 168 | CONFIG_QHAL_MAX_GPIO_CALLBACKS=2 |
| 169 | ) |
| 170 | |
| 171 | # Vendor code is not warning-clean under Zephyr's flags, and it is not ours to fix. |
| 172 | zephyr_library_compile_options( |
| 173 | # See the header: fixes qos.c's missing qerr.h include, and maps qosal's Zephyr 3.1 |
| 174 | # log_msg2 internals onto their current names. |
| 175 | -include ${CMAKE_CURRENT_LIST_DIR}/include-compat/ff_qorvo_compat.h |
| 176 | -Wno-unused-function |
| 177 | -Wno-unused-variable |
| 178 | -Wno-unused-but-set-variable |
| 179 | -Wno-sign-compare |
| 180 | -Wno-implicit-fallthrough |
| 181 | -Wno-missing-field-initializers |
| 182 | ) |
| 183 | |
| 184 | # The FiRa bundle's l1_config sections are placed in rodata purely to avoid orphan-section |
| 185 | # warnings; src/l1_config_storage_zephyr.c redirects the accessors to a RAM buffer. |
| 186 | zephyr_linker_sources(RODATA l1_config_storage.ld) |
| 187 | |
| 188 | zephyr_link_libraries(${FIRA_LIB}) |
| 189 | |
| 190 | # picolibc's malloc family (nano-malloc.o, nano-free.o) ends up on the link line |
| 191 | # alongside Zephyr's lib/libc/common allocator, and both define malloc/free. Neither is |
| 192 | # reached from our code — qosal's allocations go to k_malloc via src/qmalloc_zephyr.c — |
| 193 | # and only Zephyr's own picolibc glue references them, so one of picolibc's malloc-family |
| 194 | # objects is being pulled for an internal symbol rather than for malloc itself. |
| 195 | # |
| 196 | # Both implementations are functional and Zephyr's is encountered first, so the choice is |
| 197 | # deterministic. This is a blunt instrument though: it silences duplicate symbols for the |
| 198 | # whole image, so if a genuine symbol clash appears later this is the first thing to |
| 199 | # suspect. The real fix is to find what pulls nano-malloc.o (start with |
| 200 | # `-Wl,--print-map` and `-Wl,-y,__malloc_free_list`) and drop that reference. |
| 201 | zephyr_link_libraries(-Wl,--allow-multiple-definition) |