japaric / stm32f103xx-hal

HAL for the STM32F103xx family of microcontrollers
Apache License 2.0
115 stars 40 forks source link

Update for 1.30 beta/stable #95

Closed TeXitoi closed 5 years ago

TeXitoi commented 5 years ago

This PR make stm32f103xx-hal compile on the 1.30 beta (and hopefully 1.30 stable).

There is 3 changes:

Removing the unsize feature might decrease a bit the ergonomics. Now, if you want a buffer bigger that 32, you'll have to define a new type like that:

struct MyBuf([u8; 256]);
impl AsMut<[u8]> for MyBuf {
    fn as_mut(&mut self) -> &mut [u8] {
        &mut self.0
    }
}

@japaric OK?

TheZoq2 commented 5 years ago

I'd love to see this merged. Getting away from nightly would be lovely

TeXitoi commented 5 years ago

@therealprof This PR is quite simple and very important, can you review it?

therealprof commented 5 years ago

The examples don't work on beta due to heapless using the untagged-option crate which used #![feature(untagged_unions)] and #![feature(const_fn)].

The examples also don't compile on nightly due to duplicate symbols from the peripheral registers crate and cortex-m-rt:

  = note: rust-lld: error: duplicate symbol: __INTERRUPTS
          >>> defined at lib.rs:87 (/Users/egger/.cargo/registry/src/github.com-1ecc6299db9ec823/stm32f103xx-0.10.0/src/lib.rs:87)
          >>>            stm32f103xx-7d9cd6af6527a398.stm32f103xx.esssrri0-cgu.0.rcgu.o:(__INTERRUPTS) in archive /Users/egger/OSS/stm32f103xx-hal/target/thumbv7m-none-eabi/release/deps/libstm32f103xx-7d9cd6af6527a398.rlib
          >>> defined at lib.rs:681 (/Users/egger/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.4/src/lib.rs:681)
          >>>            cortex_m_rt-b8e2a191e50e0307.cortex_m_rt.9i15wgpy-cgu.0.rcgu.o:(.vector_table.interrupts+0x0) in archive /Users/egger/OSS/stm32f103xx-hal/target/thumbv7m-none-eabi/release/deps/libcortex_m_rt-b8e2a191e50e0307.rlib
therealprof commented 5 years ago

I got it almost to work by using @adamgreig's stm32f1 crate instead of the stm32f103xx however that would require patching or adapting to line up with @japaric's customisations, probably both. Oh and also some juggling of unsafes...

If people agree we (especially @japaric) we could go with that (that being replacing the use of stm32f103xx by stm32f1)...

TeXitoi commented 5 years ago

I'll check for nightly. For the examples on beta, that's not needed to compile a working example.

therealprof commented 5 years ago

@TeXitoi

For the examples on beta, that's not needed to compile a working example.

How come? If you can't compile the dev-dependencies you can't compile any of the included examples.

TeXitoi commented 5 years ago

https://github.com/TeXitoi/blue-pill-quickstart is working on beta

TeXitoi commented 5 years ago

You don't need to build the dev deps to use the crate

therealprof commented 5 years ago

You don't need to build the dev deps to use the crate

True, but at the very least I expect the examples to be no less working after changes.

TeXitoi commented 5 years ago

To compile the examples on beta, I will need to remove some. I can do that.

TeXitoi commented 5 years ago

Let's talk about the future of this crate (changing the device crate, stm32f1-hal...) In a dedicated issue.

therealprof commented 5 years ago

@TeXitoi Let's just move them, because they'll still compile with nightly just fine.

therealprof commented 5 years ago

I'm curious how you have solved the linking problem without recreating the peripheral registers crate.

TeXitoi commented 5 years ago

I did compile the examples on nightly, so I don't know why it's not working for you. Maybe you need a cargo update to update cortex-m-rt 0.5 with the semver trick?

TeXitoi commented 5 years ago

If it solve your problem, I need to update the cortex-m-rt in Cargo.toml

TeXitoi commented 5 years ago
$ cargo +nightly build --examples --release
    Finished release [optimized + debuginfo] target(s) in 0.08s

But I can't really require a cortex-m-rt>=0.5.7 as it's a indirect deps. You have any idea?

therealprof commented 5 years ago

But I can't really require a cortex-m-rt>=0.5.7 as it's a indirect deps. You have any idea?

Patch section.

TeXitoi commented 5 years ago
[patch.crates-io]
cortex-m-rt = "0.5.7"
$ cargo update
    Updating crates.io index
error: failed to resolve patches for `https://github.com/rust-lang/crates.io-index`                      

Caused by:
  patch for `cortex-m-rt` in `https://github.com/rust-lang/crates.io-index` points to the same source, but patches must point to different sources
therealprof commented 5 years ago
[patch.crates-io]
cortex-m-rt = "0.5.7"

You said some indirect crate needs a different version so you'll have to patch the version of the crate using the wrong version.

TeXitoi commented 5 years ago

A cargo update should fix the problem. The problem is that stm32f103xx depends on cortex-m-rt>=0.5, stm32f103xx-hal depends on cortex-m-rt>=0.6 that is compatible with cortex-m-rt>=0.5.7. Thus, I'd like to say "I need cortex-m-rt>=0.5.7 in my deps" to force 0.5.7 if a user have a cortex-m-rt<0.5.7 in its Cargo.lock.

TeXitoi commented 5 years ago
diff --git a/Cargo.toml b/Cargo.toml
index 22a6ab5..87f0fc1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,3 +1,5 @@
+cargo-features = ["rename-dependency"]
+
 [package]
 authors = ["Jorge Aparicio <jorge@japaric.io>"]
 categories = ["embedded", "hardware-support", "no-std"]
@@ -13,6 +15,7 @@ cortex-m = "0.5.7"
 nb = "0.1.1"
 stm32f103xx = "0.10.0"
 cortex-m-rt = "0.6.3"
+unused-cortex-m-rt = { version = "0.5.7", package = "cortex-m-rt" }

 [dependencies.void]
 default-features = false

is working, but only on nightly...

therealprof commented 5 years ago

Hm, weird. I just updated to the latest nightly and now it builds just fine without linker problems. Wonder what that was.

therealprof commented 5 years ago

Let's get this in then so we have a stable base for further work.

TeXitoi commented 5 years ago

A cargo update should fix your problem. I reproduced your problem by s/cortex-m-rt = "0.5.7"/cortex-m-rt = "0.5.4"/ in Cargo.lock