Skip to content

Commit 7ea8593

Browse files
committed
Avoid creating references to packed fields
Compiler is not able to verify these packed fields are aligned
1 parent 99b3ef3 commit 7ea8593

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/ethernet/eth.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ impl<const TD: usize> TDesRing<TD> {
119119
/// will be stored in the descriptors, so ensure the TDesRing is
120120
/// not moved after initialisation.
121121
pub fn init(&mut self) {
122-
for td in self.td.iter_mut() {
123-
td.init();
122+
for x in 0..TD {
123+
self.td[x].init();
124124
}
125125
self.tdidx = 0;
126126

@@ -129,9 +129,8 @@ impl<const TD: usize> TDesRing<TD> {
129129
unsafe {
130130
let dma = &*stm32::ETHERNET_DMA::ptr();
131131
dma.dmactx_dlar
132-
.write(|w| w.bits(&self.td as *const _ as u32));
133-
dma.dmactx_rlr
134-
.write(|w| w.tdrl().bits(self.td.len() as u16 - 1));
132+
.write(|w| w.bits(&self.td[0] as *const _ as u32));
133+
dma.dmactx_rlr.write(|w| w.tdrl().bits(TD as u16 - 1));
135134
dma.dmactx_dtpr
136135
.write(|w| w.bits(&self.td[0] as *const _ as u32));
137136
}
@@ -265,18 +264,17 @@ impl<const RD: usize> RDesRing<RD> {
265264
/// will be stored in the descriptors, so ensure the RDesRing is
266265
/// not moved after initialisation.
267266
pub fn init(&mut self) {
268-
for rd in self.rd.iter_mut() {
269-
rd.init();
267+
for x in 0..RD {
268+
self.rd[x].init();
270269
}
271270
self.rdidx = 0;
272271

273272
// Initialise pointers in the DMA engine
274273
unsafe {
275274
let dma = &*stm32::ETHERNET_DMA::ptr();
276275
dma.dmacrx_dlar
277-
.write(|w| w.bits(&self.rd as *const _ as u32));
278-
dma.dmacrx_rlr
279-
.write(|w| w.rdrl().bits(self.rd.len() as u16 - 1));
276+
.write(|w| w.bits(&self.rd[0] as *const _ as u32));
277+
dma.dmacrx_rlr.write(|w| w.rdrl().bits(RD as u16 - 1));
280278
}
281279

282280
// Release descriptors to the DMA engine

0 commit comments

Comments
 (0)