-
Notifications
You must be signed in to change notification settings - Fork 935
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
Support for FDCAN peripheral as found on newer STM32 micros. #2475
Conversation
1c1831e
to
8d50ae2
Compare
Commit reorganization I'd consider:
|
Question I was asking on #Embassy was whether that should be behind a |
Yes, I was thinking the same. I just ran out of time before work and needed to read up on how to split commits in rebase. I usually use mercurial rather than git. |
8d50ae2
to
63f13e2
Compare
f9138a3
to
71e3959
Compare
81b5aa5
to
af44a5c
Compare
bender run |
11329fa
to
7b03964
Compare
Looks great overall. and HIL test is passing! :D It'd be great to extend the HIL test to other chips. Ideally all chips in the HIL test farm that have FDCAN. I can give teleprobe access to anyone interested, so you can run the tests locally without having to wait for CI. Please ping me on Matrix :) Also, This is more of a general observation than a review comment but: I wonder if long-term it would be better to maintain the bxcan+fdcan drivers in-crate. There's a few negative consequences of using the bxcan/fdcan crates:
I'm just wondering long term, i'm not saying we should do in-crate CAN drivers now, it'd be a lot of work, i'm OK with these limitations for now, and |
@Dirbaio Thanks! I appreciate your time reviewing. Interesting comments on use of fdcan. This does sound like a decent bit of work. My mind is wondering about forking fdcan driver by copy-pasting it into embassy-stm32 and modify from there. Still might mean a fair bit of rework here now to get any reasonable use but do you think that is a reasonable approach? Or fork fdcan crate to make one that works better with stm32-metapac. |
I certainly followed your issues with the feature limit. Really, itas a NOOB looking in my first thought is the feature system is broken(or limited). Shouldn't it allow chip selection to use just one feature CHIP=VALUE? Why do features have to be boolean. I do wonder about the whole split thing... Longer term, I really think we need a buffered fdcan. Especially for read, dropping RX packets is really bad for most use of CAN so we really need the interrupt routine to putting things into a buffer. Often, this is a requirement for TX too. Could we have internal RX(backed by Channel or PubSubChannel) and TX(backed by Channel) buffers and just hand out senders for TX and receivers for RX? Would this do away with the need for split at all? My biggest issue is specifying the size of buffers, this would either add to features(the way arena size does) or add generic arguments. |
1f52809
to
0890049
Compare
Okay, so I have pushed updates to the PR:
|
0890049
to
021da9a
Compare
021da9a
to
2bf1d2e
Compare
Agreed that this isn't a problem to solve today but I really like this idea. The drivers for the CAN peripherals are not really that complex and this would make it easier to have a consistent API across the different hardware. |
Not to mention that the fdcan crate does not use what it can(excuse pun) from embedded hal like the ID definitions. |
I tested the code during the weekend and in general - it works. I'd not block the merge, but plan for some changes shortly. I'd assume the API not yet stable. ;) Unsure if it's worth a feature-gate. Mostly:
@@ -154,6 +157,21 @@ impl<T: Instance> interrupt::typelevel::Handler<T::IT0Interrupt> for IT0Interrup
let ir = regs.ir().read();
+ if ir.bo() {
+ /* We entered/left busoff state. This would block the awaited TX forever. Force retry. */
+ regs.ir().write(|w| w.set_bo(true));
+
+ let cccr = regs.cccr().read();
+ if cccr.init() {
+ // BusOff - so many TX errors that interface got detached.
+ regs.cccr().write(|w| w.set_init(false));
+ }
+ //return;
+ }
(...)
@@ -323,11 +343,15 @@ impl<'d, T: Instance> Fdcan<'d, T, fdcan::ConfigMode> {
can.enable_interrupt(fdcan::interrupt::Interrupt::RxFifo0NewMsg);
can.enable_interrupt(fdcan::interrupt::Interrupt::RxFifo1NewMsg);
can.enable_interrupt(fdcan::interrupt::Interrupt::TxComplete);
+ can.enable_interrupt(fdcan::interrupt::Interrupt::BusOff); This will cause the HW to wait for 129 Bus Idle states and then retry transmissions. RM0440 entry:
|
c8c162c
to
b276b94
Compare
Author: Torin Cooper-Bennun <[email protected]> Change from review.
Author: Adam Morgan <[email protected]> Break definitions out of bxcan that can be used innm fdcan. Typo
Original author: Torin Cooper-Bennun <[email protected]> Cleanup and documentaion by: Tomasz bla Fortuna <[email protected]> Corey Schuhen <[email protected]> Use new PAC method now that the names are common. Use broken out definitions that can be shared with bxcan Populate Rx struct with an embassy timestamp. Remove use of RefCell. As per review comment. - THis will probably get squashed down. Fix
Fix examples Fix examples Fix examples.
Internal loopback. fdcan: use common.rs for HIL test. Fix tests. Fix tests. Fix tests Add HIL tests for H7 even though they are a bit crippled. CI fixes Bah Test bah
b276b94
to
6e10473
Compare
These are my thoughts:
|
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.
let's merge then. Thank you everyone who helped make this happen, you're awesome ❤️ 🚀
Discussion tracked in:
#2447
This has been a group effort.