;;; -*- Mode:Asm Mode:outline-minor-mode outline-regexp:";;;+" comment-start: "; " -*- ;;; ser2.asm ;;; Frank Sergeant frank@pygmy.utoh.org ;;; Test program for the Olimex LPC P-2378 board. ;;; Use autobaud to set up the serial port. Ignore all other timing ;;; aspects -- accept timing as the bootloader leaves it. ;;; When running (with a terminal program such as minicom), the first ;;; 'A' you type sets the baudrate. Thereafter, type an 'A' as a ;;; pacing mechanism. Every time you type an 'A', this program then ;;; transmits 'Q' 'a' 'b' 'c' back to the terminal. ;;; Note, if your terminal program is line oriented rather than character ;;; oriented, you may need to press Enter after typing one or more 'A's ;;; to cause your terminal program to actually transmit the 'A's. .include "equates-lpc23xx.s" .include "olimex-lpc2378-equates.s" ;;; Code .code 32 .section .text .global vectors .org 0 .global _start ;;; Vectors ; each interrupt vector runs an endless loop except for reset vectors: b _start b . b . b . b . b . b . b . .section .text _start: ;;;; Ports and Pins ;; Set the GPIOM bit so we can use Fast GPIO. ;; (The bootloader might have set the GPIOM bit but set it ;; explicitly to be sure.) ;; set P0.2 and P0.3 as UART0 rather than GPIO pin ;; PINSEL0 bits 5:4 and 7:6 ;; ...01010000 ldr r6, = PINSEL0 mov r0, #0x50 str r0, [r6] ;;;; Serial Port Setup setser: ; Write to U0LCR to set 8 data bits, 1 stop bit, and no parity ldr r6, = U0BASE mov r0, #0x03 ; 8 bits, 1 stop, no parity strb r0, [r6, #ULCR] enfifo: mov r0, #1 ; enable FIFOs (required) strb r0, [r6, #UFCR] ; must set bit0 for uart to work at all, apparently mov r0, #0x80 ; it should not be necessary to write a 1 to the TXEN strb r0, [r6, #UTER] ; flag in the Transmit Enable Register, but just in case ... enautobaud: ; turn on the autobaud feature mov r0, #1 str r0, [r6, #UACR] awaitA: ldr r1, [r6] ; read char whether one is waiting or not cmp r1, #'A' bne awaitA ; keep waiting until an 'A' is received tx: tdre1: ldrb r2, [r6, #ULSR] tst r2, #0x20 ; Wait for transmit data register empty flag beq tdre1 ; to be true. mov r1, #'Q' ; Transmit a "Q" strb r1, [r6, #UDATA] ; via the serial port tdre2: ldrb r2, [r6, #ULSR] tst r2, #0x20 ; Wait for transmit data register empty flag beq tdre2 ; to be true. mov r1, #'a' ; Transmit an "a" strb r1, [r6, #UDATA] tdre3: ldrb r2, [r6, #ULSR] tst r2, #0x20 ; Wait for transmit data register empty flag beq tdre3 ; to be true. mov r1, #'b' ; Transmit a "b" strb r1, [r6, #UDATA] tdre4: ldrb r2, [r6, #ULSR] tst r2, #0x20 ; Wait for transmit data register empty flag beq tdre4 ; to be true. mov r1, #'c' ; Transmit a "c" strb r1, [r6, #UDATA] b awaitA ; continue forever