STM32F4 serial RXNE flag
Your code is written with the implicit assumption of a serial FIFO, but that FIFO is only 1-deep in hardware, and has not been extended to a larger size in software.

The first element of your while() loop checks to see if a character has been received, and if so will increment your counter, but it can only increment it once.

Next your code enters a blocking drain loop that will not exit until the counter has been drained to zero.

During the blocking drain loop, any number of serial characters could be received, but because the hardware only has a single holding register, the hardware can only indicate a few distinct things:


No character has been received
One character has been received
A character has been received and then the register has overflowed because another was received before it was emptied.
A serial formatting error has occurred, with or without some of these other things.


When your code that checks the serial gets to run again, it can only correctly interpret the first two of these states - so the only thing it can possibly do is to increment the counter by one, or not - no other increment is possible.

If you want to count characters that come in during a blocking LED flash sequence, you will need to use a serial receive interrupt.  Or you could do the LED flashing in a non-blocking state machine, in a loop that also polled the serial.