Skip to content

Commit a3bfe45

Browse files
CompositeEMAC inits!
1 parent bd555d9 commit a3bfe45

File tree

8 files changed

+240
-145
lines changed

8 files changed

+240
-145
lines changed

connectivity/drivers/emac/TARGET_STM/STM32EthMACv2.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
using namespace std::chrono_literals;
2525

26+
#define TRACE_GROUP "STEMACv2"
27+
2628
// Defined in stm32_eth_init.c
2729
extern "C" void EthInitPinmappings();
2830
extern "C" void EthDeinitPinmappings();
@@ -114,6 +116,11 @@ namespace mbed {
114116
base->DMACSR = ETH_DMACSR_RPS;
115117
}
116118

119+
void STM32EthMacV2::RxDMA::stopDMA() {
120+
// Disable Rx DMA
121+
base->DMACTCR &= ~ETH_DMACRCR_SR;
122+
}
123+
117124
void STM32EthMacV2::RxDMA::returnDescriptor(const size_t descIdx, uint8_t * const buffer) {
118125
auto & desc = rxDescs[descIdx];
119126

@@ -395,6 +402,8 @@ namespace mbed {
395402
// Get result
396403
result = base->MACMDIODR & ETH_MACMDIODR_MD_Msk;
397404

405+
tr_debug("MDIO read devAddr %" PRIu8 ", regAddr 0x%" PRIx8 " -> 0x%" PRIx16, devAddr, regAddr, result);
406+
398407
return ErrCode::SUCCESS;
399408
}
400409

@@ -427,6 +436,8 @@ namespace mbed {
427436
return ErrCode::TIMEOUT;
428437
}
429438

439+
tr_debug("MDIO write devAddr %" PRIu8 ", regAddr 0x%" PRIx8 " <- 0x%" PRIx16, devAddr, regAddr, data);
440+
430441
return ErrCode::SUCCESS;
431442
}
432443

@@ -472,6 +483,28 @@ namespace mbed {
472483
return ErrCode::SUCCESS;
473484
}
474485

486+
void STM32EthMacV2::MACDriver::setPassAllMcast(bool pass) {
487+
if(pass)
488+
{
489+
base->MACPFR |= ETH_MACPFR_PM;
490+
}
491+
else
492+
{
493+
base->MACPFR &= ~ETH_MACPFR_PM;
494+
}
495+
}
496+
497+
void STM32EthMacV2::MACDriver::setPromiscuous(bool enable) {
498+
if(enable)
499+
{
500+
base->MACPFR |= ETH_MACPFR_PR;
501+
}
502+
else
503+
{
504+
base->MACPFR &= ~ETH_MACPFR_PR;
505+
}
506+
}
507+
475508
STM32EthMacV2 * STM32EthMacV2::instance = nullptr;
476509

477510
STM32EthMacV2::STM32EthMacV2():
@@ -514,5 +547,11 @@ namespace mbed {
514547
"STM32 EMAC v2: Hardware reports fatal DMA error\n");
515548
}
516549
}
550+
}
517551

552+
// Provide default EMAC driver
553+
MBED_WEAK EMAC &EMAC::get_default_instance()
554+
{
555+
static mbed::STM32EthMacV2 emac;
556+
return emac;
518557
}

connectivity/drivers/emac/TARGET_STM/mbed_lib.json5

Lines changed: 0 additions & 8 deletions
This file was deleted.

connectivity/drivers/emac/include/CompositeEMAC.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ class CompositeEMAC : public EMAC
173173
/**
174174
* @brief Add a multicast MAC address that should be accepted by the MAC.
175175
*
176+
* \note Only a maximum of \c nsapi.emac-max-mcast-subscribes multicast addresses will be subscribed to
177+
* at once by the upper layer. If the application tried to subscribe to more than that, CEMAC will fall
178+
* back to enabling pass all mcast.
179+
*
176180
* @param mac MAC address to accept
177181
*
178182
* @return Error code or success
@@ -193,7 +197,7 @@ class CompositeEMAC : public EMAC
193197
*
194198
* @param pass True to pass all mcasts, false otherwise
195199
*/
196-
virtual void setPassAllMcast(bool pass);
200+
virtual void setPassAllMcast(bool pass) = 0;
197201

198202
/**
199203
* @brief Set promiscuous mode (where the Eth MAC passes all traffic up to the application, regardless
@@ -203,7 +207,7 @@ class CompositeEMAC : public EMAC
203207
*
204208
* @param enable True to pass all traffic, false otherwise
205209
*/
206-
virtual void setPromiscuous(bool enable);
210+
virtual void setPromiscuous(bool enable) = 0;
207211
};
208212

209213
/**
@@ -342,10 +346,10 @@ class CompositeEMAC : public EMAC
342346
EMACMemoryManager * memory_manager = nullptr;
343347

344348
// Instances of each of the 4 component classes
345-
MACDriver & mac;
346-
PhyDriver & phy;
347-
TxDMA & txDMA;
349+
PhyDriver * phy = nullptr;
348350
RxDMA & rxDMA;
351+
TxDMA & txDMA;
352+
MACDriver & mac;
349353

350354
// State of the MAC
351355
enum class PowerState {

0 commit comments

Comments
 (0)