Uart Transmit works in STM32CubeIDE but not in PlatformIO (I use the same code)

With the function HAL_UART_Transmit I send a string to the console.

The problem is that the whole thing works in STMCubeID but not on PlatformIO.

When I run the same code on Platform IO, I get nothing on the Consol.

I think it has something to do with the clock.

I measured the 100ms delay with a logic analyzer. On the STM32Cube I measured 107ms and on Platform IO 102ms.

platformio.ini

platform = ststm32
board = nucleo_f303k8
framework = stm32cube
board_build.f_cpu = 8000000L

main

Unfortunately, I did not see my error.

Did anyone have the same problem?

Thanks for your help

That’s a buffer overflow and thus undefined behavior. Your 43-character string (including NUL-terminator) cannot fit in a 12 byte buffer.

Thank you for your reply and advice.
I have set the buffer length to the correct size.
Unfortunately, I still can’t see anything on the console.

Are you sure this is the platformio.ini? It is missing an [env:nucleo_f303k8] line there.

Also you should add

monitor_speed = 38400

the platformio.ini (docs) so that the serial monitor will have the right baudrate as configured in the code.

Also per user manual

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.


Unfortunately I do not get any messages or errors.

The board supports Arduino per docs. Please do a short sanity check that the board is generally working.

Create a new project for the ST Nucleo F303K8 with the Arduino farmework and use

[env:nucleo_f303k8]
platform = ststm32
board = nucleo_f303k8
framework = arduino
monitor_speed = 115200
#include <Arduino.h>

void setup() { Serial.begin(115200); }
void loop() { Serial.println("Hello"); delay(1000); }

Also don’t forget to use the project environment switcher to switch to the newly created project. That’s not done automatically.

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)

Seems like the COM port is still open? Try to abort all previous PlatformIO tasks in the terminal with Ctrl+C.

The Arduino example works, but unfortunately the STM32Cube code does not.

Can you upload the whole non-working STM32Cube project?

Hello I have uploaded the project to github.
Thank you very much for your help.

For me changing the toolchain/IDE environment in STMCubeMX from EWARM ( the default ) to STMCubeIDE fixed the problem.