Skip to content

Conversation

DonBrus
Copy link

@DonBrus DonBrus commented Oct 2, 2025

The Polarfire SoC from Microchip allows a configuration of the CAN peripherals, via the SWAP_ENDIAN bit (13) of the respective CONFIG registers, that inverts the byte ordering for transmit and receive buffers.

This can be used to allow a more predictable usage of the peripheral, as the driver implementation on which this PR is based off will cause the bytes to appear on the bus possibly in inverted order with respect to expected behavior.
For example, the usage example outlined in the CAN API will result in bytes appearing on the bus in the following sequence: 0x04 0x03 0x02 0x01 0x08 0x07 0x06 0x05, which does not reflect the ordering of the input buffer. By toggling the SWAP_ENDIAN bit, the sequence will be fixed (0x01 0x02 .. 0x05 0x06 ..)

Note: this PR cherry picks the commit proposed in #95698, which adds the CAN driver in the first place.

Add a CAN driver for Microchip's PolarFire SoC platform.

Signed-off-by: Sebastian Huber <[email protected]>
Copy link

github-actions bot commented Oct 2, 2025

Hello @DonBrus, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

…DIAN bit

Default implementation of CAN driver for the Polarfire SoC inverts the byte ordering to write registers/from read registers due to platform endianness, possibly resulting in an unexpected behavior when considering the normal API usage of CAN. This adds KConfig support for
forcing a configuration bit to be set, which will take care of reversing
the byte order in hardware.

Signed-off-by: Donato Brusamento <[email protected]>
@DonBrus DonBrus force-pushed the can-mchp-mss-endian-swap branch from d2beb85 to df636d3 Compare October 3, 2025 08:41
Copy link

sonarqubecloud bot commented Oct 3, 2025

Copy link
Member

@henrikbrixandersen henrikbrixandersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Polarfire SoC from Microchip allows a configuration of the CAN peripherals, via the SWAP_ENDIAN bit (13) of the respective CONFIG registers, that inverts the byte ordering for transmit and receive buffers.

This can be used to allow a more predictable usage of the peripheral, as the driver implementation on which this PR is based off will cause the bytes to appear on the bus possibly in inverted order with respect to expected behavior. For example, the usage example outlined in the CAN API will result in bytes appearing on the bus in the following sequence: 0x04 0x03 0x02 0x01 0x08 0x07 0x06 0x05, which does not reflect the ordering of the input buffer. By toggling the SWAP_ENDIAN bit, the sequence will be fixed (0x01 0x02 .. 0x05 0x06 ..)

The sent bytes must match the order in the buffer being sent, otherwise the driver breaks the CAN controller API contract. Introducing a Kconfig for this is not the right way to solve an issue like this.

Note: this PR cherry picks the commit proposed in #95698, which adds the CAN driver in the first place.

Please add you comments regarding byte order to that PR instead.

@sebhub
Copy link
Contributor

sebhub commented Oct 6, 2025

@henrikbrixandersen Thanks, I will have a look at this.

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

Successfully merging this pull request may close these issues.

5 participants