-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
As discussed in #42513
Many board.dts files in the Zephyr tree enable peripherals by default. For example, nucleo_f091rc.dts which defines:
&i2c1 {
pinctrl-0 = <&i2c1_scl_pb8 &i2c1_sda_pb9>;
pinctrl-names = "default";
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
};
&i2c2 {
pinctrl-0 = <&i2c2_scl_pa11 &i2c2_sda_pa12>;
pinctrl-names = "default";
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
};
This does not immediately enable those peripherals, since they depend on CONFIG_I2C=y. The problem with this approach is that enabling CONFIG_I2C will enable BOTH peripherals. This is problematic for two reasons I can think of:
- Enabling an extra peripheral wastes power
- Enabling an extra peripheral can cause pin collisions with other peripherals (e.g. the default i2c pin happens to also be the uart console tx pin).
Ideally, all peripherals should be disabled by default, and enabled by a project's DTS overlay. Realistically, doing so at this point would probably break some stuff, including samples and tests enabling peripherals with Kconfig without having an overlay (thanks @gmarull for pointing this out).
Given that it isn't possible to disable peripherals in DTS, other solutions to alleviate this problem may be:
- The pinctrl driver can assert and warn/crash if multiple peripherals are configured to use the same pin.
- The build system can print or log to a file the enabled peripherals. When optimizing for power consumption, this info can be used to contrive a board overlay that filters all unused peripherals.
- (not sure this is a good idea but worth mentioning) An assertion to check if a peripheral (device) is enabled but is never accessed through
device_get_bindingor similar.
Any better ideas are of course welcomed.