2 Commits

Autor SHA1 Mensagem Data
  Mathias Gottschlag 69dce1af2a WIP. 4 anos atrás
  Mathias Gottschlag c0b41b7242 WIP. 4 anos atrás
8 arquivos alterados com 131 adições e 17 exclusões
  1. 3
    1
      .cargo/config
  2. 18
    4
      Cargo.lock
  3. 9
    1
      Cargo.toml
  4. 6
    0
      openocd.cfg
  5. 26
    0
      openocd.gdb
  6. 52
    5
      src/main.rs
  7. 3
    0
      src/usb.rs
  8. 14
    6
      src/usb_audio.rs

+ 3
- 1
.cargo/config Ver arquivo

@@ -9,4 +9,6 @@ rustflags = [
9 9
     "-C", "inline-threshold=5",
10 10
     "-C", "no-vectorize-loops",
11 11
 ]
12
-runner = "elf2uf2-rs -d"
12
+#runner = "elf2uf2-rs -d"
13
+runner = "arm-none-eabi-gdb -x openocd.gdb"
14
+

+ 18
- 4
Cargo.lock Ver arquivo

@@ -180,6 +180,15 @@ dependencies = [
180 180
  "syn",
181 181
 ]
182 182
 
183
+[[package]]
184
+name = "cortex-m-semihosting"
185
+version = "0.3.7"
186
+source = "registry+https://github.com/rust-lang/crates.io-index"
187
+checksum = "6bffa6c1454368a6aa4811ae60964c38e6996d397ff8095a8b9211b1c1f749bc"
188
+dependencies = [
189
+ "cortex-m",
190
+]
191
+
183 192
 [[package]]
184 193
 name = "crc-any"
185 194
 version = "2.4.0"
@@ -547,10 +556,14 @@ dependencies = [
547 556
 ]
548 557
 
549 558
 [[package]]
550
-name = "panic-halt"
551
-version = "0.2.0"
559
+name = "panic-semihosting"
560
+version = "0.5.6"
552 561
 source = "registry+https://github.com/rust-lang/crates.io-index"
553
-checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812"
562
+checksum = "c3d55dedd501dfd02514646e0af4d7016ce36bc12ae177ef52056989966a1eec"
563
+dependencies = [
564
+ "cortex-m",
565
+ "cortex-m-semihosting",
566
+]
554 567
 
555 568
 [[package]]
556 569
 name = "paste"
@@ -752,10 +765,11 @@ dependencies = [
752 765
  "cortex-m",
753 766
  "cortex-m-rt",
754 767
  "cortex-m-rtic",
768
+ "cortex-m-semihosting",
755 769
  "embedded-hal",
756 770
  "embedded-time",
757 771
  "nb 1.0.0",
758
- "panic-halt",
772
+ "panic-semihosting",
759 773
  "pio",
760 774
  "pio-proc",
761 775
  "rp2040-boot2",

+ 9
- 1
Cargo.toml Ver arquivo

@@ -10,10 +10,13 @@ resolver = "2"
10 10
 cortex-m = "0.7.2"
11 11
 cortex-m-rt = "0.7"
12 12
 cortex-m-rtic = "0.6.0-alpha.5"
13
+cortex-m-semihosting = "0.3.7"
13 14
 embedded-hal ="0.2.5"
14 15
 embedded-time = "0.12.0"
15 16
 nb = "1.0"
16
-panic-halt = "0.2.0"
17
+#panic-halt = "0.2.0"
18
+panic-semihosting = "0.5"
19
+#panic-write = "0.1.0"
17 20
 pio = { git = "https://github.com/rp-rs/pio-rs.git", branch = "main" }
18 21
 pio-proc = { git = "https://github.com/rp-rs/pio-rs.git", branch = "main" }
19 22
 #rp2040-hal = { git = "https://github.com/rp-rs/rp-hal.git", features = ["rt"] }
@@ -26,3 +29,8 @@ void = { version = "*", default_features = false }
26 29
 
27 30
 [patch.crates-io]
28 31
 usb-device = { path = "../usb-device" }
32
+
33
+[profile]
34
+[profile.release]
35
+debug = true
36
+lto = true

+ 6
- 0
openocd.cfg Ver arquivo

@@ -0,0 +1,6 @@
1
+source [find interface/cmsis-dap.cfg]
2
+transport select swd
3
+
4
+adapter speed 100
5
+source [find target/rp2040.cfg]
6
+

+ 26
- 0
openocd.gdb Ver arquivo

@@ -0,0 +1,26 @@
1
+set history save on
2
+set confirm off
3
+target extended-remote :3333
4
+monitor arm semihosting enable
5
+monitor reset halt
6
+
7
+# print demangled symbols
8
+set print asm-demangle on
9
+
10
+# set backtrace limit to not have infinite backtrace loops
11
+set backtrace limit 32
12
+
13
+# detect unhandled exceptions, hard faults and panics
14
+break DefaultHandler
15
+break HardFault
16
+#break rust_begin_unwind
17
+
18
+#break main
19
+
20
+load
21
+run
22
+# continue
23
+# monitor verify
24
+# monitor reset
25
+# quit
26
+

+ 52
- 5
src/main.rs Ver arquivo

@@ -1,7 +1,11 @@
1 1
 #![no_std]
2 2
 #![no_main]
3 3
 
4
-use panic_halt as _;
4
+//use panic_halt as _;
5
+use cortex_m::interrupt::CriticalSection;
6
+use panic_semihosting as _;
7
+use rp2040_hal::pac::UART0;
8
+use rp2040_hal::uart;
5 9
 
6 10
 mod audio_buffer;
7 11
 mod i2s_master;
@@ -12,6 +16,19 @@ mod usb_audio;
12 16
 #[used]
13 17
 pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER;
14 18
 
19
+/*pub fn uart<'cs>(cs: &'cs CriticalSection) -> &'cs mut uart::UartPeripheral<uart::Enabled, UART0> {
20
+    use panic_write::PanicHandler;
21
+
22
+    unsafe {
23
+        let panic_handler = app::PANIC_HANDLER.borrow(cs).get();
24
+        let panic_handler_ref = core::mem::transmute::<
25
+            *mut Option<core::pin::Pin<PanicHandler<uart::UartPeripheral<uart::Enabled, UART0>>>>,
26
+            &mut Option<core::pin::Pin<PanicHandler<uart::UartPeripheral<uart::Enabled, UART0>>>>,
27
+        >(panic_handler);
28
+        panic_handler_ref.as_mut().unwrap()
29
+    }
30
+}*/
31
+
15 32
 #[rtic::app(device = rp2040_hal::pac, peripherals = true, dispatchers = [RTC_IRQ, XIP_IRQ])]
16 33
 mod app {
17 34
     use embedded_hal::digital::v2::OutputPin;
@@ -23,15 +40,20 @@ mod app {
23 40
     use crate::audio_buffer::AudioBuffer;
24 41
     use crate::i2s_master::I2sMaster;
25 42
     use crate::usb::Usb;
26
-    use cortex_m::interrupt;
43
+    //use core::cell::UnsafeCell;
44
+    use core::fmt::Write;
45
+    use cortex_m::interrupt::{self, Mutex};
46
+    //use panic_write::PanicHandler;
27 47
     use rp2040_hal::dma::{DMAExt, SingleChannel, CH0};
28 48
     use rp2040_hal::gpio::bank0::{Gpio0, Gpio1, Gpio3, Gpio6};
29
-    use rp2040_hal::gpio::{Function, Pin, Pio0};
49
+    use rp2040_hal::gpio::{Function, FunctionUart, Pin, Pio0};
50
+    use rp2040_hal::pac::UART0;
30 51
     use rp2040_hal::pio::{PIOExt, PIO0SM0};
31 52
     use rp2040_hal::pll::common_configs::PLL_USB_48MHZ;
32 53
     use rp2040_hal::pll::{setup_pll_blocking, PLLConfig};
33 54
     use rp2040_hal::sio::Sio;
34 55
     use rp2040_hal::timer::Timer;
56
+    //use rp2040_hal::uart;
35 57
     use rp2040_hal::usb::UsbBus;
36 58
     use rp2040_hal::watchdog::Watchdog;
37 59
     use rp2040_hal::xosc::setup_xosc_blocking;
@@ -47,6 +69,14 @@ mod app {
47 69
     };
48 70
 
49 71
     static AUDIO_BUFFER: AudioBuffer<4> = AudioBuffer::new();
72
+    /*pub static UART: Mutex<
73
+        MaybeUninit<Option<&'static mut uart::UartPeripheral<uart::Enabled, UART0>>>,
74
+    > = Mutex::new(UnsafeCell::new(None));*/
75
+    /*pub static mut PANIC_HANDLER: Mutex<
76
+        UnsafeCell<
77
+            Option<core::pin::Pin<PanicHandler<uart::UartPeripheral<uart::Enabled, UART0>>>>,
78
+        >,
79
+    > = Mutex::new(UnsafeCell::new(None));*/
50 80
 
51 81
     #[monotonic(binds = SysTick, default = true)]
52 82
     type SystickMono = Systick<100>;
@@ -116,6 +146,23 @@ mod app {
116 146
         let mut led = pins.gpio25.into_push_pull_output();
117 147
         led.set_low().ok().unwrap();
118 148
 
149
+        /*// We need a UART to debug panics.
150
+        let mut uart = uart::UartPeripheral::<_, _>::enable(
151
+            c.device.UART0,
152
+            &mut resets,
153
+            uart::common_configs::_115200_8_N_1,
154
+            clocks.peripheral_clock.into(),
155
+        )
156
+        .unwrap();
157
+        let _tx_pin = pins.gpio16.into_mode::<FunctionUart>();
158
+        let _rx_pin = pins.gpio17.into_mode::<FunctionUart>();
159
+        writeln!(&mut uart, "Initializing...\r").unwrap();
160
+        interrupt::free(|cs| unsafe {
161
+            let panic_handler = PANIC_HANDLER.borrow(cs);
162
+            *panic_handler.get() = Some(PanicHandler::new(uart));
163
+            writeln!(super::uart(cs), "Panic handler installed.\r").unwrap();
164
+        });*/
165
+
119 166
         // We need a timer so that we can determine the USB SOF frequency for asynchronous USB
120 167
         // audio.
121 168
         let timer = Timer::new(c.device.TIMER, &mut resets);
@@ -192,7 +239,7 @@ mod app {
192 239
         }
193 240
     }
194 241
 
195
-    /// DMA interrupt handler.
242
+    /*/// DMA interrupt handler.
196 243
     ///
197 244
     /// DMA interrupts need to have highest priority as we need to quickly restart the DMA transfer
198 245
     /// to ensure that the PIO FIFO always contains data.
@@ -217,7 +264,7 @@ mod app {
217 264
             }
218 265
             write.write_finished(packet, cs);
219 266
         });
220
-    }
267
+    }*/
221 268
 
222 269
     /// USB interrupt handler.
223 270
     ///

+ 3
- 0
src/usb.rs Ver arquivo

@@ -44,6 +44,9 @@ impl Usb {
44 44
         // using the USB peripheral at this time.
45 45
         let sof = unsafe { (&*USBCTRL_REGS::ptr()).intr.read().dev_sof().bit_is_set() };
46 46
         if sof {
47
+            // Clear the SOF IRQ.
48
+            unsafe { (&*USBCTRL_REGS::ptr()).sof_rd.read() };
49
+
47 50
             // Calculate the frequency difference (frames versus 1kHz derived from the system
48 51
             // clock) and update the synchronization data for the USB audio class accordingly.
49 52
             // Also, add a correction factor if the buffers are running low or high.

+ 14
- 6
src/usb_audio.rs Ver arquivo

@@ -2,6 +2,7 @@
2 2
 //!
3 3
 //! See "Universal Serial Bus Device Class Definition for Audio Devices", release 1.0 (March 18,
4 4
 //! 1998) for a specification of the USB audio class.
5
+use cortex_m::interrupt;
5 6
 use usb_device::class_prelude::*;
6 7
 use usb_device::endpoint::{IsochronousSynchronizationType, IsochronousUsageType};
7 8
 use usb_device::Result;
@@ -31,7 +32,7 @@ pub struct UsbAudioClass<'a, B: UsbBus, OUTBUF: AsRef<[u32]>> {
31 32
     audio_streaming_inactive: InterfaceNumber,
32 33
     audio_streaming: InterfaceNumber,
33 34
     audio_out: EndpointOut<'a, B>,
34
-    audio_out_sync: EndpointIn<'a, B>,
35
+    //audio_out_sync: EndpointIn<'a, B>,
35 36
     //audio_in: EndpointIn<'a, B>,
36 37
     samples_per_frame: [u8; 3],
37 38
 
@@ -58,12 +59,12 @@ impl<'a, B: UsbBus, OUTBUF: AsRef<[u32]>> UsbAudioClass<'a, B, OUTBUF> {
58 59
                 256,
59 60
                 1,
60 61
             ),
61
-            audio_out_sync: bus_alloc.isochronous(
62
+            /*audio_out_sync: bus_alloc.isochronous(
62 63
                 IsochronousSynchronizationType::Asynchronous,
63 64
                 IsochronousUsageType::Feedback,
64 65
                 3,
65 66
                 1,
66
-            ),
67
+            ),*/
67 68
             /*audio_in: bus_alloc.isochronous(
68 69
                 IsochronousSynchronizationType::Asynchronous,
69 70
                 IsochronousUsageType::Data,
@@ -80,6 +81,9 @@ impl<'a, B: UsbBus, OUTBUF: AsRef<[u32]>> UsbAudioClass<'a, B, OUTBUF> {
80 81
 
81 82
 impl<B: UsbBus, OUTBUF: AsRef<[u32]>> UsbClass<B> for UsbAudioClass<'_, B, OUTBUF> {
82 83
     fn get_configuration_descriptors(&self, writer: &mut DescriptorWriter) -> Result<()> {
84
+        /*interrupt::free(|cs| {
85
+            writeln!(crate::uart(cs), "A\r").unwrap();
86
+        });*/
83 87
         writer.iad(
84 88
             self.audio_control,
85 89
             2,   // Two interfaces (control + streaming).
@@ -219,6 +223,10 @@ impl<B: UsbBus, OUTBUF: AsRef<[u32]>> UsbClass<B> for UsbAudioClass<'_, B, OUTBU
219 223
             Ok(2)
220 224
         })?;*/
221 225
 
226
+        /*interrupt::free(|cs| {
227
+            writeln!(crate::uart(cs), "B\r").unwrap();
228
+        });*/
229
+
222 230
         Ok(())
223 231
     }
224 232
 
@@ -229,7 +237,7 @@ impl<B: UsbBus, OUTBUF: AsRef<[u32]>> UsbClass<B> for UsbAudioClass<'_, B, OUTBU
229 237
 
230 238
     fn reset(&mut self) {
231 239
         // Start sending synchronization data.
232
-        self.endpoint_in_complete(self.audio_out_sync.address());
240
+        //self.endpoint_in_complete(self.audio_out_sync.address());
233 241
     }
234 242
 
235 243
     fn control_out(&mut self, xfer: ControlOut<B>) {
@@ -268,7 +276,7 @@ impl<B: UsbBus, OUTBUF: AsRef<[u32]>> UsbClass<B> for UsbAudioClass<'_, B, OUTBU
268 276
         };
269 277
     }
270 278
 
271
-    fn endpoint_out(&mut self, addr: EndpointAddress) {
279
+    /*fn endpoint_out(&mut self, addr: EndpointAddress) {
272 280
         if addr == self.audio_out.address() {
273 281
             if self.audio_out_buf.is_some() {
274 282
                 // TODO: Write data into buffer, move buffer somewhere else.
@@ -286,7 +294,7 @@ impl<B: UsbBus, OUTBUF: AsRef<[u32]>> UsbClass<B> for UsbAudioClass<'_, B, OUTBU
286 294
             // Immediately write the next sync value.
287 295
             //self.audio_out_sync.write(&self.samples_per_frame).unwrap();
288 296
         }
289
-    }
297
+    }*/
290 298
 }
291 299
 
292 300
 /*use usb_device::class_prelude::*;

Carregando…
Cancelar
Salvar