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

Swap to bxCan crate #207

Merged
merged 13 commits into from
Jul 2, 2021
Merged

Swap to bxCan crate #207

merged 13 commits into from
Jul 2, 2021

Conversation

zklapow
Copy link
Contributor

@zklapow zklapow commented Mar 7, 2021

I said I wasn't gonna have time for this, but it turns out this was a lot easier than I realized.

Currently (as before) we only support pin defs for the 302/303, but it should be trivial to add more when thats desired.

@zklapow
Copy link
Contributor Author

zklapow commented Mar 7, 2021

Also note: this is definitely a breaking change. I don't think thats a huge deal given that can was behind a feature flag anyhow and was fairly experimental.

@Sh3Rm4n
Copy link
Member

Sh3Rm4n commented Mar 9, 2021

Also note: this is definitely a breaking change. I don't think thats a huge deal given that can was behind a feature flag anyhow and was fairly experimental.

No worries. Breaking changes for now are just important to note in the changelog. Bumping the version number is not a big deal. :)

@pdgilbert
Copy link

Could you please change the version requirement to ">=0.4" or ">=0.4, <0.6" for reasons described at stm32-rs/stm32f7xx-hal#114 (comment). Discussion also available at stm32-rs/stm32f4xx-hal#285.

@zklapow zklapow force-pushed the zklapow-bxcan branch 2 times, most recently from a062975 to 64856ee Compare May 5, 2021 01:43
@zklapow
Copy link
Contributor Author

zklapow commented May 5, 2021

Apologies (as usual) it took me a bit to get back to this. Should be up to date with master now with the bxcan version issue fixed, and ready for another look (or merging).

Copy link
Member

@Sh3Rm4n Sh3Rm4n left a comment

Choose a reason for hiding this comment

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

Thanks again for your effort and no worries if it takes some time :)

src/can.rs Outdated Show resolved Hide resolved
filters.enable_bank(0, Mask32::accept_all());

// Enable filters.
drop(filters);
Copy link
Member

Choose a reason for hiding this comment

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

This seems confusing. Has the Drop trait the site effect of applying the filter?

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see, filter holds a mutual reference to can, so can can not be used later, as long as the reference is held. Is this correct? And does it still compile without this drop?

Comment on lines -400 to -410
/// Release owned peripherals
pub fn free(
self,
) -> (
pac::CAN,
gpioa::PA11<AF9<PushPull>>,
gpioa::PA12<AF9<PushPull>>,
) {
(self.can, self._rx, self._tx)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Hm. I see, the bxcan crate does consume this peripheral and is not able to free it. But I would still keep this function and submit a PR to the bxcan crate, that it also supports freeing the peripheral again.

Copy link
Member

@Sh3Rm4n Sh3Rm4n May 25, 2021

Choose a reason for hiding this comment

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

bxcan 0.5.1 now has a Can::free method, so we can use it here. So bxcan instance would return fn free(bxcan::Can<Self>) -> Self, where Self itself implements pub fn free(self) -> (pac::CAN, gpioa::PA11<...>, gpioa::PA12 <...>).

This would mean, we have to call free twice to get back the gpios: let (can, pa11, pa12) = can.free().free(); but I think, it is not too bad.

src/can.rs Outdated
Comment on lines 61 to 64
pub struct Can<TX, RX> {
_can: pac::CAN,
_tx: TX,
_rx: RX,
Copy link
Member

Choose a reason for hiding this comment

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

When the free() method is implemented, the underscore should'nt be necessary anymore:

Suggested change
pub struct Can<TX, RX> {
_can: pac::CAN,
_tx: TX,
_rx: RX,
pub struct Can<TX, RX> {
can: pac::CAN,
tx: TX,
rx: RX,

// APB1 (PCLK1): 64MHz, Bit rate: 500kBit/s, Sample Point 87.5%
// Value was calculated with http://www.bittiming.can-wiki.info/
can.modify_config()
.set_bit_timing(0x001c_0003)
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit: Could you give this magic value a name? I see, that your comment explains the reason for this value, but I (as someone who has not really looked into can) do not fully grasp the meaning of each single bit.

src/can.rs Show resolved Hide resolved
examples/can.rs Outdated
@@ -13,7 +13,9 @@ use hal::pac;
use hal::prelude::*;
use hal::watchdog::IndependentWatchDog;

use hal::can::{Can, CanFilter, CanFrame, CanId, Filter, Frame, Receiver, Transmitter};
use bxcan::filter::Mask32;
use bxcan::{Frame, StandardId};
Copy link
Member

Choose a reason for hiding this comment

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

Could be

Suggested change
use bxcan::{Frame, StandardId};
use can::bxcan::{Frame, StandardId};

if we would reexport the can module. (See other comment)

@Piroro-hs
Copy link
Contributor

How about returning bxcan::Can directly from constructor?

@Sh3Rm4n Sh3Rm4n self-requested a review June 19, 2021 17:03
This was referenced Jun 19, 2021
@Sh3Rm4n
Copy link
Member

Sh3Rm4n commented Jul 2, 2021

I've added a free method and changed some minor nits and rebased it onto current master.

Thanks for your contribution! :)

@Sh3Rm4n Sh3Rm4n enabled auto-merge (rebase) July 2, 2021 16:22
@Sh3Rm4n Sh3Rm4n merged commit 3d3a38e into stm32-rs:master Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants