TRIMUI SMART >> Assembly

UART


參考資訊:
1. pdf

UART2腳位:


APB2


Gating


Reset


UART2


計算方式

Baudrate = OSC24M/(16*divisor) = 24MHz/(16*13) = 115385 ~= 115200

main.s

    .global _start
     
    .equ CCU_BASE,   0x01c20000
    .equ GPIO_BASE,  0x01c20800
    .equ UART2_BASE, 0x01c28800
   
    .equ PLL_CPU_CTRL_REG,     0x0000
    .equ CPU_AXI_CFG_REG,      0x0050
    .equ APB2_CFG_REG,         0x0058
    .equ PLL_PERIPH0_CTRL_REG, 0x002c
    .equ BUS_CLK_GATING_REG3,  0x006c
    .equ BUS_SOFT_RST_REG4,    0x02d8
 
    .equ PB,   (0x24 * 1)
    .equ PG,   (0x24 * 6)
    .equ CFG0, 0x00
    .equ CFG1, 0x04
    .equ DATA, 0x10
    .equ RBR,  0x0000
    .equ THR,  0x0000
    .equ DLL,  0x0000
    .equ DLH,  0x0004
    .equ IER,  0x0004
    .equ IIR,  0x0008
    .equ LCR,  0x000c
    .equ MCR,  0x0010
    .equ LSR,  0x0014
    .equ USR,  0x007c
    
    .arm
    .text
_start:
    .long 0xea000016
    .byte 'e', 'G', 'O', 'N', '.', 'B', 'T', '0'
    .long 0, __spl_size
    .byte 'S', 'P', 'L', 2
    .long 0, 0
    .long 0, 0, 0, 0, 0, 0, 0, 0
    .long 0, 0, 0, 0, 0, 0, 0, 0
    
_vector:
    b reset
    b .
    b .
    b .
    b .
    b .
    b .
    b .
    
reset:
    ldr r0, =CCU_BASE
    ldr r1, =(1 << 18)
    str r1, [r0, #BUS_CLK_GATING_REG3]
    str r1, [r0, #BUS_SOFT_RST_REG4]

    ldr r0, =GPIO_BASE
    ldr r1, =0x22
    str r1, [r0, #(PB + CFG0)]
    
    ldr r0, =UART2_BASE
    ldr r1, =0x00
    str r1, [r0, #IER]
    ldr r1, =0x00
    str r1, [r0, #MCR]
    ldr r1, [r0, #LCR]
    orr r1, #(1 << 7)
    str r1, [r0, #LCR]
    ldr r1, =13
    str r1, [r0, #DLL]
    ldr r1, =0x00
    str r1, [r0, #DLH]
    ldr r1, [r0, #LCR]
    bic r1, #(1 << 7)
    str r1, [r0, #LCR]
    ldr r1, [r0, #LCR]
    bic r1, #0x1f
    orr r1, #0x03
    str r1, [r0, #LCR]
    
    ldr r2, =hello
1:
    ldr r1, [r0, #LSR]
    tst r1, #(1 << 5)
    beq 1b
    ldrb r1, [r2]
    strb r1, [r0, #THR]
    add r2, #1
    cmp r1, #0
    bne 1b
  
main:
    b main

    .align
hello: .asciz "Hello, world!"
    .end

完成


返回上一頁