Skip to content

Commit b809e21

Browse files
committed
fix(audio): setup DMA RAM in DRAM2 for all uses
This fixes scratchy audio. The problem was not setting enough DRAM2 (in terms of length) as DMA RAM (specific settings such as non-cacheable etc. are in `init_dma`). So rather than try and set each allocation up, let's just set a block of 32kb for everything to use. "Everything" at this point is only the input and output audio buffer, but in the future will be the circular buffer used for ADC DMA reads. If we need more we can increase that.
1 parent f176b61 commit b809e21

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/audio.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ impl Audio {
136136
i2c_sda: gpiob::PB11<Analog>,
137137

138138
clocks: &rcc::CoreClocks,
139-
mpu: &mut cortex_m::peripheral::MPU,
140-
scb: &mut cortex_m::peripheral::SCB,
141139
) -> Self {
142140
let rx_buffer: &'static mut [u32; DMA_BUFFER_SIZE] = unsafe { &mut RX_BUFFER };
143141
let dma_config = dma::dma::DmaConfig::default()
@@ -234,17 +232,11 @@ impl Audio {
234232
let input = Input::new(unsafe { &mut RX_BUFFER });
235233
let output = Output::new(unsafe { &mut TX_BUFFER });
236234

237-
let input_buffer_ptr: *mut u32 = unsafe { &mut RX_BUFFER[0] };
238-
let output_buffer_ptr: *mut u32 = unsafe { &mut TX_BUFFER[0] };
239-
240235
info!(
241236
"Setup up Audio DMA: input: {:?}, output: {:?}",
242-
input_buffer_ptr, output_buffer_ptr
237+
&input.buffer[0] as *const u32, &output.buffer[0] as *const u32
243238
);
244239

245-
crate::mpu::init_dma(mpu, scb, input_buffer_ptr, DMA_BUFFER_SIZE);
246-
crate::mpu::init_dma(mpu, scb, output_buffer_ptr, DMA_BUFFER_SIZE);
247-
248240
Audio {
249241
sai,
250242
input_stream,

src/system.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ use stm32h7xx_hal::{
1515

1616
use crate::{audio::Audio, *};
1717

18+
const START_OF_DRAM2: u32 = 0x30000000;
19+
const DMA_MEM_SIZE: usize = 32 * 1024;
20+
1821
const HSE_CLOCK_MHZ: MegaHertz = MegaHertz::from_raw(16);
1922
const HCLK_MHZ: MegaHertz = MegaHertz::from_raw(200);
2023
const HCLK2_MHZ: MegaHertz = MegaHertz::from_raw(200);
@@ -96,6 +99,14 @@ impl System {
9699
info!("Starting system init");
97100
let ccdr = Self::init_clocks(device.PWR, device.RCC, &device.SYSCFG);
98101

102+
info!("Setup up DMA RAM in DRAM2...");
103+
crate::mpu::init_dma(
104+
&mut core.MPU,
105+
&mut core.SCB,
106+
START_OF_DRAM2 as *mut u32,
107+
DMA_MEM_SIZE,
108+
);
109+
99110
// log_clocks(&ccdr);
100111
let mut delay = Delay::new(core.SYST, ccdr.clocks);
101112
// Setup ADCs
@@ -221,8 +232,6 @@ impl System {
221232
gpioh.ph4,
222233
gpiob.pb11,
223234
&ccdr.clocks,
224-
&mut core.MPU,
225-
&mut core.SCB,
226235
);
227236

228237
// Setup GPIOs

0 commit comments

Comments
 (0)