Skip to content
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: can: add tcan4x5x support #62033

Merged

Conversation

henrikbrixandersen
Copy link
Member

This PR adds devicetree binding and driver for the TI TCAN4x5x series of CAN controllers along with a shield definition for the TI TCAN4550EVM, an evaluation module for the TI TCAN4x5x CAN controller series. These CAN controllers are based on the Bosch M_CAN IP and interfaced via an SPI bus.

Add devicetree binding for the TI TCAN4x5x series of CAN controllers. These
CAN controllers are based on the Bosch M_CAN IP and interfaced via a SPI
bus.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add driver for the TI TCAN4x5x series of CAN controllers. These CAN
controllers are based on the Bosch M_CAN IP and interfaced via an SPI bus.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add shield definition for the TI TCAN4550EVM, an evaluation module for the
TI TCAN4x5x CAN controller series.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Add a compile test for the TI TCAN4x5x series CAN controller driver.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Copy link
Collaborator

@jfischer-no jfischer-no left a comment

Choose a reason for hiding this comment

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

Shield LGTM

Copy link
Member

@martinjaeger martinjaeger left a comment

Choose a reason for hiding this comment

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

Looks good, only got some minor comments.

tests/drivers/build_all/can/testcase.yaml Show resolved Hide resolved

static int tcan4x5x_clear_mcan_mram(const struct device *dev, uint16_t offset, size_t len)
{
static const uint8_t buf[256] = {0};
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it wastes a lot of flash memory (if the compiler isn't able to optimize it away).

This function is only called when a filter is removed and once during driver init. Maybe we could just use 4 zero-bytes on the stack instead of these 256? This would be sufficient for removal of the rx filter, but it would lead to longer initialization because of significantly more SPI transfers.

Just an idea, not blocking.

Copy link
Member Author

Choose a reason for hiding this comment

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

The tcan4x5x_clear_mcan_mram() takes up 88 bytes of flash. The buffer is stack allocated. Clearing the MRAM in 4 bytes chunks would result in 512 individual SPI transactions. A buffer size of 256 bytes was chosen since this is the largest TCAN4x5x SPI transfer size.

$ make rom_report |grep tcan4x5x_clear_mcan_mram
    │   │       ├── tcan4x5x_clear_mcan_mram                                                       88   0.07%

Copy link
Member

Choose a reason for hiding this comment

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

As the buffer is a static variable, it is not counted as part of the function, but appears at the top of the rom_report:

Root                                                                                            90116 100.00%
├── (hidden)                                                                                    20108  22.31%
├── (no paths)                                                                                   5696   6.32%
│   ...
│   ├── buf.0                                                                                     256   0.28%

Anyway, don't have any hard feelings about this. We can keep it as is.

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer a compromise with a buffer of 16 or 32 bytes.
The mram clear is only executed once.

const struct can_mcan_config *mcan_config = dev->config;
const struct tcan4x5x_config *tcan_config = mcan_config->custom;
size_t len32 = len / sizeof(uint32_t);
uint32_t src32[len32];
Copy link
Member

Choose a reason for hiding this comment

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

This looks a bit dangerous to me.
Is there a point where we need to write more than one register at once (except the msgram clear).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, as you can see from the code this is also used for writing to the MRAM. Please elaborate on why you believe this is dangerous.

Copy link
Member

Choose a reason for hiding this comment

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

Because the stack size is depending on a function parameter. A static size and a limit is saver in my opinion.

@carlescufi carlescufi merged commit 37f4cb1 into zephyrproject-rtos:main Sep 11, 2023
31 checks passed
@henrikbrixandersen henrikbrixandersen deleted the can_tcan4550evm branch September 12, 2023 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: CAN area: Devicetree Binding PR modifies or adds a Device Tree binding area: Shields Shields (add-on boards)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants