zmkfirmware / zmk

ZMK Firmware Repository
https://zmk.dev/
MIT License
2.71k stars 2.76k forks source link

Having issues with building via VS Code & Docker #1350

Closed schizoprenical closed 2 years ago

schizoprenical commented 2 years ago

I am writing my custom shield and wanted to try building it, but I am encountering errors that is beyond my debugging skills. I have tried to fix the build errors as much as I can (I think I got passed the overlay and keymap issues), but I am getting stuck with a cmake error, I think.

I am using the VS Code & Docker setup from the documentation below: https://zmk.dev/docs/development/setup#setup

Hope someone can point me in the right direction. Here is my shield config. Thanks everyone!

root@a6787d882f6b:/workspaces/zmk/app# west build -p -b nice_nano_v2 -- -DSHIELD=z50
-- west build: making build dir /workspaces/zmk/app/build pristine
-- west build: generating a build system
Including boilerplate (Zephyr base): /workspaces/zmk/zephyr/cmake/app/boilerplate.cmake
-- Application: /workspaces/zmk/app
-- Adding /workspaces/zmk/app/boards/shields/z50
-- Using keymap file: /workspaces/zmk/app/boards/shields/z50/z50.keymap
-- Zephyr version: 3.0.0 (/workspaces/zmk/zephyr)
-- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.10") found components: Interpreter 
-- Found west (found suitable version "0.13.0", minimum required is "0.7.1")
-- Board: nice_nano_v2, Shield(s): z50
-- Cache files will be written to: /root/.cache/zephyr
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.13.2 (/opt/zephyr-sdk-0.13.2)
-- Found dtc: /opt/zephyr-sdk-0.13.2/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6")
-- Found toolchain: zephyr 0.13.2 (/opt/zephyr-sdk-0.13.2)
-- Found BOARD.dts: /workspaces/zmk/app/boards/arm/nice_nano/nice_nano_v2.dts
-- Found devicetree overlay: /workspaces/zmk/app/boards/shields/z50/z50.overlay
-- Found devicetree overlay: /workspaces/zmk/app/boards/shields/z50/z50.keymap
-- Generated zephyr.dts: /workspaces/zmk/app/build/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: /workspaces/zmk/app/build/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: /workspaces/zmk/app/build/zephyr/include/generated/device_extern.h
-- Including generated dts.cmake file: /workspaces/zmk/app/build/zephyr/dts.cmake
Parsing /workspaces/zmk/app/Kconfig
Loaded configuration '/workspaces/zmk/app/boards/arm/nice_nano/nice_nano_v2_defconfig'
Merged configuration '/workspaces/zmk/app/prj.conf'
Configuration saved to '/workspaces/zmk/app/build/zephyr/.config'
Kconfig header saved to '/workspaces/zmk/app/build/zephyr/include/generated/autoconf.h'
-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- The ASM compiler identification is GNU
-- Found assembler: /opt/zephyr-sdk-0.13.2/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
-- Configuring done
CMake Warning (dev) at /workspaces/zmk/zephyr/cmake/linker/ld/target.cmake:69 (add_custom_command):
  Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
  add_custom_command().  Run "cmake --help-policy CMP0116" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.
Call Stack (most recent call first):
  /workspaces/zmk/zephyr/CMakeLists.txt:1053 (configure_linker_script)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /workspaces/zmk/zephyr/cmake/linker/ld/target.cmake:69 (add_custom_command):
  Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
  add_custom_command().  Run "cmake --help-policy CMP0116" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.
Call Stack (most recent call first):
  /workspaces/zmk/zephyr/CMakeLists.txt:1265 (configure_linker_script)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /workspaces/zmk/zephyr/cmake/linker/ld/target.cmake:69 (add_custom_command):
  Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
  add_custom_command().  Run "cmake --help-policy CMP0116" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.
Call Stack (most recent call first):
  /workspaces/zmk/zephyr/CMakeLists.txt:1322 (configure_linker_script)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /workspaces/zmk/app/build
-- west build: building application
[1/303] Preparing syscall dependency handling

