CMake warning: No SOURCES given to Zephyr library: drivers__eeprom

I've written a sample eeprom application based on the eeprom included in the nRF52 SDK to test the EEPROM we use in a project. The application worked properly about 10 days ago. Now I tried to rebuild the exact same application and debug it on the nRF52 DK. When building, the following CMake warning is displayed:

CMake Warning at C:/Users/Lukas/ncs/v1.9.1/zephyr/CMakeLists.txt:764 (message):
  No SOURCES given to Zephyr library: drivers__eeprom

  Excluding target from build.

Code in main.c:

/*
 * Copyright (c) 2021 Thomas Stranger
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>
#include <sys/printk.h>
#include <drivers/eeprom.h>
#include <device.h>

#define WRITE_BUFFER 8
#define READ_BUFFER 256

#define EEPROM DT_NODELABEL(eeprom_0)

/*
 * Get a device structure from a devicetree node with alias eeprom
 */
static const struct device *get_eeprom_device(void)
{
	const struct device *dev = device_get_binding(DT_LABEL(EEPROM));

	if (!device_is_ready(dev)) {
		printk("\nError: Device \"%s\" is not ready; "
		       "check the driver initialization logs for errors.\n",
		       dev->name);
		return NULL;
	}

	printk("Found EEPROM device \"%s\"\n", dev->name);
	return dev;
}

void main(void){
	const struct device *eeprom = get_eeprom_device();
	if(eeprom == NULL){
		return;
	}

	uint8_t write_buffer[WRITE_BUFFER];
	for (int i = 0; i < WRITE_BUFFER; i++){
		write_buffer[i] = 120;
	}

	eeprom_write(eeprom, 0x10, write_buffer, sizeof(write_buffer));

	uint8_t read_buffer[READ_BUFFER];
	for (int i = 0; i < READ_BUFFER; i++){
		read_buffer[i] = 0;
	}

	int ok = eeprom_read(eeprom, 0x00, &read_buffer, sizeof(read_buffer));
	if(ok < 0){
		printk("Error reading from EEPROM; err: %d\n", ok);
		return;
	}
}

For the EEPROM used in our project I created an overlay device tree with the following code:

&i2c0 {
    eeprom_0: br24c02@50 {
        compatible = "atmel,at24";
        size = <256>;
        pagesize = <8>;
        address-width = <8>;
        timeout = <0>;
        label = "BR24C02";
        reg = <0x50>;
    };
};

CMakeLists.txt

# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(eeprom)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

prj.conf

CONFIG_PRINTK=y
CONFIG_EEPROM=y

I can debug the application. However, when I step over the function "device_get_binding(DT_LABEL(EEPROM))" I can see that a NULL pointer is returned.

static const struct device *get_eeprom_device(void)
{
	const struct device *dev = device_get_binding(DT_LABEL(EEPROM));

	if (!device_is_ready(dev)) {
		printk("\nError: Device \"%s\" is not ready; "
		       "check the driver initialization logs for errors.\n",
		       dev->name);
		return NULL;
	}

	printk("Found EEPROM device \"%s\"\n", dev->name);
	return dev;
}

Do you have any ideas why this problem occurs and how to fix it?

Parents Reply Children
  • Thank you.

    You are missing a couple of configs in your prj.conf. Try adding these:

    CONFIG_EEPROM_AT24=y
    CONFIG_I2C=y

  • Thank you!

    Adding CONFIG_EEPROM_AT24=y and CONFIG_I2C=y removed the warning. In order to get the EEPROM device working I additionally had to add CONFIG_EEPROM_INIT_PRIORITY=75 to the prj.conf file.

    I suppose that I haven't discovered this issue at first because in the eeprom sample provided in the SDK a shield was added to CMakeLists.txt:

    set(SHIELD x_nucleo_eeprma2)

    In order to test our own EEPROM device I created a device tree overlay and deleted the shield configuration from CMakeLists.txt. However, the build must have still included the shield configuration and all it's dependencies listed in zephyr/boards/shields/x_nucleo_eeprma2/Kconfig.defconfig:

    # Copyright (c) 2021 Thomas Stranger
    # SPDX-License-Identifier: Apache-2.0
    
    if SHIELD_X_NUCLEO_EEPRMA2
    
    if EEPROM
    
    config SPI
    	default y
    
    config EEPROM_AT25
    	default y
    
    config I2C
    	default y
    
    config EEPROM_AT24
    	default y
    
    config EEPROM_INIT_PRIORITY
    	default 75
    
    endif # EEPROM
    
    endif # SHIELD_X_NUCLEO_EEPRMA2

  • Yes, makes sense. Glad to hear that it's working now!

Related