-
Notifications
You must be signed in to change notification settings - Fork 225
First attempt into rtfm, init function doubt #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can't init the PERIPHERALS resource as is, so you need to use late resources. Also, you can't take ownership of the peripherals, thus take Also, note that tasks in RTFM are not supposed to do infinite loops, it will block the lower and equal priority tasks from running. Not tested insight: const APP: () = {
static mut PERIPHERALS: stm32f103::Peripherals = ();
#[init(spawn = [task1, task2])]
fn init(c: config::Context) -> init::LateResources {
let mut p = stm32f103::Peripherals::take().unwrap()
let rcc = &mut c.resources.PERIPHERALS.RCC;
let gpioc = &mut c.resources.PERIPHERALS.GPIOC;
rcc.apb2enr.write(|w| w.iopcen().set_bit());
gpioc.crh.write(|w| unsafe{
w.mode13().bits(0b11);
w.cnf13().bits(0b00)
});
c.spawn.task1().unwrap();
c.spawn.task2().unwrap();
init::LateResources {
PERIPHERALS: p
}
}
// ...
} |
I still get the same error
I think that the problem is the init function with Context parameter.
|
ha, sure, no parameter to init in this case: fn init() -> init::LateResources {
let p = stm32f103::Peripherals::take().unwrap();
let rcc = &mut p.RCC;
let gpioc = &mut p.GPIOC;
// ...
} |
Now i get another error that i can't found in the api:
I think also that the link in description is not up to date: https://japaric.github.io/cortex-m-rtfm/book/en/ because of the link in the README.md: https://japaric.github.io/rtfm5/book/en |
Hi, you are not defining a panic handler. Use one of the ones available on crates.io: https://crates.io/keywords/panic-handler Eg, add the following to the dependencies of
and add the following statement in the app:
This should do the trick! :) |
Let's start again, what I'm trying to do is a simple led blinking with two task: one for turn on and the other for turn off. I changed the previous version thanks to the advices.
What I got from compilation is the following error due to the Context parameter in the init function:
What I've understand is that i need the Context so that the init function can spawn the task1. What I want to achieve is to have a working code that can execute to my stm32 and see the built in led blinking. |
You're using RTFM 0.4 that doesn't have the context. That's a (not yet released) 0.5 change. |
Also stm32f103xx is deprecated un favor of stm32f1. |
This was an oversight that I did due to all the attempts I made.
All the examples that I've read is with Context, what I need is a shared "shared variable" that allow me to access to the struct fields like GPIOX. How I've to modify them? I've already tried to modify What I get is something like
even if the PERIPHERALS variable is of type stm32f103::Peripheral. Edit: The following code seems to be a working version of blink application for bluepill stm32.
I still have some questions about shared resources usage, I should use the lock method before write or I'm able to write safely into the resource without worry about lock? The task can be preempted or it will end its execution without problem? |
Hi, I went through the code and fixed it up, hope it helps! Here is a complete example:
#![deny(unsafe_code)]
#![no_main]
#![no_std]
use panic_semihosting as _;
use rtfm::{app, Instant};
use stm32f1::stm32f103 as target;
const PERIOD: u32 = 2_000_000;
#[app(device = stm32f1::stm32f103)]
const APP: () = {
static mut PERIPHERALS: target::Peripherals = ();
#[init(spawn = [task1])]
fn init() -> init::LateResources {
let p = device;
let rcc = &p.RCC;
let gpioc = &p.GPIOC;
rcc.apb2enr.write(|w| w.iopcen().set_bit());
gpioc
.crh
.write(|w| w.mode13().bits(0b11).cnf13().bits(0b00));
spawn.task1().unwrap();
init::LateResources { PERIPHERALS: p }
}
#[idle]
fn idle() -> ! {
loop {}
}
#[task(schedule = [task2], resources = [PERIPHERALS])]
fn task1() {
let now = Instant::now();
let gpioc = &resources.PERIPHERALS.GPIOC;
gpioc.bsrr.write(|w| w.bs13().set_bit());
schedule.task2(now + PERIOD.cycles()).unwrap()
}
#[task(schedule = [task1], resources = [PERIPHERALS])]
fn task2() {
let now = Instant::now();
let gpioc = &resources.PERIPHERALS.GPIOC;
gpioc.brr.write(|w| w.br13().set_bit());
schedule.task1(now + PERIOD.cycles()).unwrap()
}
extern "C" {
fn TIM2();
}
}; |
Thanks for answer @korken89, my solution is pretty similar yours and is working as expected. I have a question about your solution that does not work as expected, in my opinion the problem is on the Btw i think that the problem is solved, just want figure out what what am I doing wrong. |
Can you check what the result is? |
I don't know how, I'm new in this world. If you teach me what I have to do for checking the result I will do as soon as I can. I also tried to run on qemu but it is not working. |
You can do something like this if you add let res = spawn.task1();
hprintln!("Result: {:?}", res); then the debug output should be available. |
I've modified the application to improve the debug operation, so what following will regard the code below
What I get from the debug of version 1 is:
After these two message the application stop working, no more message are printed. Instead what appened with version 2 is that:
I don't know if is this that you've requested, if more is needed let me know! Thanks for helping that you are giving to me |
I'm trying to going through the problem and get deeper in debug operation. With the version 1, the one that is not working, after the schedule of the
The code related to this freeze is the following:
I hope that this may help more than the previous comment and gives you more details about the problem! Edit |
Ah, you have unfortunately hit a common problem with embedded Rust, see the following list of things to fix during 2019 (point 12): rust-embedded/wg#269 (comment) Quite a nasty one if one does not know about it, this is why one usually does not have an idle function unless you plan to put something in the loop. |
Just to be clear, the |
Thanks, just last question: there is an official chat like gitter which I can join to due to solve future doubt? |
No problem! You can join us on Matrix at https://matrix.to/#/#rust-embedded:matrix.org |
218: CI: Add shebangs and address shellcheck warnings r=adamgreig a=jonas-schievink Co-authored-by: Jonas Schievink <[email protected]>
I have the following code:
What i get from compilation is the following error:
I don't know how to fix it, I'm reading the examples that seems to have the same syntax of mine.
For now I don't care about the correctness of the tasks
The text was updated successfully, but these errors were encountered: