STM32 Input capture PWM frequency measurement problem using HAL
What you can do is to create  a queue on the interrupt to store the period. Because the sampling frequency should be at least double the PWM frequency ,you have to handle the period asynchronously (because the main loop may be slow to handle these frequencies) .I had the same issue quite some time ago but instead of a PWM I had a saw tooth with variable frequency so I was just counting saw tooth edges. So here is the code for reference:

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef * htim)
{
    static uint32_t prev1 = 0;

    if (htim-&gt;Instance == TIM1 &amp;&amp; htim-&gt;Channel == HAL_TIM_ACTIVE_CHANNEL_4 )
    {
        auto now = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_4);
        auto diff =( 65536 + now - prev1)%65536;  
        prev1 = now;
        single_producer_single_consumer_queue.push(diff);
    }
}


Notice that because my clock wasen't fast enough to count some periods I have these normalizer for the overflows which I should handle somehow (for example compare the values of the queue for immidiate huge changes from 65000 clock periods to 1 clock period) 

( 65536 + now - prev1)%65536


Also notice that in capture mode HAL_TIM_ReadCapturedValue seems more reasonable and more "high level" than __HAL_TIM_GET_COMPARE