2 Коміти

Автор SHA1 Повідомлення Дата
  Mathias Gottschlag 69dce1af2a WIP. 4 роки тому
  Mathias Gottschlag c0b41b7242 WIP. 4 роки тому
8 змінених файлів з 131 додано та 17 видалено
  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 Переглянути файл

9
     "-C", "inline-threshold=5",
9
     "-C", "inline-threshold=5",
10
     "-C", "no-vectorize-loops",
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 Переглянути файл

180
  "syn",
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
 [[package]]
192
 [[package]]
184
 name = "crc-any"
193
 name = "crc-any"
185
 version = "2.4.0"
194
 version = "2.4.0"
547
 ]
556
 ]
548
 
557
 
549
 [[package]]
558
 [[package]]
550
-name = "panic-halt"
551
-version = "0.2.0"
559
+name = "panic-semihosting"
560
+version = "0.5.6"
552
 source = "registry+https://github.com/rust-lang/crates.io-index"
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
 [[package]]
568
 [[package]]
556
 name = "paste"
569
 name = "paste"
752
  "cortex-m",
765
  "cortex-m",
753
  "cortex-m-rt",
766
  "cortex-m-rt",
754
  "cortex-m-rtic",
767
  "cortex-m-rtic",
768
+ "cortex-m-semihosting",
755
  "embedded-hal",
769
  "embedded-hal",
756
  "embedded-time",
770
  "embedded-time",
757
  "nb 1.0.0",
771
  "nb 1.0.0",
758
- "panic-halt",
772
+ "panic-semihosting",
759
  "pio",
773
  "pio",
760
  "pio-proc",
774
  "pio-proc",
761
  "rp2040-boot2",
775
  "rp2040-boot2",

+ 9
- 1
Cargo.toml Переглянути файл

10
 cortex-m = "0.7.2"
10
 cortex-m = "0.7.2"
11
 cortex-m-rt = "0.7"
11
 cortex-m-rt = "0.7"
12
 cortex-m-rtic = "0.6.0-alpha.5"
12
 cortex-m-rtic = "0.6.0-alpha.5"
13
+cortex-m-semihosting = "0.3.7"
13
 embedded-hal ="0.2.5"
14
 embedded-hal ="0.2.5"
14
 embedded-time = "0.12.0"
15
 embedded-time = "0.12.0"
15
 nb = "1.0"
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
 pio = { git = "https://github.com/rp-rs/pio-rs.git", branch = "main" }
20
 pio = { git = "https://github.com/rp-rs/pio-rs.git", branch = "main" }
18
 pio-proc = { git = "https://github.com/rp-rs/pio-rs.git", branch = "main" }
21
 pio-proc = { git = "https://github.com/rp-rs/pio-rs.git", branch = "main" }
19
 #rp2040-hal = { git = "https://github.com/rp-rs/rp-hal.git", features = ["rt"] }
22
 #rp2040-hal = { git = "https://github.com/rp-rs/rp-hal.git", features = ["rt"] }
26
 
29
 
27
 [patch.crates-io]
30
 [patch.crates-io]
28
 usb-device = { path = "../usb-device" }
31
 usb-device = { path = "../usb-device" }
32
+
33
+[profile]
34
+[profile.release]
35
+debug = true
36
+lto = true

+ 6
- 0
openocd.cfg Переглянути файл

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 Переглянути файл

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 Переглянути файл

1
 #![no_std]
1
 #![no_std]
2
 #![no_main]
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
 mod audio_buffer;
10
 mod audio_buffer;
7
 mod i2s_master;
11
 mod i2s_master;
12
 #[used]
16
 #[used]
13
 pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER;
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
 #[rtic::app(device = rp2040_hal::pac, peripherals = true, dispatchers = [RTC_IRQ, XIP_IRQ])]
32
 #[rtic::app(device = rp2040_hal::pac, peripherals = true, dispatchers = [RTC_IRQ, XIP_IRQ])]
16
 mod app {
33
 mod app {
17
     use embedded_hal::digital::v2::OutputPin;
34
     use embedded_hal::digital::v2::OutputPin;
23
     use crate::audio_buffer::AudioBuffer;
40
     use crate::audio_buffer::AudioBuffer;
24
     use crate::i2s_master::I2sMaster;
41
     use crate::i2s_master::I2sMaster;
25
     use crate::usb::Usb;
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
     use rp2040_hal::dma::{DMAExt, SingleChannel, CH0};
47
     use rp2040_hal::dma::{DMAExt, SingleChannel, CH0};
28
     use rp2040_hal::gpio::bank0::{Gpio0, Gpio1, Gpio3, Gpio6};
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
     use rp2040_hal::pio::{PIOExt, PIO0SM0};
51
     use rp2040_hal::pio::{PIOExt, PIO0SM0};
31
     use rp2040_hal::pll::common_configs::PLL_USB_48MHZ;
52
     use rp2040_hal::pll::common_configs::PLL_USB_48MHZ;
32
     use rp2040_hal::pll::{setup_pll_blocking, PLLConfig};
53
     use rp2040_hal::pll::{setup_pll_blocking, PLLConfig};
33
     use rp2040_hal::sio::Sio;
54
     use rp2040_hal::sio::Sio;
34
     use rp2040_hal::timer::Timer;
55
     use rp2040_hal::timer::Timer;
56
+    //use rp2040_hal::uart;
35
     use rp2040_hal::usb::UsbBus;
57
     use rp2040_hal::usb::UsbBus;
36
     use rp2040_hal::watchdog::Watchdog;
58
     use rp2040_hal::watchdog::Watchdog;
37
     use rp2040_hal::xosc::setup_xosc_blocking;
59
     use rp2040_hal::xosc::setup_xosc_blocking;
47
     };
69
     };
48
 
70
 
49
     static AUDIO_BUFFER: AudioBuffer<4> = AudioBuffer::new();
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
     #[monotonic(binds = SysTick, default = true)]
81
     #[monotonic(binds = SysTick, default = true)]
52
     type SystickMono = Systick<100>;
82
     type SystickMono = Systick<100>;
116
         let mut led = pins.gpio25.into_push_pull_output();
146
         let mut led = pins.gpio25.into_push_pull_output();
117
         led.set_low().ok().unwrap();
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
         // We need a timer so that we can determine the USB SOF frequency for asynchronous USB
166
         // We need a timer so that we can determine the USB SOF frequency for asynchronous USB
120
         // audio.
167
         // audio.
121
         let timer = Timer::new(c.device.TIMER, &mut resets);
168
         let timer = Timer::new(c.device.TIMER, &mut resets);
192
         }
239
         }
193
     }
240
     }
194
 
241
 
195
-    /// DMA interrupt handler.
242
+    /*/// DMA interrupt handler.
196
     ///
243
     ///
197
     /// DMA interrupts need to have highest priority as we need to quickly restart the DMA transfer
244
     /// DMA interrupts need to have highest priority as we need to quickly restart the DMA transfer
198
     /// to ensure that the PIO FIFO always contains data.
245
     /// to ensure that the PIO FIFO always contains data.
217
             }
264
             }
218
             write.write_finished(packet, cs);
265
             write.write_finished(packet, cs);
219
         });
266
         });
220
-    }
267
+    }*/
221
 
268
 
222
     /// USB interrupt handler.
269
     /// USB interrupt handler.
223
     ///
270
     ///

+ 3
- 0
src/usb.rs Переглянути файл

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

+ 14
- 6
src/usb_audio.rs Переглянути файл

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

Завантаження…
Відмінити
Зберегти