diff --git a/.cargo/config b/.cargo/config index 23e96229a8f56d368fdc3feb23b64b7831a648e3..f604d34af8ed2d87835566a5ab4875654c9948d0 100644 --- a/.cargo/config +++ b/.cargo/config @@ -4,7 +4,6 @@ rustflags = [ "-C", "link-arg=-Tlink.x", "-C", "linker=arm-none-eabi-ld", "-Z", "linker-flavor=ld", - "-Z", "thinlto=no", ] [build] diff --git a/.gdbinit b/.gdbinit deleted file mode 100644 index a9dd8b4b0d9adf32965dfd6c0b01eee33ea53949..0000000000000000000000000000000000000000 --- a/.gdbinit +++ /dev/null @@ -1,16 +0,0 @@ -# target remote :3333 -# monitor reset init -# monitor arm semihosting enable - -# send captured ITM to the file /tmp/itm.log -# (the microcontroller SWO pin must be connected to the programmer SWO pin) -# 16000000 must match the core clock frequency -monitor tpiu config internal /tmp/itm.log uart off 16000000 - -# enable ITM port 0 -monitor itm port 0 on - -#load -#step -# monitor reset halt -# detach diff --git a/.vscode/launch.json b/.vscode/launch.json index 963cbbd0fcba94aa8104380b290f56085f63596f..e621fd12cc684790fb49c1546b5dfe34a08606cc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -89,21 +89,9 @@ "name": "c serial-dma-tx", "executable": "./target/thumbv7em-none-eabihf/debug/examples/serial-dma-tx", "configFiles": [ - "interface/stlink.cfg", + "interface/stlink-v2-1.cfg", "target/stm32f4x.cfg" ], - // "swoConfig": [ - // "enabled": "true", - // "swoFrequency": "0", - // "cpuFrequency": "0", - // "ports": [ - // [ - // "number": "0", - // "label": "0", - // "format": "console", - // ] - // ] - // ], "cwd": "${workspaceRoot}" }, { @@ -113,7 +101,7 @@ "name": "c rtfm-serial-dma-tx", "executable": "./target/thumbv7em-none-eabihf/debug/examples/rtfm-serial-dma-tx", "configFiles": [ - "interface/stlink.cfg", + "interface/stlink-v2-1.cfg", "target/stm32f4x.cfg" ], "cwd": "${workspaceRoot}" @@ -124,9 +112,8 @@ "servertype": "openocd", "name": "c serial-dma-rx", "executable": "./target/thumbv7em-none-eabihf/debug/examples/serial-dma-rx", - //"debugger_args": "so .gdbint", "configFiles": [ - "interface/stlink.cfg", + "interface/stlink-2-1.cfg", "target/stm32f4x.cfg" ], "cwd": "${workspaceRoot}" @@ -137,12 +124,112 @@ "servertype": "openocd", "name": "c rtfm-serial-dma-rx", "executable": "./target/thumbv7em-none-eabihf/debug/examples/rtfm-serial-dma-rx", - //"debugger_args": "so .gdbint", "configFiles": [ - "interface/stlink.cfg", + "interface/stlink-v2-1.cfg", + "target/stm32f4x.cfg" + ], + "cwd": "${workspaceRoot}" + }, + { + "type": "cortex-debug", + "request": "launch", + "servertype": "openocd", + "name": "c hello (semihosting)", + "executable": "./target/thumbv7em-none-eabihf/debug/examples/hello", + "postLaunchCommands": [ + "monitor arm semihosting enable" + ], + "configFiles": [ + "interface/stlink-v2-1.cfg", "target/stm32f4x.cfg" ], "cwd": "${workspaceRoot}" + }, + { + "type": "cortex-debug", + "request": "launch", + "servertype": "openocd", + "name": "c hello_debug (itm)", + "executable": "./target/thumbv7em-none-eabihf/debug/examples/hello_debug", + "configFiles": [ + "interface/stlink-v2-1.cfg", + "target/stm32f4x.cfg" + ], + "postLaunchCommands": [ + "monitor arm semihosting enable" + ], + "swoConfig": { + "enabled": true, + "cpuFrequency": 16000000, + "swoFrequency": 2000000, // you may try 1000000 if not working + "source": "probe", + "decoders": [ + { + "type": "console", + "label": "Name", + "port": 0 + } + ] + }, + "cwd": "${workspaceRoot}" + }, + { + "type": "cortex-debug", + "request": "launch", + "servertype": "openocd", + "name": "c rtfm-blinky-systic", + "executable": "./target/thumbv7em-none-eabihf/debug/examples/rtfm-blinky-systic", + "configFiles": [ + "interface/stlink-v2-1.cfg", + "target/stm32f4x.cfg" + ], + "postLaunchCommands": [ + "monitor arm semihosting enable" + ], + "swoConfig": { + "enabled": true, + "cpuFrequency": 16000000, + "swoFrequency": 2000000, // you may try 1000000 if not working + "source": "probe", + "decoders": [ + { + "type": "console", + "label": "Name", + "port": 0 + } + ] + }, + "cwd": "${workspaceRoot}" + }, + { + "type": "cortex-debug", + "request": "launch", + "servertype": "openocd", + "name": "c serial-echo", + "executable": "./target/thumbv7em-none-eabihf/debug/examples/serial-echo", + "configFiles": [ + "interface/stlink-v2-1.cfg", + "target/stm32f4x.cfg" + ], + // "postLaunchCommands": [ + // "monitor tpiu config internal /tmp/itm.fifo uart off 16000000", + // "monitor itm port 0 on" + // "monitor arm semihosting enable", + // ], + "swoConfig": { + "enabled": true, + "cpuFrequency": 16000000, + "swoFrequency": 2000000, // you may try 1000000 if not working + "source": "probe", + "decoders": [ + { + "type": "console", + "label": "Name", + "port": 0 + } + ] + }, + "cwd": "${workspaceRoot}" } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c711af759b0d280d0066bdf4808a0d9a58239d19..fe8d03840eff728fa8316bb2552f488e9a2efd77 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -5,8 +5,8 @@ "tasks": [ { "type": "shell", - "label": "xargo build --examples", - "command": "xargo build --examples", + "label": "cargo build --examples", + "command": "cargo build --examples", "problemMatcher": [ "$rustc" ], diff --git a/Cargo.toml b/Cargo.toml index d6beaf6274a62d2a962efa1fce53265d21813c08..d3fa82a96ea7ccf77830b339ac6a1c2192b3ded7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,25 +14,25 @@ embedded-hal = "0.1.0" nb = "0.1.0" [dependencies.stm32f413] -version = "0.2.0" +features = ["rt"] +#version = "0.2.0" git = "https://gitlab.henriktjader.com/pln/stm32f413" -branch = "svd2rust0.12" -#path = "../stm32f413" +branch = "svd2rust0.12b" [dependencies.cast] default-features = false version = "0.2.2" -[ dependencies.cortex-m-debug] +[dependencies.cortex-m-debug] git = "https://gitlab.henriktjader.com/pln/cortex-m-debug.git" version = "0.1.2" branch = "cortex-m-4" [dev-dependencies.stm32f413] features = ["rt"] -version = "0.2.0" +#version = "0.2.0" git = "https://gitlab.henriktjader.com/pln/stm32f413" -branch = "svd2rust0.12" +branch = "svd2rust0.12b" #path = "../stm32f413" [dev-dependencies.cortex-m-rt] diff --git a/Xargo.toml b/Xargo.toml deleted file mode 100644 index 89ad4cdcaeb6cce198c64fb0e03f570429243b42..0000000000000000000000000000000000000000 --- a/Xargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[dependencies.core] -stage = 0 - -[dependencies.compiler_builtins] -features = ["mem"] -stage = 1 \ No newline at end of file diff --git a/examples/serial-echo.rs b/examples/serial-echo.rs index 837ba7cb7aecb2ea856641d85bf825862566e406..94094d8384884a42b7a5448700dc81d0e8d5071e 100644 --- a/examples/serial-echo.rs +++ b/examples/serial-echo.rs @@ -1,7 +1,16 @@ //! Serial interface echo server //! //! In this example every received byte will be sent back to the sender. You can test this example -//! with serial terminal emulator like `minicom`. +//! with serial terminal emulator like `minicom` or `moserial`. +//! +//! Serial settings: +//! Baud Rate: 115200 +//! +//! Problems: +//! - Assumes processor to run at 16MHz. Beware `gdb > monitor reset init` might set +//! cpu to 64Mhz, wich gives 4 times higher Baud Rate +//! - Overflowing the serial input buffer will cause a panic. + #![deny(unsafe_code)] //#![deny(warnings)] #![no_std] @@ -10,6 +19,8 @@ extern crate stm32f4x_hal as f4; #[macro_use(block)] extern crate nb; +#[macro_use] +extern crate cortex_m_debug; use f4::prelude::*; use f4::serial::Serial; @@ -31,7 +42,15 @@ fn main() { let (mut tx, mut rx) = serial.split(); loop { - let byte = block!(rx.read()).unwrap(); - block!(tx.write(byte)).ok(); + ipln!("wait"); + //spln!("wait"); + if let Ok(byte) = block!(rx.read()) { + ipln!("got {:?}", byte); + //spln!("got {:?}", byte); + block!(tx.write(byte)).ok(); + } else { + ipln!("buffer overflow"); + //spln!("buffer overflow"); + } } } diff --git a/src/serial.rs b/src/serial.rs index a059023443762d2003231b01d1479babcc83df00..764926729c3dfe46b95f41242358ddc08464fe17 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -5,15 +5,15 @@ //! - TX = PA2 //! - RX = PA3 //! - Interrupt = USART2 -use core::sync::atomic::{self, Ordering}; -use core::ptr; -use core::marker::{PhantomData, Unsize}; use cast::u16; +use core::marker::{PhantomData, Unsize}; +use core::ptr; +use core::sync::atomic::{self, Ordering}; +use dma::{Static, Transfer, UsartRxStream, UsartTxStream, R, W}; use hal::serial; use nb; use stm32f4x::{USART1, USART2, USART6}; -use dma::{Static, Transfer, UsartRxStream, UsartTxStream, R, W}; // usart2 use gpio::gpioa::{PA2, PA3}; @@ -22,7 +22,7 @@ use gpio::gpioa::{PA2, PA3}; // use gpio::gpiod::{PD5, PD6, PD8, PD9}; // use gpio::gpioe::{PE0, PE1, PE15}; use gpio::AF7; -use rcc::{APB1, APB2, Clocks}; +use rcc::{Clocks, APB1, APB2}; use time::Bps; /// Interrupt event @@ -44,7 +44,8 @@ pub enum Error { Overrun, /// Parity check error Parity, - #[doc(hidden)] _Extensible, + #[doc(hidden)] + _Extensible, } // FIXME these should be "closed" traits @@ -216,6 +217,8 @@ macro_rules! hal { } else if isr.nf().bit_is_set() { nb::Error::Other(Error::Noise) } else if isr.ore().bit_is_set() { + // perhaps read the data so the error is cleared + unsafe { ptr::read_volatile(&(*$USARTX::ptr()).dr as *const _ as *const _);} nb::Error::Other(Error::Overrun) } else if isr.rxne().bit_is_set() { // NOTE(read_volatile) see `write_volatile` below