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

Hardware CRC #17

Closed
dbrgn opened this issue Mar 5, 2020 · 2 comments
Closed

Hardware CRC #17

dbrgn opened this issue Mar 5, 2020 · 2 comments

Comments

@dbrgn
Copy link
Owner

dbrgn commented Mar 5, 2020

Many STM32 MCUs (including the STM32L071) feature a hardware CRC implementation.

As an optimization, it would be nice if the default CRC software-implementation could be swapped with a custom implementation that may be faster.

This could be done using a trait:

public trait Crc {
    fn crc8(data: &[u8]) -> u8;
}

The driver struct would then be parametrized:

pub struct ShtCx<S: ShtSensor, I2C, C: Crc, D> {
    crc: C,
    ...
}

The simplest way to pass in the concrete implementation would be if the default factory functions (like shtc3) use the default implementation, but the ShtCx struct would allow swapping the implementation:

impl ShtCx<S: ShtSensor, I2C, C: Crc, D> {
    pub fn use_crc<CRC: Crc>(crc: CRC) -> Self<S, I2C, CRC, D> {
        self.crc = crc;
        self
    }
}

However, I'm not sure if the software implementation can be optimized out by the compiler or not. Probably not. Maybe a builder would be better.

What do you think, @rnestler?

@rnestler
Copy link
Collaborator

I'm not really sure if it is worth it to use hardware CRC if one just calculates the CRC of two bytes. I guess setting up the hardware CRC is overhead as well, but I may be wrong.
IMHO the hardware CRC is useful if one wants to calculate the CRC over some larger data in the flash.

@dbrgn
Copy link
Owner Author

dbrgn commented May 27, 2020

Let's close this for now, it's probably overkill for those few bytes.

@dbrgn dbrgn closed this as completed May 27, 2020
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

No branches or pull requests

2 participants