Commit 3462948c authored by Per Lindgren's avatar Per Lindgren

serial-echo works

parent 5af5dcab
Pipeline #67 failed with stages
in 57 seconds
......@@ -4,7 +4,6 @@ rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "linker=arm-none-eabi-ld",
"-Z", "linker-flavor=ld",
"-Z", "thinlto=no",
]
[build]
......
# 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
......@@ -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
......@@ -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"
],
......
......@@ -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]
......
[dependencies.core]
stage = 0
[dependencies.compiler_builtins]
features = ["mem"]
stage = 1
\ No newline at end of file
//! 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");
}
}
}
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment