Skip to content

Commit c371193

Browse files
committed
STM32 EMAC : enable mbed_trace
1 parent c5b192e commit c371193

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

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

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@
3030
#include "stm32xx_emac_config.h"
3131
#include "stm32xx_emac.h"
3232

33+
#include "mbed_trace.h"
34+
35+
#if defined(ETH_IP_VERSION_V2)
36+
#define TRACE_GROUP "STE2"
37+
#else
38+
#define TRACE_GROUP "STE1"
39+
#endif
40+
41+
/* mbed trace feature is supported */
42+
/* ex in mbed_app.json */
43+
/* "mbed-trace.enable": "1" */
44+
45+
/* mbed_trace: debug traces (tr_debug) can be disabled here with no change in mbed_app.json */
46+
// #undef TRACE_LEVEL_DEBUG
47+
// #define TRACE_LEVEL_DEBUG 0
48+
3349
#if defined(ETH_IP_VERSION_V2)
3450
#include "lan8742/lan8742.h"
3551
#include "lwip/memp.h"
@@ -296,17 +312,24 @@ bool STM32_EMAC::low_level_init_successful()
296312
EthHandle.Init.RxMode = ETH_RXINTERRUPT_MODE;
297313
EthHandle.Init.ChecksumMode = ETH_CHECKSUM_BY_SOFTWARE;
298314
EthHandle.Init.MediaInterface = ETH_MEDIA_INTERFACE_RMII;
315+
tr_info("PHY Addr %u AutoNegotiation %u", EthHandle.Init.PhyAddress, EthHandle.Init.AutoNegotiation);
316+
tr_debug("MAC Addr %02x:%02x:%02x:%02x:%02x:%02x", MACAddr[0], MACAddr[1], MACAddr[2], MACAddr[3], MACAddr[4], MACAddr[5]);
317+
tr_info("ETH buffers : %u Rx %u Tx", ETH_RXBUFNB, ETH_TXBUFNB);
318+
299319
if (HAL_ETH_Init(&EthHandle) != HAL_OK) {
320+
tr_error("HAL_ETH_Init issue");
300321
return false;
301322
}
302323

303324
/* Initialize Tx Descriptors list: Chain Mode */
304325
if (HAL_ETH_DMATxDescListInit(&EthHandle, DMATxDscrTab, &Tx_Buff[0][0], ETH_TXBUFNB) != HAL_OK) {
326+
tr_error("HAL_ETH_DMATxDescListInit issue");
305327
return false;
306328
}
307329

308330
/* Initialize Rx Descriptors list: Chain Mode */
309331
if (HAL_ETH_DMARxDescListInit(&EthHandle, DMARxDscrTab, &Rx_Buff[0][0], ETH_RXBUFNB) != HAL_OK) {
332+
tr_error("HAL_ETH_DMARxDescListInit issue");
310333
return false;
311334
}
312335

@@ -315,9 +338,11 @@ bool STM32_EMAC::low_level_init_successful()
315338

316339
/* Enable MAC and DMA transmission and reception */
317340
if (HAL_ETH_Start(&EthHandle) != HAL_OK) {
341+
tr_error("HAL_ETH_Start issue");
318342
return false;
319343
}
320344

345+
tr_info("low_level_init_successful");
321346
return true;
322347
}
323348
#else // ETH_IP_VERSION_V2
@@ -345,6 +370,9 @@ bool STM32_EMAC::low_level_init_successful()
345370
EthHandle.Init.TxDesc = DMATxDscrTab;
346371
EthHandle.Init.RxBuffLen = 1524;
347372

373+
tr_debug("MAC Addr %02x:%02x:%02x:%02x:%02x:%02x", MACAddr[0], MACAddr[1], MACAddr[2], MACAddr[3], MACAddr[4], MACAddr[5]);
374+
tr_info("ETH buffers : %u Rx %u Tx", ETH_RX_DESC_CNT, ETH_TX_DESC_CNT);
375+
348376
if (HAL_ETH_Init(&EthHandle) != HAL_OK) {
349377
return false;
350378
}
@@ -358,6 +386,7 @@ bool STM32_EMAC::low_level_init_successful()
358386
HAL_ETH_DescAssignMemory(&EthHandle, idx, Rx_Buff[idx], NULL);
359387
}
360388

389+
tr_info("low_level_init_successful");
361390
return _phy_init();
362391
}
363392
#endif // ETH_IP_VERSION_V2
@@ -433,7 +462,7 @@ bool STM32_EMAC::link_out(emac_mem_buf_t *buf)
433462

