aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4/src
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2023-12-21 10:02:11 +0000
committerGitHub <[email protected]>2023-12-21 10:02:11 +0000
commit530ead5fdeba97dd7d84798463436d1c75bbe96e (patch)
tree40c027b0f69efe9a9edb9913c0c1122a9b608318 /examples/stm32f4/src
parent8442e72589f47182f8ca1c979c668afc800e5d1e (diff)
parent0acf7b09c3bc9176d00479d601356d8df2537a9b (diff)
Merge pull request #2339 from embassy-rs/make-static-remove
Replace make_static! macro usage with non-macro version
Diffstat (limited to 'examples/stm32f4/src')
-rw-r--r--examples/stm32f4/src/bin/eth.rs13
-rw-r--r--examples/stm32f4/src/bin/usb_ethernet.rs31
2 files changed, 28 insertions, 16 deletions
diff --git a/examples/stm32f4/src/bin/eth.rs b/examples/stm32f4/src/bin/eth.rs
index 088d83c06..17a14aac4 100644
--- a/examples/stm32f4/src/bin/eth.rs
+++ b/examples/stm32f4/src/bin/eth.rs
@@ -14,7 +14,7 @@ use embassy_stm32::time::Hertz;
14use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; 14use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config};
15use embassy_time::Timer; 15use embassy_time::Timer;
16use embedded_io_async::Write; 16use embedded_io_async::Write;
17use static_cell::make_static; 17use static_cell::StaticCell;
18use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
19 19
20bind_interrupts!(struct Irqs { 20bind_interrupts!(struct Irqs {
@@ -63,8 +63,9 @@ async fn main(spawner: Spawner) -> ! {
63 63
64 let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; 64 let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
65 65
66 static PACKETS: StaticCell<PacketQueue<16, 16>> = StaticCell::new();
66 let device = Ethernet::new( 67 let device = Ethernet::new(
67 make_static!(PacketQueue::<16, 16>::new()), 68 PACKETS.init(PacketQueue::<16, 16>::new()),
68 p.ETH, 69 p.ETH,
69 Irqs, 70 Irqs,
70 p.PA1, 71 p.PA1,
@@ -88,11 +89,13 @@ async fn main(spawner: Spawner) -> ! {
88 //}); 89 //});
89 90
90 // Init network stack 91 // Init network stack
91 let stack = &*make_static!(Stack::new( 92 static STACK: StaticCell<Stack<Device>> = StaticCell::new();
93 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
94 let stack = &*STACK.init(Stack::new(
92 device, 95 device,
93 config, 96 config,
94 make_static!(StackResources::<2>::new()), 97 RESOURCES.init(StackResources::<2>::new()),
95 seed 98 seed,
96 )); 99 ));
97 100
98 // Launch network task 101 // Launch network task
diff --git a/examples/stm32f4/src/bin/usb_ethernet.rs b/examples/stm32f4/src/bin/usb_ethernet.rs
index 6bf5b1cba..57ee35e97 100644
--- a/examples/stm32f4/src/bin/usb_ethernet.rs
+++ b/examples/stm32f4/src/bin/usb_ethernet.rs
@@ -14,7 +14,7 @@ use embassy_usb::class::cdc_ncm::embassy_net::{Device, Runner, State as NetState
14use embassy_usb::class::cdc_ncm::{CdcNcmClass, State}; 14use embassy_usb::class::cdc_ncm::{CdcNcmClass, State};
15use embassy_usb::{Builder, UsbDevice}; 15use embassy_usb::{Builder, UsbDevice};
16use embedded_io_async::Write; 16use embedded_io_async::Write;
17use static_cell::make_static; 17use static_cell::StaticCell;
18use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
19 19
20type UsbDriver = Driver<'static, embassy_stm32::peripherals::USB_OTG_FS>; 20type UsbDriver = Driver<'static, embassy_stm32::peripherals::USB_OTG_FS>;
@@ -68,7 +68,8 @@ async fn main(spawner: Spawner) {
68 let p = embassy_stm32::init(config); 68 let p = embassy_stm32::init(config);
69 69
70 // Create the driver, from the HAL. 70 // Create the driver, from the HAL.
71 let ep_out_buffer = &mut make_static!([0; 256])[..]; 71 static OUTPUT_BUFFER: StaticCell<[u8; 256]> = StaticCell::new();
72 let ep_out_buffer = &mut OUTPUT_BUFFER.init([0; 256])[..];
72 let mut config = embassy_stm32::usb_otg::Config::default(); 73 let mut config = embassy_stm32::usb_otg::Config::default();
73 config.vbus_detection = true; 74 config.vbus_detection = true;
74 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer, config); 75 let driver = Driver::new_fs(p.USB_OTG_FS, Irqs, p.PA12, p.PA11, ep_out_buffer, config);
@@ -88,14 +89,18 @@ async fn main(spawner: Spawner) {
88 config.device_protocol = 0x01; 89 config.device_protocol = 0x01;
89 90
90 // Create embassy-usb DeviceBuilder using the driver and config. 91 // Create embassy-usb DeviceBuilder using the driver and config.
92 static DEVICE_DESC: StaticCell<[u8; 256]> = StaticCell::new();
93 static CONFIG_DESC: StaticCell<[u8; 256]> = StaticCell::new();
94 static BOS_DESC: StaticCell<[u8; 256]> = StaticCell::new();
95 static CONTROL_BUF: StaticCell<[u8; 128]> = StaticCell::new();
91 let mut builder = Builder::new( 96 let mut builder = Builder::new(
92 driver, 97 driver,
93 config, 98 config,
94 &mut make_static!([0; 256])[..], 99 &mut DEVICE_DESC.init([0; 256])[..],
95 &mut make_static!([0; 256])[..], 100 &mut CONFIG_DESC.init([0; 256])[..],
96 &mut make_static!([0; 256])[..], 101 &mut BOS_DESC.init([0; 256])[..],
97 &mut [], // no msos descriptors 102 &mut [], // no msos descriptors
98 &mut make_static!([0; 128])[..], 103 &mut CONTROL_BUF.init([0; 128])[..],
99 ); 104 );
100 105
101 // Our MAC addr. 106 // Our MAC addr.
@@ -104,14 +109,16 @@ async fn main(spawner: Spawner) {
104 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88]; 109 let host_mac_addr = [0x88, 0x88, 0x88, 0x88, 0x88, 0x88];
105 110
106 // Create classes on the builder. 111 // Create classes on the builder.
107 let class = CdcNcmClass::new(&mut builder, make_static!(State::new()), host_mac_addr, 64); 112 static STATE: StaticCell<State> = StaticCell::new();
113 let class = CdcNcmClass::new(&mut builder, STATE.init(State::new()), host_mac_addr, 64);
108 114
109 // Build the builder. 115 // Build the builder.
110 let usb = builder.build(); 116 let usb = builder.build();
111 117
112 unwrap!(spawner.spawn(usb_task(usb))); 118 unwrap!(spawner.spawn(usb_task(usb)));
113 119
114 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(make_static!(NetState::new()), our_mac_addr); 120 static NET_STATE: StaticCell<NetState<MTU, 4, 4>> = StaticCell::new();
121 let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(NET_STATE.init(NetState::new()), our_mac_addr);
115 unwrap!(spawner.spawn(usb_ncm_task(runner))); 122 unwrap!(spawner.spawn(usb_ncm_task(runner)));
116 123
117 let config = embassy_net::Config::dhcpv4(Default::default()); 124 let config = embassy_net::Config::dhcpv4(Default::default());
@@ -128,11 +135,13 @@ async fn main(spawner: Spawner) {
128 let seed = u64::from_le_bytes(seed); 135 let seed = u64::from_le_bytes(seed);
129 136
130 // Init network stack 137 // Init network stack
131 let stack = &*make_static!(Stack::new( 138 static STACK: StaticCell<Stack<Device<'static, MTU>>> = StaticCell::new();
139 static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
140 let stack = &*STACK.init(Stack::new(
132 device, 141 device,
133 config, 142 config,
134 make_static!(StackResources::<2>::new()), 143 RESOURCES.init(StackResources::<2>::new()),
135 seed 144 seed,
136 )); 145 ));
137 146
138 unwrap!(spawner.spawn(net_task(stack))); 147 unwrap!(spawner.spawn(net_task(stack)));