cancel
Showing results for 
Search instead for 
Did you mean: 

printf causes terminal to stay just empty.

stmax
Associate II

Hey. I tried to setup `printf` using the following forum post. I am using the `NUCLEO-L4A6ZG`.

Here what I've tried so far. I connected the `USART2` to the Pins `PA2` (RX) and `PA3` (TX):

(By default LPUART1 was configured and connected to PG7/8, since the forum post used USART2 I used it as well.)

usart2.png

After the configuration was saved, and the code generated, I used the code from the previous mentioned forum post. Here a shorter and with comments removed version:

 

 

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stdio.h"

// ...

/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart2;

// ...

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USB_OTG_FS_PCD_Init(void);
static void MX_USART2_UART_Init(void);

/* USER CODE BEGIN PFP */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
/* USER CODE END PFP */

// ...
int main(void)
{
    HAL_Init();

    SystemClock_Config();

    MX_GPIO_Init();
    MX_USB_OTG_FS_PCD_Init();
    MX_USART2_UART_Init();

    while (1)
    {
        /* USER CODE END WHILE */
        printf("Hello, World!\n\r");
	    HAL_Delay(1000);
        /* USER CODE BEGIN 3 */
    }
}

// ...

static void MX_USART2_UART_Init(void)
{
    huart2.Instance = USART2;
    huart2.Init.BaudRate = 115200;
    huart2.Init.WordLength = UART_WORDLENGTH_7B;
    huart2.Init.StopBits = UART_STOPBITS_1;
    huart2.Init.Parity = UART_PARITY_NONE;
    huart2.Init.Mode = UART_MODE_TX_RX;
    huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
    huart2.Init.OverSampling = UART_OVERSAMPLING_16;
    huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
    huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
    if (HAL_UART_Init(&huart2) != HAL_OK)
    {
        Error_Handler();
    }
}

// ...

/* USER CODE BEGIN 4 */
PUTCHAR_PROTOTYPE {
	HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);
	return ch;
}
/* USER CODE END 4 */

 

 

Then I build it, created the Debug-Profile and ran/resumed it via the Debug-Mode.

I wanted to connect via PuTTY. I turned Flow Control off, and set the data bits to 7. Here are the settings:

putty-settings.png

When I select open I can connect, but the terminal stays just empty.

putty.pngI not sure where the problem is. I would be very grateful if someone could help me.

18 REPLIES 18

@Andrew Neil wrote:

These things are also documented in the User Manual, UM2179:


Although UM2179 omits this from Fig 3

:face_with_rolling_eyes:

See separate post:

https://community.st.com/t5/stm32-mcus-boards-and-hardware/um2179-doesn-t-show-the-vcp-uart-connection/m-p/644955#M17437

 

Sorry if i need to ask again. But does the the STLK_RX/TX refer to those two pins?

IMG_20240228_115511_521.jpg

 

I tried to connect RX/TX to them like this. But it didn't work either:
IMG_20240228_115624_263.jpg

 

I'm sorry for those dumb questions. Currently feeling totally overwhelmed by all the schematics and documentation. If there is a more straight forward way to configure printf i would of course do use it too.

SofLit
ST Employee

Remove the ones crossed.

You have to use the one in rectangle and you have to connect UART2_Tx/UART2_Rx from CNx connectors

SofLit_1-1709118546818.png

 

 

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

@stmax  please keep my answer marked as solution as I've already answered your question.

Now you ask a new question so you need either to open a new thread or keep this discussion but the original question was answered.

Thank you for your understanding.

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.

Okay now It works. Thank you so much for your time and patience!

Andrew Neil
Evangelist III

@SofLit This is a common issue that comes up quite a lot.

As well as clarifying the VCP UART connection diagram (as already mentioned), I think the ST-Link section should specifically state what UART the VCP connects to, and cross-reference to the section with the details:

 

AndrewNeil_0-1709120230984.png

 

Perhaps also something could be added  on "how to use a different UART" ... ?

I think it's something managed in transversal. Each board has it's own UART (sometimes USART1, others USART3, others LPUART1 etc ..). So I think it's not easy to manage in the documentation.

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.

Fair, although the UM2179 here does specifically refer to LPUART1:

AndrewNeil_0-1709121471586.png

There should at least be a cross-reference from the ST-Link section to this section (or its equivalent).

Yes this is a specific section for this board while the other (I think) is a generic paragraph that implies all Nucleo boards. 

Does this kind of specific paragraph available in all UM?:

SofLit_0-1709124906510.png

 

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.