that should work just fine.
and, as you are using an STM32, go ahead and insert:
//Counting cycles is a piece of cake.
//Stick this code somewhere in your code.
cur_timestamp = HAL_GetTick();
printf("%4lums \n",cur_timestamp - prev_timestamp);
prev_timestamp = cur_timestamp;
Each tick is a ms. - but remember that there is going to be a roll-over at some point. But it's great for just testing!!
If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.