|
|
@@ -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
|
///
|