[2/303] Generating include/generated/version.h
-- Zephyr version: 3.0.0 (/workspaces/zmk/zephyr), build: 8adeab429a24
[21/303] Building C object CMakeFiles/app.dir/src/sensors.c.obj
/workspaces/zmk/app/src/sensors.c: In function 'zmk_sensors_init_item':
/workspaces/zmk/app/src/sensors.c:62:61: warning: passing argument 3 of 'sensor_trigger_set' from incompatible pointer type [-Wincompatible-pointer-types]
   62 |     sensor_trigger_set(sensors[i].dev, &sensors[i].trigger, zmk_sensors_trigger_handler);
      |                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                             |
      |                                                             void (*)(const struct device *, struct sensor_trigger *)
In file included from /workspaces/zmk/app/src/sensors.c:7:
/workspaces/zmk/zephyr/include/drivers/sensor.h:478:35: note: expected 'sensor_trigger_handler_t' {aka 'void (*)(const struct device *, const struct sensor_trigger *)'} but argument is of type 'void (*)(const struct device *, struct sensor_trigger *)'
  478 |          sensor_trigger_handler_t handler)
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
[72/303] Building C object CMakeFiles/app.dir/src/keymap.c.obj
FAILED: CMakeFiles/app.dir/src/keymap.c.obj 
ccache /opt/zephyr-sdk-0.13.2/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DKERNEL -DNRF52840_XXAA -D_FORTIFY_SOURCE=2 -D__PROGRAM_START -D__ZEPHYR__=1 -I/workspaces/zmk/app/include -I/workspaces/zmk/zephyr/include -I/workspaces/zmk/app/build/zephyr/include/generated -I/workspaces/zmk/zephyr/soc/arm/nordic_nrf/nrf52 -I/workspaces/zmk/zephyr/soc/arm/nordic_nrf/common/. -I/workspaces/zmk/zephyr/subsys/bluetooth -I/workspaces/zmk/zephyr/subsys/usb -I/workspaces/zmk/zephyr/subsys/settings/include -I/workspaces/zmk/modules/hal/cmsis/CMSIS/Core/Include -I/workspaces/zmk/modules/hal/nordic/nrfx -I/workspaces/zmk/modules/hal/nordic/nrfx/drivers/include -I/workspaces/zmk/modules/hal/nordic/nrfx/mdk -I/workspaces/zmk/zephyr/modules/hal_nordic/nrfx/. -I/workspaces/zmk/modules/crypto/tinycrypt/lib/include -I/workspaces/zmk/app/drivers/sensor/battery/. -isystem /workspaces/zmk/zephyr/lib/libc/minimal/include -isystem /opt/zephyr-sdk-0.13.2/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include -isystem /opt/zephyr-sdk-0.13.2/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include-fixed -Os -imacros /workspaces/zmk/app/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee -imacros /workspaces/zmk/zephyr/include/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=/workspaces/zmk/app=CMAKE_SOURCE_DIR -fmacro-prefix-map=/workspaces/zmk/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/workspaces/zmk=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -Wfatal-errors -MD -MT CMakeFiles/app.dir/src/keymap.c.obj -MF CMakeFiles/app.dir/src/keymap.c.obj.d -o CMakeFiles/app.dir/src/keymap.c.obj -c /workspaces/zmk/app/src/keymap.c
In file included from /workspaces/zmk/zephyr/include/arch/arm/aarch32/arch.h:20,
                 from /workspaces/zmk/zephyr/include/arch/cpu.h:19,
                 from /workspaces/zmk/zephyr/include/kernel_includes.h:33,
                 from /workspaces/zmk/zephyr/include/kernel.h:17,
                 from /workspaces/zmk/zephyr/include/zephyr.h:18,
                 from /workspaces/zmk/zephyr/include/net/buf.h:16,
                 from /workspaces/zmk/zephyr/include/bluetooth/bluetooth.h:23,
                 from /workspaces/zmk/app/src/keymap.c:8:
/workspaces/zmk/zephyr/include/devicetree.h:305:40: warning: implicit declaration of function 'DT_N_INST_0_zmk_keymap_FOREACH_CHILD'; did you mean 'DT_N_S_keymap_FOREACH_CHILD'? [-Wimplicit-function-declaration]
  305 | #define DT_INST(inst, compat) UTIL_CAT(DT_N_INST, DT_DASH(inst, compat))
      |                                        ^~~~~~~~~
/workspaces/zmk/zephyr/include/devicetree.h:2897:24: note: in definition of macro 'DT_CAT'
 2897 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
/workspaces/zmk/zephyr/include/devicetree.h:2323:2: note: in expansion of macro 'DT_FOREACH_CHILD'
 2323 |  DT_FOREACH_CHILD(DT_DRV_INST(inst), fn)
      |  ^~~~~~~~~~~~~~~~
/workspaces/zmk/zephyr/include/sys/util_internal.h:98:26: note: in expansion of macro 'UTIL_PRIMITIVE_CAT'
   98 | #define UTIL_CAT(a, ...) UTIL_PRIMITIVE_CAT(a, __VA_ARGS__)
      |                          ^~~~~~~~~~~~~~~~~~
/workspaces/zmk/zephyr/include/devicetree.h:305:31: note: in expansion of macro 'UTIL_CAT'
  305 | #define DT_INST(inst, compat) UTIL_CAT(DT_N_INST, DT_DASH(inst, compat))
      |                               ^~~~~~~~
/workspaces/zmk/zephyr/include/devicetree.h:2309:27: note: in expansion of macro 'DT_INST'
 2309 | #define DT_DRV_INST(inst) DT_INST(inst, DT_DRV_COMPAT)
      |                           ^~~~~~~
/workspaces/zmk/zephyr/include/devicetree.h:2323:19: note: in expansion of macro 'DT_DRV_INST'
 2323 |  DT_FOREACH_CHILD(DT_DRV_INST(inst), fn)
      |                   ^~~~~~~~~~~
/workspaces/zmk/app/src/keymap.c:35:32: note: in expansion of macro 'DT_INST_FOREACH_CHILD'
   35 | #define ZMK_KEYMAP_LAYERS_LEN (DT_INST_FOREACH_CHILD(0, LAYER_CHILD_LEN) 0)
      |                                ^~~~~~~~~~~~~~~~~~~~~
/workspaces/zmk/app/src/keymap.c:69:47: note: in expansion of macro 'ZMK_KEYMAP_LAYERS_LEN'
   69 | static struct zmk_behavior_binding zmk_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_KEYMAP_LEN] = {
      |                                               ^~~~~~~~~~~~~~~~~~~~~
/workspaces/zmk/app/src/keymap.c:35:57: error: 'LAYER_CHILD_LEN' undeclared here (not in a function)
   35 | #define ZMK_KEYMAP_LAYERS_LEN (DT_INST_FOREACH_CHILD(0, LAYER_CHILD_LEN) 0)
      |                                                         ^~~~~~~~~~~~~~~
/workspaces/zmk/zephyr/include/devicetree.h:1836:34: note: in definition of macro 'DT_FOREACH_CHILD'
 1836 |  DT_CAT(node_id, _FOREACH_CHILD)(fn)
      |                                  ^~
/workspaces/zmk/app/src/keymap.c:35:32: note: in expansion of macro 'DT_INST_FOREACH_CHILD'
   35 | #define ZMK_KEYMAP_LAYERS_LEN (DT_INST_FOREACH_CHILD(0, LAYER_CHILD_LEN) 0)
      |                                ^~~~~~~~~~~~~~~~~~~~~
/workspaces/zmk/app/src/keymap.c:69:47: note: in expansion of macro 'ZMK_KEYMAP_LAYERS_LEN'
   69 | static struct zmk_behavior_binding zmk_keymap[ZMK_KEYMAP_LAYERS_LEN][ZMK_KEYMAP_LEN] = {
      |                                               ^~~~~~~~~~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
[85/303] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/bluetooth/services/dis.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/local/bin/cmake --build /workspaces/zmk/app/build
caksoylar commented 2 years ago

Hi, I see a few issues with your shield config:

  1. Your folder should be under config/**boards**/shields/z50
  2. You cannot use the syntax in these first two lines in .defconfig files, but only in .conf files, see some pointers here from #722.
  3. You should not have a space after the comma here
  4. I haven't checked your keymap in detail, but you have a typo in the "compatible" keyword
  5. You should not need to be defining vbatt in your shield, that's a board level configuration

In the future you might get more prompt help at the ZMK Discord and it is easier for community members to help as well since we can interact real-time.

schizoprenical commented 2 years ago

@caksoylar many thanks to your pointers, I have finally built my first firmware! Turns out my keymap file was configured wrong. I added the behaviors, macros, etc. inside the keymap. After I fixed that along with following your pointers, the west build went successful. Thanks again for your help.