hopefuly working CPU transfer to bsrr

This commit is contained in:
Filipriec
2025-11-18 13:36:07 +01:00
parent c01a908b25
commit 1909497403
7 changed files with 58 additions and 88 deletions

View File

@@ -1064,17 +1064,17 @@ dependencies = [
[[package]]
name = "stm32-fmc"
version = "0.3.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7f0639399e2307c2446c54d91d4f1596343a1e1d5cab605b9cce11d0ab3858c"
checksum = "72692594faa67f052e5e06dd34460951c21e83bc55de4feb8d2666e2f15480a2"
dependencies = [
"embedded-hal 0.2.7",
"embedded-hal 1.0.0",
]
[[package]]
name = "stm32-metapac"
version = "18.0.0"
source = "git+https://github.com/embassy-rs/stm32-data-generated?tag=stm32-data-b9f6b0c542d85ee695d71c35ced195e0cef51ac0#9b8fb67703361e2237b6c1ec4f1ee5949223d412"
source = "git+https://github.com/embassy-rs/stm32-data-generated?tag=stm32-data-22374e3344a2c9150b9b3d4da45c03f398fdc54e#31546499ddabe97044beae13ca8b535575b52a56"
dependencies = [
"cortex-m",
"cortex-m-rt",

View File

@@ -9,13 +9,13 @@ version = "0.1.0"
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"] }
embassy-executor = { path = "/home/priec/programs/embassy/embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
embassy-futures = { path = "/home/priec/programs/embassy/embassy-futures" }
embassy-sync = { path = "/home/priec/programs/embassy/embassy-sync" }
embassy-time = { path = "/home/priec/programs/embassy/embassy-time", features = ["tick-hz-32_768"] }
embassy-hal-internal = { path = "/home/priec/programs/embassy/embassy-hal-internal" }
embassy-usb = { path = "/home/priec/programs/embassy/embassy-usb" }
embassy-stm32 = { path = "/home/priec/programs/embassy/embassy-stm32", features = ["unstable-pac", "stm32u575zi", "time-driver-tim2", "memory-x", "defmt"] }
embedded-hal = "1.0.0"
embedded-graphics = "0.8.1"

View File

@@ -1064,17 +1064,17 @@ dependencies = [
[[package]]
name = "stm32-fmc"
version = "0.3.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7f0639399e2307c2446c54d91d4f1596343a1e1d5cab605b9cce11d0ab3858c"
checksum = "72692594faa67f052e5e06dd34460951c21e83bc55de4feb8d2666e2f15480a2"
dependencies = [
"embedded-hal 0.2.7",
"embedded-hal 1.0.0",
]
[[package]]
name = "stm32-metapac"
version = "18.0.0"
source = "git+https://github.com/embassy-rs/stm32-data-generated?tag=stm32-data-b9f6b0c542d85ee695d71c35ced195e0cef51ac0#9b8fb67703361e2237b6c1ec4f1ee5949223d412"
source = "git+https://github.com/embassy-rs/stm32-data-generated?tag=stm32-data-22374e3344a2c9150b9b3d4da45c03f398fdc54e#31546499ddabe97044beae13ca8b535575b52a56"
dependencies = [
"cortex-m",
"cortex-m-rt",

View File

@@ -9,13 +9,13 @@ version = "0.1.0"
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"] }
embassy-executor = { path = "/home/priec/programs/embassy/embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
embassy-futures = { path = "/home/priec/programs/embassy/embassy-futures" }
embassy-sync = { path = "/home/priec/programs/embassy/embassy-sync" }
embassy-time = { path = "/home/priec/programs/embassy/embassy-time", features = ["tick-hz-32_768"] }
embassy-hal-internal = { path = "/home/priec/programs/embassy/embassy-hal-internal" }
embassy-usb = { path = "/home/priec/programs/embassy/embassy-usb" }
embassy-stm32 = { path = "/home/priec/programs/embassy/embassy-stm32", features = ["unstable-pac", "stm32u575zi", "time-driver-tim2", "memory-x", "defmt"] }
embedded-hal = "1.0.0"
embedded-graphics = "0.8.1"

View File

@@ -4,17 +4,13 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_time::{Instant, Timer, Duration};
use embassy_stm32::dma::Request;
use embassy_stm32::gpio::{Input, Output, Level, Pull, Speed};
use embassy_time::{Timer, Duration};
use embassy_stm32::gpio::{Output, Level, Speed};
use dma_gpio::software_uart::{
dma_timer::{init_tim6_for_uart, init_tim7_for_uart},
gpio_dma_uart_rx::rx_dma_task,
dma_timer::init_tim6_for_uart,
debug::dump_tim6_regs,
};
use dma_gpio::config::{BAUD, RX_OVERSAMPLE, TX_OVERSAMPLE};
use dma_gpio::config::{TX_RING_BYTES, RX_RING_BYTES};
use dma_gpio::software_uart::gpio_dma_uart_tx::tx_dma_task;
use dma_gpio::config::{BAUD, TX_OVERSAMPLE, TX_PIN_BIT, UART_CFG};
use static_cell::StaticCell;
use embassy_futures::yield_now;
use dma_gpio::hw_uart_pc::usart1;
@@ -22,7 +18,7 @@ use dma_gpio::hw_uart_pc::driver::uart_task;
use embassy_stm32::usart::{BufferedUart, Config, BufferedInterruptHandler};
use embassy_stm32::peripherals;
use embassy_stm32::bind_interrupts;
use dma_gpio::config::{PIPE_HW_TX, PIPE_HW_RX, PIPE_SW_TX, PIPE_SW_RX};
use dma_gpio::config::{PIPE_HW_TX, PIPE_HW_RX, PIPE_SW_TX};
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;
@@ -36,11 +32,6 @@ bind_interrupts!(struct Irqs2 {
USART2 => BufferedInterruptHandler<peripherals::USART2>;
});
// Software uart
pub const TIM6_UP_REQ: Request = 4;
static SW_TX_RING: StaticCell<[u32; TX_RING_BYTES]> = StaticCell::new();
static SW_RX_RING: StaticCell<[u8; RX_RING_BYTES]> = StaticCell::new();
#[embassy_executor::main]
async fn main(spawner: Spawner) {
info!("boot");
@@ -61,7 +52,7 @@ async fn main(spawner: Spawner) {
Irqs,
cfg,
).unwrap();
let yield_period = usart1::setup_and_spawn(BAUD);
let _yield_period = usart1::setup_and_spawn(BAUD);
spawner.spawn(uart_task(uart, &PIPE_HW_TX, &PIPE_HW_RX).unwrap());
// END OF HARDWARE UART to the PC
@@ -93,35 +84,19 @@ async fn main(spawner: Spawner) {
// END OF USART1 <-> USART2 bridge
// SOFTWARE UART
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);
dump_tim6_regs();
// Safe one-time init from StaticCell
let sw_tx_ring: &mut [u32; TX_RING_BYTES] = SW_TX_RING.init([0; TX_RING_BYTES]);
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_cpu_task(bsrr_ptr, p.TIM6, &PIPE_SW_TX)).unwrap();
// EDN OF SOFTWARE UART
spawner.spawn(tx_cpu_task(bsrr_ptr, &PIPE_SW_TX).unwrap());
// END 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 n = PIPE_SW_TX.read(&mut buf).await;
if n > 0 {
for &byte in &buf[..n] {
send_byte_cpu(&tx_pin, p.TIM6, byte).await;
}
}
counter += 1;
let msg = if counter % 2 == 0 {
@@ -133,7 +108,8 @@ async fn main(spawner: Spawner) {
info!("Sent: {:a}", msg);
Timer::after(Duration::from_secs(3)).await;
// Also read any incoming data from SW RX pipe
// Also read any incoming data from internal UART RX pipe
let n2 = PIPE_INT_RX.read(&mut buf).await;
if n2 > 0 {
info!("HW INT UART RX pipe: {:a}", &buf[..n2]);
@@ -176,37 +152,31 @@ pub async fn bridge_usart2_rx_to_usart1_tx(
#[embassy_executor::task]
pub async fn tx_cpu_task(
bsrr_ptr: *mut u32,
tim6: embassy_stm32::peripherals::TIM6,
pipe_tx: &'static embassy_sync::pipe::Pipe<embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex,1024,>,
pipe_tx: &'static embassy_sync::pipe::Pipe<embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex, 1024>,
) {
use dma_gpio::config::TX_PIN_BIT;
use dma_gpio::software_uart::uart_emulation::{encode_uart_byte_cfg, UART_CFG};
use dma_gpio::software_uart::uart_emulation::encode_uart_byte_cfg;
use embassy_futures::yield_now;
let tim6_regs = unsafe { &*embassy_stm32::pac::TIM6::ptr() };
// Access TIM6 registers directly via PAC
let tim6_regs = embassy_stm32::pac::TIM6;
let mut rx_buf = [0u8; 256];
let mut frame_buf = [0u32; 32];
let mut wait_tick = || async {
loop {
if tim6_regs.sr().read() & 1 != 0 {
tim6_regs.sr().write(|w| w & !1);
break;
}
embassy_futures::yield_now().await;
}
};
let mut frame_buf = [0u32; 12];
loop {
let n = pipe_tx.read(&mut rx_buf).await;
if n == 0 {
embassy_futures::yield_now().await;
yield_now().await;
continue;
}
for &byte in &rx_buf[..n] {
let used = encode_uart_byte_cfg(TX_PIN_BIT, byte, &UART_CFG, &mut frame_buf);
for word in &frame_buf[..used] {
while !tim6_regs.sr().read().uif() {
yield_now().await;
}
tim6_regs.sr().modify(|w| w.set_uif(false));
unsafe { core::ptr::write_volatile(bsrr_ptr, *word) };
wait_tick().await;
}
}
}

View File

@@ -1064,17 +1064,17 @@ dependencies = [
[[package]]
name = "stm32-fmc"
version = "0.3.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7f0639399e2307c2446c54d91d4f1596343a1e1d5cab605b9cce11d0ab3858c"
checksum = "72692594faa67f052e5e06dd34460951c21e83bc55de4feb8d2666e2f15480a2"
dependencies = [
"embedded-hal 0.2.7",
"embedded-hal 1.0.0",
]
[[package]]
name = "stm32-metapac"
version = "18.0.0"
source = "git+https://github.com/embassy-rs/stm32-data-generated?tag=stm32-data-b9f6b0c542d85ee695d71c35ced195e0cef51ac0#9b8fb67703361e2237b6c1ec4f1ee5949223d412"
source = "git+https://github.com/embassy-rs/stm32-data-generated?tag=stm32-data-22374e3344a2c9150b9b3d4da45c03f398fdc54e#31546499ddabe97044beae13ca8b535575b52a56"
dependencies = [
"cortex-m",
"cortex-m-rt",

View File

@@ -9,13 +9,13 @@ version = "0.1.0"
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"] }
embassy-executor = { path = "/home/priec/programs/embassy/embassy-executor", features = ["arch-cortex-m", "executor-thread"] }
embassy-futures = { path = "/home/priec/programs/embassy/embassy-futures" }
embassy-sync = { path = "/home/priec/programs/embassy/embassy-sync" }
embassy-time = { path = "/home/priec/programs/embassy/embassy-time", features = ["tick-hz-32_768"] }
embassy-hal-internal = { path = "/home/priec/programs/embassy/embassy-hal-internal" }
embassy-usb = { path = "/home/priec/programs/embassy/embassy-usb" }
embassy-stm32 = { path = "/home/priec/programs/embassy/embassy-stm32", features = ["unstable-pac", "stm32u575zi", "time-driver-tim2", "memory-x", "defmt"] }
embedded-hal = "1.0.0"
embedded-graphics = "0.8.1"