You put the pin in alternate-function mode and select which peripheral function it carries. On STM32 that means setting the pin's MODER field to 10 (alternate function) rather than 01 (general-purpose output), then programming the alternate-function multiplexer, the AFR (alternate function registers, AFRL/AFRH), with the AF number that routes, say, USART2_TX to that pin, per the datasheet's pin/AF mapping table. You'd also set the output type (push-pull for most digital signals), speed, and any needed pull. After that, the peripheral (the USART) drives the pin, not your code writing ODR, the GPIO block just connects the pad to the peripheral's signal internally. Getting this wrong (leaving the pin in plain output mode, or selecting the wrong AF number) is a common reason "the UART is configured but nothing comes out of the pin." So peripheral pins require two coordinated setups: the peripheral itself, and the GPIO in AF mode mapped to that peripheral.
Embedded Systems Fundamentals · Interview question
How do you use a GPIO pin for a peripheral like UART TX instead of plain output?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
GPIO: Digital I/O
Reading buttons and driving LEDs: configuring a pin's direction, push-pull vs open-drain outputs, pull-up/down inputs, and why a floating input reads noise.