summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2017-08-29 11:00:19 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2017-08-29 11:00:19 +0100
commitf556ae20ecab3c57a19ea9094400128bff7a77c4 (patch)
tree447a288fdc671ada2e9cdb871197e39de59299d6
parent6223c8619e6782552975c380efb147377942713e (diff)
downloadstm32-usb-example-f556ae20ecab3c57a19ea9094400128bff7a77c4.tar.bz2
Initial bits
-rw-r--r--.cargo/config10
-rw-r--r--.gitignore2
-rw-r--r--Cargo.lock282
-rw-r--r--Cargo.toml41
-rw-r--r--Xargo.toml6
-rw-r--r--build.rs17
-rw-r--r--memory.x5
-rw-r--r--src/main.rs47
8 files changed, 410 insertions, 0 deletions
diff --git a/.cargo/config b/.cargo/config
new file mode 100644
index 0000000..6f29034
--- /dev/null
+++ b/.cargo/config
@@ -0,0 +1,10 @@
+[target.thumbv7m-none-eabi]
+runner = 'arm-none-eabi-gdb'
+rustflags = [
+ "-C", "link-arg=-Tlink.x",
+ "-C", "linker=arm-none-eabi-ld",
+ "-Z", "linker-flavor=ld",
+]
+
+[build]
+target = "thumbv7m-none-eabi"
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7aef303
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+target
+*~
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..9eeedc9
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,282 @@
+[root]
+name = "stm32-usb-example"
+version = "0.0.0"
+dependencies = [
+ "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cortex-m-rt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cortex-m-rtfm 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cortex-m-semihosting 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "embedded-hal 0.1.0 (git+https://github.com/japaric/embedded-hal?rev=5295697669f5b48a900aa325b8ebb4d4e8d4b236)",
+ "nb 0.1.0 (git+https://github.com/japaric/nb)",
+ "static-ref 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "stm32f103xx 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "aligned"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "backtrace"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "backtrace-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "backtrace-sys"
+version = "0.1.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "bare-metal"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "cast"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "cfg-if"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "cortex-m"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "aligned 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bare-metal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "cortex-m-rt"
+version = "0.3.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "cortex-m-rtfm"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cortex-m-rtfm-macros 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rtfm-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "static-ref 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "cortex-m-rtfm-macros"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rtfm-syntax 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "cortex-m-semihosting"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "dbghelp-sys"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "embedded-hal"
+version = "0.1.0"
+source = "git+https://github.com/japaric/embedded-hal?rev=5295697669f5b48a900aa325b8ebb4d4e8d4b236#5295697669f5b48a900aa325b8ebb4d4e8d4b236"
+dependencies = [
+ "nb 0.1.0 (git+https://github.com/japaric/nb)",
+]
+
+[[package]]
+name = "error-chain"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "backtrace 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "gcc"
+version = "0.3.53"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "kernel32-sys"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.30"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "nb"
+version = "0.1.0"
+source = "git+https://github.com/japaric/nb#4696bd09c24014c5220ee360383cbdb2bffba002"
+
+[[package]]
+name = "quote"
+version = "0.3.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "r0"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "rtfm-core"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "static-ref 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rtfm-syntax"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "rustc-demangle"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "static-ref"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "stm32f103xx"
+version = "0.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bare-metal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cortex-m-rt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "syn"
+version = "0.11.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
+ "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "synom"
+version = "0.11.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "unicode-xid"
+version = "0.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "vcell"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "volatile-register"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "winapi"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi-build"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[metadata]
+"checksum aligned 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a92995cea48691c7c93e12597cca4d692bb3130d0a291c7141b9793c7829e7"
+"checksum backtrace 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "72f9b4182546f4b04ebc4ab7f84948953a118bd6021a1b6a6c909e3e94f6be76"
+"checksum backtrace-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "afccc5772ba333abccdf60d55200fa3406f8c59dcf54d5f7998c9107d3799c7c"
+"checksum bare-metal 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "19de0ac42f6977d7428858b750131ea9c8166f4ccb7deeab38b6a8656c9798b0"
+"checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427"
+"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
+"checksum cortex-m 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4d553ca1f23403c81e6d3d28a64ef6e8eadd7f395195aacda65cbc0dc987738e"
+"checksum cortex-m-rt 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ec28308ef272803380c9c4e6708bf1d794ddcc8c9d511b9976b31ac3322452e5"
+"checksum cortex-m-rtfm 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c76aeaf8a6daf3cac1445d5c37994fe80c866a8de165ba5f313380106230284"
+"checksum cortex-m-rtfm-macros 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a03563af7ed064a7d8c13c8de76a75a7a24514b639796b88f41bb33a899fa84b"
+"checksum cortex-m-semihosting 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4a7a324a8c184dcd3d6bd44cb4f6f85c158de15a2a8e7cd7f550909213ce3de8"
+"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850"
+"checksum embedded-hal 0.1.0 (git+https://github.com/japaric/embedded-hal?rev=5295697669f5b48a900aa325b8ebb4d4e8d4b236)" = "<none>"
+"checksum error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8"
+"checksum gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)" = "e8310f7e9c890398b0e80e301c4f474e9918d2b27fca8f48486ca775fa9ffc5a"
+"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
+"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915"
+"checksum nb 0.1.0 (git+https://github.com/japaric/nb)" = "<none>"
+"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
+"checksum r0 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f"
+"checksum rtfm-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a7b637764fcf0ed497ea324a494814ad9934ab7ca92826a72d42196b8cfbc9d"
+"checksum rtfm-syntax 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "36d5a5933883d513878ad090235b43c7744b52274c83ad0ef35e2df873cb7cbb"
+"checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e"
+"checksum static-ref 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "993fc46a615b7f80fd55f5f3a45b3c5c3a3c479c5906d92a4cf33e1ed53d424a"
+"checksum stm32f103xx 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "98727cd15ae4bc62ccab98bb70bf40d0efcedffebe06788162f68351a008d0ba"
+"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
+"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
+"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
+"checksum vcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45c297f0afb6928cd08ab1ff9d95e99392595ea25ae1b5ecf822ff8764e57a0d"
+"checksum volatile-register 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286"
+"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
+"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..31f9474
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,41 @@
+[package]
+name = "stm32-usb-example"
+version = "0.0.0"
+authors = ["Daniel Silverstone <dsilvers@digital-scurf.org>"]
+description = "An example of using STM32 USB device mode"
+keywords = ["arm", "cortex-m", "stm32", "usb"]
+categories = ["embedded", "no-std"]
+license = "BSD"
+#repository = "https://github.com/japaric/cortex-m-quickstart"
+
+[profile.release]
+lto = true
+debug = true
+
+[dependencies]
+static-ref = "0.2.0"
+volatile-register = "0.2.0"
+
+[dependencies.cast]
+default-features = false
+version = "0.2.2"
+
+[dependencies.embedded-hal]
+git = "https://github.com/japaric/embedded-hal"
+rev = "5295697669f5b48a900aa325b8ebb4d4e8d4b236"
+
+[dependencies.nb]
+git = "https://github.com/japaric/nb"
+
+[dependencies.stm32f103xx]
+features = ["rt"]
+version = "0.7.2"
+
+[dev-dependencies]
+cortex-m = "0.3.0"
+cortex-m-rtfm = "0.2.0"
+cortex-m-semihosting = "0.2.0"
+
+[dev-dependencies.cortex-m-rt]
+features = ["abort-on-panic"]
+version = "0.3.5"
diff --git a/Xargo.toml b/Xargo.toml
new file mode 100644
index 0000000..89ad4cd
--- /dev/null
+++ b/Xargo.toml
@@ -0,0 +1,6 @@
+[dependencies.core]
+stage = 0
+
+[dependencies.compiler_builtins]
+features = ["mem"]
+stage = 1 \ No newline at end of file
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..88f7fef
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,17 @@
+use std::env;
+use std::fs::File;
+use std::io::Write;
+use std::path::PathBuf;
+
+fn main() {
+ // Put the linker script somewhere the linker can find it
+ let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
+ File::create(out.join("memory.x"))
+ .unwrap()
+ .write_all(include_bytes!("memory.x"))
+ .unwrap();
+ println!("cargo:rustc-link-search={}", out.display());
+
+ println!("cargo:rerun-if-changed=build.rs");
+ println!("cargo:rerun-if-changed=memory.x");
+}
diff --git a/memory.x b/memory.x
new file mode 100644
index 0000000..59195b8
--- /dev/null
+++ b/memory.x
@@ -0,0 +1,5 @@
+MEMORY
+{
+ FLASH : ORIGIN = 0x08000000, LENGTH = 64K
+ RAM : ORIGIN = 0x20000000, LENGTH = 20K
+}
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..f9a2f6f
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,47 @@
+//! Example USB Device stack client code
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![feature(proc_macro)]
+#![no_std]
+
+extern crate stm32f103xx;
+extern crate cortex_m;
+extern crate cortex_m_rtfm as rtfm;
+
+use cortex_m::peripheral::SystClkSource;
+use rtfm::{app, Threshold};
+
+app! {
+ device: stm32f103xx,
+
+ resources: {
+ static ON: bool = false;
+ },
+
+ tasks: {
+ SYS_TICK: {
+ path: toggle,
+ resources: [ON],
+ },
+ },
+}
+
+fn init(p: init::Peripherals, _r: init::Resources) {
+ p.SYST.set_clock_source(SystClkSource::Core);
+ p.SYST.set_reload(8_000_000); // 1s
+ p.SYST.enable_interrupt();
+ p.SYST.enable_counter();
+}
+
+fn idle() -> ! {
+ // Sleep
+ loop {
+ rtfm::wfi();
+ }
+}
+
+// TASKS
+fn toggle(_t: &mut Threshold, r: SYS_TICK::Resources) {
+ **r.ON = !**r.ON;
+
+}