2025-05-29 5:14 AM
Hello everyone, I am having a problem with a simple program. My board is a STM32-U575ZITxQ.
Using only the USART1 interface, if I try to print the string: "USART1_READY" on my laptop's serial port, I have no problem. However, as soon as I also enable the USART2, I cannot print anything. Whether with only the USART2 enabled, or with both USART1 and USART2 enabled, if I try to print the string with USART2, I cannot. I checked all the settings of the USART1 and USART2 and they are the same (in GPIO, in Parameter setting, etc.).
/* USER CODE BEGIN PV */
char USART1 = "USART1_READY:\r\n";
char USART2= "USART2_READY:\r\n";
/* USER CODE END PV */
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim4);//ready for trigger at 1 seconds
/* USER CODE END 2 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim->Instance == TIM4)
{
//HAL_UART_Transmit(&huart1, &USART1, sizeof(USART1),HAL_MAX_DELAY);
HAL_UART_Transmit(&huart2, &USART2, sizeof(USART2),HAL_MAX_DELAY);
}
}
where am I going wrong?
Solved! Go to Solution.
2025-05-29 5:51 AM
Is this the NUCLEO-U575ZI-Q board?
USART1 is hooked up to the VCP port. USART2 is not. That's probably why one works and one does not.
2025-05-29 5:17 AM
Can you also share the INIT functions for both, usart1 and usart2.
Also, what you mean with usart1 and usart2 having same GPIO?
2025-05-29 5:22 AM - edited 2025-05-29 5:24 AM
@SMusc.1 wrote:My board is a STM32-U575ZITxQ.
That's just a chip part number - it doesn't tell what board you're using.
How are you connecting both UARTs to your laptop?
Before adding the complication of timers & interrupts, have you got this working just using blocking delays in a simple loop?
How to write your question to maximize your chances to find a solution
2025-05-29 5:43 AM
Hi, here the main function where is wrote the INIT function(i removed all timer and complication), non are enabled only the USART1 and USART2 and all other defaoult settings. I add only a delay in while loop and on the USART2 i am not able to print on serial of my laptop. If I use USART1 I can print the messagge corrctly. Only by using USART2 i can't print and he doesnt work. I attached picture where i checked the setting for both GPIO of USART1 and USART 2, I put the same.
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the System Power */
SystemPower_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_ICACHE_Init();
MX_UCPD1_Init();
MX_USB_OTG_FS_PCD_Init();
MX_MEMORYMAP_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(1000);
HAL_UART_Transmit(&huart2, &MESSAGE_FROM_US2, sizeof(MESSAGE_FROM_US2),HAL_MAX_DELAY);
}
/* USER CODE END 3 */
}
2025-05-29 5:51 AM
Is this the NUCLEO-U575ZI-Q board?
USART1 is hooked up to the VCP port. USART2 is not. That's probably why one works and one does not.
2025-05-29 5:52 AM
Hi Andrew, for first question: one at a time. (of course not both at same time).
I tried this way:
1) with both UART1 and UART2 enabled, both initialized, but using only the line of code that prints a message via USART1. Then I repeated it using USART2. It only works with USART1.
2) with only USART1 enabled and initialized, I can print a message on my laptop's serial port.
3) with only USART2 enabled and initialized, I can't print a message on my laptop's serial port. In this case the communication is frozen as in the attached image.
2025-05-29 6:03 AM
Yes, Is that my board. I tried also by using USART3 and not working as well. VCP is the com serial port of laptop right? How can I change this com port association in relation to the USART I am using?
2025-05-29 6:08 AM - edited 2025-05-29 6:08 AM
You still haven't said how you are actually connecting the two UARTs to your PC.
What is the physical connection?
As @TDK said, the VCP (Virtual COM Port) of the ST-Link in only connected to USART1 - so you won't get anything from any other UART via that route.
To see output from UART2 (or UART3, or any other UART), you will have to provide some other connection from UART2 to your PC.
2025-05-29 6:12 AM
Yes, i am using ST-Link. Now to be able to connect also from USART2 and USART3 how I have to do?
2025-05-29 6:15 AM - edited 2025-05-29 6:15 AM
The USART1 pins on the board are hooked up to the st-link chip, see the user manual and the schematic.
If you want to change to USART2 or something else, you will need to physically modify the board by breaking those connections and creating new connections with the pins for the other peripheral.
You should probably just stick with using USART1.