Skip to content

Commit 646efbd

Browse files
Mika Leppänen0xc0170
authored andcommitted
Changed STM emac driver to loop RX frame reading
1 parent ec72a38 commit 646efbd

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

features/netsocket/emac-drivers/TARGET_STM_EMAC/stm32xx_emac.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -237,26 +237,27 @@ bool STM32_EMAC::link_out(emac_mem_buf_t *buf)
237237
}
238238

239239
/**
240-
* Should allocate a a contiguous memory buffer and transfer the bytes of the incoming
240+
* Should allocate a contiguous memory buffer and transfer the bytes of the incoming
241241
* packet to the buffer.
242242
*
243-
* @return a memory buffer filled with the received packet (including MAC header)
244-
* NULL on memory error
243+
* @param buf If a frame was received and the memory buffer allocation was successful, a memory
244+
* buffer filled with the received packet (including MAC header)
245+
* @return negative value when no more frames,
246+
* zero when frame is received
245247
*/
246-
emac_mem_buf_t *STM32_EMAC::low_level_input()
248+
int STM32_EMAC::low_level_input(emac_mem_buf_t **buf)
247249
{
248250
uint16_t len = 0;
249251
uint8_t *buffer;
250252
__IO ETH_DMADescTypeDef *dmarxdesc;
251253
uint32_t bufferoffset = 0;
252254
uint32_t byteslefttocopy = 0;
253-
emac_mem_buf_t *buf = 0;
254255
emac_mem_buf_t *q;
255256
uint32_t payloadoffset = 0;
256257

257258
/* get received frame */
258-
if (HAL_ETH_GetReceivedFrame(&EthHandle) != HAL_OK) {
259-
return NULL;
259+
if (HAL_ETH_GetReceivedFrame_IT(&EthHandle) != HAL_OK) {
260+
return -1;
260261
}
261262

262263
/* Obtain the size of the packet and put it into the "len" variable. */
@@ -268,13 +269,13 @@ emac_mem_buf_t *STM32_EMAC::low_level_input()
268269

269270
if (len > 0) {
270271
/* Allocate a memory buffer chain from buffer pool */
271-
buf = memory_manager->alloc_pool(len, 0);
272+
*buf = memory_manager->alloc_pool(len, 0);
272273
}
273274

274-
if (buf != NULL) {
275+
if (*buf != NULL) {
275276
dmarxdesc = EthHandle.RxFrameInfos.FSRxDesc;
276277
bufferoffset = 0;
277-
for (q = buf; q != NULL; q = memory_manager->get_next(q)) {
278+
for (q = *buf; q != NULL; q = memory_manager->get_next(q)) {
278279
byteslefttocopy = memory_manager->get_len(q);
279280
payloadoffset = 0;
280281

@@ -316,7 +317,7 @@ emac_mem_buf_t *STM32_EMAC::low_level_input()
316317
/* Resume DMA reception */
317318
EthHandle.Instance->DMARPDR = 0;
318319
}
319-
return buf;
320+
return 0;
320321
}
321322

322323

@@ -325,15 +326,16 @@ emac_mem_buf_t *STM32_EMAC::low_level_input()
325326
*/
326327
void STM32_EMAC::packet_rx()
327328
{
328-
emac_mem_buf_t *p;
329-
330329
/* move received packet into a new buf */
331-
p = low_level_input();
332-
if (p == NULL) {
333-
return;
330+
while (1) {
331+
emac_mem_buf_t *p = NULL;
332+
if (low_level_input(&p) < 0) {
333+
break;
334+
}
335+
if (p) {
336+
emac_link_input_cb(p);
337+
}
334338
}
335-
336-
emac_link_input_cb(p);
337339
}
338340

339341
/** \brief Worker thread.

features/netsocket/emac-drivers/TARGET_STM_EMAC/stm32xx_emac.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class STM32_EMAC : public EMAC {
154154
private:
155155
bool low_level_init_successful();
156156
void packet_rx();
157-
emac_mem_buf_t *low_level_input();
157+
int low_level_input(emac_mem_buf_t **buf);
158158
static void thread_function(void* pvParameters);
159159
static void rmii_watchdog_thread_function(void* pvParameters);
160160
void phy_task();

0 commit comments

Comments
 (0)