-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Conversation
@raul-klg CANFD works on stm32g0 with this definitions. |
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 |
baa9693
to
8afb5f7
Compare
#size-cells = <0>; | ||
reg = <0x40006800 0x400>, <0x4000B800 0x350>; | ||
reg-names = "m_can", "message_ram"; | ||
interrupts = <21 0>, <22 0>; |
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.
Does can1 and can2 share the IRQ line? If not, this is probably a copy/paste error
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.
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
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.
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>; |
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.
Oh, then you have to remove the can2 node or modify the can_stm32fd.c frontend implementation to support shared IRQ lines.
I Will push code for interrupt sharing later, therefore I marked it as draft for now. |
shared-irqs = <&shared_irq21>, <&shared_irq22>; | ||
shared-irq-names = "LINE_0", "LINE_1"; |
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 wonder why these are defined at board level.
Is there some level of configuration that is left to the user?
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.
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?
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.
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 ++
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.
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?
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.
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
@mbolivar can you check the IRQ device-tree API extension? |
419f91c
to
338127a
Compare
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) |
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.
Since shared-irq can't be used alone, what about having this symbol selected by clients, when needed.
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. |
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.. |
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.