BufferedSerial not working with baremetal on Nucleo STM32F303K8

I’m using a serial interface over the built-in USB connection on STM32F303K8 board. I’m having troubles with using baudrate of 460800 or higher with baremetal profile. It works OK without baremetal.

This gist has the program to reproduce. It simply sends data back and forth between the stm and python running on the host, checking that the expected number of bytes is sent over. Quickly it gets stuck as a few bytes are dropped.

I’m using mbed-os (last commit: commit 0db72d0cf26539016efbe38f80d6f2cb7a3d4414 (HEAD -> latest, tag: mbed-os-6.3.0-rc2, tag: mbed-os-6.3.0, origin/latest)