I am trying to do the echo of the data received on the UART, i.e wait for the characters from the UART and transmit it back on the UART. I am emulating the LM3S811 board in QEMU. I have attached the .c file and the startup and linker code. I get errors while compiling the .c file and I don't know whether the approach is the correct to do the echo of data received on the UART. It would be helpful if any links explaining the bare-metal programming from scratch are provided. Thanks.
main.c
#define U0RBR (*((volatile unsigned int *) 0x4000C000))
#define U0DLL (*((volatile unsigned int *) 0x4000C000))
#define U0THR (*((volatile unsigned int *) 0x4000C000))
#define U0LCR (*((volatile unsigned int *) 0x4000C00C))
#define U0DLM (*((volatile unsigned int *) 0x4000C004))
#define U0LSR (*((volatile unsigned int *) 0x4000C014))
void UART0_init(void);
unsigned char UART0_RxChar(void);
void UART0_TxChar(char ch);
void UART0_init(void)
{
volatile unsigned int PINSEL0 = 0x0;
PINSEL0 = 0x00000005;
U0LCR = 0x83;
U0DLM = 0x00;
U0DLL = 0x61;
U0LCR = 0x03;
}
unsigned char UART0_RxChar(void)
{
while ((U0LSR & 0x01) == 0);
return U0RBR;
}
void UART0_TxChar(char ch)
{
U0THR = ch;
while ((U0LSR & 0x40) == 0);
}
int main(void)
{
char receive;
UART0_init();
while (1) {
receive = UART0_Rxchar();
UART0_TxChar(receive);
}
return 0;
}
startup.s
.thumb
.global start
start:
.word 0x20001000
.word main
flash.ld
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x00010000
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00002000
}
SECTIONS
{
.text : {
*(.vectors);
*(.text);
etext = .;
} > FLASH
.rodata : {
*(.rodata);
} > FLASH
.data : {
sdata = .;
*(.data);
edata = .;
} > SRAM AT > FLASH
.bss : {
sbss = .;
*(.bss);
ebss = .;
} > SRAM
}
Errors while compiling the .c file command : arm-none-eabi-gcc -mthumb -mcpu=cortex-m3 - c main.c -o main.o
main.c:7:2: error: 'PINSEL0' undeclared (first use in this function)
PINSEL0 = PINSEL0 | 0x00000005;
^
main.c:7:2: note: each undeclared identifier is reported only once for each function it appears in
main.c:8:2: error: 'UOLCR' undeclared (first use in this function)
UOLCR = 0x83;
^
main.c:9:2: error: 'U0DLM' undeclared (first use in this function)
U0DLM = 0x00;
^
main.c:10:2: error: 'U0DLL' undeclared (first use in this function)
U0DLL = 0x61;
^
main.c:11:2: error: 'U0LCR' undeclared (first use in this function)
U0LCR = 0x03;
After adding the register's address in Qemu only character 'a' gets printed and I am unable to type in the terminal. The command invoked was qemu-system-arm -M lm3s811evb -kernel main.bin -monitor stdio
User contributions licensed under CC BY-SA 3.0