Re: Unknown origin of error


markus.prager@...
 

Thanks for the directions, Jamie.

I have fixed that issue with the frequency - however I am now having problems with my chip-select gpio. I do not seem to be able to properly access a specific cs-gpio pin, even though I am fairly certain I declared it correctly in my devicetree.

Devicetree for spi2 on my board

&spi2 {
pinctrl-0 = <&spi2_sck_pb13
&spi2_miso_pb14 &spi2_mosi_pb15>;/*PIN34,PIN35,PIN36*/
cs-gpios = <&gpioc 6 GPIO_ACTIVE_LOW>;/* PC6, Acc_CS */
status = "okay";
};

This is based on the information found in "spi-device.yaml".


My devicetree overlay for the lis3dhh sensor

&spi2 {
lis3dhh: lis3dhh@0 {
compatible = "st,lis3dhh","st,spi_lis3dhh";
status = "okay";
reg = <0>;
label = "LIS3DHH";
spi-max-frequency = <1000000>;
irq-gpios = <&gpioc 7 GPIO_ACTIVE_HIGH>, <&gpioc 8 GPIO_ACTIVE_HIGH>; //INT1, PC7 & INT2, PC8
};
};


My spi init function (based on the init function I found for the lis2dh sensor)

int lis3dhh_spi_init(const struct device *dev)
{
struct lis3dhh_data *lis3dhh_drv_data = dev->data;
const struct lis3dhh_config *cfg = dev->config;
const struct lis3dhh_spi_cfg *spi_cfg = cfg->bus_cfg.spi_cfg;
LOG_ERR("config->cs: %p", spi_cfg->spi_conf.cs);
LOG_ERR("config->cs->gpio_dev: %p", spi_cfg->spi_conf.cs->gpio_dev);

lis3dhh_drv_data->hw_tf = &lis3dhh_spi_transfter_fn;

if (spi_cfg->cs_gpios_label != NULL)
{
lis3dhh_drv_data->cs_ctrl.gpio_dev = device_get_binding(spi_cfg->cs_gpios_label);
if (!lis3dhh_drv_data->cs_ctrl.gpio_dev)
{
LOG_ERR("unable to get GPIO SPI CS device");
return -ENODEV; //no such device
}
LOG_DBG("SPI GPIO CS configured on %s:%u", spi_cfg->cs_gpios_label, lis3dhh_drv_data->cs_ctrl.gpio_pin);
}
if (spi_cfg->cs_gpios_label == NULL) {LOG_ERR("spi_cfg cs_gpios_label is NULL");}
return 0;
}



The spi init function is called from this lis3dhh init function:

int lis3dhh_init(const struct device *dev)
{
struct lis3dhh_data *lis3dhh_drv_data = dev->data;
const struct lis3dhh_config *cfg = dev->config;
int status;
uint8_t id;

lis3dhh_drv_data->bus = device_get_binding(
cfg->bus_name);

if (!lis3dhh_drv_data->bus)
{
LOG_ERR("master not found: %s", cfg->bus_name);
return -EINVAL; // error: invalid value
}
cfg->bus_init(dev); //spi bus initialization

status = lis3dhh_drv_data->hw_tf->read_reg(
dev, LIS3DHH_REG_WAI,
&id);

if (status < 0)
{
LOG_ERR("failed to read chip id.");
return status;
}

if (id != LIS3DHH_CHIP_ID)
{
LOG_ERR("invalid chip id: %02x (hex)\n", id);
return -EINVAL; // error: invalid value
}

LOG_INF("bus=%s", cfg->bus_name);
status = lis3dhh_drv_data->hw_tf->write_reg(dev, LIS3DHH_CTRL_REG1,
(LIS3DHH_CTRL_REG1_NORM_MODE_EN |
LIS3DHH_CTRL_REG1_IF_ADD_INC |
LIS3DHH_CTRL_REG1_BOOT));
if (status < 0)
{
LOG_ERR("failed to configure ctrl reg 1");
printk("failed to configure ctrl reg 1");
return status;
}
status = lis3dhh_drv_data->hw_tf->write_reg(dev, LIS3DHH_CTRL_REG4, LIS3DHH_CTRL_REG4_ONE_1);
return status;
}



Now i get these logs:
[00:00:00.002,000] <err> lis3dhh: config->cs: 0x200004e4
[00:00:00.002,000] <err> lis3dhh: config->cs->gpio_dev: (nil)
[00:00:00.002,000] <err> lis3dhh: spi_cfg cs_gpios_label is NULL
[00:00:00.014,000] <inf> spi_ll_stm32: CS control inhibited (no GPIO device)
[00:00:00.017,000] <err> lis3dhh: invalid chip id: 00

I just don't understand why my program does not seem to be able to access the given cs-gpio from the devicetree file.

Thanks again in advance for any directions,
Markus

Join devel@lists.zephyrproject.org to automatically receive all group messages.