Open-Agriculture / AgIsoStack-rs

A Rust implementation of the ISO11783 (ISOBUS) & J1939 protocols
MIT License
24 stars 4 forks source link

embedded_can Driver and no_std support #39

Open pbert519 opened 1 year ago

pbert519 commented 1 year ago

Is it planned to support no_std, too? If yes, we should probably add the no_std flag as soon as possible, before to much std code is in place.

The embedded-can trait already provides a can driver abstraction and has some implementations, e.g. for socketcan and microcontrollers, like stm32 and similar, see https://crates.io/crates/embedded-can

I would be open to contributing a implementation if no_std is in scope for this project.

For the basics j1939, i created a very work in progress j1939 library in no_std rust. https://github.com/pbert519/j1939 Maybe some parts are reusable.

Notgnoshi commented 1 year ago

I had a conversation with @ad3154 about this before we started the project. One of my goals was to enable switching to rust for embedded micro ECUs within our organization.

We chose not to start with this goal in mind because:

While I want to have no_std support in the future, I think it introduces some pretty large design constraints.


I have a few questions / notes:

pbert519 commented 1 year ago

Thank you for your detailed answer!

Concerning your remarks: embedded_can: The embedded_can is not widely used or final/stabilized yes, but it is very similar to the currently used abstraction by this project. And the abstraction is already maintained by the embedded rust working group. It would be beneficial for the ecosystem to use them and use existing drivers / upstream newly created can drivers instead of creating an new abstraction on the same level.

On the other hand with linux as target, since windows will not be in many production systems, it might be easier to directly use the j1939 abstraction of the linux kernel. No need to have an abstraction on CAN frame level.

no_std vs std : The main difference between no_std with alloc and std is mostly os services like time or file handling. File handling can probably be optional, e.g. Pools can be included in the binary with include_bytes!. But for time, e.g timeout handling, an abstraction would be necessary. An other import point is error handling, there is currently no std::error::Error equivalent in the core library. Besides that, no_std needs some attention on a lower memory footprint (code size and heap allocation).

If the Isobus functionality is split into multiple crates, higher level crates like file-server could be std again.

JannesBrands commented 1 year ago

From the beginning I always had the intention of a no_std variant for well-known reasons. In the meantime I've gotten more familiar with Rust and have come to the same conclusion as @Notgnoshi that this would significantly change the approach, structure and design of the project and especially with the current resources we have available would be too much to achieve progress as soon as possible. Additionally due to the fact (including myself) that many are not yet 100% familiar with Rust and this would generally slow down progress.

I had read through some information on how to use std on certain embedded systems. Of course, these also have very specific and different options, so that some support std alloc and others do not. Same with the file system. Here is an interesting article: blog article

I'll have a look at the embedded-can crate, but I agree that we should reuse official/renowned projects.

JannesBrands commented 10 months ago

44 first implementation of embedded-can (not done yet)