Skip to main content
KMew
Senior III
November 29, 2023
Question

CANbus: Execution time to send a message

  • November 29, 2023
  • 3 replies
  • 3018 views

Hello,

I am utilizing the FDCAN1 CANbus protocol on the STM32H725AGI6 MCU currently. I am trying to determine the execution time for the firmware to execute the lines of code, as the timing can be critical in some applications. 

 

So for example, I would like to determine how long this line of code takes to execute:

HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, &TxData0[0]);

 

The FDCAN is running on a 48 MHz clock currently. 

 

Obviously HAL_GetTick() does not work, since it's in the time frame of milliseconds and the execution would be less than 1ms. So I am looking to get a more accurate time.

 

Does anyone know if this is possible?

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
November 29, 2023

Use a free running 32-bit TIM, say at 1 MHz, or faster. Maximal, just counting, no interrupt.

Perhaps DWT CYCCNT?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
KMew
KMewAuthor
Senior III
November 29, 2023

Hello Tesla,

Thank you for the reply!

Would you be able to elaborate a little bit further? 

Can I use any free timer? 
Would I simply do HAL_TIM_Base_Start() to start the timer, then HAL_TIM_Base_Stop() to stop the timer then check the elapsed time?

Tesla DeLorean
Guru
November 29, 2023

TIM2 and TIM5 would be 32-bit, set the ARR (period) to 0xFFFFFFFF, and PSC (prescaler) to BUS MHZ-1

Read CNT across entry and exit, and subtract to get elapsed micro-seconds.

uint32_t start, stop;

start = TIM2->CNT;

// test function

stop = TIM2->CNT;

printf("%u us\n", stop-start);

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..