Learning embedded rust book examples?

Hi,
I'm exploring the use of rust in embedded applications and am in the process of going through the suggested on-line book at rust-embedded.github.io/book. In section 2.3 Memory-mapped Registers, Using Peripheral Access Crate (PAC) there is example code which produces a compile error on the #[entry] attribute. The code is:

#[entry]
pub fn init() -> (Delay, Leds) {
let cp = cortex_m::Peripherals::take().unwrap();
let p = tm4c123x::Peripherals::take().unwrap();
...
the error message complains that the function should be marked unsafe and worse its signature should look like "[unsafe] fn() -> ! "to satisfy the rust compiler.

My question is, am I totally missing something in my understanding or was this example created at a time the the function definitions used was correct but is now incorrect? If it is the latter how many other example code inserts are out-of-date in this book?

I'm using version 1.40 of rustc, am using Visual Studio Code as my IDE, and am on a current version of Arch Linux.

Bob Stewart

before that unsafe thing, are you sure the entry can accept params? i'm not.

Thank you for the reply.

I’m not either, but I’m just learning. And, that is straight from the book example which I expected to be correct. Not only does it have parameters passed in it has no “!” as the compiler complained about, and according to what I’m learning
[entries] do not return.

Thanks,

Bob Stewart

Could you please show your full source code? And the full error message
Please format it in your message using
```
Your Code
```

This will then be shown as:

Your Code

For me it seems strange, that the entry function has a return type, normally you never return from the entry function (-> ! ) in embedded development.

Based on the documentation for cortex_m_rt::entry, the signature should be [unsafe] fn() -> !, so it seems the embedded book is incorrect/outdated in this case. Probably the best way to proceed is creating an issue at the repository for the embedded book.

If I understand correctly, the question is about this example.

Thank you for the reply.

It seems that it is pretty out-of-date a couple of other examples I tried have compile errors.

But that particular example was pretty badly constructed and I don’t think it would ever have worked. I’ll create an issue for that one, but I’ll find another tutorial source for embedded rust.

Thanks,

Bob Stewart

The code is in the embedded rust book reference I cited. Try it yourself. It will never compile.

Bob Stewart

That is the example.

Bob Stewart