Newbie Question stm32f4xx_hal


I recently started out on Rust and really enjoying letsgetrusty to boost my skills.

I do not do rust commercially but as a hobby. I use it for my embedded MCU (Not Marvel) devices

My problem is the move to embedded-hal 1.0.0. I want to move my STM32f446.

I am getting the error

^^^ the trait `SpiDevice` is not implemented for `Spi<stm32f4xx_hal::pac::SPI2>`

This used to be

    let spi: Spi<SPI2,FullDuplexMode> = Spi::new_no_cs_no_miso(

Which I do understand I need to implement this trait but it would be really useful to have a working example. I have tried googling for one but failed.


This question was quite difficult to follow. The way the code "used to be" is not really helpful. I spent far too long trying to find how Spi::new_no_cs_no_mosi is relevant to stm32f4xx-hal [1]. At the end of the day, this is a red herring.

The error message is trying to point you in the right direction, but your question does not provide any context on what the code looks like that produced that error. There is some information on embedded_hal::spi - Rust ( that is subtle and easy to miss: the difference between SpiBus and SpiDevice.

Presumably your callee wants a type that implements SpiDevice, but your caller is passing a type that implements SpiBus instead. Probably Spi in stm32f4xx_hal::spi - Rust -- but this is a best guess based only on inference from surrounding context.

Without any information about what you are calling with what types, I'm afraid at the end of my capability to provide any more assistance.

  1. It is not relevant. This constructor is part of an old version of esp-common-hal and it was removed in Improve spi master constructor by sanxus · Pull Request #901 · esp-rs/esp-hal ( ↩︎

Sorry thought stm32f4xx-hal was reasonable popular and kept my wording to a minimum.

I rhink the answer is to use

let spi: Spi<_, _> = ...;
let spi_device = ExclusiveDevice::new_no_delay(spi, cs_output_pin);

Have not tried yet as it is midnight.

Examples are far more xuseful with documentation. I struggle with just docs

In this case, implementing the spiDevice myself had me struggling with the ErrorType and ErrorKind. I am assuming my help above will show me how they achieved this

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.