-
Notifications
You must be signed in to change notification settings - Fork 8k
drivers: smbus: stm32: support packet-error-checking (pec) #96691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
e22919f
to
57a4ac9
Compare
57a4ac9
to
d34b26a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor typos in header file inline description comments. Otherwise LGTM.
drivers/smbus/smbus_utils.h
Outdated
* @note This function is intended for SMBus drivers that do not have hardware PEC support and | ||
* therefore must rely on software PEC calculation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe these should be guarded by a Kconfig symbol then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops - I still need to add some ifdefs to smbus_util.c for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
*count = msgs[2].len; | ||
ret = smbus_read_check_pec(data->config, periph_addr, msgs, num_msgs); | ||
if (ret < 0) { | ||
return ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to investigate capturing error statistics, in this block, in a subsequent PR.
Also mentioned here
https://github.com/zephyrproject-rtos/zephyr/pull/96691/files#r2413732281
d34b26a
to
3ae7fc6
Compare
In the case that SMBus hardware does not automatically perform packet error checking (PEC), provide generic inline functions in `zephyr/drivers/smbus.h` that can be used by drivers to perform PEC in software. Signed-off-by: Chris Friedt <[email protected]> Signed-off-by: Andrew Lewycky <[email protected]>
Add tests for SMBus packet error correction (PEC). The two primary utilities tested are * smbus_pec(): compute the PEC byte for a Block Write * smbus_read_check_pec(): verify a PEC after * Read Byte * Read Word * Block Read Signed-off-by: Chris Friedt <[email protected]>
Add support for SMBus packet error checking (PEC) to the stm32 driver. This feature allows SMBust communication to be slightly more robust in the presence of noise, in that packet errors can be detected on the receive side. Signed-off-by: Andrew Lewycky <[email protected]> Signed-off-by: Chris Friedt <[email protected]>
f665447
3ae7fc6
to
f665447
Compare
@etienne-lms @mathieuchopstm - sorry to ask for a re-approval. Just a minor change from the previous commit (to ensure that unnecessary code is not compiled. The difference is here |
|
SMBus device driver initialization priority. | ||
|
||
config SMBUS_SOFT_PEC | ||
bool "SMBus software PEC support" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this option configurable by the project? It seems rather a driver private config.
... hmmm, i see at least the test sample needs to enable it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's configurable by the project. Technically could be used by any driver or other code.
No problem - as a matter of fact, I was wondering if this wasn't missing when approving 😉 |
@benediktibk Would you have time to have a look ? |
depends on DT_HAS_ST_STM32_SMBUS_ENABLED | ||
depends on I2C_STM32 | ||
select PINCTRL | ||
select SMBUS_SOFT_PEC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose there are two ways to look at this:
- PEC is a feature, which is implemented in the STM32 SMBus driver
- PEC is a capability which is required by the SMBus driver
With the select here it is more the latter one, although it should actually be the first one? But this then would also mean that everything has to be ifdef-ed in the driver itself, so I'm not sure if it is actually a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slowly I start to understand it, you actually need this config-flag so that the utility functions for PEC (which themselves require CRC) are only pulled in when necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the select here it is more the latter one, although it should actually be the first one?
"Should" is potentially debatable. E.g. intel_pch_smbus.c
implicitly supports PEC.
zephyr/drivers/smbus/intel_pch_smbus.c
Line 332 in d3e645e
if (auxs & PCH_SMBUS_AUXS_CRC_ERROR) { |
The stm32 driver is the only other smbus driver in-tree.
It's almost completely platform-independent, actually, with the exception of i2c_stm32_smbalert_enable()
, i2c_stm32_smbalert_disable()
, and i2c_stm32_set_smbus_mode()
.
Personally, I would feel better if there was a uniform API, so that PEC can at least be configured by the application, but it isn't disabled by default here (the Zephyr convention), so I can see your point.
everything has to be ifdef-ed in the driver itself, so I'm not sure if it is actually a good idea.
SMBUS_SOFT_PEC
could use depends on CRC
instead of select
, and the stm32 driver could use conditional compilation throughout.
I'm ok to go either way.
@benediktibk , @erwango , @etienne-lms - do you have preferences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everything has to be ifdef-ed in the driver itself, so I'm not sure if it is actually a good idea.
SMBUS_SOFT_PEC
could usedepends on CRC
instead ofselect
, and the stm32 driver could use conditional compilation throughout.I'm ok to go either way.
I'd go for SMBUS_SOFT_PEC
select
'ing CRC
and the consumer drivers select
'ing SMBUS_SOFT_PEC
as done in PR right now. This avoids duplicating the select CRC
in every driver's Kconfig and is just more sensical IMO.
Uh oh!
There was an error while loading. Please reload this page.