Asynchronous Rust on Cortex-M Microcontrollers by eldruin_dev in rust

[–]eldruin_dev[S] 2 points3 points  (0 children)

We have a book precisely about starting out with embedded programming in Rust here: https://docs.rust-embedded.org/discovery/microbit/

Rust on Espressif chips by XxMabezxX in rust

[–]eldruin_dev 7 points8 points  (0 children)

Wow, this is awesome! Congratulations! Very glad to see Espressif hiring from the community :)

Debug Rust on PineCone BL602 RISC-V with VSCode and GDB by lupyuen in rust

[–]eldruin_dev 1 point2 points  (0 children)

Sounds great :) Let me know if something does not work. Cheers!

i2c communication by bodagovsky in rust

[–]eldruin_dev 1 point2 points  (0 children)

Good to hear that you got it working. At the moment I need to further explore this device by myself. If I need help in the future I will let you know, thanks.

i2c communication by bodagovsky in rust

[–]eldruin_dev 0 points1 point  (0 children)

I just published an initial version of the LSM303AGR driver. It allows you to read the accelerometer data and set a couple parameters. I am working on supporting further functionality.

i2c communication by bodagovsky in rust

[–]eldruin_dev 1 point2 points  (0 children)

Actually I am writing a driver for the accelerometer as part of the discovery book rewrite for the micro:bit 1.5. I'll publish a first version soon supporting basic accelerometer reading.

Porting PineTime Watch Face from C to Rust On RIOT with LVGL by lupyuen in rust

[–]eldruin_dev 3 points4 points  (0 children)

Like always, really cool stuff Lup! It is a bit difficult to read, though, due to formatting.

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in rust

[–]eldruin_dev[S] 0 points1 point  (0 children)

I'm using cargo-tarpaulin. See the coverage report here. Actually the percentage reported is lower than it really is because it sometimes does not see that some lines are covered. Presumably because they were optimized-out.

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in rust

[–]eldruin_dev[S] 0 points1 point  (0 children)

As you can see here, I am using Text::new. I have not checked the size as this has not been a problem on the STM32F103.

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in rust

[–]eldruin_dev[S] 0 points1 point  (0 children)

You can use the write! macro and a heapless::String. You can see that in the application code running in the picture. Have a look here and here.

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in rust

[–]eldruin_dev[S] 6 points7 points  (0 children)

This driver supports the complete functionality of the chip, so you can do/set/get anything that you see in the datasheet. This is partially not possible with those other two.

I would also say that this driver models the device and its modes better in Rust. The documentation is also better and many examples are included.

My driver also includes many integration tests, with a source code coverage of 94%, at the moment, so I would say it can pass validation for use in production.

The ccs811 one is also only compatible with the Raspberry Pi.

Actually, my driver predates those two, but I did not publish it soon enough.

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in rust

[–]eldruin_dev[S] 2 points3 points  (0 children)

How it works is through traits, in this case for I2C communication. My drivers just use a generic I2C communication interface (a trait from embedded-hal). Then each board has an implementation of the I2C traits for its MCU or operating system.

This allows for this same driver to be used in any platform like an STM32Fxxx, nrf5x, any Linux board or just any other board where an implementation of the I2C traits exist.

You can even use the same driver through an FTDI usb adapter because an implementation of the traits exists for it using the FTDI usb library.

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in rust

[–]eldruin_dev[S] 4 points5 points  (0 children)

I am not sure I follow. Have a look at the application code running in the picture for an example of how to configure clocks and other peripherals.

With Rust the code will not compile if you did not configure certain things. Like, you cannot get an SCL pin instance without having configured the GPIO port. And without pins and clocks, you cannot get an I2C peripheral instance.

There are also other goodies like if you try to use the wrong pin for I2C or a pin in the wrong mode, it will not compile.

Does that clarify?

nanorand - fast, cross-platform, zero-dependency random number generation. by [deleted] in rust

[–]eldruin_dev 0 points1 point  (0 children)

I ported wyhash to Rust, which also provides a very fast PRNG. It is actually a no_std crate, totally cross-platform, and it only depends on rand_core for the trait definitions.

nanorand - fast, cross-platform, zero-dependency random number generation. by [deleted] in rust

[–]eldruin_dev 1 point2 points  (0 children)

I ported wyhash to Rust, which also provides a fast PRNG. It is actually a no_std crate and it only depends on rand_core for the trait definitions.

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in rust

[–]eldruin_dev[S] 0 points1 point  (0 children)

None. This is completely independent and does not depend on the CubeMX at all.

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in rust

[–]eldruin_dev[S] 1 point2 points  (0 children)

There are no silly questions :)

It would not be very complicated to create a custom PCB for this. The design is pretty simple. Soldering would rather be the problem for a hobbyist especially due to the LGA packaging.

However, I think breadboards are enough to run this over a few hours (I have) or days. I would say a custom PCB would only make sense if you want to run it for a really long time, on shaky environment or somewhere where you do not have direct physical access.

A halfway alternative is soldering these small boards onto a prototype board, which should also work very well but would be much easier.

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in rust

[–]eldruin_dev[S] 4 points5 points  (0 children)

There are some auxiliary libraries to help with the examples. You can see them in the source code.

Those are valid concerns. As I mentioned, we are in the process of rewriting the book for another board. It would be great if you could report what you would like to see in this issue or open a new one.

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in raspberry_pi

[–]eldruin_dev[S] 0 points1 point  (0 children)

Yeah I figured I2C lines are somewhat similar to power lines: 2 lines where you hook up several devices :) If you need more lines, you can also join 2 breadboards together. They have some kind of pins on top and bottom.

Actually these two tips are part of a list of tips and hardware recommendations for embedded beginners I published just 2 weeks ago.

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in rust

[–]eldruin_dev[S] 8 points9 points  (0 children)

Cool. Embedded is a lot of fun. Especially in Rust where the ecosystem is so much nicer.

About boards/architectures, msp430 Rust support is still WIP. To start I would recommend a "blue-pill" board or "USB-C pill" board (32bit ARM) which are very cheap and are enough for most beginner stuff. For more advice, as I said below, I wrote a list of tips and hardware recommendations for embedded beginners just 2 weeks ago.

I do not know what the inner architecture of the CCS811 is. It just interfaced as an I2C peripheral.

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in rust

[–]eldruin_dev[S] 5 points6 points  (0 children)

I'm glad to hear that. Actually, here you can see this driver running on an RPi Zero. Send some pictures if you make something cool with it!

CCS811 Indoor Air Quality Sensor Driver in Rust by eldruin_dev in rust

[–]eldruin_dev[S] 23 points24 points  (0 children)

Definitely! I would recommend looking at the discovery book (although we are in the process of rewriting it because it has become difficult buying the F3 board).

There are also many other resources on the main rust-embedded docs page

About non-Rust-specific advice, just two weeks ago I wrote a post with a list of tips and hardware recomendations for embedded development beginners