2024-02-28 01:06 AM - edited 2024-02-28 02:23 AM
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.)
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:
When I select open I can connect, but the terminal stays just empty.
I not sure where the problem is. I would be very grateful if someone could help me.
Solved! Go to Solution.
2024-02-28 02:50 AM - edited 2024-02-28 02:52 AM
@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:
2024-02-28 03:02 AM
Sorry if i need to ask again. But does the the STLK_RX/TX refer to those two pins?
I tried to connect RX/TX to them like this. But it didn't work either:
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.
2024-02-28 03:06 AM - edited 2024-02-28 03:10 AM
Remove the ones crossed.
You have to use the one in rectangle and you have to connect UART2_Tx/UART2_Rx from CNx connectors
2024-02-28 03:13 AM - edited 2024-02-28 03:14 AM
@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.
2024-02-28 03:14 AM
Okay now It works. Thank you so much for your time and patience!
2024-02-28 03:39 AM
@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:
Perhaps also something could be added on "how to use a different UART" ... ?
2024-02-28 03:43 AM - edited 2024-02-28 03:43 AM
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.
2024-02-28 03:59 AM
Fair, although the UM2179 here does specifically refer to LPUART1:
There should at least be a cross-reference from the ST-Link section to this section (or its equivalent).
2024-02-28 04:55 AM
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?: