tx stale nefunguje

This commit is contained in:
Priec
2025-11-12 23:37:32 +01:00
parent 66521896b3
commit fa343624e7
52 changed files with 133 additions and 150 deletions

View File

@@ -1,46 +0,0 @@
[package]
authors = ["Priec <filippriec@gmail.com>"]
name = "dma_gpio"
edition = "2024"
version = "0.1.0"
[dependencies]
cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.5"
panic-halt = "1.0.0"
embassy-executor = { git = "https://github.com/embassy-rs/embassy.git", branch = "main", features = ["arch-cortex-m", "executor-thread"] }
embassy-futures = { git = "https://github.com/embassy-rs/embassy.git", branch = "main" }
embassy-sync = { git = "https://github.com/embassy-rs/embassy.git", branch = "main" }
embassy-time = { git = "https://github.com/embassy-rs/embassy.git", branch = "main", features = ["tick-hz-32_768"] }
embassy-hal-internal = { git = "https://github.com/embassy-rs/embassy.git", branch = "main" }
embassy-usb = { git = "https://github.com/embassy-rs/embassy.git", branch = "main" }
embassy-stm32 = { git = "https://github.com/embassy-rs/embassy.git", branch = "main", features = ["unstable-pac", "stm32u575zi", "time-driver-tim2", "memory-x", "defmt"] }
embedded-hal = "1.0.0"
embedded-graphics = "0.8.1"
heapless = { version = "0.9.1", default-features = false }
micromath = "2.1.0"
tinybmp = "0.6.0"
panic-probe = { version = "1.0.0", features = ["defmt"] }
defmt-rtt = "1.1.0"
defmt = "1.0.1"
static_cell = "2.1.1"
embedded-io = "0.6.1"
embedded-io-async = "0.6.1"
[dev-dependencies]
defmt-test = "0.4.0"
[[test]]
name = "uart_emulation"
harness = false
[lib]
test = false
[[bin]]
name = "main"
path = "src/bin/main.rs"
test = false

View File

@@ -0,0 +1,45 @@
[package]
authors = ["Priec <filippriec@gmail.com>"]
name = "dma_gpio"
edition = "2024"
version = "0.1.0"
[dependencies]
cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.5"
panic-halt = "1.0.0"
embassy-executor = { path = "/home/filip/programs/embassy/embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
embassy-futures = { path = "/home/filip/programs/embassy/embassy-futures" }
embassy-sync = { path = "/home/filip/programs/embassy/embassy-sync" }
embassy-time = { path = "/home/filip/programs/embassy/embassy-time", features = ["tick-hz-32_768"] }
embassy-hal-internal = { path = "/home/filip/programs/embassy/embassy-hal-internal" }
embassy-usb = { path = "/home/filip/programs/embassy/embassy-usb" }
embassy-stm32 = { path = "/home/filip/programs/embassy/embassy-stm32", features = ["unstable-pac", "stm32u575zi", "time-driver-tim2", "memory-x", "defmt"] }
embedded-hal = "1.0.0"
embedded-graphics = "0.8.1"
heapless = { version = "0.9.1", default-features = false }
micromath = "2.1.0"
tinybmp = "0.6.0"
panic-probe = { version = "1.0.0", features = ["defmt"] }
defmt-rtt = "1.1.0"
defmt = "1.0.1"
static_cell = "2.1.1"
embedded-io = "0.6.1"
embedded-io-async = "0.6.1"
[dev-dependencies]
defmt-test = "0.4.0"
[[test]]
name = "uart_emulation"
harness = false
[lib]
test = false
[[bin]]
name = "main"
path = "src/bin/main.rs"
test = false

View File

@@ -27,6 +27,7 @@ use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, pipe::Pipe};
use dma_gpio::hw_uart_internal::usart2;
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 {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs {
@@ -79,12 +80,10 @@ async fn main(spawner: Spawner) {
RX_BUF2.init([0; 256]),
Irqs2,
cfg2,
)
.unwrap();
).unwrap();
let _ = usart2::setup_and_spawn(BAUD);
spawner
.spawn(uart_task_internal(uart2, &PIPE_INT_TX, &PIPE_INT_RX).unwrap());
spawner.spawn(uart_task_internal(uart2, &PIPE_INT_TX, &PIPE_INT_RX).unwrap());
info!("USART2 ready");
// END OF INTERNAL HARDWARE UART (USART2)
@@ -95,7 +94,8 @@ async fn main(spawner: Spawner) {
// END OF USART1 <-> USART2 bridge
// SOFTWARE UART
let _rx = Input::new(p.PC3, Pull::Up);
// let _rx = Input::new(p.PD6, Pull::Up);
let mut rx_pin = Input::new(p.PD6, Pull::Up);
let _tx = Output::new(p.PB0, Level::High, Speed::VeryHigh);
init_tim6_for_uart(p.TIM6, BAUD, TX_OVERSAMPLE);
init_tim7_for_uart(p.TIM7, BAUD, RX_OVERSAMPLE);
@@ -105,8 +105,8 @@ async fn main(spawner: Spawner) {
let sw_rx_ring: &mut [u8; RX_RING_BYTES] = SW_RX_RING.init([0; RX_RING_BYTES]);
// let sw_tx_ring: &mut [u32; TX_RING_BYTES] = SW_TX_RING.init([0; TX_RING_BYTES]);
let gpioc_idr = embassy_stm32::pac::GPIOC.idr().as_ptr() as *mut u8; // POZOR C REGISTER
spawner.spawn(rx_dma_task(p.GPDMA1_CH1, gpioc_idr, sw_rx_ring, &PIPE_SW_RX).unwrap());
let gpio_idr = embassy_stm32::pac::GPIOD.idr().as_ptr() as *mut u8; // POZOR C REGISTER
spawner.spawn(rx_dma_task(p.GPDMA1_CH1, gpio_idr, sw_rx_ring, &PIPE_SW_RX).unwrap());
// Create and start the TX DMA ring in main.
let bsrr_ptr = embassy_stm32::pac::GPIOB.bsrr().as_ptr() as *mut u32; // POZOR B REGISTER
@@ -118,6 +118,7 @@ async fn main(spawner: Spawner) {
let mut last_yield = Instant::now();
let mut buf = [0u8; 32];
let mut last_state: u8 = 0;
loop {
info!("tick start");
// Timer::after(Duration::from_millis(100)).await;
@@ -131,6 +132,16 @@ async fn main(spawner: Spawner) {
// }
// yield_now().await;
let bit = rx_pin.is_high();
if bit as u8 != last_state {
info!(
"SW RX -> PD6 changed, new state = {}",
if bit { "HIGH" } else { "LOW" }
);
last_state = bit as u8;
}
Timer::after(Duration::from_millis(1)).await;
let n2 = PIPE_SW_RX.read(&mut buf).await;
if n2 > 0 {
info!("SW UART RX pipe: {:a}", &buf[..n2]);

View File

@@ -1,46 +0,0 @@
[package]
authors = ["Priec <filippriec@gmail.com>"]
name = "dma_gpio"
edition = "2024"
version = "0.1.0"
[dependencies]
cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.5"
panic-halt = "1.0.0"
embassy-executor = { git = "https://github.com/embassy-rs/embassy.git", branch = "main", features = ["arch-cortex-m", "executor-thread"] }
embassy-futures = { git = "https://github.com/embassy-rs/embassy.git", branch = "main" }
embassy-sync = { git = "https://github.com/embassy-rs/embassy.git", branch = "main" }
embassy-time = { git = "https://github.com/embassy-rs/embassy.git", branch = "main", features = ["tick-hz-32_768"] }
embassy-hal-internal = { git = "https://github.com/embassy-rs/embassy.git", branch = "main" }
embassy-usb = { git = "https://github.com/embassy-rs/embassy.git", branch = "main" }
embassy-stm32 = { git = "https://github.com/embassy-rs/embassy.git", branch = "main", features = ["unstable-pac", "stm32u575zi", "time-driver-tim2", "memory-x", "defmt"] }
embedded-hal = "1.0.0"
embedded-graphics = "0.8.1"
heapless = { version = "0.9.1", default-features = false }
micromath = "2.1.0"
tinybmp = "0.6.0"
panic-probe = { version = "1.0.0", features = ["defmt"] }
defmt-rtt = "1.1.0"
defmt = "1.0.1"
static_cell = "2.1.1"
embedded-io = "0.6.1"
embedded-io-async = "0.6.1"
[dev-dependencies]
defmt-test = "0.4.0"
[[test]]
name = "uart_emulation"
harness = false
[lib]
test = false
[[bin]]
name = "main"
path = "src/bin/main.rs"
test = false

View File

@@ -330,7 +330,6 @@ dependencies = [
[[package]]
name = "embassy-embedded-hal"
version = "0.5.0"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"defmt 1.0.1",
"embassy-futures",
@@ -348,7 +347,6 @@ dependencies = [
[[package]]
name = "embassy-executor"
version = "0.9.1"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"cordyceps",
"cortex-m",
@@ -361,7 +359,6 @@ dependencies = [
[[package]]
name = "embassy-executor-macros"
version = "0.7.0"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"darling",
"proc-macro2",
@@ -372,17 +369,14 @@ dependencies = [
[[package]]
name = "embassy-executor-timer-queue"
version = "0.1.0"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
[[package]]
name = "embassy-futures"
version = "0.1.2"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
[[package]]
name = "embassy-hal-internal"
version = "0.3.0"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"cortex-m",
"critical-section",
@@ -393,7 +387,6 @@ dependencies = [
[[package]]
name = "embassy-net-driver"
version = "0.2.0"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"defmt 1.0.1",
]
@@ -401,7 +394,6 @@ dependencies = [
[[package]]
name = "embassy-net-driver-channel"
version = "0.3.2"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"embassy-futures",
"embassy-net-driver",
@@ -411,7 +403,6 @@ dependencies = [
[[package]]
name = "embassy-stm32"
version = "0.4.0"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"aligned",
"bit_field",
@@ -460,7 +451,6 @@ dependencies = [
[[package]]
name = "embassy-sync"
version = "0.7.2"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"cfg-if",
"critical-section",
@@ -474,7 +464,6 @@ dependencies = [
[[package]]
name = "embassy-time"
version = "0.5.0"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"cfg-if",
"critical-section",
@@ -490,7 +479,6 @@ dependencies = [
[[package]]
name = "embassy-time-driver"
version = "0.2.1"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"document-features",
]
@@ -498,7 +486,6 @@ dependencies = [
[[package]]
name = "embassy-time-queue-utils"
version = "0.3.0"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"embassy-executor-timer-queue",
"heapless 0.8.0",
@@ -507,7 +494,6 @@ dependencies = [
[[package]]
name = "embassy-usb"
version = "0.5.1"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"embassy-futures",
"embassy-net-driver-channel",
@@ -522,7 +508,6 @@ dependencies = [
[[package]]
name = "embassy-usb-driver"
version = "0.2.0"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"defmt 1.0.1",
"embedded-io-async",
@@ -531,7 +516,6 @@ dependencies = [
[[package]]
name = "embassy-usb-synopsys-otg"
version = "0.3.1"
source = "git+https://github.com/embassy-rs/embassy.git?branch=main#9b1add3d83e98c6c9ae9230bf35cd89bba530a20"
dependencies = [
"critical-section",
"defmt 1.0.1",

View File

@@ -0,0 +1,45 @@
[package]
authors = ["Priec <filippriec@gmail.com>"]
name = "dma_gpio"
edition = "2024"
version = "0.1.0"
[dependencies]
cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = "0.7.5"
panic-halt = "1.0.0"
embassy-executor = { path = "/home/filip/programs/embassy/embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
embassy-futures = { path = "/home/filip/programs/embassy/embassy-futures" }
embassy-sync = { path = "/home/filip/programs/embassy/embassy-sync" }
embassy-time = { path = "/home/filip/programs/embassy/embassy-time", features = ["tick-hz-32_768"] }
embassy-hal-internal = { path = "/home/filip/programs/embassy/embassy-hal-internal" }
embassy-usb = { path = "/home/filip/programs/embassy/embassy-usb" }
embassy-stm32 = { path = "/home/filip/programs/embassy/embassy-stm32", features = ["unstable-pac", "stm32u575zi", "time-driver-tim2", "memory-x", "defmt"] }
embedded-hal = "1.0.0"
embedded-graphics = "0.8.1"
heapless = { version = "0.9.1", default-features = false }
micromath = "2.1.0"
tinybmp = "0.6.0"
panic-probe = { version = "1.0.0", features = ["defmt"] }
defmt-rtt = "1.1.0"
defmt = "1.0.1"
static_cell = "2.1.1"
embedded-io = "0.6.1"
embedded-io-async = "0.6.1"
[dev-dependencies]
defmt-test = "0.4.0"
[[test]]
name = "uart_emulation"
harness = false
[lib]
test = false
[[bin]]
name = "main"
path = "src/bin/main.rs"
test = false

View File

@@ -4,7 +4,7 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_time::Instant;
use embassy_time::{Instant, Timer, Duration};
use embassy_stm32::dma::Request;
use embassy_stm32::gpio::{Input, Output, Level, Pull, Speed};
use dma_gpio::software_uart::{
@@ -73,18 +73,16 @@ async fn main(spawner: Spawner) {
let uart2 = BufferedUart::new(
p.USART2,
p.PA3, // RX
p.PD6, // RX
p.PA2, // TX
TX_BUF2.init([0; 256]),
RX_BUF2.init([0; 256]),
Irqs2,
cfg2,
)
.unwrap();
).unwrap();
let _ = usart2::setup_and_spawn(BAUD);
spawner
.spawn(uart_task_internal(uart2, &PIPE_INT_TX, &PIPE_INT_RX).unwrap());
spawner.spawn(uart_task_internal(uart2, &PIPE_INT_TX, &PIPE_INT_RX).unwrap());
info!("USART2 ready");
// END OF INTERNAL HARDWARE UART (USART2)
@@ -95,53 +93,45 @@ async fn main(spawner: Spawner) {
// END OF USART1 <-> USART2 bridge
// SOFTWARE UART
let _rx = Input::new(p.PC3, Pull::Up);
let _tx = Output::new(p.PB0, Level::High, Speed::VeryHigh);
let tx = Output::new(p.PB0, Level::High, Speed::VeryHigh);
init_tim6_for_uart(p.TIM6, BAUD, TX_OVERSAMPLE);
init_tim7_for_uart(p.TIM7, BAUD, RX_OVERSAMPLE);
dump_tim6_regs();
// Safe one-time init from StaticCell
let sw_rx_ring: &mut [u8; RX_RING_BYTES] = SW_RX_RING.init([0; RX_RING_BYTES]);
// let sw_tx_ring: &mut [u32; TX_RING_BYTES] = SW_TX_RING.init([0; TX_RING_BYTES]);
let sw_tx_ring: &mut [u32; TX_RING_BYTES] = SW_TX_RING.init([0; TX_RING_BYTES]);
let gpioc_idr = embassy_stm32::pac::GPIOC.idr().as_ptr() as *mut u8; // POZOR C REGISTER
spawner.spawn(rx_dma_task(p.GPDMA1_CH1, gpioc_idr, sw_rx_ring, &PIPE_SW_RX).unwrap());
// Create and start the TX DMA ring in main.
let bsrr_ptr = embassy_stm32::pac::GPIOB.bsrr().as_ptr() as *mut u32; // POZOR B REGISTER
// let odr_ptr = embassy_stm32::pac::GPIOA.odr().as_ptr() as *mut u32; // NEEDS DECODE CHANGE
// spawner.spawn(tx_dma_task(p.GPDMA1_CH0, bsrr_ptr, sw_tx_ring, &PIPE_SW_TX).unwrap());
spawner.spawn(tx_dma_task(p.GPDMA1_CH0, bsrr_ptr, sw_tx_ring, &PIPE_SW_TX).unwrap());
// EDN OF SOFTWARE UART
let mut last_yield = Instant::now();
let mut buf = [0u8; 32];
let mut counter: u32 = 0;
loop {
info!("tick start");
// Timer::after(Duration::from_millis(100)).await;
// info!("tick end");
// let n1 = PIPE_HW_RX.read(&mut buf).await;
// if n1 > 0 {
// info!("PC received: {:a}", &buf[..n1]);
// let _ = PIPE_SW_TX.write(&buf[..n1]).await;
// info!("SW UART TX sent echo: {:a}", &buf[..n1]);
// }
// yield_now().await;
counter += 1;
let msg = if counter % 2 == 0 {
b"AAAAA\n"
} else {
b"Hello\n"
};
PIPE_SW_TX.write(msg).await;
info!("Sent: {:a}", msg);
let n2 = PIPE_SW_RX.read(&mut buf).await;
Timer::after(Duration::from_secs(3)).await;
// Also read any incoming data from SW RX pipe
let n2 = PIPE_INT_RX.read(&mut buf).await;
if n2 > 0 {
info!("SW UART RX pipe: {:a}", &buf[..n2]);
info!("HW INT UART RX pipe: {:a}", &buf[..n2]);
}
yield_now().await;
// if Instant::now().duration_since(last_yield) >= yield_period {
// yield_now().await;
// last_yield = Instant::now();
// }
}
}

View File

@@ -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 = 115_200;
// 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 = 13;
pub const RX_RING_BYTES: usize = 4096;
pub const TX_RING_BYTES: usize = 4096;

View File

@@ -44,7 +44,7 @@ pub async fn tx_dma_task(
ch: Peri<'static, GPDMA1_CH0>,
register: *mut u32, // Either odr or bsrr
tx_ring_mem: &'static mut [u32],
pipe_rx: &'static Pipe<CriticalSectionRawMutex, 1024>,
pipe_tx: &'static Pipe<CriticalSectionRawMutex, 1024>,
) {
let mut tx_opts = TransferOptions::default();
tx_opts.half_transfer_ir = true;
@@ -68,7 +68,7 @@ pub async fn tx_dma_task(
let mut rx_buf = [0u8; 256];
loop {
let n = pipe_rx.read(&mut rx_buf).await;
let n = pipe_tx.read(&mut rx_buf).await;
if n == 0 {
yield_now().await;
continue;