├── Hello01 ├── startup.s ├── memmap.ld ├── Makefile ├── hello01.c └── README.txt ├── Hello02 ├── startup.s ├── memmap.ld ├── Makefile ├── hello02.c └── README.txt ├── Hello03 ├── startup.s ├── memmap.ld ├── Makefile ├── README.txt └── hello03.c ├── Hello04 ├── startup.s ├── memmap.ld ├── hello04.c ├── Makefile ├── xuartps.c ├── README.txt └── xuartps.h ├── Hello05 ├── startup.s ├── memmap.ld ├── Makefile ├── hello05.c ├── xuartps.c ├── printf.h ├── printf.c ├── README.txt └── xuartps.h ├── HelloQemu ├── startup.s ├── cmd.txt ├── memmap.ld ├── Makefile ├── helloq.c └── README.txt ├── XilinxUploadHowTo.txt └── README.txt /Hello01/startup.s: -------------------------------------------------------------------------------- 1 | LDR sp, =stack_top 2 | BL c_entry 3 | B . 4 | -------------------------------------------------------------------------------- /Hello02/startup.s: -------------------------------------------------------------------------------- 1 | LDR sp, =stack_top 2 | BL c_entry 3 | B . 4 | -------------------------------------------------------------------------------- /Hello03/startup.s: -------------------------------------------------------------------------------- 1 | LDR sp, =stack_top 2 | BL c_entry 3 | B . 4 | -------------------------------------------------------------------------------- /Hello04/startup.s: -------------------------------------------------------------------------------- 1 | LDR sp, =stack_top 2 | BL c_entry 3 | B . 4 | -------------------------------------------------------------------------------- /Hello05/startup.s: -------------------------------------------------------------------------------- 1 | LDR sp, =stack_top 2 | BL c_entry 3 | B . 4 | -------------------------------------------------------------------------------- /HelloQemu/startup.s: -------------------------------------------------------------------------------- 1 | LDR sp, =stack_top 2 | BL c_entry 3 | B . 4 | -------------------------------------------------------------------------------- /HelloQemu/cmd.txt: -------------------------------------------------------------------------------- 1 | target remote 127.0.0.1:1234 2 | load helloq.elf 3 | c 4 | 5 | -------------------------------------------------------------------------------- /Hello01/memmap.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x10000; 4 | start = 0x10000; /* Informs .elf uploaders on start address*/ 5 | .ro : { 6 | startup.o (.text) 7 | *(.text) 8 | *(.rodata) 9 | } 10 | .rw : { 11 | *(.data) 12 | *(.bss) *(COMMON) 13 | } 14 | . = ALIGN(8); 15 | 16 | heap_low = .; /* for _sbrk */ 17 | . = . + 0x10000; /* 64kB of heap memory */ 18 | heap_top = .; /* for _sbrk */ 19 | . = . + 0x10000; /* 64kB of stack memory */ 20 | stack_top = .; /* for startup.s */ 21 | } -------------------------------------------------------------------------------- /Hello02/memmap.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x10000; 4 | start = 0x10000; /* Informs .elf uploaders on start address*/ 5 | .ro : { 6 | startup.o (.text) 7 | *(.text) 8 | *(.rodata) 9 | } 10 | .rw : { 11 | *(.data) 12 | *(.bss) *(COMMON) 13 | } 14 | . = ALIGN(8); 15 | 16 | heap_low = .; /* for _sbrk */ 17 | . = . + 0x10000; /* 64kB of heap memory */ 18 | heap_top = .; /* for _sbrk */ 19 | . = . + 0x10000; /* 64kB of stack memory */ 20 | stack_top = .; /* for startup.s */ 21 | } -------------------------------------------------------------------------------- /Hello03/memmap.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x10000; 4 | start = 0x10000; /* Informs .elf uploaders on start address*/ 5 | .ro : { 6 | startup.o (.text) 7 | *(.text) 8 | *(.rodata) 9 | } 10 | .rw : { 11 | *(.data) 12 | *(.bss) *(COMMON) 13 | } 14 | . = ALIGN(8); 15 | 16 | heap_low = .; /* for _sbrk */ 17 | . = . + 0x10000; /* 64kB of heap memory */ 18 | heap_top = .; /* for _sbrk */ 19 | . = . + 0x10000; /* 64kB of stack memory */ 20 | stack_top = .; /* for startup.s */ 21 | } -------------------------------------------------------------------------------- /Hello04/memmap.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x10000; 4 | start = 0x10000; /* Informs .elf uploaders on start address*/ 5 | .ro : { 6 | startup.o (.text) 7 | *(.text) 8 | *(.rodata) 9 | } 10 | .rw : { 11 | *(.data) 12 | *(.bss) *(COMMON) 13 | } 14 | . = ALIGN(8); 15 | 16 | heap_low = .; /* for _sbrk */ 17 | . = . + 0x10000; /* 64kB of heap memory */ 18 | heap_top = .; /* for _sbrk */ 19 | . = . + 0x10000; /* 64kB of stack memory */ 20 | stack_top = .; /* for startup.s */ 21 | } -------------------------------------------------------------------------------- /Hello05/memmap.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x10000; 4 | start = 0x10000; /* Informs .elf uploaders on start address*/ 5 | .ro : { 6 | startup.o (.text) 7 | *(.text) 8 | *(.rodata) 9 | } 10 | .rw : { 11 | *(.data) 12 | *(.bss) *(COMMON) 13 | } 14 | . = ALIGN(8); 15 | 16 | heap_low = .; /* for _sbrk */ 17 | . = . + 0x10000; /* 64kB of heap memory */ 18 | heap_top = .; /* for _sbrk */ 19 | . = . + 0x10000; /* 64kB of stack memory */ 20 | stack_top = .; /* for startup.s */ 21 | } -------------------------------------------------------------------------------- /HelloQemu/memmap.ld: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | . = 0x10000; 4 | start = 0x10000; /* Informs .elf uploaders on start address*/ 5 | .ro : { 6 | startup.o (.text) 7 | *(.text) 8 | *(.rodata) 9 | } 10 | .rw : { 11 | *(.data) 12 | *(.bss) *(COMMON) 13 | } 14 | . = ALIGN(8); 15 | 16 | heap_low = .; /* for _sbrk */ 17 | . = . + 0x10000; /* 64kB of heap memory */ 18 | heap_top = .; /* for _sbrk */ 19 | . = . + 0x10000; /* 64kB of stack memory */ 20 | stack_top = .; /* for startup.s */ 21 | } -------------------------------------------------------------------------------- /Hello04/hello04.c: -------------------------------------------------------------------------------- 1 | /* 2 | ZedBoard / Zynq-7000 3 | UART info could be found in 4 | B.33 UART Controller (UART) / Page 1626 in 5 | Zynq-7000 6 | All Programmable SoC 7 | Technical Reference Manual 8 | 9 | http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf 10 | */ 11 | 12 | 13 | #include 14 | #include "xuartps.h" /*Maps stdout to use the RS232 uart*/ 15 | 16 | void c_entry() 17 | { 18 | init_uart1_RxTx_115200_8N1(); 19 | printf("\nHello world!\n"); 20 | while(1) ; /*dont exit the program*/ 21 | } 22 | -------------------------------------------------------------------------------- /HelloQemu/Makefile: -------------------------------------------------------------------------------- 1 | ARMGNU ?= arm-linux-gnueabihf 2 | COPS = 3 | ARCH = -mcpu=cortex-a9 -mfpu=vfpv3 4 | 5 | gcc : helloq.bin 6 | 7 | all : gcc clang 8 | 9 | clean : 10 | rm -f *.o 11 | rm -f *.bin 12 | rm -f *.hex 13 | rm -f *.elf 14 | rm -f *.list 15 | rm -f *.img 16 | rm -f *.bc 17 | 18 | clang: hello02.bin 19 | 20 | startup.o : startup.s 21 | $(ARMGNU)-as $(ARCH) startup.s -o startup.o 22 | 23 | helloq.o : helloq.c 24 | $(ARMGNU)-gcc $(COPS) $(ARCH) -c helloq.c -o helloq.o 25 | 26 | helloq.bin : memmap.ld startup.o helloq.o 27 | $(ARMGNU)-ld startup.o helloq.o -T memmap.ld -o helloq.elf 28 | $(ARMGNU)-objdump -D helloq.elf > helloq.list 29 | $(ARMGNU)-objcopy helloq.elf -O ihex helloq.hex 30 | $(ARMGNU)-objcopy helloq.elf -O binary helloq.bin 31 | -------------------------------------------------------------------------------- /Hello01/Makefile: -------------------------------------------------------------------------------- 1 | ARMGNU ?= arm-linux-gnueabihf 2 | COPS = 3 | ARCH = -mcpu=cortex-a9 -mfpu=vfpv3 4 | 5 | gcc : hello01.bin 6 | 7 | all : gcc clang 8 | 9 | clean : 10 | rm -f *.o 11 | rm -f *.bin 12 | rm -f *.hex 13 | rm -f *.elf 14 | rm -f *.list 15 | rm -f *.img 16 | rm -f *.bc 17 | 18 | clang: hello02.bin 19 | 20 | startup.o : startup.s 21 | $(ARMGNU)-as $(ARCH) startup.s -o startup.o 22 | 23 | hello01.o : hello01.c 24 | $(ARMGNU)-gcc $(COPS) $(ARCH) -c hello01.c -o hello01.o 25 | 26 | hello01.bin : memmap.ld startup.o hello01.o 27 | $(ARMGNU)-ld startup.o hello01.o -T memmap.ld -o hello01.elf 28 | $(ARMGNU)-objdump -D hello01.elf > hello01.list 29 | $(ARMGNU)-objcopy hello01.elf -O ihex hello01.hex 30 | $(ARMGNU)-objcopy hello01.elf -O binary hello01.bin 31 | -------------------------------------------------------------------------------- /Hello02/Makefile: -------------------------------------------------------------------------------- 1 | ARMGNU ?= arm-linux-gnueabihf 2 | COPS = 3 | ARCH = -mcpu=cortex-a9 -mfpu=vfpv3 4 | 5 | gcc : hello02.bin 6 | 7 | all : gcc clang 8 | 9 | clean : 10 | rm -f *.o 11 | rm -f *.bin 12 | rm -f *.hex 13 | rm -f *.elf 14 | rm -f *.list 15 | rm -f *.img 16 | rm -f *.bc 17 | 18 | clang: hello02.bin 19 | 20 | startup.o : startup.s 21 | $(ARMGNU)-as $(ARCH) startup.s -o startup.o 22 | 23 | hello02.o : hello02.c 24 | $(ARMGNU)-gcc $(COPS) $(ARCH) -c hello02.c -o hello02.o 25 | 26 | hello02.bin : memmap.ld startup.o hello02.o 27 | $(ARMGNU)-ld startup.o hello02.o -T memmap.ld -o hello02.elf 28 | $(ARMGNU)-objdump -D hello02.elf > hello02.list 29 | $(ARMGNU)-objcopy hello02.elf -O ihex hello02.hex 30 | $(ARMGNU)-objcopy hello02.elf -O binary hello02.bin 31 | -------------------------------------------------------------------------------- /Hello03/Makefile: -------------------------------------------------------------------------------- 1 | ARMGNU ?= arm-linux-gnueabihf 2 | COPS = 3 | ARCH = -mcpu=cortex-a9 -mfpu=vfpv3 4 | 5 | gcc : hello03.bin 6 | 7 | all : gcc clang 8 | 9 | clean : 10 | rm -f *.o 11 | rm -f *.bin 12 | rm -f *.hex 13 | rm -f *.elf 14 | rm -f *.list 15 | rm -f *.img 16 | rm -f *.bc 17 | 18 | clang: hello03.bin 19 | 20 | startup.o : startup.s 21 | $(ARMGNU)-as $(ARCH) startup.s -o startup.o 22 | 23 | hello03.o : hello03.c 24 | $(ARMGNU)-gcc $(COPS) $(ARCH) -c hello03.c -o hello03.o 25 | 26 | hello03.bin : memmap.ld startup.o hello03.o 27 | $(ARMGNU)-ld startup.o hello03.o -T memmap.ld -o hello03.elf 28 | $(ARMGNU)-objdump -D hello03.elf > hello03.list 29 | $(ARMGNU)-objcopy hello03.elf -O ihex hello03.hex 30 | $(ARMGNU)-objcopy hello03.elf -O binary hello03.bin 31 | -------------------------------------------------------------------------------- /Hello01/hello01.c: -------------------------------------------------------------------------------- 1 | /* 2 | ZedBoard / Zynq-7000 3 | UART info could be found in 4 | B.33 UART Controller (UART) / Page 1626 in 5 | Zynq-7000 6 | All Programmable SoC 7 | Technical Reference Manual 8 | 9 | http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf 10 | */ 11 | 12 | 13 | #define UART1_BASE 0xe0001000 14 | #define UART1_TxRxFIFO0 ((unsigned int *) (UART1_BASE + 0x30)) 15 | 16 | volatile unsigned int * const TxRxUART1 = UART1_TxRxFIFO0; 17 | 18 | void print_uart1(const char *s) 19 | { 20 | while(*s != '\0') 21 | { /* Loop until end of string */ 22 | *TxRxUART1 = (unsigned int)(*s); /* Transmit char */ 23 | s++; /* Next char */ 24 | } 25 | } 26 | 27 | void c_entry() 28 | { 29 | print_uart1("\r\nHello world!"); 30 | while(1) ; /*dont exit the program*/ 31 | } -------------------------------------------------------------------------------- /Hello04/Makefile: -------------------------------------------------------------------------------- 1 | ARMGNU ?= arm-linux-gnueabihf 2 | COPS = 3 | ARCH = -mcpu=cortex-a9 -mfpu=vfpv3 4 | 5 | gcc : hello04.bin 6 | 7 | all : gcc clang 8 | 9 | clean : 10 | rm -f *.o 11 | rm -f *.bin 12 | rm -f *.hex 13 | rm -f *.elf 14 | rm -f *.list 15 | rm -f *.img 16 | rm -f *.bc 17 | 18 | clang: hello04.bin 19 | 20 | startup.o : startup.s 21 | $(ARMGNU)-as $(ARCH) startup.s -o startup.o 22 | 23 | xuartps.o : xuartps.c 24 | $(ARMGNU)-gcc $(COPS) $(ARCH) -c xuartps.c -o xuartps.o 25 | 26 | hello04.o : hello04.c 27 | $(ARMGNU)-gcc $(COPS) $(ARCH) -c hello04.c -o hello04.o 28 | 29 | hello04.bin : memmap.ld startup.o hello04.o xuartps.o 30 | $(ARMGNU)-ld startup.o xuartps.o hello04.o -T memmap.ld -o hello04.elf 31 | $(ARMGNU)-objdump -D hello04.elf > hello04.list 32 | $(ARMGNU)-objcopy hello04.elf -O ihex hello04.hex 33 | $(ARMGNU)-objcopy hello04.elf -O binary hello04.bin 34 | -------------------------------------------------------------------------------- /Hello05/Makefile: -------------------------------------------------------------------------------- 1 | ARMGNU ?= arm-linux-gnueabihf 2 | COPS = 3 | ARCH = -mcpu=cortex-a9 -mfpu=vfpv3 4 | 5 | gcc : hello05.bin 6 | 7 | all : gcc clang 8 | 9 | clean : 10 | rm -f *.o 11 | rm -f *.bin 12 | rm -f *.hex 13 | rm -f *.elf 14 | rm -f *.list 15 | rm -f *.img 16 | rm -f *.bc 17 | 18 | clang: hello05.bin 19 | 20 | startup.o : startup.s 21 | $(ARMGNU)-as $(ARCH) startup.s -o startup.o 22 | 23 | printf.o : printf.c 24 | $(ARMGNU)-gcc $(COPS) $(ARCH) -c printf.c -o printf.o 25 | 26 | 27 | xuartps.o : xuartps.c 28 | $(ARMGNU)-gcc $(COPS) $(ARCH) -c xuartps.c -o xuartps.o 29 | 30 | hello05.o : hello05.c 31 | $(ARMGNU)-gcc $(COPS) $(ARCH) -c hello05.c -o hello05.o 32 | 33 | hello05.bin : memmap.ld startup.o hello05.o xuartps.o printf.o 34 | $(ARMGNU)-ld startup.o printf.o xuartps.o hello05.o -T memmap.ld -o hello05.elf 35 | $(ARMGNU)-objdump -D hello05.elf > hello05.list 36 | $(ARMGNU)-objcopy hello05.elf -O ihex hello05.hex 37 | $(ARMGNU)-objcopy hello05.elf -O binary hello05.bin 38 | -------------------------------------------------------------------------------- /Hello02/hello02.c: -------------------------------------------------------------------------------- 1 | /* 2 | ZedBoard / Zynq-7000 3 | UART info could be found in 4 | B.33 UART Controller (UART) / Page 1626 in 5 | Zynq-7000 6 | All Programmable SoC 7 | Technical Reference Manual 8 | 9 | http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf 10 | */ 11 | 12 | #include 13 | #define UART1_BASE 0xe0001000 14 | #define UART1_TxRxFIFO0 ((unsigned int *) (UART1_BASE + 0x30)) 15 | 16 | volatile unsigned int * const TxRxUART1 = UART1_TxRxFIFO0; 17 | 18 | /* 's printf uses puts to send chars 19 | puts so that printf sends char to the serial port*/ 20 | int puts(const char *s) 21 | { 22 | while(*s != '\0') 23 | { /* Loop until end of string */ 24 | *TxRxUART1 = (unsigned int)(*s); /* Transmit char */ 25 | s++; /* Next char */ 26 | } 27 | return 0; 28 | } 29 | 30 | void c_entry() 31 | { 32 | printf("\nHello world!\n"); 33 | while(1) ; /*dont exit the program*/ 34 | } -------------------------------------------------------------------------------- /Hello05/hello05.c: -------------------------------------------------------------------------------- 1 | /* 2 | Please note: 3 | File: printf.h 4 | 5 | Copyright (C) 2004,2008 Kustaa Nyholm 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 | */ 21 | 22 | 23 | #include 24 | #include "printf.h" /*support for printf %d,%u,%s,%x,%X */ 25 | #include "xuartps.h" /*Maps stdout to use the RS232 uart */ 26 | 27 | void c_entry() 28 | { 29 | init_uart1_RxTx_115200_8N1(); 30 | printf("\nHello number %d\n",1); 31 | while(1) ; /*dont exit the program*/ 32 | } 33 | -------------------------------------------------------------------------------- /HelloQemu/helloq.c: -------------------------------------------------------------------------------- 1 | /* 2 | ZedBoard / Zynq-7000 3 | UART info could be found in 4 | B.33 UART Controller (UART) / Page 1626 in 5 | Zynq-7000 6 | All Programmable SoC 7 | Technical Reference Manual 8 | 9 | http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf 10 | */ 11 | 12 | 13 | #define UART0_BASE 0xe0000000 14 | #define UART0_CTRL ((unsigned int *) (UART0_BASE + 0x00)) /* UART Control Register */ 15 | #define UART0_TxRxFIFO0 ((unsigned int *) (UART0_BASE + 0x30)) /* UART FIFO */ 16 | 17 | volatile unsigned int * const TxRxUART0 = UART0_TxRxFIFO0; 18 | volatile unsigned int * const ctrlUART0 = UART0_CTRL; 19 | 20 | #define XUARTPS_CR_TXEN (1<<4) /* Transmit enable */ 21 | #define XUARTPS_CR_RXEN (1<<2) /* Receive enable */ 22 | #define XUARTPS_CR_TXRES (1<<1) /* Software reset for Tx data path */ 23 | #define XUARTPS_CR_RXRES (1<<0) /* Software reset for Rx data path */ 24 | 25 | void enable_uart0() 26 | { 27 | *ctrlUART0= XUARTPS_CR_TXEN | XUARTPS_CR_RXEN | XUARTPS_CR_TXRES | XUARTPS_CR_RXRES; 28 | } 29 | 30 | 31 | void print_uart0(const char *s) 32 | { 33 | while(*s != '\0') 34 | { /* Loop until end of string */ 35 | *TxRxUART0 = (unsigned int)(*s); /* Transmit char */ 36 | s++; /* Next char */ 37 | } 38 | } 39 | 40 | void c_entry() 41 | { 42 | enable_uart0(); 43 | print_uart0("\r\nHello world!"); 44 | while(1) ; /*dont exit the program*/ 45 | } 46 | -------------------------------------------------------------------------------- /XilinxUploadHowTo.txt: -------------------------------------------------------------------------------- 1 | 2 | How to upload and run hello01 using the Xilinx Microprocessor Debugger (XMD) 3 | 4 | Download and install the Xilinx ISE form http://www.xilinx.com/support/download/index.htm 5 | 6 | a) Connect the USB micro port named prog on the ZedBoard to the PC 7 | b) From the terminal window start XMD by typing: 8 | xmd 9 | c) connect arm hw <- Connects to the the ARM Cortex-A9 processor 10 | d) dow hello01.elf <- Download the .elf file to the ZedBoard 11 | c) con <- Starts the procssor/program 12 | 13 | Retults: 14 | The serial port should send out "Hello World!" (not show in the xmd console) 15 | 16 | 17 | Screen dum of expected result: 18 | 19 | XMD% connect arm hw 20 | 21 | JTAG chain configuration 22 | -------------------------------------------------- 23 | Device ID Code IR Length Part Name 24 | 1 4ba00477 4 Cortex-A9 25 | 2 03727093 6 XC7Z020 26 | 27 | CortexA9 Processor Configuration 28 | ------------------------------------- 29 | Version.............................0x00000003 30 | User ID.............................0x00000000 31 | No of PC Breakpoints................6 32 | No of Addr/Data Watchpoints.........1 33 | 34 | Connected to "arm" target. id = 64 35 | Starting GDB server for "arm" target (id = 64) at TCP port no 1234 36 | XMD% dow hello01.elf 37 | Downloading Program -- hello01.elf 38 | section, .ro: 0x00010000-0x0001008f 39 | Setting PC with Program Start Address 0x00010000 40 | XMD% con 41 | Processor started. Type "stop" to stop processor 42 | 43 | RUNNING> XMD% exit 44 | -------------------------------------------------------------------------------- /Hello04/xuartps.c: -------------------------------------------------------------------------------- 1 | /* 2 | ZedBoard / Zynq-7000 3 | UART info could be found in 4 | B.33 UART Controller (UART) / Page 1626 in 5 | Zynq-7000 6 | All Programmable SoC 7 | Technical Reference Manual 8 | 9 | http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf 10 | */ 11 | 12 | 13 | #include "xuartps.h" 14 | 15 | /* 16 | * Initiate UART1 ( /dev/ttyACM0 on host computer ) 17 | * 115,200 Baud 8-bit No-Parity 1-stop-bit 18 | */ 19 | void init_uart1_RxTx_115200_8N1() 20 | { 21 | /* Disable the transmitter and receiver before writing to the Baud Rate Generator */ 22 | UART1->control_reg0=0; 23 | 24 | /* Set Baudrate to 115,200 Baud */ 25 | UART1->baud_rate_divider =XUARTPS_BDIV_CD_115200; 26 | UART1->baud_rate_gen= XUARTPS_BRGR_CD_115200; 27 | 28 | /*Set 8-bit NoParity 1-StopBit*/ 29 | UART1->mode_reg0 = XUARTPS_MR_PAR_NONE; 30 | 31 | /*Enable Rx & Tx*/ 32 | UART1->control_reg0= XUARTPS_CR_TXEN | XUARTPS_CR_RXEN | XUARTPS_CR_TXRES | XUARTPS_CR_RXRES ; 33 | } 34 | 35 | void sendUART1char(char s) 36 | { 37 | /*Make sure that the uart is ready for new char's before continuing*/ 38 | while ((( UART1->channel_sts_reg0 ) & UART_STS_TXFULL) > 0) ; 39 | 40 | /* Loop until end of string */ 41 | UART1->tx_rx_fifo= (unsigned int) s; /* Transmit char */ 42 | } 43 | 44 | /* 's printf uses puts to send chars 45 | puts so that printf sends char to the serial port*/ 46 | int puts(const char *s) 47 | { 48 | while(*s != '\0') 49 | { 50 | if(*s=='\n') 51 | sendUART1char('\r'); 52 | 53 | sendUART1char(*s); /*Send char to the UART1*/ 54 | s++; /* Next char */ 55 | } 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /Hello05/xuartps.c: -------------------------------------------------------------------------------- 1 | /* 2 | ZedBoard / Zynq-7000 3 | UART info could be found in 4 | B.33 UART Controller (UART) / Page 1626 in 5 | Zynq-7000 6 | All Programmable SoC 7 | Technical Reference Manual 8 | 9 | http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf 10 | */ 11 | 12 | #include 13 | #include "printf.h" /*From http://www.sparetimelabs.com/tinyprintf/index.html */ 14 | #include "xuartps.h" 15 | 16 | void putc(int *p ,char c); 17 | 18 | /* 19 | * Initiate UART1 ( /dev/ttyACM0 on host computer ) 20 | * 115,200 Baud 8-bit No-Parity 1-stop-bit 21 | */ 22 | void init_uart1_RxTx_115200_8N1() 23 | { 24 | /* Disable the transmitter and receiver before writing to the Baud Rate Generator */ 25 | UART1->control_reg0=0; 26 | 27 | /* Set Baudrate to 115,200 Baud */ 28 | UART1->baud_rate_divider =XUARTPS_BDIV_CD_115200; 29 | UART1->baud_rate_gen= XUARTPS_BRGR_CD_115200; 30 | 31 | /*Set 8-bit NoParity 1-StopBit*/ 32 | UART1->mode_reg0 = XUARTPS_MR_PAR_NONE; 33 | 34 | /*Enable Rx & Tx*/ 35 | UART1->control_reg0= XUARTPS_CR_TXEN | XUARTPS_CR_RXEN | XUARTPS_CR_TXRES | XUARTPS_CR_RXRES ; 36 | 37 | 38 | } 39 | 40 | void sendUART1char(char s) 41 | { 42 | /*Make sure that the uart is ready for new char's before continuing*/ 43 | while ((( UART1->channel_sts_reg0 ) & UART_STS_TXFULL) > 0) ; 44 | 45 | /* Loop until end of string */ 46 | UART1->tx_rx_fifo= (unsigned int) s; /* Transmit char */ 47 | } 48 | 49 | /* "print.h" uses this function for is's printf implementation */ 50 | void putchar(char c) 51 | { 52 | if(c=='\n') 53 | sendUART1char('\r'); 54 | sendUART1char(c); 55 | } 56 | 57 | /* 's printf uses puts to send chars 58 | puts so that printf sends char to the serial port*/ 59 | int puts(const char *s) 60 | { 61 | while(*s != '\0') 62 | { 63 | if(*s=='\n') 64 | sendUART1char('\r'); 65 | 66 | sendUART1char(*s); /*Send char to the UART1*/ 67 | s++; /* Next char */ 68 | } 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /Hello05/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | File: printf.h 3 | 4 | Copyright (C) 2004,2008 Kustaa Nyholm 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | 20 | This library is realy just two files: 'printf.h' and 'printf.c'. 21 | 22 | They provide a simple and small (+100 loc) printf functionality to 23 | be used in embedded systems. 24 | 25 | I've found them so usefull in debugging that I do not bother with a 26 | debugger at all. 27 | 28 | They are distributed in source form, so to use them, just compile them 29 | into your project. 30 | 31 | The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'. 32 | 33 | Zero padding and field width (limited to 255) are also supported. 34 | 35 | The memory foot print of course depends on the target cpu, compiler and 36 | compiler options, but a rough guestimate (based on a HC08 target) is about 37 | 600 - 1100 bytes for code and some twenty bytes of static data. Note 38 | that this printf is not re-entrant. 39 | 40 | Note that the code expects that int size is 16 bits, and that char is 41 | 8 bits. 42 | 43 | To use the printf you need to supply your own character output function, 44 | something like : 45 | 46 | void putchar (char c) 47 | { 48 | while (!SERIAL_PORT_EMPTY) ; 49 | SERIAL_PORT_TX_REGISTER = c; 50 | } 51 | 52 | 53 | The printf function is actually a macro that translates to 'tfp_printf'. 54 | This makes it possible to use it along with 'stdio.h' printf's in a single 55 | source file. You just need to undef the names before you include the 'stdio.h'. 56 | Note that these are not function-like macros, so if you have variables 57 | or struct members with these names, things will explode in your face. 58 | Without variadic macros this is the best we can do. If it is a problem 59 | just give up the macros and use the functions directly or rename them. 60 | 61 | For further details see source code. 62 | 63 | regs Kusti, 26.2.2008 64 | */ 65 | 66 | 67 | #ifndef __TFP_PRINTF__ 68 | #define __TFP_PRINTF__ 69 | 70 | #include 71 | 72 | void tfp_printf(char *fmt, ...); 73 | 74 | #define printf tfp_printf 75 | 76 | #endif 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /HelloQemu/README.txt: -------------------------------------------------------------------------------- 1 | HelloQemu 2 | ====================== 3 | 4 | Makes a .bin file that could be uploaded to qemu (the FAST! processor emulator) 5 | emulator display Hello World using the emulated serial uart 6 | 7 | BUILD REQUIREMENTS 8 | =================== 9 | 10 | Build requirements for Linux Mint 15 (Olivia) (should work for all debian 11 | installation on x86 platfom) 12 | 13 | Install ARM Cross-Compiler: 14 | 15 | Refresh list of software available 16 | sudo apt-get update 17 | 18 | Install the ARM Cross-Compiler using 19 | sudo apt-get install gcc-arm-linux-gnueabihf 20 | 21 | Install qemu using: 22 | sudo apt-get install quemu qemu-utils qemu-system-arm 23 | 24 | BUILD 25 | ====== 26 | 27 | The helloq.bin file is compiled using make :) 28 | 29 | 30 | UPLOAD AND RUNNING USING QEMU 31 | =============================== 32 | 33 | Start xuilinx-zynq qemu emulation by uploading helloq.bin to 0x1000 and run it. 34 | qemu-system-arm -machine xilinx-zynq-a9 -kernel ./helloq.bin -nographic 35 | 36 | Kill emulation by: 37 | 38 | Ctrl-A X 39 | 40 | 1) First press [Ctrl] and [a] 41 | 2) Release the keys 42 | 3) Press [x] 43 | 44 | 45 | UPLOAD AND RUNNING USING QEMU & GDB 46 | ==================================== 47 | 48 | Install gdb for multi architecture 49 | sudo apt install gdb-multiarch 50 | 51 | 52 | 53 | Start xuilinx-zynq qemu emulation : 54 | qemu-system-arm -machine xilinx-zynq-a9 -s -S 55 | 56 | 57 | Start gdb in the current diectory 58 | gdb-multiarch -d $PWD 59 | 60 | Run the commands: 61 | target remote 127.0.0.1:1234 62 | load helloq.elf 63 | c 64 | 65 | (or gdb-multiarch -d $PWD -x cmd.txt ) 66 | 67 | In QEMU click "View | serial0" and see the text :) 68 | To run the program once more click "machine | reset" 69 | 70 | 71 | 72 | LICENSE 73 | ========== 74 | 75 | Copyright (C) 2020 Rune Langoy 76 | 77 | Permission is hereby granted, free of charge, to any person obtaining a copy 78 | of this software and associated documentation files (the "Software"), to 79 | deal in the Software without restriction, including without limitation the 80 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 81 | sell copies of the Software, and to permit persons to whom the Software is 82 | furnished to do so, subject to the following conditions: 83 | 84 | The above copyright notice and this permission notice shall be included in 85 | all copies or substantial portions of the Software. 86 | 87 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 88 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 89 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 90 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 91 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 92 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 93 | IN THE SOFTWARE. 94 | -------------------------------------------------------------------------------- /Hello02/README.txt: -------------------------------------------------------------------------------- 1 | Hello02 2 | ========= 3 | 4 | Same example as in Hello01 but uses - printf to write "Hello 5 | World" on the serial line 6 | 7 | BUILD REQUIREMENTS 8 | =================== 9 | 10 | Build requirements for Linux Mint 15 (Olivia) (should work for all debian 11 | installation on x86 platfom) 12 | 13 | Install ARM Cross-Compiler: 14 | 15 | Refresh list of software available 16 | sudo apt-get update 17 | 18 | Install the ARM Cross-Compiler using 19 | sudo apt-get install gcc-arm-linux-gnueabihf 20 | 21 | 22 | BUILD 23 | ====== 24 | 25 | The hello01.bin file is compiled using make :) 26 | 27 | 28 | UPLOAD AND RUNNING USING U-BOOT 29 | =============================== 30 | 31 | hello01.bin has its entrypoint / start address at: 0x10000 32 | 33 | a) Connect the Zedboard UART (USB) to the Computer. 34 | b) use a serial terminal program to comunicate width the ZedBoard's UART 35 | Windows: can use Tera Term from 36 | http://hp.vector.co.jp/authors/VA002416/teraterm.html ) 37 | Linux: 38 | Start a new terminal 39 | Install minicom: 40 | sudo apt-install minicom 41 | minicom -D/dev/ttyACM0 -b115200 -o 42 | 43 | c) power on the ZedBoard and wait for the message: 44 | Hit any key to stop autoboot: 45 | and stop it by pressing a key :) 46 | 47 | d) Upload the program hello01.bin using 48 | loady 0x10000 49 | Send the file hello01.bin using the y-modem protocol 50 | Push ([Ctrl] + 'a') and then 'S' Select ymodem 51 | And select the file hello01.bin (using space) and [enter] 52 | (enter folders pushing space) 53 | Linux: 54 | Stop screen by pushing ( [Ctrl] + 'a') and then 'k' 55 | 56 | e) Run the program using 57 | go 0x10000 58 | 59 | Now you shold se 60 | ## Starting application at 0x00010000 ... 61 | Hello world! 62 | 63 | LICENSE 64 | ============== 65 | 66 | Copyright (C) Rune Langoy 2012 67 | 68 | Permission is hereby granted, free of charge, to any person obtaining a copy 69 | of this software and associated documentation files (the "Software"), to 70 | deal in the Software without restriction, including without limitation the 71 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 72 | sell copies of the Software, and to permit persons to whom the Software is 73 | furnished to do so, subject to the following conditions: 74 | 75 | The above copyright notice and this permission notice shall be included in 76 | all copies or substantial portions of the Software. 77 | 78 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 79 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 80 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 81 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 82 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 83 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 84 | IN THE SOFTWARE. 85 | -------------------------------------------------------------------------------- /Hello01/README.txt: -------------------------------------------------------------------------------- 1 | Hello01 2 | ====================== 3 | 4 | Makes a .bin file that could be uploaded using u-Boot 5 | to the Zedboard and display Hello World using the serial uart 6 | 7 | BUILD REQUIREMENTS 8 | =================== 9 | 10 | Build requirements for Linux Mint 15 (Olivia) (should work for all debian 11 | installation on x86 platfom) 12 | 13 | Install ARM Cross-Compiler: 14 | 15 | Refresh list of software available 16 | sudo apt-get update 17 | 18 | Install the ARM Cross-Compiler using 19 | sudo apt-get install gcc-arm-linux-gnueabihf 20 | 21 | BUILD 22 | ====== 23 | 24 | The hello01.bin file is compiled using make :) 25 | 26 | 27 | UPLOAD AND RUNNING USING U-BOOT 28 | =============================== 29 | 30 | hello01.bin has its entrypoint / start address at: 0x10000 31 | 32 | a) Connect the Zedboard UART (USB) to the Computer. 33 | b) use a serial terminal program to comunicate width the ZedBoard's UART 34 | Windows: can use Tera Term from 35 | http://hp.vector.co.jp/authors/VA002416/teraterm.html ) 36 | Linux: 37 | Start a new terminal 38 | Install minicom: 39 | sudo apt-install minicom 40 | minicom -D/dev/ttyACM0 -b115200 -o 41 | 42 | c) power on the ZedBoard and wait for the message: 43 | Hit any key to stop autoboot: 44 | and stop it by pressing a key :) 45 | 46 | d) Upload the program hello01.bin using 47 | loady 0x10000 48 | Send the file hello01.bin using the y-modem protocol 49 | Push ([Ctrl] + 'a') and then 'S' Select ymodem 50 | And select the file hello01.bin (using space) and [enter] 51 | (enter folders pushing space) 52 | Linux: 53 | Stop screen by pushing ( [Ctrl] + 'a') and then 'k' 54 | 55 | e) Run the program using 56 | go 0x10000 57 | 58 | Now you shold se 59 | ## Starting application at 0x00010000 ... 60 | Hello world! 61 | 62 | LICENSE 63 | ========== 64 | 65 | Copyright (C) 2012 Rune Langoy 66 | 67 | Permission is hereby granted, free of charge, to any person obtaining a copy 68 | of this software and associated documentation files (the "Software"), to 69 | deal in the Software without restriction, including without limitation the 70 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 71 | sell copies of the Software, and to permit persons to whom the Software is 72 | furnished to do so, subject to the following conditions: 73 | 74 | The above copyright notice and this permission notice shall be included in 75 | all copies or substantial portions of the Software. 76 | 77 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 78 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 79 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 80 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 81 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 82 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 83 | IN THE SOFTWARE. 84 | -------------------------------------------------------------------------------- /Hello04/README.txt: -------------------------------------------------------------------------------- 1 | Hello04 2 | ========= 3 | 4 | Same example as in Hello03 but seperates the "main" program and the 5 | UART functions (located in xuartps.h) 6 | 7 | BUILD REQUIREMENTS 8 | =================== 9 | 10 | Build requirements for Linux Mint 15 (Olivia) (should work for all debian 11 | installation on x86 platfom) 12 | 13 | Install ARM Cross-Compiler: 14 | 15 | Refresh list of software available 16 | sudo apt-get update 17 | 18 | Install the ARM Cross-Compiler using 19 | sudo apt-get install gcc-arm-linux-gnueabihf 20 | 21 | 22 | BUILD 23 | ====== 24 | 25 | The hello01.bin file is compiled using make :) 26 | 27 | 28 | UPLOAD AND RUNNING USING U-BOOT 29 | =============================== 30 | 31 | hello01.bin has its entrypoint / start address at: 0x10000 32 | 33 | a) Connect the Zedboard UART (USB) to the Computer. 34 | b) use a serial terminal program to comunicate width the ZedBoard's UART 35 | Windows: can use Tera Term from 36 | http://hp.vector.co.jp/authors/VA002416/teraterm.html ) 37 | Linux: 38 | Start a new terminal 39 | Install minicom: 40 | sudo apt-install minicom 41 | minicom -D/dev/ttyACM0 -b115200 -o 42 | 43 | c) power on the ZedBoard and wait for the message: 44 | Hit any key to stop autoboot: 45 | and stop it by pressing a key :) 46 | 47 | d) Upload the program hello03.bin using 48 | loady 0x10000 49 | Send the file hello01.bin using the y-modem protocol 50 | Push ([Ctrl] + 'a') and then 'S' Select ymodem 51 | And select the file hello01.bin (using space) and [enter] 52 | (enter folders pushing space) 53 | Linux: 54 | Stop screen by pushing ( [Ctrl] + 'a') and then 'k' 55 | 56 | e) Run the program using 57 | go 0x10000 58 | 59 | Now you shold se 60 | ## Starting application at 0x00010000 ... 61 | Hello world! 62 | 63 | LICENSE 64 | ============== 65 | 66 | Copyright (C) Rune Langoy 2012 67 | 68 | Permission is hereby granted, free of charge, to any person obtaining a copy 69 | of this software and associated documentation files (the "Software"), to 70 | deal in the Software without restriction, including without limitation the 71 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 72 | sell copies of the Software, and to permit persons to whom the Software is 73 | furnished to do so, subject to the following conditions: 74 | 75 | The above copyright notice and this permission notice shall be included in 76 | all copies or substantial portions of the Software. 77 | 78 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 79 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 80 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 81 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 82 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 83 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 84 | IN THE SOFTWARE. 85 | -------------------------------------------------------------------------------- /Hello03/README.txt: -------------------------------------------------------------------------------- 1 | Hello03 2 | ========= 3 | 4 | Same example as in Hello03 initiates the UART to use: 5 | baudrate: 11,5200 8-N-1 (8-bit no-parity one-stop-bit) 6 | The example show impements a structure describing the UART registers 7 | and some registers bitmask.This sample dosent depent on U-Boot 8 | (to setup the baudrate etc) 9 | 10 | BUILD REQUIREMENTS 11 | =================== 12 | 13 | Build requirements for Linux Mint 15 (Olivia) (should work for all debian 14 | installation on x86 platfom) 15 | 16 | Install ARM Cross-Compiler: 17 | 18 | Refresh list of software available 19 | sudo apt-get update 20 | 21 | Install the ARM Cross-Compiler using 22 | sudo apt-get install gcc-arm-linux-gnueabihf 23 | 24 | 25 | BUILD 26 | ====== 27 | 28 | The hello01.bin file is compiled using make :) 29 | 30 | 31 | UPLOAD AND RUNNING USING U-BOOT 32 | =============================== 33 | 34 | hello01.bin has its entrypoint / start address at: 0x10000 35 | 36 | a) Connect the Zedboard UART (USB) to the Computer. 37 | b) use a serial terminal program to comunicate width the ZedBoard's UART 38 | Windows: can use Tera Term from 39 | http://hp.vector.co.jp/authors/VA002416/teraterm.html ) 40 | Linux: 41 | Start a new terminal 42 | Install minicom: 43 | sudo apt-install minicom 44 | minicom -D/dev/ttyACM0 -b115200 -o 45 | 46 | c) power on the ZedBoard and wait for the message: 47 | Hit any key to stop autoboot: 48 | and stop it by pressing a key :) 49 | 50 | d) Upload the program hello03.bin using 51 | loady 0x10000 52 | Send the file hello01.bin using the y-modem protocol 53 | Push ([Ctrl] + 'a') and then 'S' Select ymodem 54 | And select the file hello01.bin (using space) and [enter] 55 | (enter folders pushing space) 56 | Linux: 57 | Stop screen by pushing ( [Ctrl] + 'a') and then 'k' 58 | 59 | e) Run the program using 60 | go 0x10000 61 | 62 | Now you shold se 63 | ## Starting application at 0x00010000 ... 64 | Hello world! 65 | 66 | 67 | LICENSE 68 | ============== 69 | 70 | Copyright (C) Rune Langoy 2012 71 | 72 | Permission is hereby granted, free of charge, to any person obtaining a copy 73 | of this software and associated documentation files (the "Software"), to 74 | deal in the Software without restriction, including without limitation the 75 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 76 | sell copies of the Software, and to permit persons to whom the Software is 77 | furnished to do so, subject to the following conditions: 78 | 79 | The above copyright notice and this permission notice shall be included in 80 | all copies or substantial portions of the Software. 81 | 82 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 83 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 84 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 85 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 86 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 87 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 88 | IN THE SOFTWARE. 89 | -------------------------------------------------------------------------------- /Hello05/printf.c: -------------------------------------------------------------------------------- 1 | /* 2 | File: printf.c 3 | 4 | Copyright (C) 2004,2008 Kustaa Nyholm 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with this library; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | 20 | */ 21 | //putchar#include 22 | 23 | #include "printf.h" 24 | 25 | void putchar(char c); 26 | 27 | static char* bf; 28 | static char buf[12]; 29 | static unsigned int num; 30 | static char uc; 31 | static char zs; 32 | 33 | static void out(char c) { 34 | *bf++ = c; 35 | } 36 | 37 | static void outDgt(char dgt) { 38 | out(dgt+(dgt<10 ? '0' : (uc ? 'A' : 'a')-10)); 39 | zs=1; 40 | } 41 | 42 | static void divOut(unsigned int div) { 43 | unsigned char dgt=0; 44 | num &= 0xffff; // just for testing the code with 32 bit ints 45 | while (num>=div) { 46 | num -= div; 47 | dgt++; 48 | } 49 | if (zs || dgt>0) 50 | outDgt(dgt); 51 | } 52 | 53 | void tfp_printf(char *fmt, ...) 54 | { 55 | va_list va; 56 | char ch; 57 | char* p; 58 | 59 | va_start(va,fmt); 60 | 61 | while ((ch=*(fmt++))) { 62 | if (ch!='%') { 63 | putchar(ch); 64 | } 65 | else { 66 | char lz=0; 67 | char w=0; 68 | ch=*(fmt++); 69 | if (ch=='0') { 70 | ch=*(fmt++); 71 | lz=1; 72 | } 73 | if (ch>='0' && ch<='9') { 74 | w=0; 75 | while (ch>='0' && ch<='9') { 76 | w=(((w<<2)+w)<<1)+ch-'0'; 77 | ch=*fmt++; 78 | } 79 | } 80 | bf=buf; 81 | p=bf; 82 | zs=0; 83 | switch (ch) { 84 | case 0: 85 | goto abort; 86 | case 'u': 87 | case 'd' : 88 | num=va_arg(va, unsigned int); 89 | if (ch=='d' && (int)num<0) { 90 | num = -(int)num; 91 | out('-'); 92 | } 93 | divOut(10000); 94 | divOut(1000); 95 | divOut(100); 96 | divOut(10); 97 | outDgt(num); 98 | break; 99 | case 'x': 100 | case 'X' : 101 | uc= ch=='X'; 102 | num=va_arg(va, unsigned int); 103 | divOut(0x1000); 104 | divOut(0x100); 105 | divOut(0x10); 106 | outDgt(num); 107 | break; 108 | case 'c' : 109 | out((char)(va_arg(va, int))); 110 | break; 111 | case 's' : 112 | p=va_arg(va, char*); 113 | break; 114 | case '%' : 115 | out('%'); 116 | default: 117 | break; 118 | } 119 | *bf=0; 120 | bf=p; 121 | while (*bf++ && w > 0) 122 | w--; 123 | while (w-- > 0) 124 | putchar(lz ? '0' : ' '); 125 | while ((ch= *p++)) 126 | putchar(ch); 127 | } 128 | } 129 | abort:; 130 | va_end(va); 131 | } 132 | 133 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | ZedBoard Hello BareMetal 2 | ======================== 3 | 4 | This is a collection of examples of "Bare Metal" programs for the ARM 5 | processon on the ZedBoard. 6 | 7 | Programs : 8 | .\Hello01 -> Makes a .bin file that could be uploaded using u-Boot 9 | to the Zedboard and displays "Hello World" using the serial uart 10 | .\Hello02 -> Same as Hello01, but uses printf to displays "Hello World" 11 | using the serial uart 12 | .\Hello03 -> Same example as in Hello03 initiates the UART to use: 13 | baudrate: 11,5200 8-N-1 (8-bit no-parity one-stop-bit) 14 | The example show impements a structure describing the UART 15 | and some registers bitmask.The sample dosent depent on U-Boot 16 | (to setup the baudrate etc) 17 | .\Hello04 -> Same example as in Hello03 but seperates the "main" program 18 | and the UART functions (located in xuartps.h) 19 | .\Hello05 -> Same example as in Hello04 but implements printf support for 20 | %d,%u,%c,%s,%x%,X 21 | Using the printf libaray Copyright (C) 2004,2008 by Kustaa Nyholm 22 | http://www.sparetimelabs.com/printfrevisited/index.html 23 | Please read Copy right notice on in the end of this file 24 | 25 | .\HelloQemu -> Simple example and doc for simulation using QEMU 26 | The sample uses UART0 27 | 28 | 29 | .\drivers -> Driver for serial-port 30 | .\arch -> Startup scripts 31 | .\scripts -> xmd scripts 32 | 33 | 34 | All programs contains a README.txt for a more detailed description 35 | 36 | 37 | BUILD REQUIREMENTS 38 | ================== 39 | 40 | Build requirements for Linux Mint 15 (Olivia) (should work for all debian 41 | installation on x86 platfom) 42 | 43 | Install ARM Cross-Compiler: 44 | 45 | Refresh list of software available 46 | sudo apt-get update 47 | 48 | Install the ARM Cross-Compiler using 49 | sudo apt-get install gcc-arm-linux-gnueabihf 50 | 51 | 52 | PLEASE NOTE 53 | ============ 54 | 55 | More information on printf.h & print.c could be found at: 56 | http://www.sparetimelabs.com/printfrevisited/index.html 57 | 58 | The files printf.h & printf.c 59 | ============================= 60 | 61 | Copyright (C) 2004,2008 Kustaa Nyholm 62 | 63 | This library is free software; you can redistribute it and/or 64 | modify it under the terms of the GNU Lesser General Public 65 | License as published by the Free Software Foundation; either 66 | version 2.1 of the License, or (at your option) any later version. 67 | 68 | This library is distributed in the hope that it will be useful, 69 | but WITHOUT ANY WARRANTY; without even the implied warranty of 70 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 71 | Lesser General Public License for more details. 72 | 73 | You should have received a copy of the GNU Lesser General Public 74 | License along with this library; if not, write to the Free Software 75 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 76 | 77 | 78 | LICENSE for all files excluding printf.c and printf.h 79 | ===================================================== 80 | 81 | Copyright (C) 2012-2020 Rune Langoy 82 | 83 | Permission is hereby granted, free of charge, to any person obtaining a copy 84 | of this software and associated documentation files (the "Software"), to 85 | deal in the Software without restriction, including without limitation the 86 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 87 | sell copies of the Software, and to permit persons to whom the Software is 88 | furnished to do so, subject to the following conditions: 89 | 90 | The above copyright notice and this permission notice shall be included in 91 | all copies or substantial portions of the Software. 92 | 93 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 94 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 95 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 96 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 97 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 98 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 99 | IN THE SOFTWARE. 100 | -------------------------------------------------------------------------------- /Hello05/README.txt: -------------------------------------------------------------------------------- 1 | Hello05 2 | ========= 3 | 4 | Same example as in Hello04 but implements printf support for %d,%u,%c,%s,%x%,X 5 | Using the printf libaray Copyright (C) 2004,2008 by Kustaa Nyholm 6 | More info on: http://www.sparetimelabs.com/printfrevisited/index.html 7 | Please read Copy right notice on in the end of this file 8 | 9 | BUILD REQUIREMENTS 10 | =================== 11 | 12 | Build requirements for Linux Mint 15 (Olivia) (should work for all debian 13 | installation on x86 platfom) 14 | 15 | Install ARM Cross-Compiler: 16 | 17 | Refresh list of software available 18 | sudo apt-get update 19 | 20 | Install the ARM Cross-Compiler using 21 | sudo apt-get install gcc-arm-linux-gnueabihf 22 | 23 | 24 | BUILD 25 | ====== 26 | 27 | The hello05.bin file is compiled using make :) 28 | 29 | 30 | UPLOAD AND RUNNING USING U-BOOT 31 | =============================== 32 | 33 | hello05.bin has its entrypoint / start address at: 0x10000 34 | 35 | a) Connect the Zedboard UART (USB) to the Computer. 36 | b) use a serial terminal program to comunicate width the ZedBoard's UART 37 | Windows: can use Tera Term from 38 | http://hp.vector.co.jp/authors/VA002416/teraterm.html ) 39 | Linux: 40 | Start a new terminal 41 | Install minicom: 42 | sudo apt-install minicom 43 | minicom -D/dev/ttyACM0 -b115200 -o 44 | 45 | c) power on the ZedBoard and wait for the message: 46 | Hit any key to stop autoboot: 47 | and stop it by pressing a key :) 48 | 49 | d) Upload the program hello03.bin using 50 | loady 0x10000 51 | Send the file hello01.bin using the y-modem protocol 52 | Push ([Ctrl] + 'a') and then 'S' Select ymodem 53 | And select the file hello01.bin (using space) and [enter] 54 | (enter folders pushing space) 55 | Linux: 56 | Stop screen by pushing ( [Ctrl] + 'a') and then 'k' 57 | 58 | e) Run the program using 59 | go 0x10000 60 | 61 | Now you shold se 62 | ## Starting application at 0x00010000 ... 63 | Hello number 1 64 | 65 | 66 | PLEASE NOTE 67 | ============ 68 | 69 | More information on printf.h & print.c could be found at: 70 | http://www.sparetimelabs.com/printfrevisited/index.html 71 | 72 | The files printf.h & printf.c 73 | ============================= 74 | 75 | Copyright (C) 2004,2008 Kustaa Nyholm 76 | 77 | This library is free software; you can redistribute it and/or 78 | modify it under the terms of the GNU Lesser General Public 79 | License as published by the Free Software Foundation; either 80 | version 2.1 of the License, or (at your option) any later version. 81 | 82 | This library is distributed in the hope that it will be useful, 83 | but WITHOUT ANY WARRANTY; without even the implied warranty of 84 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 85 | Lesser General Public License for more details. 86 | 87 | You should have received a copy of the GNU Lesser General Public 88 | License along with this library; if not, write to the Free Software 89 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 90 | 91 | LICENSE all files except printf.c and printf.h 92 | =============================================== 93 | 94 | Copyright (C) Rune Langoy 2012 95 | 96 | Permission is hereby granted, free of charge, to any person obtaining a copy 97 | of this software and associated documentation files (the "Software"), to 98 | deal in the Software without restriction, including without limitation the 99 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 100 | sell copies of the Software, and to permit persons to whom the Software is 101 | furnished to do so, subject to the following conditions: 102 | 103 | The above copyright notice and this permission notice shall be included in 104 | all copies or substantial portions of the Software. 105 | 106 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 107 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 108 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 109 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 110 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 111 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 112 | IN THE SOFTWARE. 113 | -------------------------------------------------------------------------------- /Hello04/xuartps.h: -------------------------------------------------------------------------------- 1 | /* 2 | ZedBoard / Zynq-7000 3 | UART info could be found in 4 | B.33 UART Controller (UART) / Page 1626 in 5 | Zynq-7000 6 | All Programmable SoC 7 | Technical Reference Manual 8 | 9 | http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf 10 | */ 11 | 12 | 13 | #ifndef u32 14 | #define u32 unsigned int 15 | #endif 16 | 17 | #define UART1_BASE 0xe0001000 18 | // Register Description as found in 19 | // B.33 UART Controller (UART) p.1626 20 | struct XUARTPS{ 21 | u32 control_reg0; /* UART Control Register def=0x128 */ 22 | u32 mode_reg0; /* UART Mode Register def=0 */ 23 | u32 intrpt_en_reg0; /* Interrupt Enable Register def=0 */ 24 | u32 intrpt_dis_reg0; /* Interrupt Disable Register def=0 */ 25 | u32 intrpt_mask_reg0; /* Interrupt Mask Register def=0 */ 26 | u32 chnl_int_sts_reg0; /* Channel Interrupt Status Register def=x200 */ 27 | u32 baud_rate_gen; /* Baud Rate Generator Register def=0x28B */ 28 | u32 Rcvr_timeout_reg0; /* Receiver Timeout Register def=0 */ 29 | u32 Rcvr_FIFO_trigger_level0; /* Receiver FIFO Trigger Level Register */ 30 | u32 Modem_ctrl_reg0; /* Modem Control Register def=0 */ 31 | u32 Modem_sts_reg0; /* Modem Status Register */ 32 | u32 channel_sts_reg0; /* Channel Status Register def=0 */ 33 | u32 tx_rx_fifo; /* Transmit and Receive FIFO def=0 */ 34 | u32 baud_rate_divider; /* Baud Rate Divider def=0xf */ 35 | u32 Flow_delay_reg0; /* Flow Control Delay Register def=0*/ 36 | u32 Tx_FIFO_trigger_level;}; /* Transmitter FIFO Trigger Level Register */ 37 | 38 | static struct XUARTPS *UART1=(struct XUARTPS*) UART1_BASE; 39 | 40 | /* 41 | Page 496 42 | Simplifyed Table 19-1 UART Parameter Value Examples 43 | Parameter Value Examples 44 | Clock Baud BRGR-CD BDIV-CD Actual Baud Rate 45 | UART Ref clock 600 10417 7 46 | UART Ref clock 9,600 651 7 47 | UART Ref clock 28,800 347 4 48 | UART Ref clock 115,200 62 6 49 | UART Ref clock 230,400 31 6 50 | */ 51 | 52 | /*Baudrates assuming input clock speed is 3125000L */ 53 | /*Baud_rate_gen_reg0*/ 54 | #define XUARTPS_BRGR_CD_115200 62 /*Baud Rate Clock Divisor*/ 55 | 56 | /*Register Baud_rate_divider_reg0 Details*/ 57 | #define XUARTPS_BDIV_CD_115200 6 /*Baud Rate Clock Divisor*/ 58 | 59 | /* Bits defined in the Register Channel_sts_reg0 */ 60 | #define UART_STS_TXFULL 1<<4 /* Transmitter FIFO Full continuous status: 61 | 0: Tx FIFO is not full 62 | 1: Tx FIFO is full*/ 63 | 64 | /*Register Control_reg0 BitMask */ 65 | #define XUARTPS_CR_STOPBRK (1<<8) /* Stop transmitter break */ 66 | #define XUARTPS_CR_STTBRK (1<<7) /* Start transmitter break */ 67 | #define XUARTPS_CR_RSTTO (1<<6) /* Restart receiver timeout counter */ 68 | #define XUARTPS_CR_TXDIS (1<<5) /* Transmit disable */ 69 | #define XUARTPS_CR_TXEN (1<<4) /* Transmit enable */ 70 | #define XUARTPS_CR_RXDIS (1<<3) /* Receive disable */ 71 | #define XUARTPS_CR_RXEN (1<<2) /* Receive enable */ 72 | #define XUARTPS_CR_TXRES (1<<1) /* Software reset for Tx data path */ 73 | #define XUARTPS_CR_RXRES (1<<0) /* Software reset for Rx data path */ 74 | 75 | /*Register Control mode_reg0 BitMask*/ 76 | #define XUARTPS_MR_PAR /*Parity type select [5:3]*/ 77 | #define XUARTPS_MR_PAR_EVEN 0 /* 000: even parity 78 | 001: odd parity 79 | 010: forced to 0 parity (space) 80 | 011: forced to 1 parity (mark)*/ 81 | #define XUARTPS_MR_PAR_NONE (1<<5) /* 1xx: no parity*/ 82 | #define XUARTPS_MR_CHRL /* Character length select: 83 | 11: 6 bits 84 | 10: 7 bits*/ 85 | #define XUARTPS_MR_CHRL_8 /* 0x: 8 bits*/ 86 | 87 | #define XUARTPS_MR_CLKS /* Clock source select:*/ 88 | #define XUARTPS_MR_CLKS_REF_CLK 0 /* 0: clock source is uart_ref_clk*/ 89 | 90 | /* 91 | * Initiate UART1 ( /dev/ttyACM0 on host computer ) 92 | * 115,200 Baud 8-bit No-Parity 1-stop-bit 93 | */ 94 | void init_uart1_RxTx_115200_8N1(); 95 | void sendUART1char(char s); 96 | int puts(const char *s); 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /Hello05/xuartps.h: -------------------------------------------------------------------------------- 1 | /* 2 | ZedBoard / Zynq-7000 3 | UART info could be found in 4 | B.33 UART Controller (UART) / Page 1626 in 5 | Zynq-7000 6 | All Programmable SoC 7 | Technical Reference Manual 8 | 9 | http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf 10 | */ 11 | 12 | #ifndef u32 13 | #define u32 unsigned int 14 | #endif 15 | 16 | #define UART1_BASE 0xe0001000 17 | // Register Description as found in 18 | // B.33 UART Controller (UART) p.1626 19 | struct XUARTPS{ 20 | u32 control_reg0; /* UART Control Register def=0x128 */ 21 | u32 mode_reg0; /* UART Mode Register def=0 */ 22 | u32 intrpt_en_reg0; /* Interrupt Enable Register def=0 */ 23 | u32 intrpt_dis_reg0; /* Interrupt Disable Register def=0 */ 24 | u32 intrpt_mask_reg0; /* Interrupt Mask Register def=0 */ 25 | u32 chnl_int_sts_reg0; /* Channel Interrupt Status Register def=x200 */ 26 | u32 baud_rate_gen; /* Baud Rate Generator Register def=0x28B */ 27 | u32 Rcvr_timeout_reg0; /* Receiver Timeout Register def=0 */ 28 | u32 Rcvr_FIFO_trigger_level0; /* Receiver FIFO Trigger Level Register */ 29 | u32 Modem_ctrl_reg0; /* Modem Control Register def=0 */ 30 | u32 Modem_sts_reg0; /* Modem Status Register */ 31 | u32 channel_sts_reg0; /* Channel Status Register def=0 */ 32 | u32 tx_rx_fifo; /* Transmit and Receive FIFO def=0 */ 33 | u32 baud_rate_divider; /* Baud Rate Divider def=0xf */ 34 | u32 Flow_delay_reg0; /* Flow Control Delay Register def=0*/ 35 | u32 Tx_FIFO_trigger_level;}; /* Transmitter FIFO Trigger Level Register */ 36 | 37 | static struct XUARTPS *UART1=(struct XUARTPS*) UART1_BASE; 38 | 39 | /* 40 | Page 496 41 | Simplifyed Table 19-1 UART Parameter Value Examples 42 | Parameter Value Examples 43 | Clock Baud BRGR-CD BDIV-CD Actual Baud Rate 44 | UART Ref clock 600 10417 7 45 | UART Ref clock 9,600 651 7 46 | UART Ref clock 28,800 347 4 47 | UART Ref clock 115,200 62 6 48 | UART Ref clock 230,400 31 6 49 | */ 50 | 51 | /*Baudrates assuming input clock speed is 3125000L */ 52 | /*Baud_rate_gen_reg0*/ 53 | #define XUARTPS_BRGR_CD_115200 62 /*Baud Rate Clock Divisor*/ 54 | 55 | /*Register Baud_rate_divider_reg0 Details*/ 56 | #define XUARTPS_BDIV_CD_115200 6 /*Baud Rate Clock Divisor*/ 57 | 58 | /* Bits defined in the Register Channel_sts_reg0 */ 59 | #define UART_STS_TXFULL 1<<4 /* Transmitter FIFO Full continuous status: 60 | 0: Tx FIFO is not full 61 | 1: Tx FIFO is full*/ 62 | 63 | /*Register Control_reg0 BitMask */ 64 | #define XUARTPS_CR_STOPBRK (1<<8) /* Stop transmitter break */ 65 | #define XUARTPS_CR_STTBRK (1<<7) /* Start transmitter break */ 66 | #define XUARTPS_CR_RSTTO (1<<6) /* Restart receiver timeout counter */ 67 | #define XUARTPS_CR_TXDIS (1<<5) /* Transmit disable */ 68 | #define XUARTPS_CR_TXEN (1<<4) /* Transmit enable */ 69 | #define XUARTPS_CR_RXDIS (1<<3) /* Receive disable */ 70 | #define XUARTPS_CR_RXEN (1<<2) /* Receive enable */ 71 | #define XUARTPS_CR_TXRES (1<<1) /* Software reset for Tx data path */ 72 | #define XUARTPS_CR_RXRES (1<<0) /* Software reset for Rx data path */ 73 | 74 | /*Register Control mode_reg0 BitMask*/ 75 | #define XUARTPS_MR_PAR /*Parity type select [5:3]*/ 76 | #define XUARTPS_MR_PAR_EVEN 0 /* 000: even parity 77 | 001: odd parity 78 | 010: forced to 0 parity (space) 79 | 011: forced to 1 parity (mark)*/ 80 | #define XUARTPS_MR_PAR_NONE (1<<5) /* 1xx: no parity*/ 81 | #define XUARTPS_MR_CHRL /* Character length select: 82 | 11: 6 bits 83 | 10: 7 bits*/ 84 | #define XUARTPS_MR_CHRL_8 /* 0x: 8 bits*/ 85 | 86 | #define XUARTPS_MR_CLKS /* Clock source select:*/ 87 | #define XUARTPS_MR_CLKS_REF_CLK 0 /* 0: clock source is uart_ref_clk*/ 88 | 89 | /* 90 | * Initiate UART1 ( /dev/ttyACM0 on host computer ) 91 | * 115,200 Baud 8-bit No-Parity 1-stop-bit 92 | */ 93 | void init_uart1_RxTx_115200_8N1(); 94 | void sendUART1char(char s); 95 | int puts(const char *s); 96 | //void putc((void*), char); 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /Hello03/hello03.c: -------------------------------------------------------------------------------- 1 | /* 2 | ZedBoard / Zynq-7000 3 | UART info could be found in 4 | B.33 UART Controller (UART) / Page 1626 in 5 | Zynq-7000 6 | All Programmable SoC 7 | Technical Reference Manual 8 | 9 | http://www.xilinx.com/support/documentation/user_guides/ug585-Zynq-7000-TRM.pdf 10 | */ 11 | 12 | 13 | #include 14 | #define u32 unsigned int 15 | 16 | #define UART1_BASE 0xe0001000 17 | // Register Description as found in 18 | // B.33 UART Controller (UART) p.1626 19 | struct XUARTPS{ 20 | u32 control_reg0; /* UART Control Register def=0x128 */ 21 | u32 mode_reg0; /* UART Mode Register def=0 */ 22 | u32 intrpt_en_reg0; /* Interrupt Enable Register def=0 */ 23 | u32 intrpt_dis_reg0; /* Interrupt Disable Register def=0 */ 24 | u32 intrpt_mask_reg0; /* Interrupt Mask Register def=0 */ 25 | u32 chnl_int_sts_reg0; /* Channel Interrupt Status Register def=x200 */ 26 | u32 baud_rate_gen; /* Baud Rate Generator Register def=0x28B */ 27 | u32 Rcvr_timeout_reg0; /* Receiver Timeout Register def=0 */ 28 | u32 Rcvr_FIFO_trigger_level0; /* Receiver FIFO Trigger Level Register */ 29 | u32 Modem_ctrl_reg0; /* Modem Control Register def=0 */ 30 | u32 Modem_sts_reg0; /* Modem Status Register */ 31 | u32 channel_sts_reg0; /* Channel Status Register def=0 */ 32 | u32 tx_rx_fifo; /* Transmit and Receive FIFO def=0 */ 33 | u32 baud_rate_divider; /* Baud Rate Divider def=0xf */ 34 | u32 Flow_delay_reg0; /* Flow Control Delay Register def=0*/ 35 | u32 Tx_FIFO_trigger_level;}; /* Transmitter FIFO Trigger Level Register */ 36 | 37 | static struct XUARTPS *UART1=(struct XUARTPS*) UART1_BASE; 38 | 39 | /* 40 | Page 496 41 | Simplifyed Table 19-1 UART Parameter Value Examples 42 | Parameter Value Examples 43 | Clock Baud BRGR-CD BDIV-CD Actual Baud Rate 44 | UART Ref clock 600 10417 7 45 | UART Ref clock 9,600 651 7 46 | UART Ref clock 28,800 347 4 47 | UART Ref clock 115,200 62 6 48 | UART Ref clock 230,400 31 6 49 | */ 50 | 51 | /*Baudrates assuming input clock speed is 3125000L */ 52 | /*Baud_rate_gen_reg0*/ 53 | #define XUARTPS_BRGR_CD_115200 62 /*Baud Rate Clock Divisor*/ 54 | 55 | /*Register Baud_rate_divider_reg0 Details*/ 56 | #define XUARTPS_BDIV_CD_115200 6 /*Baud Rate Clock Divisor*/ 57 | 58 | /* Bits defined in the Register Channel_sts_reg0 */ 59 | #define UART_STS_TXFULL 1<<4 /* Transmitter FIFO Full continuous status: 60 | 0: Tx FIFO is not full 61 | 1: Tx FIFO is full*/ 62 | 63 | /*Register Control_reg0 BitMask */ 64 | #define XUARTPS_CR_STOPBRK (1<<8) /* Stop transmitter break */ 65 | #define XUARTPS_CR_STTBRK (1<<7) /* Start transmitter break */ 66 | #define XUARTPS_CR_RSTTO (1<<6) /* Restart receiver timeout counter */ 67 | #define XUARTPS_CR_TXDIS (1<<5) /* Transmit disable */ 68 | #define XUARTPS_CR_TXEN (1<<4) /* Transmit enable */ 69 | #define XUARTPS_CR_RXDIS (1<<3) /* Receive disable */ 70 | #define XUARTPS_CR_RXEN (1<<2) /* Receive enable */ 71 | #define XUARTPS_CR_TXRES (1<<1) /* Software reset for Tx data path */ 72 | #define XUARTPS_CR_RXRES (1<<0) /* Software reset for Rx data path */ 73 | 74 | /*Register Control mode_reg0 BitMask*/ 75 | #define XUARTPS_MR_PAR /*Parity type select [5:3]*/ 76 | #define XUARTPS_MR_PAR_EVEN 0 /* 000: even parity 77 | 001: odd parity 78 | 010: forced to 0 parity (space) 79 | 011: forced to 1 parity (mark)*/ 80 | #define XUARTPS_MR_PAR_NONE (1<<5) /* 1xx: no parity*/ 81 | #define XUARTPS_MR_CHRL /* Character length select: 82 | 11: 6 bits 83 | 10: 7 bits*/ 84 | #define XUARTPS_MR_CHRL_8 /* 0x: 8 bits*/ 85 | 86 | #define XUARTPS_MR_CLKS /* Clock source select:*/ 87 | #define XUARTPS_MR_CLKS_REF_CLK 0 /* 0: clock source is uart_ref_clk*/ 88 | 89 | 90 | /* 91 | * Initiate UART1 ( /dev/ttyACM0 on host computer ) 92 | * 115,200 Baud 8-bit No-Parity 1-stop-bit 93 | */ 94 | void init_uart1_RxTx_115200_8N1() 95 | { 96 | /* Disable the transmitter and receiver before writing to the Baud Rate Generator */ 97 | UART1->control_reg0=0; 98 | 99 | /* Set Baudrate to 115,200 Baud */ 100 | UART1->baud_rate_divider =XUARTPS_BDIV_CD_115200; 101 | UART1->baud_rate_gen= XUARTPS_BRGR_CD_115200; 102 | 103 | /*Set 8-bit NoParity 1-StopBit*/ 104 | UART1->mode_reg0 = XUARTPS_MR_PAR_NONE; 105 | 106 | /*Enable Rx & Tx*/ 107 | UART1->control_reg0= XUARTPS_CR_TXEN | XUARTPS_CR_RXEN | XUARTPS_CR_TXRES | XUARTPS_CR_RXRES ; 108 | } 109 | 110 | void sendUART1char(char s) 111 | { 112 | /*Make sure that the uart is ready for new char's before continuing*/ 113 | while ((( UART1->channel_sts_reg0 ) & UART_STS_TXFULL) > 0) ; 114 | 115 | /* Loop until end of string */ 116 | UART1->tx_rx_fifo= (unsigned int) s; /* Transmit char */ 117 | } 118 | 119 | /* 's printf uses puts to send chars 120 | puts so that printf sends char to the serial port*/ 121 | int puts(const char *s) 122 | { 123 | while(*s != '\0') 124 | { 125 | if(*s=='\n') 126 | sendUART1char('\r'); 127 | 128 | sendUART1char(*s); /*Send char to the UART1*/ 129 | s++; /* Next char */ 130 | } 131 | return 0; 132 | } 133 | 134 | void c_entry() 135 | { 136 | init_uart1_RxTx_115200_8N1(); 137 | printf("\nHello world!\n"); 138 | while(1) ; /*dont exit the program*/ 139 | } 140 | --------------------------------------------------------------------------------