Skip to content
Snippets Groups Projects
Commit 82a7c7f1 authored by Per Lindgren's avatar Per Lindgren
Browse files

usart3

parent bc42009c
No related branches found
No related tags found
No related merge requests found
......@@ -793,5 +793,89 @@
"svdFile": "STM32F413.svd",
"cwd": "${workspaceRoot}"
},
{
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"name": "usb (debug)",
"preLaunchTask": "cargo build --example usb",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/usb",
// uses local config files
"configFiles": [
"./stlink.cfg",
"./stm32f4x.cfg"
],
"swoConfig": {
"enabled": true,
"cpuFrequency": 16000000,
"swoFrequency": 2000000,
"source": "probe",
"decoders": [
{
"type": "console",
"label": "ITM",
"port": 0
}
]
},
"svdFile": "STM32F413.svd",
"cwd": "${workspaceRoot}"
},
{
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"name": "usart3 (release)",
"preLaunchTask": "cargo build --example usart3 --release",
"executable": "./target/thumbv7em-none-eabihf/release/examples/usart3",
// uses local config files
"configFiles": [
"./stlink.cfg",
"./stm32f4x.cfg"
],
"swoConfig": {
"enabled": true,
"cpuFrequency": 16000000,
"swoFrequency": 2000000,
"source": "probe",
"decoders": [
{
"type": "console",
"label": "ITM",
"port": 0
}
]
},
"svdFile": "STM32F413.svd",
"cwd": "${workspaceRoot}"
},
{
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"name": "usart3 (debug)",
"preLaunchTask": "cargo build --example usart3",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/usart3",
// uses local config files
"configFiles": [
"./stlink.cfg",
"./stm32f4x.cfg"
],
"swoConfig": {
"enabled": true,
"cpuFrequency": 16000000,
"swoFrequency": 2000000,
"source": "probe",
"decoders": [
{
"type": "console",
"label": "ITM",
"port": 0
}
]
},
"svdFile": "STM32F413.svd",
"cwd": "${workspaceRoot}"
},
]
}
\ No newline at end of file
......@@ -339,5 +339,41 @@
"isDefault": true
}
},
{
"type": "shell",
"label": "cargo build --example usb",
"command": "cargo build --example usb --features hal",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "cargo build --example usart3 --release",
"command": "cargo build --example usart3 --release --features hal",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "cargo build --example usart3",
"command": "cargo build --example usart3 --features hal",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
]
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ version = "0.1.0"
[patch.crates-io]
stm32f4xx-hal = { path = "../stm32f4xx-hal" }
# stm32fxx-hal = {git = "https://github.com/stm32-rs/stm32f4xx-hal.git" }
# # stm32fxx-hal = {git = "https://github.com/stm32-rs/stm32f4xx-hal.git" }
[dependencies]
cortex-m-rt = "0.6.7"
......
//! Serial echo
//!
//! Connect using e.g., `moserial` to `/dev/ttyACM0`
//! 115200 8N1
//!
//! The MCU will echo incoming data and send a trace over ITM.
//! Notice, as the hardware has a single byte buffer only, the input
//! buffer may overflow.
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
extern crate panic_halt;
use cortex_m_rt::entry;
use nb::block;
extern crate stm32f4xx_hal as hal;
use crate::hal::prelude::*;
use crate::hal::serial::{config::Config, Serial};
use cortex_m::iprintln;
#[entry]
fn main() -> ! {
let mut c = hal::stm32::CorePeripherals::take().unwrap();
let stim = &mut c.ITM.stim[0];
iprintln!(stim, "usb");
let p = hal::stm32::Peripherals::take().unwrap();
// let mut flash = p.FLASH.constrain();
let rcc = p.RCC.constrain();
//let gpioa = p.GPIOA.split();
let gpiod = p.GPIOD.split();
// let clocks = rcc.cfgr.freeze(&mut flash.acr);
// let clocks = rcc.cfgr.freeze();
let clocks = rcc.cfgr.freeze();
iprintln!(stim, "after freeze");
// let hclk: i32 = clocks.hclk().into();
// iprintln!(stim, "clk {:?}", hclk);
// let tx = gpioa.pa2.into_alternate_af7();
// let rx = gpioa.pa3.into_alternate_af7();
let tx = gpiod.pd8.into_alternate_af7();
let rx = gpiod.pd9.into_alternate_af7();
let serial = Serial::usart3(
p.USART3,
(tx, rx),
Config::default().baudrate(115_200.bps()),
clocks,
)
.unwrap();
// Separate out the sender and receiver of the serial port
let (mut tx, mut rx) = serial.split();
loop {
match block!(rx.read()) {
Ok(byte) => {
iprintln!(stim, "Ok {:?}", byte);
let _ = tx.write(byte);
}
Err(err) => {
iprintln!(stim, "Error {:?}", err);
}
}
}
}
......@@ -33,19 +33,24 @@ fn main() -> ! {
// let mut flash = p.FLASH.constrain();
let rcc = p.RCC.constrain();
let gpioa = p.GPIOA.split();
//let gpioa = p.GPIOA.split();
let gpiod = p.GPIOD.split();
// let clocks = rcc.cfgr.freeze(&mut flash.acr);
// let clocks = rcc.cfgr.freeze();
let clocks = rcc.cfgr.freeze();
let hclk: i32 = clocks.hclk().into();
iprintln!(stim, "clk {:?}", hclk);
iprintln!(stim, "after freeze");
let tx = gpioa.pa2.into_alternate_af7();
let rx = gpioa.pa3.into_alternate_af7();
// let hclk: i32 = clocks.hclk().into();
// iprintln!(stim, "clk {:?}", hclk);
let serial = Serial::usart2(
p.USART2,
// let tx = gpioa.pa2.into_alternate_af7();
// let rx = gpioa.pa3.into_alternate_af7();
let tx = gpiod.pd8.into_alternate_af7();
let rx = gpiod.pd9.into_alternate_af7();
let serial = Serial::usart3(
p.USART3,
(tx, rx),
Config::default().baudrate(115_200.bps()),
clocks,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment