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?