UART sample code output junk characters

I am using sample UART code download from website and it is uses the following function. When i reboot the LPC2148 board, i got junk char display in hypter terminal, i verified the serial port settings.

void initUART0(int baud) {

int divisor = divide(getCclk(), (VPBDIV * 16 * baud));

U0LCR = 0x83; // 8 bit, 1 stop bit, no parity, enable DLAB

U0DLL = divisor & 0xFF;

U0DLM = (divisor >> 8) & 0xFF;

//U0DLL = 0x10; // = 60,000,000 / VPBDIV / (16 * 115200)

U0LCR &= ~0x80; // Disable DLAB

PINSEL0 = (PINSEL0 & 0xFFFFFFF0) | 0x00000005;

U0FCR = 0x03;

}

int put(int ch) {

if (ch == ‘\n’) {

while (!(U0LSR & 0x20));

U0THR = ‘\r’;

}

while (!(U0LSR & 0x20));

U0THR = ch;

}

When i use KEIL compiled uart code which is using SWI. It works well.

But i can’t use the same SWI routine in my GCC WinARM environment. I got the following error.

src/startup/crt.s: Assembler messages:

src/startup/crt.s:122: Error: bad instruction `dcd SWI_Cnt’

src/startup/crt.s:124: Error: bad instruction `import __SWI_8’

src/startup/crt.s:125: Error: bad instruction `import __SWI_9’

src/startup/crt.s:128: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:129: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:130: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:131: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:132: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:133: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:134: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:135: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:136: Error: bad instruction `dcd __SWI_8’

src/startup/crt.s:137: Error: bad instruction `dcd __SWI_9’

src/startup/crt.s:139: Error: bad instruction `swi_end’

Can you guess what might be a problem?

karunanithy:
When i use KEIL compiled uart code which is using SWI. It works well.

But i can’t use the same SWI routine in my GCC WinARM environment. I got the following error.

src/startup/crt.s: Assembler messages:

src/startup/crt.s:122: Error: bad instruction `dcd SWI_Cnt’

src/startup/crt.s:124: Error: bad instruction `import __SWI_8’

src/startup/crt.s:125: Error: bad instruction `import __SWI_9’

src/startup/crt.s:128: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:129: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:130: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:131: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:132: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:133: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:134: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:135: Error: bad instruction `dcd SWI_Dead’

src/startup/crt.s:136: Error: bad instruction `dcd __SWI_8’

src/startup/crt.s:137: Error: bad instruction `dcd __SWI_9’

src/startup/crt.s:139: Error: bad instruction `swi_end’

Can you guess what might be a problem?

No guess necessary! All of your your assembler error messages show that your assembly code in “crt.s” are using the assembly syntax of the standard ARM assembler. You need to port your assembly code to the GNU assembler syntax if you want to use that “crt.s” with the GNU toolset. It is easy enough to do, you just need to know what was intended by the ARM assembler instruction and then change that instruction line to use the equivalent GNU assembler command. It helps to have the user manuals for both assemblers handy.

Thank you for your suggesstion.

I don’t know how to replace that DCD command. I am still searcing in internet, that how to replace it.

If you know, please let me know.

Karun

karunanithy:
Thank you for your suggesstion.

I don’t know how to replace that DCD command. I am still searcing in internet, that how to replace it.

If you know, please let me know.

Karun

“DCD” in ARM assembly is the same as “.word” in GCC assembly.

That information is also available in their respective user manuals.

T_Bit EQU 0x20

PRESERVE8 ; 8-Byte aligned Stack

AREA SWI_Area, CODE, READONLY

ARM

EXPORT SWI_Handler

SWI_Handler

STMFD SP!, {R12, LR} ; Store R12, LR

MRS R12, SPSR ; Get SPSR

STMFD SP!, {R8, R12} ; Store R8, SPSR

TST R12, #T_Bit ; Check Thumb Bit

LDRNEH R12, [LR,#-2] ; Thumb: Load Halfword

BICNE R12, R12, #0xFF00 ; Extract SWI Number

LDREQ R12, [LR,#-4] ; ARM: Load Word

BICEQ R12, R12, #0xFF000000 ; Extract SWI Number

LDR R8, SWI_Count

CMP R12, R8

BHS SWI_Dead ; Overflow

ADR R8, SWI_Table

LDR R12, [R8,R12,LSL #2] ; Load SWI Function Address

MOV LR, PC ; Return Address

BX R12 ; Call SWI Function

LDMFD SP!, {R8, R12} ; Load R8, SPSR

MSR SPSR_cxsf, R12 ; Set SPSR

LDMFD SP!, {R12, PC}^ ; Restore R12 and Return

SWI_Dead B SWI_Dead ; None Existing SWI

SWI_Cnt EQU (SWI_End-SWI_Table)/4

SWI_Count DCD SWI_Cnt

IMPORT __SWI_8

IMPORT __SWI_9

SWI_Table

DCD SWI_Dead ; SWI 0 Function Entry

DCD SWI_Dead ; SWI 1 Function Entry

DCD SWI_Dead ; SWI 2 Function Entry

DCD SWI_Dead ; SWI 3 Function Entry

DCD SWI_Dead ; SWI 4 Function Entry

DCD SWI_Dead ; SWI 5 Function Entry

DCD SWI_Dead ; SWI 6 Function Entry

DCD SWI_Dead ; SWI 7 Function Entry

DCD __SWI_8 ; SWI 8 Function Entry

DCD __SWI_9 ; SWI 9 Function Entry

; …

SWI_End

I have converted the above code as follows

T_Bit = 0x20

SWIHandler:

STMFD SP!, {r12, lr} // Store R12, LR

MRS R12, SPSR //Get SPSR

STMFD SP!, {R8, R12} // Store R8, SPSR

TST R12, #T_Bit // Check Thumb Bit

LDRNEH R12, [LR,#-2] // Thumb: Load Halfword

BICNE R12, R12, #0xFF00 // Extract SWI Number

LDREQ R12, [LR,#-4] // ARM: Load Word

BICEQ R12, R12, #0xFF000000 // Extract SWI Number

LDR R8, SWI_Count

CMP R12, R8

BHS SWI_Dead // Overflow

ADR R8, SWI_Table

LDR R12, [R8,R12,LSL #2] // Load SWI Function Address

MOV LR, PC // Return Address

BX R12 // Call SWI Function

LDMFD SP!, {R8, R12} // Load R8, SPSR

MSR SPSR_cxsf, R12 // Set SPSR

LDMFD SP!, {R12, PC}^ // Restore R12 and Return

SWI_Cnt = (10-SWI_Table)/4

SWI_Count:

.word SWI_Cnt

// IMPORT __SWI_8

// IMPORT __SWI_9

SWI_Table:

.word SWI_Dead // SWI 0 Function Entry

.word SWI_Dead // SWI 1 Function Entry

.word SWI_Dead // SWI 2 Function Entry

.word SWI_Dead // SWI 3 Function Entry

.word SWI_Dead // SWI 4 Function Entry

.word SWI_Dead // SWI 5 Function Entry

.word SWI_Dead // SWI 6 Function Entry

.word SWI_Dead // SWI 7 Function Entry

.word __SWI_8 // SWI 8 Function Entry

.word __SWI_9 // SWI 9 Function Entry

//SWI_End

SWI_Dead:

B SWI_Dead // None Existing SWI

I got the following error

src/startup/crt.s: Assembler messages:

src/startup/crt.s:125: Error: invalid sections for operation on L0☺' and SWI_Table’

Could you help me to solve this problem