Shoud I set PM_DEVICE_ACTION_SUSPEND on I2C0 before sys_poweroff() ?

Dear Sir :

              We are now developing on nrf52840, with ncs v2.6.1 and zephyr.

We want to put I2C0 to PM_DEVICE_ACTION_SUSPEND before sys_poweroff().

Our code is below :

const struct device *const i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));

int rc = pm_device_action_run(i2c_dev, PM_DEVICE_ACTION_SUSPEND);

if (rc < 0) {
   printf("Could not suspend I2C (%d)\n", rc);
   return 0;
}

sys_poweroff();

But it always return "Could not suspend I2C (-120)".

Our I2C connects to an EEPROM and all read/write operations work fine.

We had search Nordic Q&A and someone said: only UART is not handled when using sys_poweroff(), others are handled automatically.

Does it mean that it is not necessary to put I2C to PM_DEVICE_ACTION_SUSPEND, becasue sys_poweroff will turn off I2C automatically?

Just run sys_poweroff() directly is enough or not?

Device tree overlay for reference :


&i2c0 {
compatible = "nordic,nrf-twim";
status = "okay";
clock-frequency = <100000>;
pinctrl-0 = <&i2c0_default>;
pinctrl-1 = <&i2c0_sleep>;
zephyr,concat-buf-size = <64>;
zephyr,flash-buf-max-size = <64>;

};

&pinctrl {
i2c0_default: i2c0_default {
group1 {
psels = <NRF_PSEL(TWIM_SDA, 0, 26)>,
<NRF_PSEL(TWIM_SCL, 0, 27)>;
};
};

i2c0_sleep: i2c0_sleep {
group1 {
psels = <NRF_PSEL(TWIM_SDA, 0, 26)>,
<NRF_PSEL(TWIM_SCL, 0, 27)>;
low-power-enable;
};
};
};

Parents
  • Hello,

    It is recommended to suspend the I2C device before calling sys_poweroff(). 

    Did you add CONFIG_PM_DEVICE=y in prj.conf file?

    TWI shares registers and other resources with other peripherals that have the same ID as TWI.

    Therefore, you must disable all peripherals that have the same ID as TWI before TWI can be configured and used. Disabling a peripheral that has the same ID as TWI will not reset any of the registers that are shared with TWI. It is therefore important to configure all relevant TWI registers explicitly to secure that it operates correctly.

    You can check if SDA and SCL pins of I2C are not used for other peripherals.

  • Hi~

    Yes, I had add CONFIG_PM_DEVICE=y in prj.conf,

    At first, I add these lines:

    CONFIG_PM_DEVICE=y

    CONFIG_PM_DEVICE_RUNTIME=y

    CONFIG_POWEROFF=y

    Since "CONFIG_PM_DEVICE_RUNTIME=y" conflicts with PM_DEVICE_ACTION_SUSPEND, I remove it. 

    There are two relative setting left now:

    CONFIG_PM_DEVICE=y

    CONFIG_POWEROFF=y

    After remove "CONFIG_PM_DEVICE_RUNTIME", I2c can be.SUSPEND successfully.

    But I still don't know remove  CONFIG_PM_DEVICE_RUNTIME has any portential disadvantage?

  • Hello,

    ''But I still don't know remove CONFIG_PM_DEVICE_RUNTIME has any portential disadvantage?''

    This could potentially lead to conflicts if not managed properly.

    If you want to use PM_DEVICE_ACTION_SUSPEND, you have to set CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE as ''n''. It is enabled by default when CONFIG_PM_DEVICE_RUNTIME is enabled. You have disabled CONFIG_PM_DEVICE_RUNTIME. So, I think it's ok.

    you can read Device Runtime Power Management (nordicsemi.com) this documentation.

Reply Children
  • Hi~

    Thanks for your efforts.

    I tried to set CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE=n when CONFIG_PM_DEVICE_RUNTIME=y.

    But still get ""Could not suspend I2C (-120)" when set I2C to PM_DEVICE_STATE_SUSPEND.

    So I have to turn off CONFIG_PM_DEVICE_RUNTIME.

    After set CONFIG_PM_DEVICE_RUNTIME=n , I get a yellow under line warning on CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE.

    It says CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE is associated with CONFIG_PM_DEVICE_RUNTIME.

    Finally, I remove CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE=n and CONFIG_PM_DEVICE_RUNTIME=n .

    Now I can put I2C to PM_DEVICE_STATE_SUSPEND after remove CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE and CONFIG_PM_DEVICE_RUNTIME.

     

  • Hello,

    So, your problem is solved in this way?

    Usually CONFIG_PM_DEVICE_RUNTIME should be enabled when you use I2C device. 

    If both CONFIG_PM_DEVICE_RUNTIME and CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE are off, it means that the automatic power management handled by these configurations is not active. I think because of your application type this would work. 

  • Hi, sorry for replying late.

    My work around is : 

    remove CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE and CONFIG_PM_DEVICE_RUNTIME

    As you said, this work around has trade off is to give up "automatic power management".

    But, at this time, we have no better solutions.

Related