You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

STM32F373VCT6的USART1配置无报错,但PC接收不到数据求排查

Hey there! Let's walk through the issues in your code and figure out why your USART1 isn't sending data to the PC. I've spotted several key points that need fixing:

1. Missing USART1 Pin Remapping Configuration

You're using PC4 (TX) and PC5 (RX) for USART1, but these are remapped pins—not the default PA9/PA10. You enabled the SYSCFG clock, but didn't actually set up the remapping. Add this line in your USART1_Config() function before enabling USART1:

// Remap USART1 to PC4/PC5 (AF7)
SYSCFG->CFGR1 |= SYSCFG_CFGR1_USART1_REMAP;

Without this, the MCU won't route USART1 signals to PC4/PC5.

2. Incorrect GPIO Output Type for TX Pin

You set PC4 to open-drain (OD) mode with GPIOC->OTYPER |= 1 << (4*1);. Open-drain requires an external pull-up resistor to drive the signal high, which you probably don't have connected. Change this to push-pull instead:

// Set PC4 to push-pull output (remove the OD setting)
GPIOC->OTYPER &= ~(1 << 4);

Push-pull is the right choice for direct TTL-level communication with PL2303.

3. Verify System Clock Frequency

Your baud rate calculation uses 72000000/115200, but you need to confirm that your system clock is actually running at 72MHz. Check the SystemInit() function in system_stm32f37x.c—make sure the PLL is configured correctly to generate 72MHz from the HSE or HSI. If the clock is lower (e.g., 8MHz default), your baud rate will be way off, causing communication failure.

4. Adjust USART Initialization Order

While not a critical bug, it's better practice to configure all USART parameters before enabling the USART peripheral. Reorder your USART1_Config() code like this:

void USART1_Config(void) {
    RCC->APB2ENR |= RCC_APB2ENR_USART1EN | RCC_APB2ENR_SYSCFGEN; 
    // Add remapping first
    SYSCFG->CFGR1 |= SYSCFG_CFGR1_USART1_REMAP;

    // Configure USART parameters
    USART1->BRR = 72000000 / 115200;
    USART1->CR1 &= ~USART_CR1_OVER8;
    USART1->CR1 &= ~USART_CR1_M;
    USART1->CR2 &= ~(USART_CR2_STOP_1 | USART_CR2_STOP_0);
    USART1->CR1 &= ~USART_CR1_PCE;

    // Enable transmitter and receiver FIRST, then USART
    USART1->CR1 |= USART_CR1_TE | USART_CR1_RE;
    USART1->CR1 |= USART_CR1_UE;
}

5. Double-Check Hardware Connections

Don't overlook the basics:

  • Connect PL2303's TX pin to STM32's PC5 (RX)
  • Connect PL2303's RX pin to STM32's PC4 (TX)
  • Make sure both devices share a common GND (this is crucial for TTL communication)
  • Verify that PL2303 drivers are installed correctly on your PC, and the serial port settings match (115200 baud, 8N1, no flow control)

Fixed GPIO_Config() Function

Here's the corrected version of your GPIO configuration with the push-pull fix:

void GPIO_Config(void) {
    // PC4 (TX) configuration
    RCC->AHBENR |= 1 << 19; // Enable GPIOC clock
    GPIOC->MODER |= 2 << (4*2); // GPIO_Mode_AF
    GPIOC->OTYPER &= ~(1 << 4); // GPIO_OType_PP (push-pull)
    GPIOC->OSPEEDR |= 3 << (4*2); // GPIO_Speed_50MHz
    GPIOC->PUPDR &= ~(3 << (4*2)); // GPIO_PuPd_NOPULL
    GPIOC->AFR[0] |= 7 << (4*4); // AF7 for USART1_TX

    // PC5 (RX) configuration
    GPIOC->MODER |= 2 << (5*2); // GPIO_Mode_AF
    GPIOC->AFR[0] |= 7 << (5*4); // AF7 for USART1_RX
}

After making these changes, reflash your MCU and test the serial communication again. Most likely, the missing pin remapping and open-drain output were the main culprits.

内容的提问来源于stack exchange,提问作者Cường Thân Cao

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:31:32