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

Enable CAN peripheral on STM32G0 #34963

Closed
wants to merge 7 commits into from

Conversation

str4t0m
Copy link
Collaborator

@str4t0m str4t0m commented May 7, 2021

This PR enables CAN support for stm32g0.
The driver introduced in #31061 by @alexanderwachter does work for this series as well without issues.
All tests pass with this definitions on nucleo_g0b1re.

@str4t0m
Copy link
Collaborator Author

str4t0m commented May 7, 2021

@raul-klg CANFD works on stm32g0 with this definitions.

@raul-klg
Copy link
Contributor

raul-klg commented May 7, 2021

Thanks, @str4t0m That's something very similar to what I had. Probably I'll review again according to your comments and news from https://github.com/alexanderwachter/zephyr/tree/can_mcan_stm
Regards,

#size-cells = <0>;
reg = <0x40006800 0x400>, <0x4000B800 0x350>;
reg-names = "m_can", "message_ram";
interrupts = <21 0>, <22 0>;
Copy link
Member

Choose a reason for hiding this comment

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

Does can1 and can2 share the IRQ line? If not, this is probably a copy/paste error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the review.
Yes they share the interrupt:
Interrupt 21 is TIM16 and FDCAN_IT0 global interrupt and 22 is TIM17 and FDCAN_IT1 global interrupt

Copy link
Member

Choose a reason for hiding this comment

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

Oh, then you have to remove the can2 node or modify the can_stm32fd.c frontend implementation to support shared IRQ lines.

#size-cells = <0>;
reg = <0x40006800 0x400>, <0x4000B800 0x350>;
reg-names = "m_can", "message_ram";
interrupts = <21 0>, <22 0>;
Copy link
Member

Choose a reason for hiding this comment

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

Oh, then you have to remove the can2 node or modify the can_stm32fd.c frontend implementation to support shared IRQ lines.

@str4t0m str4t0m marked this pull request as draft June 11, 2021 09:57
@str4t0m
Copy link
Collaborator Author

str4t0m commented Jun 11, 2021

I Will push code for interrupt sharing later, therefore I marked it as draft for now.

@github-actions github-actions bot added area: API Changes to public APIs area: Devicetree Binding PR modifies or adds a Device Tree binding labels Jun 15, 2021
Comment on lines 154 to 155
shared-irqs = <&shared_irq21>, <&shared_irq22>;
shared-irq-names = "LINE_0", "LINE_1";
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why these are defined at board level.
Is there some level of configuration that is left to the user?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My initial idea was that irq conflicts arise depending on which peripherals are used in the application.
In cases where only CAN1 is used there is no need to share the interrupt.
In cases where only CAN1 and TIM16 are used irq21 could be shared while irq22 is only used by CAN1 line_1.

However this has the downside that additional configuration by the "user" is needed.
Would you prefer if the driver would simply use shared-irqs all the time, or enable shared-irq support by another means?

Copy link
Member

Choose a reason for hiding this comment

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

ok, I get your point.

Actually I was not sure you considered the case of having different IRQ scheme depending on conflicts possibility (looking at the modifications done to config_can_##inst##_irq function.

I'd prefer to avoid having users configuring this. Device tree is already complex for new comers, and this would add one more significant step.

I see following options:

  • A] Keep shared IRQ used even if there is no conflict in user configuration
    (+) Simple to handle at driver level
    (+) Same code used with or w/o conflicting devices enabled. Which is better in general for analysis if real time issues
    (-) Useless footprint/performance overhead
    (-) Different real time behavior of potentially conflicting nodes and no conflict nodes
  • B] Detect conflicting configurations (using DT macros) and enable shared IRQ only when required
    (+) Performance/Footprint optimization
    (-) Increased complexity at driver level
    (-) Different code used in both cases
  • C] User configurable B] (same as B], but with Kconfig option that allows to always use shared IRQ, even if no conflict is possible)
    (+) User can choose between Performance/Footprint optimization and similar real time behavior
    (-) Driver complexity ++

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for this detailed listing of options.
I have now as a first step moved the lines highlighted above into the soc's dtsi.
There was really no good reason not to have them already defined. Now shared-irqs are used if the referenced shared-irq is enabled, meaning the user would still have to set status = "okay" for the relevant irq nodes.
Before I comment on above options, may I ask if

I'd prefer to avoid having users configuring this.

also refers to setting status = "okay" for the shared-irq nodes?

Copy link
Member

Choose a reason for hiding this comment

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

also refers to setting status = "okay" for the shared-irq nodes?

It depends on the solution chosen in the end, but if we can minimize the possibility of errors for end users, it would be great

@alexanderwachter
Copy link
Member

alexanderwachter commented Jun 16, 2021

@mbolivar can you check the IRQ device-tree API extension?

@str4t0m str4t0m force-pushed the stm32g0_can branch 2 times, most recently from 419f91c to 338127a Compare June 17, 2021 09:49
@str4t0m
Copy link
Collaborator Author

str4t0m commented Jun 17, 2021

I am wondering if the Macros with the _COND suffix are worth it or this logic should be implemented by each driver using shared-irqs itself? Mostly because zephyr also has ZLI and #32575 for example provides the possibility to choose between "normal" and direct IRQs .

Would you prefer to open a separate PR for the commit "drivers: shared_irq: add devicetree helper macros", or should I rename this PR accordingly.

This commit adds helper macros to reduce boilerplate code in drivers
that (conditionally) use the shared irq driver.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
This commit enables SHARED_IRQ config option per default if any
shared_irq node is enabled.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
This commit adds shared_irq support to can_stm32fd driver, such that
two can instances can be used on stm32g0.

Additinally to the necessary code changes, bindings are added to
st,stm32-fdacn.yaml,
and the SHARED_IRQ is automatically enabled in KConfig if the can
devices define a shared-irqs phandle-array.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
The shared-irq nodes are necessary to use the shared irq-driver
This commit adds the necessary nodes for can1, can2, tim16, and tim17.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
In stm32g0 series only stm32g0b1 and stm32g0c1 socs support can.
This commit adds the CAN nodes to the stm32g0b1 soc.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
This commit adds CAN support to the nucleo_g0b1re board.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
This commit should be removed once the pr is not in draft status
anymore.
It adds some additionl definitions which are not intended to be merged.
Those definitions enable 2 can instances and the shared irq driver
on the nucleo_g0b1re board.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
@@ -5,6 +5,7 @@

menuconfig SHARED_IRQ
bool "Shared interrupt driver"
default $(dt_compat_enabled,shared-irq)
Copy link
Member

Choose a reason for hiding this comment

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

Since shared-irq can't be used alone, what about having this symbol selected by clients, when needed.

@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Aug 21, 2021
@henrikbrixandersen henrikbrixandersen removed their request for review August 25, 2021 09:20
@github-actions github-actions bot closed this Sep 9, 2021
@dresco
Copy link
Contributor

dresco commented Nov 21, 2022

Hi, just wondering if there are still plans for moving this forwards? I have an app running on F4 that I'd like to port to G0, and found this issue while searching for info on CAN support.

I also found the shared interrupts issue, so perhaps is waiting for that to be added first?

Thanks in advance for any feedback..

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