David-OConnor / stm32-hal

This library provides access to STM32 peripherals in Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filtered IMU example code discrepancies(?)

762SPR opened this issue · comments

Hello, Thank you for this great HAL! I find it much more intuitive than the embedded-HAL based HALs.
I am writing a program for the L432 that uses RTIC, SPI, and DMA to read from a sensor so I have been referencing your filtered IMU example and have come across a couple places that the code needs to be tweaked to compile. Not sure if this is actually an issue or if it is more of a versioning or issue specific to the L4 chips, but I figured I would bring it up just in case!

First is with the clock config:

let clock_cfg = Default::default();

I have found this needs to be:
let clock_cfg = Clocks::default();

Next, clearing the DMA interrupt:

dma.clear_interrupt(DmaInterrupt::TransferComplete);

Needs a channel input. I think this may be an L4 thing, since they handle channels/streams a little different...
dma.clear_interrupt(DmaChannel::C2, DmaInterrupt::TransferComplete);

And finally, the DMA import seems to be missing. Easy fix with rust analyzer but just letting you know :)

use stm32_hal2::{gpio::Pin, pac::SPI1, spi::Spi};

spi::Spi, dma::{Dma, DmaChannel, DmaInterrupt, ChannelCfg, Priority, Circular, IncrMode}
(I have some extras in here because I am setting up configurations for each channel vs. using the defaults.

Again, thank you so much for the work you have put into this!

I forget the initial error when I tried it, I just put a note in the code that it had to be changed. However, I just new tried to change it back and it gave me an error on the next line at
clock_cfg.setup().unwrap();
That: "type annotations needed type must be known at this point"

So that may have been why I changed it. Of course forcing the type with
let clock_cfg: Clocks = Default::default();
made that go away. Perhaps it is just an IDE discrepancy, I am using VSCodium with Rust Analyzer, maybe your setup can figure it out easier than RA?

All these are pretty trivial anyway and probably addressed by more experienced users without a second thought but as a beginner it took me a little bit to work through them. Hopefully the next newbie will have a better time of it!

Closing as completed. LMK if you learn any more on the Default:: vs Clocks::