Skip to content

Commit 04df62f

Browse files
bors[bot]AlyoshaVasilievaadamgreig
authored
Merge #248 #249
248: Make more CRC methods const r=richardeoin a=AlyoshaVasilieva The only one that has any significant effect is Config's `reflect` since it's now usable when you're making a const Config. 249: Ethernet: Disable RA in filtering, fix MAC address setting r=richardeoin a=adamgreig The MACA0LR/HR registers hold the address the MAC can use for filtering received packets, but they're only loaded into the MAC core when LR is written to. Currently the ethernet driver writes to LR first and then HR, so the MAC core doesn't get the bits from HR, which breaks filtering. I believe that's why the RA (receive-all) bit has been set, which bypasses the filtering. This PR fixes writing the MAC address and disables the no-longer-required RA bit. I've tested this with an H745 nucleo board and the ethernet-rtic-stm32h747i-disco example, changing just the GPIO setup to match the Nucleo. See also embassy-rs/embassy#389. Co-authored-by: Malloc Voidstar <1284317+AlyoshaVasilieva@users.noreply.github.com> Co-authored-by: Adam Greig <adam@adamgreig.com>
3 parents 6b59b8c + 8d226fd + 842c6d7 commit 04df62f

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/crc.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl Polynomial {
210210
}
211211

212212
/// Return POLYSIZE register value.
213-
fn polysize(self) -> u8 {
213+
const fn polysize(self) -> u8 {
214214
(match self.0 {
215215
Poly::B7(_) => crc::cr::POLYSIZE_A::POLYSIZE7,
216216
Poly::B8(_) => crc::cr::POLYSIZE_A::POLYSIZE8,
@@ -220,7 +220,7 @@ impl Polynomial {
220220
}
221221

222222
/// Return POL register value.
223-
fn pol(self) -> u32 {
223+
const fn pol(self) -> u32 {
224224
match self.0 {
225225
Poly::B7(pol) | Poly::B8(pol) => pol as u32,
226226
Poly::B16(pol) => pol as u32,
@@ -229,7 +229,7 @@ impl Polynomial {
229229
}
230230

231231
/// Return mask for output XOR according to size.
232-
fn xor_mask(self) -> u32 {
232+
const fn xor_mask(self) -> u32 {
233233
match self.0 {
234234
Poly::B7(_) => 0x7F,
235235
Poly::B8(_) => 0xFF,
@@ -362,8 +362,7 @@ impl Config {
362362
/// Set whether to reflect the CRC. When enabled, reflection is
363363
/// [`BitReversal::Byte`] and output reversal enabled. This is simply
364364
/// a convenience function as many CRC algorithms call for this.
365-
pub fn reflect(self, reflect: bool) -> Self {
366-
// Rust 1.46 and higher: This function can be const.
365+
pub const fn reflect(self, reflect: bool) -> Self {
367366
if reflect {
368367
self.reverse_input(Some(BitReversal::Byte))
369368
.reverse_output(true)

src/ethernet/eth.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,14 @@ pub unsafe fn new_unchecked<'a>(
478478
.dcrcc()
479479
.clear_bit()
480480
});
481-
// Set the MAC address
481+
// Set the MAC address.
482+
// Writes to LR trigger both registers to be loaded into the MAC,
483+
// so write to LR last.
484+
eth_mac.maca0hr.write(|w| {
485+
w.addrhi().bits(
486+
u16::from(mac_addr.0[4]) | (u16::from(mac_addr.0[5]) << 8),
487+
)
488+
});
482489
eth_mac.maca0lr.write(|w| {
483490
w.addrlo().bits(
484491
u32::from(mac_addr.0[0])
@@ -487,14 +494,6 @@ pub unsafe fn new_unchecked<'a>(
487494
| (u32::from(mac_addr.0[3]) << 24),
488495
)
489496
});
490-
eth_mac.maca0hr.write(
491-
|w| {
492-
w.addrhi().bits(
493-
u16::from(mac_addr.0[4]) | (u16::from(mac_addr.0[5]) << 8),
494-
)
495-
}, //.sa().clear_bit()
496-
//.mbc().bits(0b000000)
497-
);
498497
// frame filter register
499498
eth_mac.macpfr.modify(|_, w| {
500499
w.dntu()
@@ -523,7 +522,7 @@ pub unsafe fn new_unchecked<'a>(
523522
.clear_bit()
524523
// Receive All
525524
.ra()
526-
.set_bit()
525+
.clear_bit()
527526
// Promiscuous mode
528527
.pr()
529528
.clear_bit()

0 commit comments

Comments
 (0)