aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThales Fragoso <[email protected]>2021-06-11 11:51:51 -0300
committerDario Nieuwenhuis <[email protected]>2021-06-16 16:48:35 +0200
commit6daa55a897ec886f34ceb9e7e7026c44c109989b (patch)
tree9c1bf3db32996a44d71ac97f09a6ce6a9de79e7e
parent0b42e12604bace0839d488b345baea4380583351 (diff)
eth-v2: Fix setting the registers for the descriptors
Also, the interrupts are set to 1 to clear, the manual could have helped with that one...
-rw-r--r--embassy-stm32/src/eth/v2/descriptors.rs13
-rw-r--r--embassy-stm32/src/eth/v2/mod.rs16
2 files changed, 17 insertions, 12 deletions
diff --git a/embassy-stm32/src/eth/v2/descriptors.rs b/embassy-stm32/src/eth/v2/descriptors.rs
index 0c0046704..4ce90d1b5 100644
--- a/embassy-stm32/src/eth/v2/descriptors.rs
+++ b/embassy-stm32/src/eth/v2/descriptors.rs
@@ -102,10 +102,10 @@ impl<const N: usize> TDesRing<N> {
102 let dma = ETH.ethernet_dma(); 102 let dma = ETH.ethernet_dma();
103 103
104 dma.dmactx_dlar() 104 dma.dmactx_dlar()
105 .write(|w| w.set_tdesla(&self.td as *const _ as u32)); 105 .write(|w| w.0 = &self.td as *const _ as u32);
106 dma.dmactx_rlr().write(|w| w.set_tdrl((N as u16) - 1)); 106 dma.dmactx_rlr().write(|w| w.set_tdrl((N as u16) - 1));
107 dma.dmactx_dtpr() 107 dma.dmactx_dtpr()
108 .write(|w| w.set_tdt(&self.td[0] as *const _ as u32)); 108 .write(|w| w.0 = &self.td[0] as *const _ as u32);
109 } 109 }
110 } 110 }
111 111
@@ -148,7 +148,7 @@ impl<const N: usize> TDesRing<N> {
148 unsafe { 148 unsafe {
149 ETH.ethernet_dma() 149 ETH.ethernet_dma()
150 .dmactx_dtpr() 150 .dmactx_dtpr()
151 .write(|w| w.set_tdt(&self.td[x] as *const _ as u32)); 151 .write(|w| w.0 = &self.td[x] as *const _ as u32);
152 } 152 }
153 self.tdidx = x; 153 self.tdidx = x;
154 Ok(()) 154 Ok(())
@@ -279,8 +279,7 @@ impl<const N: usize> RDesRing<N> {
279 unsafe { 279 unsafe {
280 let dma = ETH.ethernet_dma(); 280 let dma = ETH.ethernet_dma();
281 281
282 dma.dmacrx_dlar() 282 dma.dmacrx_dlar().write(|w| w.0 = self.rd.as_ptr() as u32);
283 .write(|w| w.set_rdesla(self.rd.as_ptr() as u32));
284 dma.dmacrx_rlr().write(|w| w.set_rdrl((N as u16) - 1)); 283 dma.dmacrx_rlr().write(|w| w.set_rdrl((N as u16) - 1));
285 284
286 // We manage to allocate all buffers, set the index to the last one, that means 285 // We manage to allocate all buffers, set the index to the last one, that means
@@ -290,7 +289,7 @@ impl<const N: usize> RDesRing<N> {
290 let tail_ptr = &self.rd[last_index] as *const _ as u32; 289 let tail_ptr = &self.rd[last_index] as *const _ as u32;
291 fence(Ordering::Release); 290 fence(Ordering::Release);
292 291
293 dma.dmacrx_dtpr().write(|w| w.set_rdt(tail_ptr)); 292 dma.dmacrx_dtpr().write(|w| w.0 = tail_ptr);
294 } 293 }
295 } 294 }
296 295
@@ -340,7 +339,7 @@ impl<const N: usize> RDesRing<N> {
340 unsafe { 339 unsafe {
341 ETH.ethernet_dma() 340 ETH.ethernet_dma()
342 .dmacrx_dtpr() 341 .dmacrx_dtpr()
343 .write(|w| w.set_rdt(&self.rd[self.tail_idx] as *const _ as u32)); 342 .write(|w| w.0 = &self.rd[self.tail_idx] as *const _ as u32);
344 } 343 }
345 344
346 self.tail_idx = (self.tail_idx + 1) % N; 345 self.tail_idx = (self.tail_idx + 1) % N;
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs
index 4c68294bc..ce5f25ebd 100644
--- a/embassy-stm32/src/eth/v2/mod.rs
+++ b/embassy-stm32/src/eth/v2/mod.rs
@@ -116,9 +116,13 @@ impl<'d, P: PHY, const TX: usize, const RX: usize> Ethernet<'d, P, TX, RX> {
116 mtl.mtltx_qomr().modify(|w| w.set_tsf(true)); 116 mtl.mtltx_qomr().modify(|w| w.set_tsf(true));
117 117
118 // TODO: Address aligned beats plus fixed burst ? 118 // TODO: Address aligned beats plus fixed burst ?
119 dma.dmactx_cr().modify(|w| w.set_txpbl(1)); // 32 ? 119 dma.dmasbmr().modify(|w| {
120 w.set_aal(true);
121 w.set_fb(true);
122 });
123 dma.dmactx_cr().modify(|w| w.set_txpbl(32)); // 32 ?
120 dma.dmacrx_cr().modify(|w| { 124 dma.dmacrx_cr().modify(|w| {
121 w.set_rxpbl(1); // 32 ? 125 w.set_rxpbl(32); // 32 ?
122 w.set_rbsz(MTU as u16); 126 w.set_rbsz(MTU as u16);
123 }); 127 });
124 } 128 }
@@ -162,7 +166,8 @@ impl<'d, P: PHY, const TX: usize, const RX: usize> Ethernet<'d, P, TX, RX> {
162 pub fn init(self: Pin<&mut Self>) { 166 pub fn init(self: Pin<&mut Self>) {
163 // NOTE(unsafe) We won't move this 167 // NOTE(unsafe) We won't move this
164 let this = unsafe { self.get_unchecked_mut() }; 168 let this = unsafe { self.get_unchecked_mut() };
165 let mutex = unsafe { Pin::new_unchecked(&mut this.state) }; 169 let mut mutex = unsafe { Pin::new_unchecked(&mut this.state) };
170 mutex.as_mut().register_interrupt();
166 171
167 mutex.with(|s, _| { 172 mutex.with(|s, _| {
168 s.desc_ring.init(); 173 s.desc_ring.init();
@@ -360,8 +365,9 @@ impl<'d, const TX: usize, const RX: usize> PeripheralState for Inner<'d, TX, RX>
360 let dma = ETH.ethernet_dma(); 365 let dma = ETH.ethernet_dma();
361 366
362 dma.dmacsr().modify(|w| { 367 dma.dmacsr().modify(|w| {
363 w.set_ti(false); 368 w.set_ti(true);
364 w.set_ri(false); 369 w.set_ri(true);
370 w.set_nis(true);
365 }); 371 });
366 // Delay two peripheral's clock 372 // Delay two peripheral's clock
367 dma.dmacsr().read(); 373 dma.dmacsr().read();