diff options
| author | Ulf Lilleengen <[email protected]> | 2023-12-21 10:02:11 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-12-21 10:02:11 +0000 |
| commit | 530ead5fdeba97dd7d84798463436d1c75bbe96e (patch) | |
| tree | 40c027b0f69efe9a9edb9913c0c1122a9b608318 /examples/stm32l5/src | |
| parent | 8442e72589f47182f8ca1c979c668afc800e5d1e (diff) | |
| parent | 0acf7b09c3bc9176d00479d601356d8df2537a9b (diff) | |
Merge pull request #2339 from embassy-rs/make-static-remove
Replace make_static! macro usage with non-macro version
Diffstat (limited to 'examples/stm32l5/src')
| -rw-r--r-- | examples/stm32l5/src/bin/usb_ethernet.rs | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index 0b0a0e2db..214235bd5 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs | |||
| @@ -15,7 +15,7 @@ use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; | |||
| 15 | use embassy_usb::{Builder, UsbDevice}; | 15 | use embassy_usb::{Builder, UsbDevice}; |
| 16 | use embedded_io_async::Write; | 16 | use embedded_io_async::Write; |
| 17 | use rand_core::RngCore; | 17 | use rand_core::RngCore; |
| 18 | use static_cell::make_static; | 18 | use static_cell::StaticCell; |
| 19 | use {defmt_rtt as _, panic_probe as _}; | 19 | use {defmt_rtt as _, panic_probe as _}; |
| 20 | 20 | ||
| 21 | type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; | 21 | type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; |
| @@ -76,14 +76,18 @@ async fn main(spawner: Spawner) { | |||
| 76 | config.device_protocol = 0x01; | 76 | config.device_protocol = 0x01; |
| 77 | 77 | ||
| 78 | // Create embassy-usb DeviceBuilder using the driver and config. | 78 | // Create embassy-usb DeviceBuilder using the driver and config. |
| 79 | static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new(); | ||
| 80 | static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new(); | ||
| 81 | static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new(); | ||
| 82 | static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new(); | ||
| 79 | let mut builder = Builder::new( | 83 | let mut builder = Builder::new( |
| 80 | driver, | 84 | driver, |
| 81 | config, | 85 | config, |
| 82 | &mut make_static!([0; 256])[..], | 86 | &mut DEVICE_DESC.init([0; 256])[..], |
| 83 | &mut make_static!([0; 256])[..], | 87 | &mut CONFIG_DESC.init([0; 256])[..], |
| 84 | &mut make_static!([0; 256])[..], | 88 | &mut BOS_DESC.init([0; 256])[..], |
| 85 | &mut [], // no msos descriptors | 89 | &mut [], // no msos descriptors |
| 86 | &mut make_static!([0; 128])[..], | 90 | &mut CONTROL_BUF.init([0; 128])[..], |
| 87 | ); | 91 | ); |
| 88 | 92 | ||
| 89 | // Our MAC addr. | 93 | // Our MAC addr. |
| @@ -92,14 +96,16 @@ async fn main(spawner: Spawner) { | |||
| 92 | let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; | 96 | let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; |
| 93 | 97 | ||
| 94 | // Create classes on the builder. | 98 | // Create classes on the builder. |
| 95 | let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); | 99 | static STATE: StaticCell<State> = StaticCell::new(); |
| 100 | let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64); | ||
| 96 | 101 | ||
| 97 | // Build the builder. | 102 | // Build the builder. |
| 98 | let usb = builder.build(); | 103 | let usb = builder.build(); |
| 99 | 104 | ||
| 100 | unwrap!(spawner.spawn(usb_task(usb))); | 105 | unwrap!(spawner.spawn(usb_task(usb))); |
| 101 | 106 | ||
| 102 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); | 107 | static NET_STATE: StaticCell<NetState<MTU, 4, 4>> = StaticCell::new(); |
| 108 | let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(NET_STATE.init(NetState::new()), our_mac_addr); | ||
| 103 | unwrap!(spawner.spawn(usb_ncm_task(runner))); | 109 | unwrap!(spawner.spawn(usb_ncm_task(runner))); |
| 104 | 110 | ||
| 105 | let config = embassy_net::Config::dhcpv4(Default::default()); | 111 | let config = embassy_net::Config::dhcpv4(Default::default()); |
| @@ -114,11 +120,13 @@ async fn main(spawner: Spawner) { | |||
| 114 | let seed = rng.next_u64(); | 120 | let seed = rng.next_u64(); |
| 115 | 121 | ||
| 116 | // Init network stack | 122 | // Init network stack |
| 117 | let stack = &*make_static!(Stack::new( | 123 | static STACK: StaticCell<Stack<Device<'static, MTU>>> = StaticCell::new(); |
| 124 | static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new(); | ||
| 125 | let stack = &*STACK.init(Stack::new( | ||
| 118 | device, | 126 | device, |
| 119 | config, | 127 | config, |
| 120 | make_static!(StackResources::<2>::new()), | 128 | RESOURCES.init(StackResources::<2>::new()), |
| 121 | seed | 129 | seed, |
| 122 | )); | 130 | )); |
| 123 | 131 | ||
| 124 | unwrap!(spawner.spawn(net_task(stack))); | 132 | unwrap!(spawner.spawn(net_task(stack))); |
