1 Commits

Author SHA1 Message Date
Priec
3a2c65f16b hardfault fixed 2025-11-07 20:04:20 +01:00
2 changed files with 30 additions and 5 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
*.pdf *.pdf
dma_example/

View File

@@ -29,9 +29,10 @@ unsafe fn start_dma<'a>(
} }
pub const TIM6_UP_REQ: Request = 4; pub const TIM6_UP_REQ: Request = 4;
const DMA_BUF_WORDS: usize = 256;
static BUF_A: StaticCell<[u32; 8]> = StaticCell::new(); static BUF_A: StaticCell<[u32; DMA_BUF_WORDS]> = StaticCell::new();
static BUF_B: StaticCell<[u32; 8]> = StaticCell::new(); static BUF_B: StaticCell<[u32; DMA_BUF_WORDS]> = StaticCell::new();
#[embassy_executor::main] #[embassy_executor::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
@@ -41,8 +42,16 @@ async fn main(_spawner: Spawner) {
init_tim6_for_uart(p.TIM6, BAUD, TX_OVERSAMPLE); init_tim6_for_uart(p.TIM6, BAUD, TX_OVERSAMPLE);
dump_tim6_regs(); dump_tim6_regs();
let buf_a = BUF_A.init([0u32; 8]); let buf_a = BUF_A.init([0u32; DMA_BUF_WORDS]);
let buf_b = BUF_B.init([0u32; 8]); let buf_b = BUF_B.init([0u32; DMA_BUF_WORDS]);
// Pre-fill with idle high level (stop bit level)
let idle = 1u32 << TX_PIN_BIT;
for w in buf_a.iter_mut() {
*w = idle;
}
for w in buf_b.iter_mut() {
*w = idle;
}
let mut opts = TransferOptions::default(); let mut opts = TransferOptions::default();
opts.priority = Priority::VeryHigh; opts.priority = Priority::VeryHigh;
@@ -58,10 +67,25 @@ async fn main(_spawner: Spawner) {
(&*buf_b, &mut *buf_a) (&*buf_b, &mut *buf_a)
}; };
// Start from idle pattern
let idle = 1u32 << TX_PIN_BIT;
for w in cpu_buf.iter_mut() {
*w = idle;
}
let used = encode_uart_frames(TX_PIN_BIT, b"Hello marshmallow\r\n", cpu_buf).await; let used = encode_uart_frames(TX_PIN_BIT, b"Hello marshmallow\r\n", cpu_buf).await;
let len = if used == 0 { 1 } else { used };
// At least one word so DMA is always valid.
let transfer = unsafe { let transfer = unsafe {
start_dma(ch0.reborrow(), TIM6_UP_REQ, odr_ptr, &dma_buf[..used], opts) start_dma(
ch0.reborrow(),
TIM6_UP_REQ,
odr_ptr,
&dma_buf[..len],
opts,
)
}; };
transfer.await; transfer.await;
using_a = !using_a; using_a = !using_a;