434463
/* Prepare transmit descriptors to give to DMA */
435464
if (HAL_ETH_TransmitFrame(&EthHandle, framelength) != HAL_OK) {
436-
465+
tr_error("HAL_ETH_TransmitFrame issue");
437466
success = false;
438467
}
439468

@@ -473,7 +502,7 @@ bool STM32_EMAC::link_out(emac_mem_buf_t *buf)
473502
/* copy frame from pbufs to driver buffers */
474503
for (q = p; q != NULL; q = q->next) {
475504
if (i >= ETH_TX_DESC_CNT) {
476-
printf("Error : ETH_TX_DESC_CNT not sufficient\n");
505+
tr_error("Error : ETH_TX_DESC_CNT not sufficient");
477506
goto error;
478507
}
479508

@@ -499,7 +528,7 @@ bool STM32_EMAC::link_out(emac_mem_buf_t *buf)
499528
if (status == HAL_OK) {
500529
success = 1;
501530
} else {
502-
printf("Error returned by HAL_ETH_Transmit (%d)\n", status);
531+
tr_error("Error returned by HAL_ETH_Transmit (%d)", status);
503532
success = 0;
504533
}
505534

@@ -538,6 +567,7 @@ int STM32_EMAC::low_level_input(emac_mem_buf_t **buf)
538567

539568
/* get received frame */
540569
if (HAL_ETH_GetReceivedFrame_IT(&EthHandle) != HAL_OK) {
570+
tr_debug("low_level_input no frame");
541571
return -1;
542572
}
543573

@@ -549,6 +579,7 @@ int STM32_EMAC::low_level_input(emac_mem_buf_t **buf)
549579
dmarxdesc = EthHandle.RxFrameInfos.FSRxDesc;
550580

551581
if (len > 0) {
582+
tr_debug("low_level_input len %u", len);
552583
/* Allocate a memory buffer chain from buffer pool */
553584
*buf = memory_manager->alloc_pool(len, 0);
554585
}
@@ -607,7 +638,7 @@ int STM32_EMAC::low_level_input(emac_mem_buf_t **buf)
607638

608639
if (HAL_ETH_GetRxDataBuffer(&EthHandle, &RxBuff) == HAL_OK) {
609640
if (HAL_ETH_GetRxDataLength(&EthHandle, &frameLength) != HAL_OK) {
610-
printf("Error: returned by HAL_ETH_GetRxDataLength\n");
641+
tr_error("Error: returned by HAL_ETH_GetRxDataLength");
611642
return -1;
612643
}
613644

@@ -679,12 +710,16 @@ void STM32_EMAC::phy_task()
679710
if (HAL_ETH_ReadPHYRegister(&EthHandle, PHY_BSR, &status) == HAL_OK) {
680711
if ((emac_link_state_cb) && (status != 0xFFFF)) {
681712
if ((status & PHY_LINKED_STATUS) && !(phy_status & PHY_LINKED_STATUS)) {
713+
tr_info("emac_link_state_cb set to true");
682714
emac_link_state_cb(true);
683715
} else if (!(status & PHY_LINKED_STATUS) && (phy_status & PHY_LINKED_STATUS)) {
716+
tr_info("emac_link_state_cb set to false");
684717
emac_link_state_cb(false);
685718
}
686719
}
687720
phy_status = status;
721+
} else {
722+
tr_error("HAL_ETH_ReadPHYRegister issue");
688723
}
689724

690725
}
@@ -721,8 +756,10 @@ void STM32_EMAC::phy_task()
721756
if (emac_link_state_cb) {
722757
if (is_up && !was_up) {
723758
emac_link_state_cb(true);
759+
tr_info("emac_link_state_cb set to true");
724760
} else if (!is_up && was_up) {
725761
emac_link_state_cb(false);
762+
tr_info("emac_link_state_cb set to false");
726763
}
727764
}
728765

@@ -829,6 +866,8 @@ void mbed_default_mac_address(char *mac)
829866

830867
bool STM32_EMAC::power_up()
831868
{
869+
tr_info("power_up");
870+
832871
sleep_manager_lock_deep_sleep();
833872

834873
/* Initialize the hardware */
@@ -912,6 +951,8 @@ void STM32_EMAC::set_all_multicast(bool all)
912951

913952
void STM32_EMAC::power_down()
914953
{
954+
tr_info("power_down");
955+
915956
/* No-op at this stage */
916957
sleep_manager_unlock_deep_sleep();
917958
}

0 commit comments

Comments
 (0)