so PA2 and PA15 should be the UART TX/RX pins. The code should be okay though, I used STM32CubeMX to generate the default code for the Nucleo F303K8 and its main.c looks practically the same.
You enter the serial monitor by executing the project task “Upload and Monitor”, right? Do you see that it selects the correct COM port of the Nucleo?
I have added monitor_speed = 38400 in the platformio.ini file.
Unfortunately it does not work.
In the serial monitor tab I can see that it selects COM10. In the device manager I can also see the device on COM10.
I have created a new project with the Arduino Framwork and your code.
Now I get this error message in the serial console: could not open port 'COM10': could not open port 'COM10': PermissionError(13, 'Access is denied.', None, 5)