Can't Get Timestamp of IEEE 1588 on XMC4700

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User20049
Level 1
Level 1
Hello everone,

We are implementing IEEE 1588 time sync on XMC4700 relax kit, we base on the DAVE example source code named "HTTP_SERVER_RTOS_XMC47". Our main function is as in the embedded code (print out timestamp of transmitted frame).

However, we always have same output, like "frame transmitted at 0 second, 4 nanosecond", this output only varies when I remove "malloc".

Inside the XMC_ETH_MAC_InitPTP function, I realized that the below assignment, the value of eth_mac->regs->TIMESTAMP_CONTROL always keeps 0, no mater what value I gave to the variable "config".

eth_mac->regs->TIMESTAMP_CONTROL = ETH_TIMESTAMP_CONTROL_TSENA_Msk | ETH_TIMESTAMP_CONTROL_TSCTRLSSR_Msk | config;

So my questions:

- Would any of you have solution?

- Is it possible/better to develop 1588 application without using library (like without using XMC_ETH_MAC_InitPTP from /HTTP_SERVER_RTOS_XMC47/Libraries/XMCLib/inc/xmc_eth_mac.h)? I mean we read/write register by ourself by refering the document "Reference Manual of XMC4700/XMC4800 Microcontroller" (the pdf with ~2893 pages)?

Thanks so much in advance for your help!

Thi



////////////////////////////we define///////////////////////////
#define MAC_ADDR0 0x8C
#define MAC_ADDR1 0x04
#define MAC_ADDR2 0xBA
#define MAC_ADDR3 0x17
#define MAC_ADDR4 0x8A
#define MAC_ADDR5 0x4A
#define MAC_ADDR ((uint64_t)MAC_ADDR0 | \
((uint64_t)MAC_ADDR1 << 😎 | \
((uint64_t)MAC_ADDR2 << 16) | \
((uint64_t)MAC_ADDR3 << 24) | \
((uint64_t)MAC_ADDR4 << 32) | \
((uint64_t)MAC_ADDR5 << 40))

#define XMC_ETH_MAC_NUM_RX_BUF (4)
#define XMC_ETH_MAC_NUM_TX_BUF (4)

static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t rx_desc[XMC_ETH_MAC_NUM_RX_BUF] __attribute__((section ("ETH_RAM")));
static __attribute__((aligned(4))) XMC_ETH_MAC_DMA_DESC_t tx_desc[XMC_ETH_MAC_NUM_TX_BUF] __attribute__((section ("ETH_RAM")));
static __attribute__((aligned(4))) uint8_t rx_buf[XMC_ETH_MAC_NUM_RX_BUF][XMC_ETH_MAC_BUF_SIZE] __attribute__((section ("ETH_RAM")));
static __attribute__((aligned(4))) uint8_t tx_buf[XMC_ETH_MAC_NUM_TX_BUF][XMC_ETH_MAC_BUF_SIZE] __attribute__((section ("ETH_RAM")));
////////////////////////////we define///////////////////////////

int main(void)
{
DAVE_STATUS_t status;
status = DAVE_Init();
if(status != DAVE_STATUS_SUCCESS)
{
XMC_DEBUG("DAVE APPs initialization failed\n");
while(1U)
{
}
}
cgi_init();
ssi_init();
osThreadCreate (osThread(main_thread), NULL);



////////////////////////// our 1588 code ////////////////////////////
XMC_ETH_MAC_TIME_t *txTime;
char data[10];
uint32_t config = (uint32_t)ETH_TIMESTAMP_CONTROL_TSENALL_Msk;

memset(data, '\0', 10);
snprintf(data, 10, "%s", "mydata");
txTime = (XMC_ETH_MAC_TIME_t*)malloc(sizeof(XMC_ETH_MAC_TIME_t));
XMC_ETH_MAC_t ethMac =
{
.regs = ETH0,
.address = MAC_ADDR,
.rx_desc = rx_desc,
.tx_desc = tx_desc,
.rx_buf = &rx_buf[0][0],
.tx_buf = &tx_buf[0][0],
.num_rx_buf = XMC_ETH_MAC_NUM_RX_BUF,
.num_tx_buf = XMC_ETH_MAC_NUM_TX_BUF
};

XMC_ETH_MAC_InitPTP(&ethMac, config);
lwip_send(0, data, sizeof(data), 1);
XMC_ETH_MAC_GetTxTimeStamp(&ethMac, txTime);
printf("transmitted at %"PRIu32" second, %"PRIu32" nanosecond \n", txTime->seconds, txTime->nanoseconds);
////////////////////////// our 1588 code ////////////////////////////



osKernelStart();
}
0 Likes
1 Reply
MultipleMono
Level 1
Level 1
25 sign-ins 10 sign-ins 5 questions asked

This is a necropost but in case anyone else finds this and is wondering the same thing: Tx packet timestamps for an Ethernet packet are only available once the DMA descriptor with that ethernet packet is completely transmitted by the MAC peripheral.  I'm not sure if LwIP in this application is running with interrupts or with polling, but the general process is:

  • Tell LwIP to send a packet
  • Wait until packet is passed to the ETH MAC (you can't even safely call GetTxTimeStamp until this happens, as it will refer to the previous sent packet)
  • Wait until packet descriptor returns from the ETH MAC (GetTxTimeStamp will return busy during this period)
  • Get the timestamp using GetTxTimeStamp

Additionally, you need to ensure that the ETH_MAC_DMA_TDES0_TTSE bit is set on the Tx DMA descriptor's status word, or the timestamp won't be recorded.  This requires modifications to the default ethernet code.

0 Likes