Removing delay in UART communication layer
HAL_UART_Receive_IT() only initiates UART receive. It doesn't wait until any data is received. Thus, when you check the variable 'd' straight afterwards, the byte might have been received... but maybe not. Only in HAL_UART_RxCpltCallback() can you be sure the data has been set to a valid value.

To complicate matters, if you have fast UART speed your code might not yet have setup the UART driver to receiving the next byte when the byte arrives.

What you should do is a single call to HAL_UART_Receive_IT() to start saving the maximum number of bytes to a large enough buffer, then check from you non-interrupt code if new data has been written by checking huart->RxXferCount or huart->pRxBuffPtr.
When you have received the last byte, stop the UART or simply ignore further data.

Pseudocode:

uint8_t buffer[200];
HAL_UART_Receive_IT(huart, buffer, 200);
uint8_t* nextToProcess = &amp;buffer[0];
while (!timeout) {
  if (huart-&gt;pRxBuffPtr &gt; nextToProcess) {
    uint8_t received = *nextToProcess;
    nextToProcess++;
    // Handle the 'received' byte here, checking for end-of-transmission
  }
}