cancel
Showing results for 
Search instead for 
Did you mean: 

UART2 communicaton NUCLEO-C031C6

DonPotokon
Associate

Hello

I just started with programming Nucleos and I tried to establish a UART communication with my laptop. So the problem is I can only select USART1 when i open my connectivity tab in IOC file. And to use USART1 i have to unsolder those 2 resistors on SB27 and SB32 and solder them to SB31 to SB32, am i correct? That would we my last option. I am just wondering why i cannot use or even select USART2 in the first place. I am using NUCLEO-C031C6. Has anybody faced that kind of problem? Any tips or solutions are welcome. 

DonPotokon_0-1714750558282.png

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

As I said previously and by default, in HW, USART2 is the one connected to VCP.

The pinned pins in pink are reserved for USART2 for VCP.

The code generated for this is as follwoing:

  /* Initialize COM1 port (115200, 8 bits (7-bit data + 1 stop bit), no parity */
  BspCOMInit.BaudRate   = 115200;
  BspCOMInit.WordLength = COM_WORDLENGTH_8B;
  BspCOMInit.StopBits   = COM_STOPBITS_1;
  BspCOMInit.Parity     = COM_PARITY_NONE;
  BspCOMInit.HwFlowCtl  = COM_HWCONTROL_NONE;
  if (BSP_COM_Init(COM1, &BspCOMInit) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }

Here COM1 points to USART2. So by default VCP is using USART2.

If you want to use USART1 instead of USART2 you need to disable Virtual Com Port in Bsp menu and modify the solder bridges to connect USART1 to the STLINK - VCP:

  • Disconnect SB27/ConnectSB31.
  • Disconnect SB32/ConnectSB33

+ Configure USART1_TX / PB6 and USART1_TX / PB7

SofLit_0-1714776334636.png

Hope it's clear now.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

5 REPLIES 5
SofLit
ST Employee

Hello,

I think this is because when you started a new project based on the board and not on an MCU and you selected to generate the code with Virtual Com port. 

SofLit_0-1714757948530.png

By default, in HW, USART2 is the one connected to VCP.

Go to Bsp menu and check if Virtual Com Port is enabled. So PA2 and PA3 are pinned to be VCP_TX and VCP_RX (USART2_TX and USART2_RX).

SofLit_2-1714758508285.png

Hope it does answer your question.

 

 

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
SofLit
ST Employee

Meanwhile, when I checked the Bsp config in stm32c0xx_nucleo.h I found that USART1 is the one set by default for VCP which is in my opinion is not inline with the default HW config on that Nucleo board.

I need to check internally and get back to you.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

First of all, thank you for your answer, but I still dont know understand fully what are you trying to say. I already had the VCP enabled but I dont know how to operate with this configuration. First of all why are the pins unmapped and locked(pink and not green) and if i enable USART1 communication and i pick random pins to have as a TX and RX pins, the system automatically generates the needed code and functions in main.c and everywhere else. But with this configuration(VCP_TX and VCP_RX) if I save this file, I dont see the necesarry code that should be autatically generated. I thought this pins should be green and initialized as USART2_TX and RX.

As I said previously and by default, in HW, USART2 is the one connected to VCP.

The pinned pins in pink are reserved for USART2 for VCP.

The code generated for this is as follwoing:

  /* Initialize COM1 port (115200, 8 bits (7-bit data + 1 stop bit), no parity */
  BspCOMInit.BaudRate   = 115200;
  BspCOMInit.WordLength = COM_WORDLENGTH_8B;
  BspCOMInit.StopBits   = COM_STOPBITS_1;
  BspCOMInit.Parity     = COM_PARITY_NONE;
  BspCOMInit.HwFlowCtl  = COM_HWCONTROL_NONE;
  if (BSP_COM_Init(COM1, &BspCOMInit) != BSP_ERROR_NONE)
  {
    Error_Handler();
  }

Here COM1 points to USART2. So by default VCP is using USART2.

If you want to use USART1 instead of USART2 you need to disable Virtual Com Port in Bsp menu and modify the solder bridges to connect USART1 to the STLINK - VCP:

  • Disconnect SB27/ConnectSB31.
  • Disconnect SB32/ConnectSB33

+ Configure USART1_TX / PB6 and USART1_TX / PB7

SofLit_0-1714776334636.png

Hope it's clear now.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

That was a bug found last year ago though I can't find the post. If I remember correctly, I verified that CubeIDE generated the code for UART1 instead of UART2. 

I still have that project from last October and sure enough, it's generated for UART1. 

I'm surprised that ST has never fixed it to this day? 

 

Edit: Never mind, I misread the OP's post. The newest FW does select UART2 but you can't change any of the settings in the IOC file.

 

So OP, instead of seeing this

UART_HandleTypeDef huart1; // or huart2

You get this

COM_InitTypeDef BspCOMInit;

and as @SofLit mentions, you make your parameter changes for BspCOMInit in the main code  before the while loop.

 

 

If you find my answers useful, click the accept button so that way others can see the solution.