cooked / zephyr-trinamic

Zephyr OS support for Trinamic TMC drivers
12 stars 4 forks source link

Adding zephyr-trinamic as a west module to an existing zephyr project #13

Open kaizoku-oh opened 9 months ago

kaizoku-oh commented 9 months ago

I have a working zephyr project running on nucleo_u575zi_q board and I'm trying to use the zephyr-trinamic inside my project.

After making the following changes in my project I'm getting a build error:

Screenshot from 2024-01-28 15-46-29

Screenshot from 2024-01-28 15-47-33

Screenshot from 2024-01-28 15-47-57

Screenshot from 2024-01-28 15-52-15

cooked commented 9 months ago

Hi @kaizoku-oh, try to change your manifest to:

- name: trinamic
      remote: trinamic
      repo-path: zephyr-trinamic
      path: deps/modules/trinamic
      import: true

the TMC-API is just a dependency of the zephyr-trinamic driver (this repo), to reuse most of the headers from TRINAMIC. The dependency on TMC-API is satisfied by pulling it in with the import statement (i.e. in the end you will find it in your modules tree)

let me know how it goes.

stef

kaizoku-oh commented 7 months ago

Hi, I changed my manifest like you said.

When I try to build the project using the following manifest, config and overlay, I get a build error and a cmake warning No SOURCES given to Zephyr library: ..__..__modules__hal__tmc:

My qustion is: Do I need to change anything else in my project aside from the manifest, board config and overlay like shown below?

west.yml

manifest:
  version: 0.7

  defaults:
    remote: zephyrproject

  remotes:
    - name: zephyrproject
      url-base: https://github.com/zephyrproject-rtos

    - name: trinamic
      url-base: https://github.com/cooked

  projects:
    - name: zephyr
      repo-path: zephyr
      revision: a6eef0ba3755f2530c5ce93524e5ac4f5be30194 # v3.5.0
      path: zephyr
      import:
        path-prefix: deps
        name-allowlist:
          - cmsis
          - hal_stm32
          - mcuboot
          - mbedtls

    - name: trinamic
      remote: trinamic
      repo-path: zephyr-trinamic
      path: deps/modules/trinamic
      import: true

  self:
    path: app

nucleo_u575zi_q.conf

CONFIG_TMC_SPI=y
CONFIG_TMC5160=y

nucleo_u575zi_q.overlay

/ {
    aliases {
        tmc0 = &tmc_0;
    };
};

&spi1 {
    cs-gpios = <&gpioa 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;

    tmc_0: tmc5160@0 {
        compatible = "trinamic,tmc5160";
        status = "okay";
        reg = <0x00>;

        // 4MHz internal, 8MHz external clock
        // TODO: seems not to work for higher speed than 1MHz
        spi-max-frequency = <1000000>;

        rotation-distance = <1>;    // [mm/turn]
    };
};

Building...

$ west build app -d app/build -p auto -b nucleo_u575zi_q 

-- west build: generating a build system Loading Zephyr default modules (Zephyr base). -- Application: /workspace/app -- CMake version: 3.25.1 -- Found Python3: /opt/venv/bin/python3 (found suitable version "3.11.2", minimum required is "3.8") found components: Interpreter -- Cache files will be written to: /root/.cache/zephyr -- Zephyr version: 3.5.0 (/workspace/deps/zephyr) -- Found west (found suitable version "1.2.0", minimum required is "0.14.0") -- Board: nucleo_u575zi_q -- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK -- Found host-tools: zephyr 0.16.4 (/opt/toolchains/zephyr-sdk-0.16.4) -- Found toolchain: zephyr 0.16.4 (/opt/toolchains/zephyr-sdk-0.16.4) -- Found Dtc: /usr/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6") -- Found BOARD.dts: /workspace/deps/zephyr/boards/arm/nucleo_u575zi_q/nucleo_u575zi_q.dts -- Found devicetree overlay: /workspace/app/boards/nucleo_u575zi_q.overlay node '/soc/spi@40013000/tmc5160@0' compatible 'trinamic,tmc5160' has unknown vendor prefix 'trinamic' -- Generated zephyr.dts: /workspace/app/build/zephyr/zephyr.dts -- Generated devicetree_generated.h: /workspace/app/build/zephyr/include/generated/devicetree_generated.h -- Including generated dts.cmake file: /workspace/app/build/zephyr/dts.cmake Parsing /workspace/deps/zephyr/Kconfig Loaded configuration '/workspace/deps/zephyr/boards/arm/nucleo_u575zi_q/nucleo_u575zi_q_defconfig' Merged configuration '/workspace/app/prj.conf' Merged configuration '/workspace/app/boards/nucleo_u575zi_q.conf' Configuration saved to '/workspace/app/build/zephyr/.config' Kconfig header saved to '/workspace/app/build/zephyr/include/generated/autoconf.h' -- Found GnuLd: /opt/toolchains/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd (found version "2.38") -- The C compiler identification is GNU 12.2.0 -- The CXX compiler identification is GNU 12.2.0 -- The ASM compiler identification is GNU -- Found assembler: /opt/toolchains/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc CMake Warning at /workspace/deps/zephyr/CMakeLists.txt:887 (message): No SOURCES given to Zephyr library: ..__..__modules__hal__tmc

