cancel
Showing results for 
Search instead for 
Did you mean: 

How to transmit data over ST virtual com port with USART2?

raphaelplante
Associate II
Posted on June 03, 2017 at 16:02

Platform: STM32L4DISCO

IDE: SW4STM32

Hi,

I used CubeMx to configure the USART2 with the following parameter

  • Baud rate: 115200
  • Word lenght 8 bits
  • Parity none
  • Stop bits 1

I used Putty as the serial terminal with the COM3 wich is the COM port that I saw on my device manager.

I used the HAL command

HAL_UART_Transmit(&huart2, (uint8_t*)'Hello', 6, 10000);

But I don't see anything on the terminal. Is there something else I need to do before being able to send data to the terminal?

Thanks

#stm32-usart2 #stm32l4

Note: this post was migrated and contained many threaded conversations, some content may be missing.
9 REPLIES 9
john doe
Lead
Posted on June 03, 2017 at 21:05

you need to add syscalls.c to your Src directory. you should then see some output. If you want to print floating point values, you would need to remove nano.specs from your linker options.

________________

Attachments :

syscalls.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HydX&d=%2Fa%2F0X0000000bAJ%2F83tKgt_nyOD2Z676aSc62KN_sHtDD4lsPvrQ1Yjc4V8&asPdf=false
Posted on June 03, 2017 at 23:33

Hi,

I added syscalls.c to my Src directory, but I still don't have any response on my putty terminal. What is the point of this file? Is it supposed to print inside system workbench IDE console?

Thanks,

Posted on June 04, 2017 at 01:15

crap i forgot the other half of the equation is to reroute printf

you also need to add

♯ ifdef __GNUC__

/* With GCC, small printf (option LD Linker->Libraries->Small printf

   set to 'Yes') calls __io_putchar() */

♯ define PUTCHAR_PROTOTYPE int __io_putchar(int ch)

♯ else

♯ define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)

♯ endif /* __GNUC__ */

to your private function prototypes, and add this to user code 4

PUTCHAR_PROTOTYPE

{

  /* Place your implementation of fputc here */

  /* e.g. write a character to the USART2 and Loop until the end of transmission */

  HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);

  return ch;

}

sorry about the incomplete info

Posted on June 04, 2017 at 03:31

This thing is the HAL_UART_Transmit function is not working and that is the root of my problem, so use printf that calls HAL_UART_Transmit won't work either.

Posted on June 04, 2017 at 04:00

you need to add syscalls.c to your project, and add the code i posted above to your main.c

that would redirect uart2 to vcp over usb

Posted on June 04, 2017 at 14:25

Hi,

I don't have the small printf option when I go to LD Linker->Libraries->. How can I get this option?

Posted on June 04, 2017 at 19:22

you dont need it to get printf to work.

Posted on June 04, 2017 at 22:17

Hi,

The main.c you attached doesn't configure the USART2 Pin PA2 and PA3. Instead, it is the joystick that is configured. Did you generate this file with CubeMx? If so could you send me the project?

Thanks for your patience.