Skip to main content
Sign in
Snippets Groups Projects
Commit ae34d895 authored by Edvin Åkerfeldt's avatar Edvin Åkerfeldt
Browse files

Working, sort of... now just send pulses....

parent ea64a4ec
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,8 @@ use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
use stm32f4;
use stm32f4::stm32f413::GPIOA;
use stm32f4::stm32f413::NVIC;
use stm32f4::stm32f413::Interrupt;
//use stm32f411::{GPIOA, RCC};
//const bit_string: u16 = 0x0;
......@@ -15,8 +17,8 @@ use stm32f4::stm32f413::GPIOA;
const bit_string: u16 = 0x0FFF;
//actual string 0b1_01111101_1111 (send value 255)
//const bit_s: u32 = 0b10_0110101010100110_10101010; // Start stop high 26 bits (start pos 25)
//const bit_s: u32 = 0b01_0110101010100110_01010101; // Start stop low
const bit_s: u32 = 0b10_0101010101010101_10101010;
const bit_s: u32 = 0b01_0110101010100110_01010101; // Start stop low
//const bit_s: u32 = 0b10_0101010101010101_10101010;
// actual string 0b1_00000000_1111 (send value 0)
//const bit_s: u32 = 0b10_0101010101010101_10101010; // Start stop high
......@@ -39,7 +41,7 @@ const big_endian: bool = true;
const APP: () = {
struct Resources {
dwt: DWT,
ON: bool,
send: bool,
point: u16,
tick: u16,
}
......@@ -65,10 +67,41 @@ const APP: () = {
let rcc = cx.device.RCC;
rcc.ahb1enr.modify(|_, w| w.gpioaen().set_bit());
// power on GPIOC
rcc.ahb1enr.modify(|_, w| w.gpiocen().set_bit());
// Enable perihperalclock
rcc.apb2enr.modify(|_, w| w.syscfgen().set_bit());
// configure PA5 as output
let gpioa = cx.device.GPIOA;
gpioa.moder.modify(|_, w| unsafe { w.moder5().bits(1) });
gpioa.moder.modify(|_, w| unsafe { w.moder6().bits(1) });
// No need to configure PC13, it's by default in input mode
let gpioc = cx.device.GPIOC;
gpioc.moder.modify(|_, w| unsafe {w.moder13().bits(0)});
gpioc.pupdr.modify(|_, w| unsafe {w.pupdr13().pull_down()});
// Change interupt source of EXTI13 to PC pin (PC13)
let syscfg = cx.device.SYSCFG;
syscfg.exticr4.modify(|_, w| unsafe{ w.exti13().bits(2) });
cx.device.EXTI.imr.modify(|_, w| unsafe { w.mr13().unmasked() });
cx.device.EXTI.ftsr.modify(|_, w| unsafe {w.tr13().enabled() }); // Trigger on falling edge
//cx.device.EXTI.rtsr.modify(|_, w| unsafe {w.tr13().enabled() }); // Trigger on rising edge
/*
unsafe {
cx.core.nvic.unmask(stm32f4::stm32f413::Interrupt::EXTI15_10);
}
*/
//exticr4.
unsafe {
(*GPIOA::ptr()).odr.modify(|_, w| w.odr5().bit(false));
}
/*
unsafe {
(*GPIOA::ptr()).odr.modify(|_, w| w.odr5().bit(true));
......@@ -80,7 +113,7 @@ const APP: () = {
init::LateResources {
dwt: cx.core.DWT,
ON: false,
send: false,
point: point,
tick: tick,
}
......@@ -100,11 +133,23 @@ const APP: () = {
}
}
#[task(binds = SysTick, resources = [ON, point, tick],)]
#[task(binds=EXTI15_10, resources = [send])]
fn btn(cx: btn::Context) {
//rprintln!("BTN");
*cx.resources.send = true;
/*unsafe {
(*GPIOA::ptr()).odr.modify(|_, w| w.odr5().bit(true));
}*/
NVIC::unpend(Interrupt::EXTI15_10);
}
#[task(binds = SysTick, resources = [send, point, tick])]
fn syst(cx: syst::Context) {
let r = cx.resources;
if *r.point != 0 && false {
let m = bit_s >> *r.point & 0x1;
if *r.tick < 2400 && *r.send {
*r.tick = *r.tick +1;
} else if *r.send && *r.point != 0 && *r.tick >= 2400{
let m = (bit_s >> *r.point) & 0x1;
unsafe {
if m == 1 {
(*GPIOA::ptr()).odr.modify(|_, w| w.odr5().bit(true));
......@@ -113,15 +158,25 @@ const APP: () = {
}
}
*r.point = *r.point - 1;
} else {
}
if *r.send && *r.tick >= 2400 && *r.point == 0 {
rprintln!("RST");
rprintln!("{}", *r.send);
*r.send = false;
rprintln!("{}", *r.send);
*r.tick = 0;
*r.point = 25;
/*
unsafe {
(*GPIOA::ptr()).odr.modify(|_, w| w.odr5().bit(false));
}
}*/
/*
*r.tick = *r.tick + 1;
if *r.tick >= WAIT_TICKS {
*r.point = 25;
*r.tick = 0;
}
*/
}
/*
let r = cx.resources;
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment