Giter Site home page Giter Site logo

Comments (13)

japaric avatar japaric commented on July 21, 2024 1

@osterwood I would suggest reading through RTFM book and running the QEMU examples for now. You'll need to wait until svd2rust v0.14.0 is released and the device crates in the ecosystem catch up before you can run rtfm v0.4.0 on hardware.

@geomatsi v0.4.0 is using SCB.set_priority, which should do the right thing on ARMv6-M.

from rtic.

TeXitoi avatar TeXitoi commented on July 21, 2024

Maybe just trying to use edition 2015, i.e. remove this line in Cargo.toml:

edition = "2018"

from rtic.

osterwood avatar osterwood commented on July 21, 2024

That's better! Now down to two errors (once I changed device stm32f0::stm32f0x2 to device stm32f0x2 and made the end of init a () return (instead of returning the init::LateResources struct).

error[E0308]: mismatched types                                                                                                                               
  --> examples/rtfm-one.rs:28:1                                                                                                                              
   |                                                                                                                                                         
28 | / app! {                                                                                                                                                
29 | |     device: stm32f0x2,                                                                                                                                
30 | |                                                                                                                                                       
31 | |     // Here data resources are declared                                                                                                               
...  |                                                                                                                                                       
57 | |     }                                                                                                                                                 
58 | | }                                                                                                                                                     
   | |_^ expected struct `_initLateResources`, found ()                                                                                                      
   |                                                                                                                                                         
   = note: expected type `for<'r> fn(init::Peripherals, _initResources<'r>) -> _initLateResources`                                                           
              found type `for<'r> fn(init::Peripherals, _initResources<'r>) {init}`                                                                          
                                                                                                                                                             
error[E0308]: mismatched types                                                                                                                               
  --> examples/rtfm-one.rs:28:1                                                                                                                              
   |                                                                                                                                                         
28 | / app! {                                                                                                                                                
29 | |     device: stm32f0x2,                                                                                                                                
30 | |                                                                                                                                                       
31 | |     // Here data resources are declared                                                                                                               
...  |                                                                                                                                                       
57 | |     }                                                                                                                                                 
58 | | }                                                                                                                                                     
   | |_^ expected u32, found u8                                                                                                                              
help: you can cast an `u8` to `u32`, which will zero-extend the source value                                                                                 
   |                                                                                                                                                         
28 | app! {                                                                                                                                                  
29 |     device: stm32f0x2,                                                                                                                                  
30 |                                                                                                                                                         
31 |     // Here data resources are declared                                                                                                                 
32 |     //                                                                                                                                                  
33 |     // Data resources are static variables that are safe to share across tasks                                                                          
 ...                                                                                                                                                                                                                                                                                                                
error: aborting due to 2 previous errors   

from rtic.

TeXitoi avatar TeXitoi commented on July 21, 2024

init must return LateResources, that's tthe first error.

from rtic.

TeXitoi avatar TeXitoi commented on July 21, 2024

You'll aalso need the update branch of RTFM as commented in your Cargo.toml to use cortex-m 0.5

from rtic.

osterwood avatar osterwood commented on July 21, 2024

Thank so much for the help. I had pulled the init signature from an example which didn't use LateResources and neglected to change it when I added one.

I think I'm nearly there. Now have this error about SYS_TICK

error[E0599]: no variant named `SYS_TICK` found for type `hal::stm32::Interrupt` in the current scope                                                        
  --> examples/rtfm-one.rs:27:1                                                                                                                              
   |                                                                                                                                                         
27 | app! {                                                                                                                                                  
   | ^ variant not found in `hal::stm32::Interrupt`                                                                                                          
                                                                                                                                                             
error: aborting due to previous error              

I've looked through rtfm, stm32-rs, stm32f042-hal, stm32f103xx -- and I don't see where SYS_TICK is defined. stm32f103xx now only uses them in outdated examples. Should I revert to using a hardware timer?

from rtic.

burrbull avatar burrbull commented on July 21, 2024

now is SysTick

from rtic.

geomatsi avatar geomatsi commented on July 21, 2024

After changing this name it is possible to go a bit further. Next error looks like the following:

error[E0308]: mismatched types                                                                                                                                                                             
  --> examples/rtfm-one.rs:28:1                                                                                                                                                                            
   |                                                                                                                                                                                                       
28 | app! {                                                                                                                                                                                                
   | ^ expected u32, found u8                                                                                                                                                                              
help: you can cast an `u8` to `u32`, which will zero-extend the source value                                                                                                                               
   |                                                                                                                                                                                                       
28 | a.into()pp! {                                                                                                                                                                                         
   | ^^^^^^^^                                                                                                                                                                                              
                                                                                                                                                                                                           
error: aborting due to previous error                                                                                                                                                                      
                                                                                                                                                                                                           
For more information about this error, try `rustc --explain E0308`.

On the first glance it looks like cortex-m-rtfm type issue for task priority: task priority is u8 while scb.shpr[] is [u32]. The following fix on top of PR#87 helps to go further:

diff --git a/macros/src/trans.rs b/macros/src/trans.rs
index 894abd7..08b8a90 100644
--- a/macros/src/trans.rs
+++ b/macros/src/trans.rs
@@ -366,7 +366,7 @@ fn init(app: &App, main: &mut Vec<TokenStream>, root: &mut Vec<TokenStream>) {
                 }
 
                 let nr = e.nr();
-                let priority = task.priority;
+                let priority = task.priority as u32;
                 exceptions.push(quote! {
                     let prio_bits = #device::NVIC_PRIO_BITS;
                     let hw = ((1 << prio_bits) - #priority) << (8 - prio_bits);

However something is still wrong:

error: index out of bounds: the len is 2 but the index is 11                                                                                                                                               
  --> examples/rtfm-one.rs:28:1                                                                                                                                                                            
   |                                                                                                                                                                                                       
28 | app! {                                                                                                                                                                                                
   | ^                                                                                                                                                                                                     
   |                                                                                                                                                                                                       
   = note: #[deny(const_err)] on by default                                                                                                                                                                
                                                                                                                                                                                                           
error: aborting due to previous error       

Build can be completed by adding #![allow(const_err)], but this hack is definitely wrong since that check exists somewhere in cortex-m-rtfm for reason.

from rtic.

osterwood avatar osterwood commented on July 21, 2024

Thanks so much for the additional comments and work here. I've forked ykomatsu's update branch and added your fix. I also ran into an error about a depreciated NVIC method, so changed that as well. https://github.com/osterwood/cortex-m-rtfm/tree/update

I've been trying to track down the source of the out of bounds error, and have isolated it to the use of LateResources. Defining tasks & resources builds without error. It's just when LateResources are introduced does the compile error appear.

from rtic.

geomatsi avatar geomatsi commented on July 21, 2024

Just for the record, all these issues pop up only when we try to use SysTick timer. I have several cortex-m-rtfm examples for stm32f030 and stm32f103 using TIM timers. Those examples work like a charm w/o any compilation issues with the same list of dependencies in Cargo.toml.

from rtic.

geomatsi avatar geomatsi commented on July 21, 2024

Finally, the root cause is as follows: cortex-m-rtfm calculates index for writing to scb.shpr[] in a way which is suitable for armv7, but not for armv6. The difference is clear from file src/peripheral/scb.rs from cortex-m source tree: see function set_priority

Quick hack (specific to armv6 only) which makes the app work on stm32f0 is as follows:

diff --git a/macros/src/trans.rs b/macros/src/trans.rs
index 894abd7..1f91a24 100644
--- a/macros/src/trans.rs
+++ b/macros/src/trans.rs
@@ -366,11 +366,11 @@ fn init(app: &App, main: &mut Vec<TokenStream>, root: &mut Vec<TokenStream>) {
                 }
 
                 let nr = e.nr();
-                let priority = task.priority;
+                let priority = task.priority as u32;
                 exceptions.push(quote! {
                     let prio_bits = #device::NVIC_PRIO_BITS;
                     let hw = ((1 << prio_bits) - #priority) << (8 - prio_bits);
-                    scb.shpr[#nr - 4].write(hw);
+                    scb.shpr[(#nr - 8) / 4].write(hw);
                 });
             }
             Kind::Interrupt { enabled } => {

@japaric , does it makes sense to work on a proper fix ? or this is a known issue and fix is somewhere on its way to cortex-m-rtfm/master ?

from rtic.

osterwood avatar osterwood commented on July 21, 2024

@japaric and @geomatsi Thanks for your help on this. Looks like v0.4.0 will be really nice to work with. In the meantime, I think I'll move to an armv7 MCU for my prototyping & testing.

from rtic.

japaric avatar japaric commented on July 21, 2024

I'm going to close this issue since it's about v0.3.x, which is no longer supported / maintained.

from rtic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.