diff options
Diffstat (limited to 'examples/rp/src/bin/usb_ethernet.rs')
| -rw-r--r-- | examples/rp/src/bin/usb_ethernet.rs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/examples/rp/src/bin/usb_ethernet.rs b/examples/rp/src/bin/usb_ethernet.rs index cc63029fb..01f0d5967 100644 --- a/examples/rp/src/bin/usb_ethernet.rs +++ b/examples/rp/src/bin/usb_ethernet.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | #![no_std] | 5 | #![no_std] |
| 6 | #![no_main] | 6 | #![no_main] |
| 7 | #![feature(type_alias_impl_trait)] | ||
| 8 | 7 | ||
| 9 | use defmt::*; | 8 | use defmt::*; |
| 10 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| @@ -17,7 +16,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState | |||
| 17 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; | 16 | use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; |
| 18 | use embassy_usb::{Builder, Config, UsbDevice}; | 17 | use embassy_usb::{Builder, Config, UsbDevice}; |
| 19 | use embedded_io_async::Write; | 18 | use embedded_io_async::Write; |
| 20 | use static_cell::make_static; | 19 | use static_cell::StaticCell; |
| 21 | use {defmt_rtt as _, panic_probe as _}; | 20 | use {defmt_rtt as _, panic_probe as _}; |
| 22 | 21 | ||
| 23 | bind_interrupts!(struct Irqs { | 22 | bind_interrupts!(struct Irqs { |
| @@ -65,14 +64,18 @@ async fn main(spawner: Spawner) { | |||
| 65 | config.device_protocol = 0x01; | 64 | config.device_protocol = 0x01; |
| 66 | 65 | ||
| 67 | // Create embassy-usb DeviceBuilder using the driver and config. | 66 | // Create embassy-usb DeviceBuilder using the driver and config. |
| 67 | static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); | ||
| 68 | static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); | ||
| 69 | static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); | ||
| 70 | static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); | ||
| 68 | let mut builder = Builder::new( | 71 | let mut builder = Builder::new( |
| 69 | driver, | 72 | driver, |
| 70 | config, | 73 | config, |
| 71 | &mut make_static!([0; 256])[..], | 74 | &mut DEVICE_DESC.init([0; 256])[..], |
| 72 | &mut make_static!([0; 256])[..], | 75 | &mut CONFIG_DESC.init([0; 256])[..], |
| 73 | &mut make_static!([0; 256])[..], | 76 | &mut BOS_DESC.init([0; 256])[..], |
| 74 | &mut [], // no msos descriptors | 77 | &mut [], // no msos descriptors |
| 75 | &mut make_static!([0; 128])[..], | 78 | &mut CONTROL_BUF.init([0; 128])[..], |
| 76 | ); | 79 | ); |
| 77 | 80 | ||
| 78 | // Our MAC addr. | 81 | // Our MAC addr. |
| @@ -81,14 +84,16 @@ async fn main(spawner: Spawner) { | |||
| 81 | let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; | 84 | let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; |
| 82 | 85 | ||
| 83 | // Create classes on the builder. | 86 | // Create classes on the builder. |
| 84 | let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); | 87 | static STATE: StaticCell<State> = StaticCell::new(); |
| 88 | let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64); | ||
| 85 | 89 | ||
| 86 | // Build the builder. | 90 | // Build the builder. |
| 87 | let usb = builder.build(); | 91 | let usb = builder.build(); |
| 88 | 92 | ||
| 89 | unwrap!(spawner.spawn(usb_task(usb))); | 93 | unwrap!(spawner.spawn(usb_task(usb))); |
| 90 | 94 | ||
| 91 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); | 95 | static NET_STATE: StaticCell<NetState<MTU, 4, 4>> = StaticCell::new(); |
| 96 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(NET_STATE.init(NetState::new()), our_mac_addr); | ||
| 92 | unwrap!(spawner.spawn(usb_ncm_task(runner))); | 97 | unwrap!(spawner.spawn(usb_ncm_task(runner))); |
| 93 | 98 | ||
| 94 | let config = embassy_net::Config::dhcpv4(Default::default()); | 99 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| @@ -102,11 +107,13 @@ async fn main(spawner: Spawner) { | |||
| 102 | let seed = 1234; // guaranteed random, chosen by a fair dice roll | 107 | let seed = 1234; // guaranteed random, chosen by a fair dice roll |
| 103 | 108 | ||
| 104 | // Init network stack | 109 | // Init network stack |
| 105 | let stack = &*make_static!(Stack::new( | 110 | static STACK: StaticCell<Stack<Device<'static, MTU>>> = StaticCell::new(); |
| 111 | static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new(); | ||
| 112 | let stack = &*STACK.init(Stack::new( | ||
| 106 | device, | 113 | device, |
| 107 | config, | 114 | config, |
| 108 | make_static!(StackResources::<2>::new()), | 115 | RESOURCES.init(StackResources::<2>::new()), |
| 109 | seed | 116 | seed, |
| 110 | )); | 117 | )); |
| 111 | 118 | ||
| 112 | unwrap!(spawner.spawn(net_task(stack))); | 119 | unwrap!(spawner.spawn(net_task(stack))); |
