cancel
Showing results for 
Search instead for 
Did you mean: 

Function for printing values

skon.1
Senior

Hello,

I'm working with the NUCLEO-F722ZE EVB on STM32CubeIDE.

I want to use the main USB connection to the PC as a UART.

The default CubeMX pin configuration already has PD8 and PD9 configured as a UART, so I proceeded with code generation (the auto generated main.c file is attached).

What's the recommended function I to print characters to the PC terminal over the UART ?

For example, if I want to send: "Hello World".

What would be the code for it ?

13 REPLIES 13
S.Ma
Principal

otherwise, try for run to get an HC-06 BT dongle (few bucks) and plug it on a free usart. It's 3.3 or 5V powered, 4 wires, then you can work wirelessly even when STlink is removed or your app is reloaded. The default speed is 9600bps and with the well documented AT+BAUD8 you can reprogram it to 115200bps which works reliably (don't try higher baud rate if sending continuously, BT packetize+timeout+buffer_when_out_of_range_momentaritly)

And you can even use it with remote display on open plateforms such as android (look at Bluetooth Electronics in Play Store)

RMcCa
Senior II

I don't use hal, but I'm pretty sure it's not gonna work if you don't pass the address of the buffer to the hal transmit function. Clive's code passes the address of the buffer to his tansmit function, so there is (void *) cast in the hal function call to keep ​the compiler quiet. You need the & operator to dereference ( get the address of ) the buffer.

  1. What's "LL" ?
  2. I found out that his problem only happens when I use the board defaults. As I explained in this post: https://community.st.com/s/question/0D53W00000DKSfVSAX/uart-problem-when-using-default-initialization

Forget all of that and use the register interface. A debugger, the reference manual and a decent knowledge of C is all you need. HAL is a perfect example of why you shouldn't use others code.​