cancel
Showing results for 
Search instead for 
Did you mean: 

CANbus: Execution time to send a message

KMew
Senior III

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?

3 REPLIES 3

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
Up vote any posts that you find helpful, it shows what's working..

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?

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
Up vote any posts that you find helpful, it shows what's working..