-
Notifications
You must be signed in to change notification settings - Fork 7.8k
drivers/sensor/st: Fix wrong data byte swap for be #76557
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
drivers/sensor/st: Fix wrong data byte swap for be #76557
Conversation
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'm a little confused, it's fine if we want access to the raw numbers, but the get function should convert things to the system endianess.
@yperess
with
If we do not remove the |
@yperess still any doubt? |
Any feedback on this fix? |
@kartben do you possibly have any feedback on this fix? Thanks |
@avisconti sorry, I am not really an expert on that stuff and was hoping maybe other sensor maintainers/collaborators could chime in to confirm it's the right approach. Thanks! |
Even if big endian architectures are not so frequent I would like to see whether this approach is correct or not. Who can be added to the list of reviewers? @fabiobaltieri Fabio, do you know if there is anyone with some expertise on endianity? Thanks |
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.
If I understand this correctly: we're reverting these BE/LE omitting these sys_le16_to_cpu
conversions because the ST HAL is already taking care of it.
May we capture that in the drivers code? Personally, I wouldn't have inferred it, had I not looked at the GH Issue.
Yes, correct.
Do you mean if we can reproduce it on a big endian system? If so, unfortunately I do not have access to such h/w setup. |
The code changes look fine. It's clear that the byteswapping helpers aren't needed when the byte manipulation is done in the zephyr driver; what's a little less clear is when the ST HAL handles it under the hood. It would get repetitive to comment in every driver, so could you at least mention it in the commit message? |
Sorry - I just meant if we could drop a comment explaining. Just what Maureen said. |
As a side-note: A few months back I was able to compile/run big-endian on Linux with QEMU (using |
Yeah, I was looking into something like that in fact, just to make some compile tests and clear my mind against any possible doubt. But I think that theory is pretty clear. So I will re-elaborate the commit message adding some more info as requested by Maureen and you. |
4275f06
to
3971d81
Compare
Added a better commit header and copied here on this PR as well. |
A 16-bit value built using byte shifts and ORs from a given couple of lsb and msb bytes will result to be the same on both little-endian and big-endian architectures, e.g. uint8_t lsb, msb; int16_t val; /* val is the same number on both le and be archs, but has different layout in memory */ val = (msb << 8) | lsb; All the xyz_raw_get() APIs of stmemsc sensor module build the sensor data using the above method and DO NOT hence require (it actually leads to wrong values on big-endian machines) to use any le/be swap routines, such as sys_le16_to_cpu(). Fix zephyrproject-rtos#75758 Signed-off-by: Armando Visconti <[email protected]>
3971d81
to
62a6526
Compare
repushed just to give a kick to ci to run again |
A 16-bit value built using byte shifts and ORs from a given
couple of lsb and msb bytes will result to be the same on both
little-endian and big-endian architectures, e.g.
All the xyz_raw_get() APIs of stmemsc sensor module build the sensor
data using the above method and DO NOT hence require (it actually leads
to wrong values on big-endian machines) to use any le/be swap routines,
such as sys_le16_to_cpu().
Fix #75758