Skip to content

Conversation

@cfriedt
Copy link
Member

@cfriedt cfriedt commented Nov 8, 2025

This change fixes multiple errors in in the SMBus area.

  • Use a default smbus driver initialization priority of CONFIG_KERNEL_INIT_PRIORITY_DEVICE
  • Add cast to avoid warning in stm32 smbus driver
  • Add a build-all testsuite for smbus drivers

Without the first fix:

$ twister -i -c -p nucleo_g071rb -T tests/drivers/build_all/smbus/
...
Memory region         Used Size  Region Size  %age Used
           FLASH:       83416 B       128 KB     63.64%
             RAM:         11 KB        36 KB     30.56%
           SRAM0:          0 GB        36 KB      0.00%
        IDT_LIST:          0 GB        32 KB      0.00%
Generating files from ZEPHYR_BASE/twister-out/nucleo_g071rb_stm32g071xx/zephyr/tests/drivers/build_all/smbus/drivers.smbus.build.stm32/zephyr/zephyr.elf for board: nucleo_g071rb
ERROR: Device initialization priority validation failed, the sequence of initialization calls does not match the devicetree dependencies.
ERROR: /smbus1 <smbus_stm32_init> is initialized before its dependency /soc/i2c@40005400 <i2c_stm32_init> (POST_KERNEL+1 < POST_KERNEL+4)
ninja: build stopped: subcommand failed.
...

Without the second fix:

$ twister -i -c -p nucleo_g071rb -T tests/drivers/build_all/smbus/
...
.dir/smbus_stm32.c.obj.d -o zephyr/drivers/smbus/CMakeFiles/drivers__smbus.dir/smbus_stm32.c.obj -c ZEPHYR_BASE/drivers/smbus/smbus_stm32.c
ZEPHYR_BASE/drivers/smbus/smbus_stm32.c: In function 'smbus_stm32_pcall':
ZEPHYR_BASE/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,
      |                                ^
ZEPHYR_BASE/drivers/smbus/smbus_stm32.c:358:32: note: (near initialization for 'messages[1].buf')
ZEPHYR_BASE/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,
      |                                ^~~~~~~~~
ZEPHYR_BASE/drivers/smbus/smbus_stm32.c:363:32: note: (near initialization for 'messages[2].buf')
cc1: all warnings being treated as errors
[138/196] Building C object zephyr/drivers/interrupt_controller/CMakeFiles/drivers__interrupt_controller.dir/intc_exti_stm32.c.obj

Testing done:

$ twister -i -c -p nucleo_g071rb -T tests/drivers/build_all/smbus/
Deleting output directory ZEPHYR_BASE/twister-out
INFO    - Using Ninja..
INFO    - Zephyr version: v4.3.0-rc3-3-g6960ac63093c
INFO    - Using 'zephyr' toolchain.
INFO    - Building initial testsuite list...
INFO    - Writing JSON report ZEPHYR_BASE/twister-out/testplan.json
INFO    - JOBS: 32
INFO    - Adding tasks to the queue...
INFO    - Added initial list of jobs to queue
INFO    - Total complete:    1/   1  100%  built (not run):    1, filtered:    0, failed:    0, error:    0
INFO    - 1 test scenarios (1 configurations) selected, 0 configurations filtered (0 by static filter, 0 at runtime).
INFO    - 0 of 1 executed test configurations passed (0.00%), 1 built (not run), 0 failed, 0 errored, with no warnings in 16.23 seconds.
INFO    - 0 of 0 executed test cases passed (0.00%) on 0 out of total 1259 platforms (0.00%).
INFO    - 1 selected test cases not executed: 1 not run (built only).
INFO    - 0 test configurations executed on platforms, 1 test configurations were only built.
INFO    - Saving reports...
INFO    - Writing JSON report ZEPHYR_BASE/twister-out/twister.json
INFO    - Writing xunit report ZEPHYR_BASE/twister-out/twister.xml...
INFO    - Writing xunit report ZEPHYR_BASE/twister-out/twister_report.xml...
INFO    - Run completed

Fixes #99129
Fixes #99130
Fixes #99131

@cfriedt cfriedt force-pushed the smbus-stm32-add-cast-to-avoid-warning branch 2 times, most recently from de7a7c2 to ced7dc5 Compare November 8, 2025 23:33
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 <smbus_stm32_init> is initialized before its dependency \
/soc/i2c@40005400 <i2c_stm32_init> (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 <cfriedt@tenstorrent.com>
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 <cfriedt@tenstorrent.com>
To ensure that code compiles error (and warning) free, add a build-all
testsuite for smbus drivers.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
@cfriedt cfriedt force-pushed the smbus-stm32-add-cast-to-avoid-warning branch from ced7dc5 to 6960ac6 Compare November 9, 2025 12:59
@cfriedt cfriedt changed the title drivers: smbus: stm32: add cast to avoid warning drivers: smbus: fix multiple errors Nov 9, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 9, 2025

@cfriedt cfriedt added bug The issue is a bug, or the PR is fixing a bug Regression Something, which was working, does not anymore area: SMBus platform: STM32 ST Micro STM32 labels Nov 9, 2025
@cfriedt cfriedt marked this pull request as ready for review November 9, 2025 13:44
@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label Nov 9, 2025
@cfriedt cfriedt requested a review from jhedberg November 10, 2025 11:46
@cfriedt cfriedt added this to the v4.3.0 milestone Nov 10, 2025
@cfriedt
Copy link
Member Author

cfriedt commented Nov 10, 2025

Adding the 4.3.0 milestone to this, since a regression was added during the stabilization period, since the change itself is quite self-contained, since it fixes multiple bugs, and since it improves stability.

@cfriedt
Copy link
Member Author

cfriedt commented Nov 10, 2025

Will determine at the release meeting if this is a "release blocker" and whether it will actually go in to the 4.3.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: SMBus area: Tests Issues related to a particular existing or missing test bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32 Regression Something, which was working, does not anymore

Projects

None yet

6 participants