Skip to content

Commit 7e4eb5c

Browse files
committed
LPC546XX: Correct Ethernet length calculations
Subtract 4 from the received packet length - the buffer contains the CRC, which we shouldn't pass up. Ensure we allocate receive buffers of a size corresponding to the rounded-up size we tell the hardware - the hardware was overrunning the allocation by a couple of bytes.
1 parent 97b9980 commit 7e4eb5c

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

features/netsocket/emac-drivers/TARGET_NXP_EMAC/TARGET_LPC546XX/lpc546xx_emac.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,27 +202,27 @@ bool LPC546XX_EMAC::low_level_init_successful()
202202
AT_NONCACHEABLE_SECTION_ALIGN(static enet_rx_bd_struct_t rx_desc_start_addr[ENET_RX_RING_LEN], ENET_BUFF_ALIGNMENT);
203203
AT_NONCACHEABLE_SECTION_ALIGN(static enet_tx_bd_struct_t tx_desc_start_addr[ENET_TX_RING_LEN], ENET_BUFF_ALIGNMENT);
204204

205+
/* prepare the buffer configuration. */
206+
enet_buffer_config_t buffCfg = {
207+
ENET_RX_RING_LEN,
208+
ENET_TX_RING_LEN,
209+
&tx_desc_start_addr[0],
210+
&tx_desc_start_addr[0],
211+
&rx_desc_start_addr[0],
212+
&rx_desc_start_addr[ENET_RX_RING_LEN],
213+
rx_ptr,
214+
ENET_BuffSizeAlign(ENET_ETH_MAX_FLEN),
215+
};
216+
205217
/* Create buffers for each receive BD */
206218
for (i = 0; i < ENET_RX_RING_LEN; i++) {
207-
rx_buff[i] = memory_manager->alloc_heap(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT);
219+
rx_buff[i] = memory_manager->alloc_heap(buffCfg.rxBuffSizeAlign, ENET_BUFF_ALIGNMENT);
208220
if (NULL == rx_buff[i])
209221
return false;
210222

211223
rx_ptr[i] = (uint32_t)memory_manager->get_ptr(rx_buff[i]);
212224
}
213225

214-
/* prepare the buffer configuration. */
215-
enet_buffer_config_t buffCfg = {
216-
ENET_RX_RING_LEN,
217-
ENET_TX_RING_LEN,
218-
&tx_desc_start_addr[0],
219-
&tx_desc_start_addr[0],
220-
&rx_desc_start_addr[0],
221-
&rx_desc_start_addr[ENET_RX_RING_LEN],
222-
rx_ptr,
223-
ENET_ALIGN(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT),
224-
};
225-
226226
ENET_Init(ENET, &config, hwaddr, refClock);
227227

228228
/* Enable the tx & rx interrupt. */
@@ -266,7 +266,7 @@ emac_mem_buf_t *LPC546XX_EMAC::low_level_input()
266266
update_read_buffer(bdPtr, NULL);
267267
} else {
268268
if (bdPtr->control & ENET_RXDESCRIP_WR_LD_MASK) {
269-
length = (bdPtr->control & ENET_RXDESCRIP_WR_PACKETLEN_MASK);
269+
length = (bdPtr->control & ENET_RXDESCRIP_WR_PACKETLEN_MASK) - 4;
270270
} else {
271271
length = rxBdRing->rxBuffSizeAlign;
272272
}
@@ -276,7 +276,7 @@ emac_mem_buf_t *LPC546XX_EMAC::low_level_input()
276276
memory_manager->set_len(p, length);
277277

278278
/* Attempt to queue new buffer */
279-
temp_rxbuf = memory_manager->alloc_heap(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT);
279+
temp_rxbuf = memory_manager->alloc_heap(rxBdRing->rxBuffSizeAlign, ENET_BUFF_ALIGNMENT);
280280
if (NULL == temp_rxbuf) {
281281
/* Re-queue the same buffer */
282282
update_read_buffer(bdPtr, NULL);

0 commit comments

Comments
 (0)