From 2d6f8c0e5eef2b9a4af2060a6145dd917d9db7a5 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Sun, 9 Nov 2025 07:52:19 -0500 Subject: [PATCH 1/3] drivers: smbus: use correct device initialization priority The smbus driver initialization priority was previously set to `KERNEL_INIT_PRIORITY_DEFAULT` (which is 40). However, the default init priority of devices is typically `KERNEL_INIT_PRIORITY_DEVICE` (which is 50). Since the stm32 smbus driver uses a reference to the underlying i2c device, and since this driver was not being built in CI, this led to the discovery that the smbus driver was initialized too early. ```shell ERROR: Device initialization priority validation failed, the sequence of \ initialization calls does not match the devicetree dependencies. ERROR: /smbus1 is initialized before its dependency \ /soc/i2c@40005400 (POST_KERNEL+1 < POST_KERNEL+4) ``` By setting the initialization priority to `KERNEL_INIT_PRIORITY_DEVICE`, both smbus1 and i2c1 have their priorities evaluated in the same group, and it becomes possible to determine relative priorities via phandle dependency. Signed-off-by: Chris Friedt --- drivers/smbus/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/smbus/Kconfig b/drivers/smbus/Kconfig index c32eaed9c68e3..fa0b945645854 100644 --- a/drivers/smbus/Kconfig +++ b/drivers/smbus/Kconfig @@ -24,7 +24,7 @@ config SMBUS_STATS config SMBUS_INIT_PRIORITY int "Init priority" - default KERNEL_INIT_PRIORITY_DEFAULT + default KERNEL_INIT_PRIORITY_DEVICE help SMBus device driver initialization priority. From 3a4ffa8e02f12f8babcdd64ef551d3356302bd3e Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Sat, 8 Nov 2025 18:07:44 -0500 Subject: [PATCH 2/3] drivers: smbus: stm32: add cast to avoid warning Previously, the function `smbus_stm32_pcall()` implicitly cast `uint16_t *` to `uint8_t *`. Add an explicit cast to avoid warning. ```shell ..drivers/smbus/smbus_stm32.c:358:32: error: initialization of \ 'uint8_t *' {aka 'unsigned char *'} from incompatible pointer type \ 'uint16_t *' {aka 'short unsigned int *'} \ [-Werror=incompatible-pointer-types] 358 | .buf = &send_word, | ^ ..drivers/smbus/smbus_stm32.c:358:32: note: (near initialization \ for 'messages[1].buf') ..drivers/smbus/smbus_stm32.c:363:32: error: initialization of \ 'uint8_t *' {aka 'unsigned char *'} from incompatible pointer type \ 'uint16_t *' {aka 'short unsigned int *'} \ [-Werror=incompatible-pointer-types] 363 | .buf = recv_word, | ^~~~~~~~~ ``` Signed-off-by: Chris Friedt --- drivers/smbus/smbus_stm32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/smbus/smbus_stm32.c b/drivers/smbus/smbus_stm32.c index 1d7ed57aae120..a5fe47a8c3ed5 100644 --- a/drivers/smbus/smbus_stm32.c +++ b/drivers/smbus/smbus_stm32.c @@ -355,12 +355,12 @@ static int smbus_stm32_pcall(const struct device *dev, uint16_t periph_addr, uin .flags = I2C_MSG_WRITE, }, { - .buf = &send_word, + .buf = (uint8_t *)&send_word, .len = sizeof(send_word), .flags = I2C_MSG_WRITE, }, { - .buf = recv_word, + .buf = (uint8_t *)recv_word, .len = sizeof(*recv_word), .flags = I2C_MSG_READ | I2C_MSG_RESTART, }, From 6960ac63093ced4365280236f5452016a274bec4 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Sat, 8 Nov 2025 18:28:37 -0500 Subject: [PATCH 3/3] tests: drivers: build_all: smbus: add build-all suite for smbus drivers To ensure that code compiles error (and warning) free, add a build-all testsuite for smbus drivers. Signed-off-by: Chris Friedt --- tests/drivers/build_all/smbus/CMakeLists.txt | 8 ++++++++ .../build_all/smbus/boards/nucleo_g071rb.conf | 1 + .../build_all/smbus/boards/nucleo_g071rb.overlay | 13 +++++++++++++ tests/drivers/build_all/smbus/prj.conf | 3 +++ tests/drivers/build_all/smbus/src/main.c | 9 +++++++++ tests/drivers/build_all/smbus/testcase.yaml | 10 ++++++++++ 6 files changed, 44 insertions(+) create mode 100644 tests/drivers/build_all/smbus/CMakeLists.txt create mode 100644 tests/drivers/build_all/smbus/boards/nucleo_g071rb.conf create mode 100644 tests/drivers/build_all/smbus/boards/nucleo_g071rb.overlay create mode 100644 tests/drivers/build_all/smbus/prj.conf create mode 100644 tests/drivers/build_all/smbus/src/main.c create mode 100644 tests/drivers/build_all/smbus/testcase.yaml diff --git a/tests/drivers/build_all/smbus/CMakeLists.txt b/tests/drivers/build_all/smbus/CMakeLists.txt new file mode 100644 index 0000000000000..518596a02f780 --- /dev/null +++ b/tests/drivers/build_all/smbus/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(build_all) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/drivers/build_all/smbus/boards/nucleo_g071rb.conf b/tests/drivers/build_all/smbus/boards/nucleo_g071rb.conf new file mode 100644 index 0000000000000..aafb657f5b9a0 --- /dev/null +++ b/tests/drivers/build_all/smbus/boards/nucleo_g071rb.conf @@ -0,0 +1 @@ +CONFIG_I2C=y diff --git a/tests/drivers/build_all/smbus/boards/nucleo_g071rb.overlay b/tests/drivers/build_all/smbus/boards/nucleo_g071rb.overlay new file mode 100644 index 0000000000000..8067e2d0a4625 --- /dev/null +++ b/tests/drivers/build_all/smbus/boards/nucleo_g071rb.overlay @@ -0,0 +1,13 @@ +/* + * SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +&i2c1 { + status = "okay"; +}; + +&smbus1 { + i2c = <&i2c1>; + status = "okay"; +}; diff --git a/tests/drivers/build_all/smbus/prj.conf b/tests/drivers/build_all/smbus/prj.conf new file mode 100644 index 0000000000000..994daaf9b3019 --- /dev/null +++ b/tests/drivers/build_all/smbus/prj.conf @@ -0,0 +1,3 @@ +CONFIG_TEST=y +CONFIG_TEST_USERSPACE=y +CONFIG_SMBUS=y diff --git a/tests/drivers/build_all/smbus/src/main.c b/tests/drivers/build_all/smbus/src/main.c new file mode 100644 index 0000000000000..0ff69028dfddf --- /dev/null +++ b/tests/drivers/build_all/smbus/src/main.c @@ -0,0 +1,9 @@ +/* + * SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +int main(void) +{ + return 0; +} diff --git a/tests/drivers/build_all/smbus/testcase.yaml b/tests/drivers/build_all/smbus/testcase.yaml new file mode 100644 index 0000000000000..1b58d0b86eeeb --- /dev/null +++ b/tests/drivers/build_all/smbus/testcase.yaml @@ -0,0 +1,10 @@ +common: + build_only: true + tags: + - drivers + - i2c + - smbus +tests: + drivers.smbus.build.stm32: + platform_allow: + - nucleo_g071rb