assembly ARM组件中的stm32g030 UART

bksxznpy  于 2023-05-18  发布在  其他
关注(0)|答案(2)|浏览(247)

我正在尝试将stm32 g 030(SOP 8)配置为使用UART。
下面你可以看到我到现在为止写的汇编代码。
添加的LED Flink ,因此循环正常工作。
GDB显示寄存器中的正确值。
但是逻辑分析仪什么也没显示,没有任何数据。
引脚始终为高电平。
@寄存器值

RCC_IOPENR = 0x00000003       @ GPIOA(UART) and 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

@距离逻辑分析仪30秒
通道1-LED Flink
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 for GPIOA (UART1)
    orrs    r2, r2, r3              
    str     r2, [r0]                

    ldr     r0, =RCC_APBENR2        @       (0x40021040) UART clock enable
    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              @       define alternate AF1 for PA9 0x10
    orrs    r2, r2, r3              
    str     r2, [r0]

    ldr     r0, =GPIOA_MODER        @       (0x50000000)
    ldr     r2, [r0]                
    ldr     r3, =#0xfffbffff        @   turn on alternate for 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 and 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 enabled
    orrs    r2, r2, r3
    str     r2, [r0]

    ldr     r0, =USART_CR1          @       (0x40013800)
    ldr     r2, [r0]
    movs    r3, #0x8               @       transmiter enabled
    orrs    r2, r2, r3
    str     r2, [r0]
                              
teack_check:
    ldr     r0, =USART_ISR          @       (0x4001381c)
    ldr     r2, [r0]
    ldr     r3, =#0x200000          @       waiting for TEACK
    tst     r2, r3
    beq     teack_check

@ UART配置结束
@用于LED的GPIOB

ldr     r0, =RCC_IOPENR         @       (0x40021034)
    ldr     r2, [r0]                
    movs    r3, #0x2               @    0x2 for GPIOB (LED)
    orrs    r2, r2, r3              
    str     r2, [r0]                

    ldr     r1, =GPIOB_MODER        @       (0x50000400)
    ldr     r4, [r1]                       
    ldr     r6, =#0xffff7fff        @       0xffff7fff for 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 turn on
        str     r1, [r0]

        ldr     r2, =#10000000
    wait_1:
        subs    r2, #1
        bne     wait_1

        ldr     r1, =#0x800000          @   LED turn off
        str     r1, [r0]

        ldr     r2, =#10000000
    wait_2:
        subs    r2, #1
        bne     wait_2

        b       blink_loop
mum43rcc

mum43rcc1#

引脚5默认为PA 11;对于PA 9,必须设置SYSCFG_CFGR1.PA11_RMP。
顺便说一句,不要忘记在RCC中启用SYSCFG时钟。
JW

nbnkbykc

nbnkbykc2#

好的,通过wek解决了。
我相应地修改了代码,现在它像预期的那样工作。

相关问题