Excluding target from build.

-- Configuring done -- Generating done -- Build files have been written to: /workspace/app/build -- west build: building application [1/223] Preparing syscall dependency handling

[3/223] Generating include/generated/version.h -- Zephyr version: 3.5.0 (/workspace/deps/zephyr), build: zephyr-v3.5.0 [175/223] Building C object modules/trinamic/drivers/tmc5160/CMakeFiles/..modulestrinamicdriverstmc5160.dir/src/tmc5160.c.obj /workspace/deps/modules/trinamic/drivers/tmc5160/src/tmc5160.c: In function 'tmc5160_init': /workspace/deps/modules/trinamic/drivers/tmc5160/src/tmc5160.c:80:9: warning: 'spi_is_ready' is deprecated [-Wdeprecated-declarations] 80 | if (!spi_is_ready(&cfg->spi)) { | ^~ In file included from /workspace/deps/modules/trinamic/drivers/tmc/./tmc.h:16, from /workspace/deps/modules/trinamic/drivers/tmc5160/src/tmc5160.c:20: /workspace/deps/zephyr/include/zephyr/drivers/spi.h:677:20: note: declared here 677 | static inline bool spi_is_ready(const struct spi_dt_spec spec) | ^~~~ /workspace/deps/modules/trinamic/drivers/tmc5160/src/tmc5160.c:64:26: warning: unused variable 'data' [-Wunused-variable] 64 | struct tmc_data data = dev->data; | ^~~~ In file included from /workspace/deps/zephyr/include/zephyr/sys/util_macro.h:34, from /workspace/deps/zephyr/include/zephyr/sys/util.h:17, from /workspace/deps/zephyr/include/zephyr/devicetree.h:25, from /workspace/deps/zephyr/include/zephyr/device.h:12, from /workspace/deps/modules/trinamic/drivers/tmc5160/src/tmc5160.c:12: /workspace/deps/modules/trinamic/drivers/tmc5160/src/tmc5160.c: At top level: /workspace/deps/modules/trinamic/drivers/tmc5160/src/tmc5160.c:365:60: warning: missing braces around initializer [-Wmissing-braces] 365 | static const struct tmc_config tmcconfig##inst = { \ | ^ /workspace/deps/zephyr/include/zephyr/sys/util_internal.h:72:26: note: in definition of macro 'DEBRACKET' 72 | #define DEBRACKET(...) VA_ARGS__ | ^~~ /workspace/deps/zephyr/include/zephyr/sys/util_internal.h:64:9: note: in expansion of macro 'GET_ARG2_DEBRACKET' 64 | GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code) | ^~~~~~~~ /workspace/deps/zephyr/include/zephyr/sys/util_internal.h:59:9: note: in expansion of macro 'COND_CODE' 59 | COND_CODE(_XXXX##_flag, _if_1_code, _else_code) | ^~~ /workspace/deps/zephyr/include/zephyr/sys/util_macro.h:180:9: note: in expansion of macro 'Z_COND_CODE_1' 180 | Z_COND_CODE_1(_flag, _if_1_code, _else_code) | ^~~~~ /workspace/deps/zephyr/include/zephyr/devicetree.h:4071:9: note: in expansion of macro 'COND_CODE_1' 4071 | COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT), \ | ^~~ /workspace/app/build/zephyr/include/generated/devicetree_generated.h:18994:51: note: in expansion of macro 'TMC5160_DEFINE' 18994 | #define DT_FOREACH_OKAY_INST_trinamic_tmc5160(fn) fn(0) | ^~ /workspace/deps/zephyr/include/zephyr/sys/util_internal.h:105:36: note: in expansion of macro 'DT_FOREACH_OKAY_INST_trinamic_tmc5160' 105 | #define UTIL_PRIMITIVE_CAT(a, ...) a##VA_ARGS | ^ /workspace/deps/modules/trinamic/drivers/tmc5160/src/tmc5160.c:394:1: note: in expansion of macro 'DT_INST_FOREACH_STATUS_OKAY' 394 | DT_INST_FOREACH_STATUS_OKAY(TMC5160_DEFINE) | ^~~~~~~ [176/223] Building C object modules/trinamic/drivers/tmc/CMakeFiles/..modulestrinamicdriverstmc.dir/tmc_shell.c.obj /workspace/deps/modules/trinamic/drivers/tmc/tmc_shell.c:96:12: warning: 'cmd_tmc_cur' defined but not used [-Wunused-function] 96 | static int cmd_tmc_cur(const struct shell shell, size_t argc, char argv[]) | ^~~ [218/223] Linking CXX executable zephyr/zephyr_pre0.elf FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /workspace/app/build/zephyr/zephyr_pre0.map : && /opt/toolchains/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-g++ -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -fuse-ld=bfd -T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=/workspace/app/build/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/common/libarchcommon.a zephyr/arch/arch/arm/core/libarcharmcore.a zephyr/arch/arch/arm/core/cortex_m/libarcharmcorecortex_m.a zephyr/arch/arch/arm/core/cortex_m/cmse/libarcharmcorecortex_mcmse.a zephyr/arch/arch/arm/core/mpu/libarcharmcorempu.a zephyr/lib/libc/picolibc/libliblibcpicolibc.a zephyr/lib/libc/common/libliblibccommon.a zephyr/lib/posix/liblibposix.a zephyr/lib/smf/liblibsmf.a zephyr/soc/soc/arm/common/cortex_m/libsocarmcommoncortex_m.a zephyr/subsys/rtio/libsubsysrtio.a zephyr/subsys/zbus/libsubsyszbus.a zephyr/drivers/interrupt_controller/libdriversinterrupt_controller.a zephyr/drivers/adc/libdriversadc.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/console/libdriversconsole.a zephyr/drivers/flash/libdriversflash.a zephyr/drivers/gpio/libdriversgpio.a zephyr/drivers/hwinfo/libdrivershwinfo.a zephyr/drivers/pinctrl/libdriverspinctrl.a zephyr/drivers/reset/libdriversreset.a zephyr/drivers/sensor/stm32_temp/libdriverssensorstm32_temp.a zephyr/drivers/sensor/stm32_vbat/libdriverssensorstm32_vbat.a zephyr/drivers/sensor/stm32_vref/libdriverssensorstm32_vref.a zephyr/drivers/sensor/libdriverssensor.a zephyr/drivers/serial/libdriversserial.a zephyr/drivers/spi/libdriversspi.a zephyr/drivers/timer/libdriverstimer.a modules/trinamic/drivers/tmc/lib..modulestrinamicdriverstmc.a modules/trinamic/drivers/tmc5160/lib..modulestrinamicdriverstmc5160.a modules/stm32/stm32cube/lib..moduleshalstm32__stm32cube.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a -L"/opt/toolchains/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v8-m.main/nofp" -L/workspace/app/build/zephyr -lgcc zephyr/arch/common/libisr_tables.a -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -Wl,-X -Wl,-N -Wl,--orphan-handling=warn -lstdc++ -Wl,-no-pie -DPICOLIBC_DOUBLE_PRINTF_SCANF --specs=picolibc.specs -lc -lgcc && cd /workspace/app/build/zephyr && /usr/bin/cmake -E true /opt/toolchains/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(main.cpp.obj): in functionmain': /workspace/app/src/main.cpp:22: undefined reference to tmc_run(device const*, unsigned char, int, int)' collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed. FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /workspace/app/build