STM32G030(SOP8) UART配置异常求助:TX引脚无数据输出
STM32G030(SOP8)UART配置故障排查
我正在尝试通过ARM汇编配置STM32G030(SOP8)的UART功能。目前外接LED可正常闪烁,说明循环逻辑正常;GDB显示寄存器值正确,但逻辑分析仪检测不到任何数据,TX引脚始终处于高电平状态。
当前寄存器数值
RCC_IOPENR = 0x00000003 @ GPIOA(UART) 和 GPIOB(LED) RCC_APBENR2 = 0x00004000 GPIOA_AFRH = 0x00000010 GPIOA_MODER = 0xebfbffff USART_BRR = 0x00000683 USART_CR1 = 0x00000009 USART_CR2 = 0x00000000 USART_CR3 = 0x00000000 USART_ISR = 0x002000c0
逻辑分析仪监测结果
- 通道1:LED正常闪烁
- STM32 TX引脚:预期输出连续的'A',但实际始终处于高电平状态

请问我配置中存在什么问题?恳请各位提供帮助!
汇编代码
寄存器地址定义
.syntax unified .cpu cortex-m0plus .thumb .word _StackEnd @ 0x20000100 .word Reset_Handler @ 0x00000004 .space 0xb4 .equ RCC, (0x40021000) .equ RCC_IOPENR, (RCC + (0x34)) .equ RCC_APBENR2, (RCC + (0x40)) .equ SYSCFG, (0x40010000) .equ SYSCFG_CFGR1, (SYSCFG + (0x00)) .equ GPIOB, (0x50000400) .equ GPIOB_MODER, (GPIOB + (0x00)) .equ GPIOB_BSRR, (GPIOB + (0x18)) .equ GPIOA, (0x50000000) .equ GPIOA_MODER, (GPIOA + (0x00)) .equ GPIOA_AFRH, (GPIOA + (0x24)) .equ USART1, (0x40013800) .equ USART_CR1, (USART1 + (0x00)) .equ USART_CR2, (USART1 + (0x04)) .equ USART_CR3, (USART1 + (0x08)) .equ USART_BRR, (USART1 + (0x0c)) .equ USART_TDR, (USART1 + (0x28)) .equ USART_ISR, (USART1 + (0x1c))
UART配置代码
.text .type Reset_Handler, %function Reset_Handler: ldr r0, =RCC_IOPENR @ (0x40021034) ldr r2, [r0] movs r3, #0x1 @ 0x1 用于GPIOA (UART1) orrs r2, r2, r3 str r2, [r0] ldr r0, =RCC_APBENR2 @ (0x40021040) UART时钟使能 ldr r2, [r0] ldr r3, =#0x4001 @ orrs r2, r2, r3 str r2, [r0] ldr r0, =SYSCFG_CFGR1 @ (0x40010000) ldr r2, [r0] movs r3, #0x8 orrs r2, r2, r3 str r2, [r0] ldr r0, =GPIOA_AFRH @ (0x50000024) ldr r2, [r0] ldr r3, =#0x10 @ 为PA9配置复用功能AF1 0x10 orrs r2, r2, r3 str r2, [r0] ldr r0, =GPIOA_MODER @ (0x50000000) ldr r2, [r0] ldr r3, =#0xfffbffff @ 为PA9开启复用模式 ands r2, r2, r3 str r2, [r0] ldr r0, =USART_CR1 @ (0x40013800), movs r3, #0x0 @ str r3, [r0] ldr r0, =USART_BRR @ (0x4001380c) ldr r3, =#0x683 @ 16MHz时钟,9600波特率 str r3, [r0] ldr r0, =USART_CR2 @ (0x40013804), movs r3, #0x0 @ str r3, [r0] ldr r0, =USART_CR3 @ (0x40013808), movs r3, #0x0 @ str r3, [r0] ldr r0, =USART_CR1 @ (0x40013800), ldr r2, [r0] movs r3, #0x1 @ 使能USART orrs r2, r2, r3 str r2, [r0] ldr r0, =USART_CR1 @ (0x40013800) ldr r2, [r0] movs r3, #0x8 @ 使能发送器 orrs r2, r2, r3 str r2, [r0] teack_check: ldr r0, =USART_ISR @ (0x4001381c) ldr r2, [r0] ldr r3, =#0x200000 @ 等待TEACK tst r2, r3 beq teack_check
LED配置与主循环代码
ldr r0, =RCC_IOPENR @ (0x40021034) ldr r2, [r0] movs r3, #0x2 @ 0x2 用于GPIOB (LED) orrs r2, r2, r3 str r2, [r0] ldr r1, =GPIOB_MODER @ (0x50000400) ldr r4, [r1] ldr r6, =#0xffff7fff @ 0xffff7fff 用于PB7 ands r4, r4, r6 str r4, [r1] blink_loop: txe_check: ldr r1, =USART_ISR @ (0x4001381c) ldr r2, [r1] ldr r3, =#0x80 tst r2, r3 beq txe_check ldr r1, =USART_TDR @ (0x40013828) movs r3, #0x41 uxtb r4, r3 str r4, [r1] tc_check: ldr r1, =USART_ISR @ (0x4001381c) ldr r2, [r1] ldr r3, =#0x40 tst r2, r3 beq tc_check ldr r0, =GPIOB_BSRR @ 0x50000418 ldr r1, =#0x80 @ LED点亮 str r1, [r0] ldr r2, =#10000000 wait_1: subs r2, #1 bne wait_1 ldr r1, =#0x800000 @ LED熄灭 str r1, [r0] ldr r2, =#10000000 wait_2: subs r2, #1 bne wait_2 b blink_loop
内容的提问来源于stack exchange,提问作者michal
相关产品推荐
相关产品推荐

