working only at 600 baud, we are reading data of the pin in the interrupt
This commit is contained in:
@@ -29,12 +29,15 @@ use dma_gpio::hw_uart_internal::driver::uart_task as uart_task_internal;
|
||||
use dma_gpio::config::{PIPE_INT_TX, PIPE_INT_RX};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_stm32::pac;
|
||||
use embassy_stm32::interrupt;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
use cortex_m::interrupt::Mutex;
|
||||
use core::cell::RefCell;
|
||||
use embassy_sync::channel::Channel;
|
||||
|
||||
static RX_PIN_GLOBAL: Mutex<RefCell<Option<&'static Input<'static>>>> = Mutex::new(RefCell::new(None));
|
||||
static PD6_BITS: Channel<CriticalSectionRawMutex, u8, 512> = Channel::new();
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
USART1 => BufferedInterruptHandler<peripherals::USART1>;
|
||||
@@ -113,18 +116,46 @@ async fn main(spawner: Spawner) {
|
||||
init_tim6_for_uart(p.TIM6, BAUD, TX_OVERSAMPLE);
|
||||
init_tim7_for_uart(p.TIM7, BAUD, RX_OVERSAMPLE);
|
||||
|
||||
unsafe { cortex_m::peripheral::NVIC::unmask(pac::Interrupt::TIM7); }
|
||||
info!("TIM7 Interrupt enabled");
|
||||
dump_tim6_regs();
|
||||
// EDN OF SOFTWARE UART
|
||||
|
||||
|
||||
|
||||
unsafe { cortex_m::peripheral::NVIC::unmask(pac::Interrupt::TIM7); }
|
||||
loop {
|
||||
if let Ok(bit) = PD6_BITS.try_receive() {
|
||||
// only called when ISR pushed something
|
||||
info!("c");
|
||||
}
|
||||
yield_now().await;
|
||||
}
|
||||
}
|
||||
|
||||
#[interrupt]
|
||||
fn TIM7() {
|
||||
let tim = unsafe { pac::TIM7 };
|
||||
|
||||
// acknowledge update
|
||||
if tim.sr().read().uif() {
|
||||
tim.sr().modify(|w| w.set_uif(false));
|
||||
|
||||
// quick PD6 read
|
||||
let bit = cortex_m::interrupt::free(|cs| {
|
||||
RX_PIN_GLOBAL
|
||||
.borrow(cs)
|
||||
.borrow()
|
||||
.as_ref()
|
||||
.map(|pin| pin.is_high())
|
||||
.unwrap_or(false)
|
||||
});
|
||||
|
||||
// track state change; push if different
|
||||
static mut LAST: bool = false;
|
||||
if bit != unsafe { LAST } {
|
||||
unsafe { LAST = bit; }
|
||||
let _ = PD6_BITS.try_send(bit as u8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
pub async fn bridge_usart1_rx_to_usart2_tx(
|
||||
usart1_rx: &'static Pipe<CriticalSectionRawMutex, 1024>,
|
||||
|
||||
@@ -3,13 +3,13 @@ use crate::software_uart::uart_emulation::{Parity, StopBits, UartConfig};
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_sync::pipe::Pipe;
|
||||
|
||||
pub const BAUD: u32 = 9_600;
|
||||
pub const BAUD: u32 = 600;
|
||||
// pub const TX_PIN_BIT: u8 = 2; // PA2
|
||||
// pub const RX_PIN_BIT: u8 = 3; // PA3
|
||||
pub const TX_PIN_BIT: u8 = 0; // PB2
|
||||
pub const RX_PIN_BIT: u8 = 3; // PC3
|
||||
pub const TX_OVERSAMPLE: u16 = 1;
|
||||
pub const RX_OVERSAMPLE: u16 = 16;
|
||||
pub const RX_OVERSAMPLE: u16 = 1;
|
||||
|
||||
pub const RX_RING_BYTES: usize = 4096;
|
||||
pub const TX_RING_BYTES: usize = 4096;
|
||||
|
||||
Reference in New Issue
Block a user