KScan example build fails for nrf52840dk

Dear Nordic team,

We are using the nRF connect SDK version 2.1.2. Our prototype uses the nrf52840dk board and the KScan application template. However, when directly trying to build the project it first raises a warning:

CMake Warning at C:/NordicSemi/v2.1.2/zephyr/CMakeLists.txt:831 (message):
  No SOURCES given to Zephyr library: drivers__kscan

  Excluding target from build.

And then later fails with the following errors:

[48/173] Building C object CMakeFiles/app.dir/src/main.c.obj
FAILED: CMakeFiles/app.dir/src/main.c.obj 
C:\NordicSemi\toolchains\v2.1.2\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DNRF52840_XXAA -DUSE_PARTITION_MANAGER=0 -D_FORTIFY_SOURCE=2 -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/NordicSemi/v2.1.2/zephyr/include/zephyr -IC:/NordicSemi/v2.1.2/zephyr/include -Izephyr/include/generated -IC:/NordicSemi/v2.1.2/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/NordicSemi/v2.1.2/zephyr/soc/arm/nordic_nrf/common/. -IC:/NordicSemi/v2.1.2/nrf/include -IC:/NordicSemi/v2.1.2/modules/hal/cmsis/CMSIS/Core/Include -IC:/NordicSemi/v2.1.2/modules/hal/nordic/nrfx -IC:/NordicSemi/v2.1.2/modules/hal/nordic/nrfx/drivers/include -IC:/NordicSemi/v2.1.2/modules/hal/nordic/nrfx/mdk -IC:/NordicSemi/v2.1.2/zephyr/modules/hal_nordic/nrfx/. -IC:/NordicSemi/v2.1.2/modules/debug/segger/SEGGER -IC:/NordicSemi/v2.1.2/modules/debug/segger/Config -IC:/NordicSemi/v2.1.2/zephyr/modules/segger/. -isystem C:/NordicSemi/v2.1.2/zephyr/lib/libc/minimal/include -isystem c:/nordicsemi/toolchains/v2.1.2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include -isystem c:/nordicsemi/toolchains/v2.1.2/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/include-fixed -isystem C:/NordicSemi/v2.1.2/nrfxlib/crypto/nrf_cc310_platform/include -Os -imacros C:/MS/Keyboard/Applications/kscan/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=C:/NordicSemi/toolchains/v2.1.2/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/NordicSemi/v2.1.2/zephyr/include/zephyr/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=C:/MS/Keyboard/Applications/kscan=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/NordicSemi/v2.1.2/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/NordicSemi/v2.1.2=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles\app.dir\src\main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c ../src/main.c
In file included from C:\NordicSemi\v2.1.2\zephyr\include\zephyr\toolchain\gcc.h:88,
                 from C:\NordicSemi\v2.1.2\zephyr\include\zephyr\toolchain.h:50,
                 from C:\NordicSemi\v2.1.2\zephyr\include\zephyr\kernel_includes.h:19,
                 from C:\NordicSemi\v2.1.2\zephyr\include\zephyr\kernel.h:17,
                 from C:\NordicSemi\v2.1.2\zephyr\include\zephyr\zephyr.h:18,
                 from c:\MS\Keyboard\Applications\kscan\src\main.c:7:
C:\NordicSemi\v2.1.2\zephyr\include\zephyr\device.h:96:39: error: '__device_dts_ord_DT_N_ALIAS_kscan0_ORD' undeclared here (not in a function)
   96 | #define DEVICE_NAME_GET(name) _CONCAT(__device_, name)
      |                                       ^~~~~~~~~
C:\NordicSemi\v2.1.2\zephyr\include\zephyr\toolchain\common.h:132:26: note: in definition of macro '_DO_CONCAT'
  132 | #define _DO_CONCAT(x, y) x ## y
      |                          ^
C:\NordicSemi\v2.1.2\zephyr\include\zephyr\device.h:96:31: note: in expansion of macro '_CONCAT'
   96 | #define DEVICE_NAME_GET(name) _CONCAT(__device_, name)
      |                               ^~~~~~~
C:\NordicSemi\v2.1.2\zephyr\include\zephyr\device.h:276:37: note: in expansion of macro 'DEVICE_NAME_GET'
  276 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_NAME(node_id))
      |                                     ^~~~~~~~~~~~~~~
C:\NordicSemi\v2.1.2\zephyr\include\zephyr\device.h:296:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
  296 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
      |                                  ^~~~~~~~~~~~~~~~~~
c:\MS\Keyboard\Applications\kscan\src\main.c:20:34: note: in expansion of macro 'DEVICE_DT_GET'
   20 | const struct device *kscan_dev = DEVICE_DT_GET(KSCAN_NODE);
      |                                  ^~~~~~~~~~~~~
[49/173] Building C object zephyr/soc/arm/nordic_nrf/nrf52/CMakeFiles/soc__arm__nordic_nrf__nrf52.dir/power.c.obj
[50/173] Building C object zephyr/soc/arm/nordic_nrf/nrf52/CMakeFiles/soc__arm__nordic_nrf__nrf52.dir/soc.c.obj
[51/173] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/strtoul.c.obj
[52/173] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strerror.c.obj
[53/173] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/qsort.c.obj
[54/173] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/string/strstr.c.obj
[55/173] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/bsearch.c.obj
[56/173] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/malloc.c.obj
[57/173] Building C object zephyr/lib/libc/minimal/CMakeFiles/lib__libc__minimal.dir/source/stdlib/exit.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'c:\NordicSemi\toolchains\v2.1.2\opt\bin\cmake.EXE' --build 'c:\MS\Keyboard\Applications\kscan\build'

 *  The terminal process terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it.

It seems that the KScan library does not get included successfully in the project. Is there anything we still need to configure at this point in order to build this application?

Thank you in advance!

  • Hi,

    I am not familiar with kscan, so I apologize if I ask any silly questions. Luckily, I am familiar with the errors you are seeing and what is causing them.

    Am I correct that this is the sample application found at zephyr/samples/drivers/kscan?

    Are you using a physical kscan module or controller of some type? If so which one would be good to know.

    This sample requires a kscan0 node to be defined in the devicetree, which is not done by default for any of our boards. If you have connected a kscan device to the DK, you would need to add the device to the devicetree using an overlay file. If you are not familiar with Zephyr and overlay files or the devicetree I can help you with that if I know the device you are connecting. If a driver for your device does not exist in Zephyr you may need to port or write one yourself.

  • Hi Øivind,

    Thank you for the quick reply. For future reference, we have been able to successfully compile the sample application by adding the following lines to our prj.conf file:

    CONFIG_STDOUT_CONSOLE=y
    CONFIG_PRINTK=y
    CONFIG_KSCAN=y
    CONFIG_KSCAN_INIT_PRIORITY=95
    CONFIG_KSCAN_HT16K33=y
    CONFIG_HT16K33=y
    CONFIG_HT16K33_KEYSCAN=y
    CONFIG_LED=y
    CONFIG_I2C=y
    CONFIG_LOG=y


    As you said, the devicetree also needs to be adjusted to include a kscan device as follows:

    / {
        chosen {
            kscan = &ht16k33;
        };
    
        aliases {
            kscan0 = &ht16k33;
        };
    };
    
    &i2c0 {
        ht16k33: ht16k33@70 {
            compatible = "holtek,ht16k33";
            reg = <0x70>;
        };
    };


    This adjustment was done in an app.overlay file in the source directory. Of course, the application will fail at runtime because we don't have an HT16K33 chip connected to our I2C bus.

    What we are looking for specifically is how to use the kscan driver to use the GPIO pins of the microcontroller instead. Do you have any sample code or additional information on how to achieve this? Thank you!

  • If I understand you correctly, you want to use the driver without the HT16K33 device? Since that's a significantly different issue than the original ticket, it would be great if you could open a new ticket specifically for that. This helps a lot with keeping the forum searchable.

    My initial thoughts are that this would require a significant rewrite of the drivers initialization process at the very least, as it sends multiple commands to the device returns errors if it does not receive the expected response.

Related