Skip to content

Commit af891c9

Browse files
Almost working! Just missing memory freed callback
1 parent 1613a25 commit af891c9

File tree

7 files changed

+22
-22
lines changed

7 files changed

+22
-22
lines changed

connectivity/drivers/emac/TARGET_STM/STM32EthMACv2.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ namespace mbed {
9494

9595
// Move tail pointer register to point to the descriptor after this descriptor.
9696
// This tells the MAC to transmit until it reaches the given descriptor, then stop.
97-
base->DMACTDTPR = reinterpret_cast<uint32_t>(&txDescs[txSendIndex]);
97+
const auto nextDescIdx = (descIdx + 1) % MBED_CONF_NSAPI_EMAC_TX_NUM_DESCS;
98+
base->DMACTDTPR = reinterpret_cast<uint32_t>(&txDescs[nextDescIdx]);
9899
}
99100

100101
void STM32EthMacV2::RxDMA::startDMA()
@@ -147,9 +148,9 @@ namespace mbed {
147148
base->DMACRDTPR = reinterpret_cast<uint32_t>(&rxDescs[nextDescIdx]);
148149
}
149150

150-
size_t STM32EthMacV2::RxDMA::getTotalLen(const size_t firstDescIdx) {
151-
// Total length of the packet is in the first descriptor
152-
return rxDescs[firstDescIdx].formats.fromDMA.pktLength;
151+
size_t STM32EthMacV2::RxDMA::getTotalLen(const size_t firstDescIdx, const size_t lastDescIdx) {
152+
// Total length of the packet is in the last descriptor
153+
return rxDescs[lastDescIdx].formats.fromDMA.pktLength;
153154
}
154155

155156
void STM32EthMacV2::MACDriver::ETH_SetMDIOClockRange(ETH_TypeDef * const base)
@@ -275,7 +276,8 @@ namespace mbed {
275276
base->MAC1USTCR = (HAL_RCC_GetHCLKFreq() / 1000000U) - 1U;
276277

277278
// MAC configuration
278-
base->MACCR = ETH_MACCR_SARC_REPADDR0; // Replace the SA field in Tx packets with the configured source address
279+
base->MACCR = ETH_MACCR_SARC_REPADDR0 | // Replace the SA field in Tx packets with the configured source address
280+
ETH_MACCR_CST_Msk; // Don't include the CRC when forwarding Rx packets to the application
279281
base->MTLTQOMR |= ETH_MTLTQOMR_TSF_Msk; // Enable store and forward mode for transmission (default in the HAL)
280282

281283
// Enable multicast hash and perfect filter

connectivity/drivers/emac/TARGET_STM/STM32EthMACv2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace mbed {
5858

5959
void returnDescriptor(size_t descIdx, uint8_t *buffer) override;
6060

61-
size_t getTotalLen(size_t firstDescIdx) override;
61+
size_t getTotalLen(size_t firstDescIdx, size_t lastDescIdx) override;
6262

6363
public:
6464
explicit RxDMA(ETH_TypeDef * const base):

connectivity/drivers/emac/include/GenericEthDMA.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ namespace mbed {
197197
}
198198
}
199199

200-
tr_info("Transmitting packet of length %lu in %zu buffers and %zu descs\n",
200+
tr_debug("Transmitting packet of length %lu in %zu buffers and %zu descs\n",
201201
memory_manager->get_total_len(buf), memory_manager->count_buffers(buf), neededDescs);
202202

203203
// Step 2: Copy packet if needed
@@ -341,9 +341,9 @@ namespace mbed {
341341
virtual void returnDescriptor(size_t descIdx, uint8_t * buffer) = 0;
342342

343343
/// Get the length of the packet starting at firstDescIdx and continuing until the
344-
/// next descriptor with the last descriptor flag set. Descriptors have already been validated to contain a
344+
/// given last descriptor. Descriptors have already been validated to contain a
345345
/// complete packet at this point.
346-
virtual size_t getTotalLen(size_t firstDescIdx) = 0;
346+
virtual size_t getTotalLen(size_t firstDescIdx, size_t lastDescIdx) = 0;
347347

348348
public:
349349
CompositeEMAC::ErrCode init() override {
@@ -512,7 +512,7 @@ namespace mbed {
512512

513513
// Set length of first buffer
514514
net_stack_mem_buf_t *const headBuffer = rxDescStackBufs[*firstDescIdx];
515-
size_t lenRemaining = getTotalLen(*firstDescIdx);
515+
size_t lenRemaining = getTotalLen(*firstDescIdx, *lastDescIdx);
516516
memory_manager->set_len(headBuffer, std::min(lenRemaining, rxPoolPayloadSize));
517517
lenRemaining -= std::min(lenRemaining, rxPoolPayloadSize);
518518

@@ -546,7 +546,7 @@ namespace mbed {
546546
}
547547
#endif
548548

549-
tr_info("Returning packet of length %lu, start %p from Rx descriptors %zu-%zu (%p-%p)\n",
549+
tr_debug("Returning packet of length %lu, start %p from Rx descriptors %zu-%zu (%p-%p)\n",
550550
memory_manager->get_total_len(headBuffer), memory_manager->get_ptr(headBuffer), *firstDescIdx, *lastDescIdx,
551551
&rxDescs[*firstDescIdx], &rxDescs[*lastDescIdx]);
552552

connectivity/netsocket/mbed_lib.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"value": 592 // LwIP default value (assuming default TCP MSS)
8484
},
8585
"emac-rx-pool-num-bufs": {
86-
"help": "Number of buffers (of size netsocket.emac-rx-pool-buf-size) in the EMAC receive pool. This controls how much memory is preallocated for Ethernet reception. A larger number means that more Ethernet packets can be received per second without dropping any. Some EMACs need up to 4 extra buffers, so this should be set such that this value minus 4 times the buffer size is at least 1514 (so we can receive one full Ethernet frame).",
86+
"help": "Number of buffers (of size netsocket.emac-rx-pool-buf-size) in the EMAC receive pool. This controls how much memory is preallocated for Ethernet reception. A larger number means that more Ethernet packets can be received per second without dropping any. Some EMACs need up to 4 extra buffers, so this should be set such that (this value minus 4) times the buffer size is at least 1514 (so we can receive one full Ethernet frame).",
8787
"value": 7
8888
},
8989
"emac-tx-num-descs": {

connectivity/netsocket/tests/TESTS/network/emac/emac_test_initialize.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ void test_emac_initialize()
3636
worker_loop_init();
3737
mbed_trace_init();
3838

39-
// Set memory manager parameters
40-
EmacTestMemoryManager::get_instance().set_alloc_unit(256); // Use a relatively small allocation unit size so packets have to be split up into a lot of buffers
41-
4239
static NetworkInterface *network_interface = get_network_interface();
4340

4441
// Power up the interface and emac driver

connectivity/netsocket/tests/emac_test_utils/EmacTestMemoryManager.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636

3737
#define CHECK_ASSERT(value, fmt, ...) check_value(value, fmt, ##__VA_ARGS__)
3838

39-
#define BUF_POOL_SIZE (14 + 40 + 20 + 536) /* Ethernet + IP + TCP + payload */
40-
4139
#define MEM_MNGR_TRACE "test mem mngr: "
4240

4341
char s_trace_buffer[100] = MEM_MNGR_TRACE;
@@ -74,7 +72,7 @@ void emac_heap_error_handler(heap_fail_t event)
7472
EmacTestMemoryManager::EmacTestMemoryManager()
7573
: m_mem_mutex(),
7674
m_mem_buffers(),
77-
m_alloc_unit(BUF_POOL_SIZE),
75+
m_alloc_unit(MBED_CONF_NSAPI_EMAC_RX_POOL_BUF_SIZE),
7876
m_memory_available(true)
7977
{
8078
#ifdef ETHMEM_SECTION

targets/targets.json5

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,9 +3111,7 @@ mode is recommended for target MCUs with small amounts of flash and RAM.",
31113111
"LPTICKER",
31123112
"CAN",
31133113
"SERIAL_FC",
3114-
"WATCHDOG",
3115-
"ETHERNET",
3116-
"EMAC"
3114+
"WATCHDOG"
31173115
],
31183116
"is_mcu_family_target": true
31193117
},
@@ -3128,6 +3126,10 @@ mode is recommended for target MCUs with small amounts of flash and RAM.",
31283126
],
31293127
"macros_add": [
31303128
"STM32H503xx"
3129+
],
3130+
"device_has_remove": [
3131+
"ETHERNET",
3132+
"EMAC"
31313133
]
31323134
},
31333135
"NUCLEO_H503RB": {
@@ -3141,7 +3143,8 @@ mode is recommended for target MCUs with small amounts of flash and RAM.",
31413143

31423144
// ADC reference voltage is same as MCU VDD.
31433145
// MCU VDD defaults to 3.3V though can be changed to 1.8V based on JP2 setting on nucleo board.
3144-
"default-adc-vref": 3.3
3146+
"default-adc-vref": 3.3,
3147+
"network-default-interface-type": "ETHERNET"
31453148
},
31463149
"device_has_remove": [
31473150
"ANALOGOUT" // both DAC pins are in conflict with LED1 and STDIO_UART_TX

0 commit comments

Comments
 (0)