zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.62k stars 6.5k forks source link

STM32: change the pinctrl state for i2c bus dinamically #71427

Closed marcorivolta-LSI closed 5 months ago

marcorivolta-LSI commented 5 months ago

I'm working on a custom board with a STM32WB controller and an array of five I2C sensors.

Due to some constraints, the five sensors are on the same i2c bus. Since the sensor allows up to 4 configurable addresses, there are two SCL lines. The first one goes to sensor 1 to 4, the second one goes to sensor 5.

I'm trying to determine if it's possible to dynamically change the SCL pin used by the I2C bus with the STM32 I2C driver, but it doesn't seem feasible.

The i2c bus is activated by "i2c_stm32_activate" function in "i2c_ll_stm32.c":

/* Move pins to active/default state */
ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
if (ret < 0) {
    LOG_ERR("I2C pinctrl setup failed (%d)", ret);
    return ret;
}   

It would seem that there is no possibility to change the pinctrl state at runtime.

github-actions[bot] commented 5 months ago

Hi @marcorivolta-LSI! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

erwango commented 5 months ago

See dynamic pinctrl status in doc: https://docs.zephyrproject.org/latest/hardware/pinctrl/index.html#dynamic-pin-control

This feature is supported to some extent, but not in the scope of your expectations. I'm closing the issue for the time being.