2023-11-29 11:10 AM
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?
2023-11-29 11:32 AM - edited 2023-11-29 11:33 AM
Use a free running 32-bit TIM, say at 1 MHz, or faster. Maximal, just counting, no interrupt.
Perhaps DWT CYCCNT?
2023-11-29 11:47 AM
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?
2023-11-29 01:57 PM
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);