[STM32F411RE] USART2 data always goes to ST-LINK VCP instead of PA2/PA3 pins
Problem description
Hi everyone,
I’m working with a NUCLEO-F411RE board and I need to use USART2 (PA2=TX, PA3=RX) to communicate with a LoRa module (Reyax RYLR998).
The issue is: even though I configure USART2 in CubeMX, all data I send ends up on the COM9 (ST-LINK VCP) of my PC (USB micro connector), not on the physical pins PA2/PA3.
What I want:
Data should go out via PA2/PA3 → LoRa module.
But instead it always goes to the PC via COM9.
What I already checked
CubeMX configuration
USART2 enabled in Asynchronous mode.
PA2 assigned to USART2_TX, PA3 assigned to USART2_RX.
Baudrate = 115200, 8N1, no flow control.
SYS/Debug set to Serial Wire (not Trace Asynchronous SW).
printf redirection
No active redirection to ITM/SWV.
When using printf, I have _write function pointing to huart2:
int _write(int file, char *ptr, int len) { HAL_UART_Transmit(&huart2, (uint8_t*)ptr, len, HAL_MAX_DELAY); return len; }
SWV disabled
In CubeMX: Debug = Serial Wire only.
Not using ITM or ITM_SendChar.
Direct test in code
Configured PA2/PA3 manually as alternate function AF7 and tested:HAL_Delay(2000); char test[] = "UART2_FISICO_TEST\r\n"; HAL_UART_Transmit(&huart2, (uint8_t*)test, strlen(test), 1000);→ The string still shows up on COM9, not on the LoRa module.
Registers checked in debugger
GPIOA->MODER shows AF mode for PA2/PA3.
GPIOA->AFR[0] = 7 for those pins.
USART2->CR1 is enabled.
My suspicions
Maybe printf redirection is still enabled towards ST-LINK VCP somehow.
On NUCLEO boards, solder bridges SB62/SB63 connect PA2/PA3 to the ST-LINK VCP, so maybe that’s why the PC always sees the data.
I’m not sure if it’s even possible to receive from an external sensor on USART2_RX (PA3) while those solder bridges remain connected, or if that would cause line conflicts with ST-LINK RX.
Question
How can I force USART2 to use only the physical PA2/PA3 pins and not be redirected to COM9 (ST-LINK VCP)?
Is cutting SB62/SB63 really the only option, or is there a CubeMX/firmware configuration I’m missing?
If I connect a sensor to USART2_RX (PA3), will it conflict with ST-LINK RX and cause collisions?
Any advice on how to free PA2/PA3 for my LoRa module (ideally without losing COM9 debugging) would be very helpful.
Thanks in advance!
