├── boot ├── start.elf ├── bootcode.bin └── readme.md ├── part-1 ├── armc-03 │ ├── bin-rpi │ │ └── kernel.img │ ├── bin-rpi-2 │ │ └── kernel.img │ ├── bin-rpi-bplus │ │ └── kernel.img │ ├── build.bat │ ├── build.sh │ ├── build-rpi-2.bat │ ├── build-rpi-2.sh │ ├── build-rpi-bplus.bat │ └── build-rpi-bplus.sh ├── armc-00 │ ├── armc-00.c │ ├── build.bat │ ├── build.sh │ ├── build-rpi-2.bat │ └── build-rpi-2.sh ├── armc-01 │ ├── build.bat │ ├── build.sh │ ├── build-rpi-2.sh │ ├── build-rpi-2.bat │ ├── build-rpi-bplus.bat │ ├── build-rpi-bplus.sh │ └── armc-01.c └── armc-02 │ ├── build.bat │ ├── build.sh │ ├── build-rpi-2.sh │ ├── build-rpi-2.bat │ ├── build-rpi-bplus.bat │ └── build-rpi-bplus.sh ├── part-2 ├── armc-04 │ ├── disassemble.bat │ ├── disassemble.sh │ ├── build.bat │ ├── build.sh │ ├── build-rpi-2.bat │ ├── build-rpi-2.sh │ ├── build-rpi-bplus.bat │ ├── build-rpi-bplus.sh │ ├── armc-04.c │ └── rpi-gpio.h ├── armc-05 │ ├── disassemble.bat │ ├── disassemble.sh │ ├── build.bat │ ├── build.sh │ ├── build-rpi-2.bat │ ├── build-rpi-2.sh │ ├── build-rpi-bplus.sh │ ├── build-rpi-bplus.bat │ ├── armc-05.c │ └── rpi-gpio.h ├── armc-06 │ ├── disassemble.bat │ ├── disassemble.sh │ ├── build.bat │ ├── build.sh │ ├── build-rpi-2.bat │ ├── build-rpi-2.sh │ ├── build-rpi-bplus.bat │ ├── build-rpi-bplus.sh │ ├── armc-06.c │ └── rpi-gpio.h ├── armc-07 │ ├── disassemble.bat │ ├── disassemble.sh │ ├── build.bat │ ├── build.sh │ ├── build-rpi-2.bat │ ├── build-rpi-2.sh │ ├── build-rpi-bplus.sh │ ├── build-rpi-bplus.bat │ ├── armc-07.c │ └── rpi-gpio.h ├── armc-08 │ ├── disassemble.bat │ ├── disassemble.sh │ ├── build.bat │ ├── build.sh │ ├── build-rpi-2.bat │ ├── build-rpi-2.sh │ ├── build-rpi-bplus.sh │ ├── build-rpi-bplus.bat │ ├── armc-08-start.S │ ├── armc-08-cstartup.c │ ├── armc-08.c │ └── rpi-gpio.h └── armc-09 │ ├── disassemble.bat │ ├── disassemble.sh │ ├── build.bat │ ├── build.sh │ ├── build-rpi-2.bat │ ├── build-rpi-2.sh │ ├── build-rpi-bplus.bat │ ├── build-rpi-bplus.sh │ ├── armc-09-start.S │ ├── armc-09-cstartup.c │ └── armc-09.c ├── part-5 ├── images │ ├── putty-rpi-connection.png │ ├── ftdi-ttl-232r-3v3-rpi-connection.png │ └── ftdi-ttl-232r-3v3-rpi-connection-photo.jpg ├── armc-014 │ ├── scripts │ │ ├── configure_rpi.bat │ │ ├── configure_rpi2.bat │ │ ├── configure_rpibplus.bat │ │ ├── configure_rpi.sh │ │ ├── configure_rpi2.sh │ │ └── configure_rpibplus.sh │ ├── rpi-armtimer.c │ ├── rpi-systimer.c │ ├── rpi-base.h │ ├── rpi-systimer.h │ ├── armc-cstartup.c │ ├── rpi-aux.c │ ├── rpi-gpio.c │ ├── rpi-mailbox.h │ ├── rpi-mailbox.c │ ├── CMakeLists.txt │ └── toolchain-arm-none-eabi-rpi.cmake ├── armc-015 │ ├── scripts │ │ ├── configure_rpi.bat │ │ ├── configure_rpi2.bat │ │ ├── configure_rpibplus.bat │ │ ├── configure_rpi.sh │ │ ├── configure_rpi2.sh │ │ └── configure_rpibplus.sh │ ├── rpi-armtimer.c │ ├── rpi-systimer.c │ ├── rpi-base.h │ ├── rpi-systimer.h │ ├── armc-cstartup.c │ ├── rpi-aux.c │ ├── rpi-gpio.c │ ├── rpi-mailbox.h │ ├── rpi-mailbox.c │ ├── CMakeLists.txt │ └── toolchain-arm-none-eabi-rpi.cmake └── armc-016 │ ├── scripts │ ├── configure_rpi.bat │ ├── configure_rpi2.bat │ ├── configure_rpibplus.bat │ ├── configure_rpi.sh │ ├── configure_rpi2.sh │ └── configure_rpibplus.sh │ ├── rpi-armtimer.c │ ├── rpi-systimer.c │ ├── rpi-base.h │ ├── rpi-systimer.h │ ├── armc-cstartup.c │ ├── rpi-aux.c │ ├── rpi-gpio.c │ ├── rpi-mailbox.h │ ├── rpi-mailbox.c │ └── CMakeLists.txt ├── part-3 ├── arm010 │ ├── scripts │ │ ├── configure_rpi.bat │ │ ├── configure_rpi2.bat │ │ ├── configure_rpibplus.bat │ │ ├── configure_rpi.sh │ │ ├── configure_rpi2.sh │ │ └── configure_rpibplus.sh │ ├── armc-010-start.S │ ├── armc-010-cstartup.c │ ├── CMakeLists.txt │ ├── armc-010.c │ └── toolchain-arm-none-eabi-rpi.cmake ├── arm011 │ ├── scripts │ │ ├── configure_rpi.bat │ │ ├── configure_rpi2.bat │ │ ├── configure_rpibplus.bat │ │ ├── configure_rpi.sh │ │ ├── configure_rpi2.sh │ │ └── configure_rpibplus.sh │ ├── rpi-base.h │ ├── rpi-systimer.c │ ├── rpi-systimer.h │ ├── armc-011-start.S │ ├── armc-011-cstartup.c │ ├── armc-011.c │ ├── CMakeLists.txt │ └── toolchain-arm-none-eabi-rpi.cmake └── arm012 │ ├── scripts │ ├── configure_rpi.bat │ ├── configure_rpi2.bat │ ├── configure_rpibplus.bat │ ├── configure_rpi.sh │ ├── configure_rpi2.sh │ └── configure_rpibplus.sh │ ├── rpi-base.h │ ├── rpi-systimer.c │ ├── rpi-systimer.h │ ├── armc-012-start.S │ ├── armc-012-cstartup.c │ ├── CMakeLists.txt │ └── toolchain-arm-none-eabi-rpi.cmake ├── part-4 └── armc-013 │ ├── scripts │ ├── configure_rpi.bat │ ├── configure_rpi2.bat │ ├── configure_rpibplus.bat │ ├── configure_rpi.sh │ ├── configure_rpi2.sh │ └── configure_rpibplus.sh │ ├── images │ └── armv5-figure-a2-1-register-organization.png │ ├── rpi-gpio.c │ ├── rpi-armtimer.c │ ├── rpi-systimer.c │ ├── rpi-base.h │ ├── rpi-systimer.h │ ├── armc-013-cstartup.c │ ├── armc-013.c │ ├── CMakeLists.txt │ ├── rpi-interrupts.h │ └── toolchain-arm-none-eabi-rpi.cmake ├── .gitattributes └── readme.md /boot/start.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wujunze/arm-tutorial-rpi/master/boot/start.elf -------------------------------------------------------------------------------- /boot/bootcode.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wujunze/arm-tutorial-rpi/master/boot/bootcode.bin -------------------------------------------------------------------------------- /part-1/armc-03/bin-rpi/kernel.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wujunze/arm-tutorial-rpi/master/part-1/armc-03/bin-rpi/kernel.img -------------------------------------------------------------------------------- /part-2/armc-04/disassemble.bat: -------------------------------------------------------------------------------- 1 | 2 | arm-none-eabi-objdump -D kernel.elf > kernel.asm 3 | arm-none-eabi-nm kernel.elf > kernel.nm -------------------------------------------------------------------------------- /part-2/armc-05/disassemble.bat: -------------------------------------------------------------------------------- 1 | 2 | arm-none-eabi-objdump -D kernel.elf > kernel.asm 3 | arm-none-eabi-nm kernel.elf > kernel.nm -------------------------------------------------------------------------------- /part-2/armc-06/disassemble.bat: -------------------------------------------------------------------------------- 1 | 2 | arm-none-eabi-objdump -D kernel.elf > kernel.asm 3 | arm-none-eabi-nm kernel.elf > kernel.nm -------------------------------------------------------------------------------- /part-2/armc-07/disassemble.bat: -------------------------------------------------------------------------------- 1 | 2 | arm-none-eabi-objdump -D kernel.elf > kernel.asm 3 | arm-none-eabi-nm kernel.elf > kernel.nm -------------------------------------------------------------------------------- /part-2/armc-08/disassemble.bat: -------------------------------------------------------------------------------- 1 | 2 | arm-none-eabi-objdump -D kernel.elf > kernel.asm 3 | arm-none-eabi-nm kernel.elf > kernel.nm -------------------------------------------------------------------------------- /part-2/armc-09/disassemble.bat: -------------------------------------------------------------------------------- 1 | 2 | arm-none-eabi-objdump -D kernel.elf > kernel.asm 3 | arm-none-eabi-nm kernel.elf > kernel.nm -------------------------------------------------------------------------------- /part-1/armc-03/bin-rpi-2/kernel.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wujunze/arm-tutorial-rpi/master/part-1/armc-03/bin-rpi-2/kernel.img -------------------------------------------------------------------------------- /part-1/armc-00/armc-00.c: -------------------------------------------------------------------------------- 1 | 2 | int main(void) 3 | { 4 | while(1) 5 | { 6 | 7 | } 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /part-5/images/putty-rpi-connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wujunze/arm-tutorial-rpi/master/part-5/images/putty-rpi-connection.png -------------------------------------------------------------------------------- /part-1/armc-03/bin-rpi-bplus/kernel.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wujunze/arm-tutorial-rpi/master/part-1/armc-03/bin-rpi-bplus/kernel.img -------------------------------------------------------------------------------- /part-3/arm010/scripts/configure_rpi.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 2 | -------------------------------------------------------------------------------- /part-3/arm011/scripts/configure_rpi.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 2 | -------------------------------------------------------------------------------- /part-3/arm012/scripts/configure_rpi.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 2 | -------------------------------------------------------------------------------- /part-2/armc-04/disassemble.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-objdump -D ./kernel.elf > ./kernel.asm 4 | arm-none-eabi-nm ./kernel.elf > ./kernel.nm 5 | -------------------------------------------------------------------------------- /part-2/armc-05/disassemble.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-objdump -D ./kernel.elf > ./kernel.asm 4 | arm-none-eabi-nm ./kernel.elf > ./kernel.nm 5 | -------------------------------------------------------------------------------- /part-2/armc-06/disassemble.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-objdump -D ./kernel.elf > ./kernel.asm 4 | arm-none-eabi-nm ./kernel.elf > ./kernel.nm 5 | -------------------------------------------------------------------------------- /part-2/armc-07/disassemble.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-objdump -D ./kernel.elf > ./kernel.asm 4 | arm-none-eabi-nm ./kernel.elf > ./kernel.nm 5 | -------------------------------------------------------------------------------- /part-2/armc-08/disassemble.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-objdump -D ./kernel.elf > ./kernel.asm 4 | arm-none-eabi-nm ./kernel.elf > ./kernel.nm 5 | -------------------------------------------------------------------------------- /part-2/armc-09/disassemble.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-objdump -D ./kernel.elf > ./kernel.asm 4 | arm-none-eabi-nm ./kernel.elf > ./kernel.nm 5 | -------------------------------------------------------------------------------- /part-3/arm010/scripts/configure_rpi2.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 2 | -------------------------------------------------------------------------------- /part-3/arm011/scripts/configure_rpi2.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 2 | -------------------------------------------------------------------------------- /part-3/arm012/scripts/configure_rpi2.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 2 | -------------------------------------------------------------------------------- /part-4/armc-013/scripts/configure_rpi.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 2 | -------------------------------------------------------------------------------- /part-4/armc-013/scripts/configure_rpi2.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 2 | -------------------------------------------------------------------------------- /part-5/armc-014/scripts/configure_rpi.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 2 | -------------------------------------------------------------------------------- /part-5/armc-014/scripts/configure_rpi2.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 2 | -------------------------------------------------------------------------------- /part-5/armc-015/scripts/configure_rpi.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 2 | -------------------------------------------------------------------------------- /part-5/armc-015/scripts/configure_rpi2.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 2 | -------------------------------------------------------------------------------- /part-5/armc-016/scripts/configure_rpi.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 2 | -------------------------------------------------------------------------------- /part-5/armc-016/scripts/configure_rpi2.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 2 | -------------------------------------------------------------------------------- /part-1/armc-00/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -g armc-00.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-1/armc-00/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -g armc-00.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-3/arm010/scripts/configure_rpibplus.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 2 | -------------------------------------------------------------------------------- /part-3/arm011/scripts/configure_rpibplus.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 2 | -------------------------------------------------------------------------------- /part-3/arm012/scripts/configure_rpibplus.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 2 | -------------------------------------------------------------------------------- /part-4/armc-013/scripts/configure_rpibplus.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 2 | -------------------------------------------------------------------------------- /part-5/armc-014/scripts/configure_rpibplus.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 2 | -------------------------------------------------------------------------------- /part-5/armc-015/scripts/configure_rpibplus.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 2 | -------------------------------------------------------------------------------- /part-5/armc-016/scripts/configure_rpibplus.bat: -------------------------------------------------------------------------------- 1 | cmake -G "CodeBlocks - MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 2 | -------------------------------------------------------------------------------- /part-5/images/ftdi-ttl-232r-3v3-rpi-connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wujunze/arm-tutorial-rpi/master/part-5/images/ftdi-ttl-232r-3v3-rpi-connection.png -------------------------------------------------------------------------------- /part-1/armc-00/build-rpi-2.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -g armc-00.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-1/armc-00/build-rpi-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -g armc-00.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-3/arm010/scripts/configure_rpi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 4 | -------------------------------------------------------------------------------- /part-3/arm010/scripts/configure_rpi2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 4 | -------------------------------------------------------------------------------- /part-3/arm011/scripts/configure_rpi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 4 | -------------------------------------------------------------------------------- /part-3/arm011/scripts/configure_rpi2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 4 | -------------------------------------------------------------------------------- /part-3/arm012/scripts/configure_rpi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 4 | -------------------------------------------------------------------------------- /part-3/arm012/scripts/configure_rpi2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 4 | -------------------------------------------------------------------------------- /part-4/armc-013/scripts/configure_rpi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 4 | -------------------------------------------------------------------------------- /part-4/armc-013/scripts/configure_rpi2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 4 | -------------------------------------------------------------------------------- /part-5/armc-014/scripts/configure_rpi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 4 | -------------------------------------------------------------------------------- /part-5/armc-014/scripts/configure_rpi2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 4 | -------------------------------------------------------------------------------- /part-5/armc-015/scripts/configure_rpi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 4 | -------------------------------------------------------------------------------- /part-5/armc-015/scripts/configure_rpi2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 4 | -------------------------------------------------------------------------------- /part-5/armc-016/scripts/configure_rpi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi.cmake ../ 4 | -------------------------------------------------------------------------------- /part-5/armc-016/scripts/configure_rpi2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpi2.cmake ../ 4 | -------------------------------------------------------------------------------- /part-1/armc-01/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-01.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-1/armc-01/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-01.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-1/armc-02/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-02.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-1/armc-02/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-02.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-3/arm010/scripts/configure_rpibplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 4 | -------------------------------------------------------------------------------- /part-3/arm011/scripts/configure_rpibplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 4 | -------------------------------------------------------------------------------- /part-3/arm012/scripts/configure_rpibplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 4 | -------------------------------------------------------------------------------- /part-4/armc-013/scripts/configure_rpibplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 4 | -------------------------------------------------------------------------------- /part-5/armc-014/scripts/configure_rpibplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 4 | -------------------------------------------------------------------------------- /part-5/armc-015/scripts/configure_rpibplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 4 | -------------------------------------------------------------------------------- /part-5/armc-016/scripts/configure_rpibplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi-rpibplus.cmake ../ 4 | -------------------------------------------------------------------------------- /part-5/images/ftdi-ttl-232r-3v3-rpi-connection-photo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wujunze/arm-tutorial-rpi/master/part-5/images/ftdi-ttl-232r-3v3-rpi-connection-photo.jpg -------------------------------------------------------------------------------- /part-1/armc-01/build-rpi-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g armc-01.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-1/armc-02/build-rpi-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g armc-02.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-1/armc-01/build-rpi-2.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g armc-01.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-1/armc-01/build-rpi-bplus.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -DRPIBPLUS -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-01.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-1/armc-01/build-rpi-bplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -DRPIBPLUS -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-01.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-1/armc-02/build-rpi-2.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g armc-02.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-1/armc-02/build-rpi-bplus.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-02.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-1/armc-02/build-rpi-bplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-02.c -o kernel.elf 4 | -------------------------------------------------------------------------------- /part-4/armc-013/images/armv5-figure-a2-1-register-organization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wujunze/arm-tutorial-rpi/master/part-4/armc-013/images/armv5-figure-a2-1-register-organization.png -------------------------------------------------------------------------------- /part-1/armc-01/armc-01.c: -------------------------------------------------------------------------------- 1 | 2 | int main(void) 3 | { 4 | while(1) 5 | { 6 | 7 | } 8 | 9 | return 0; 10 | } 11 | 12 | void exit(int code) 13 | { 14 | while(1) 15 | ; 16 | } 17 | -------------------------------------------------------------------------------- /boot/readme.md: -------------------------------------------------------------------------------- 1 | 2 | It's best to always use the latest bootcode.bin and start.elf from 3 | https://github.com/raspberrypi/firmware/tree/master/boot 4 | 5 | But here for convenience are current working versions for the tutorials. 6 | -------------------------------------------------------------------------------- /part-1/armc-03/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-03.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-1/armc-03/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-03.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-04/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-04.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-04/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-04.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-05/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-verbose armc-05.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-05/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-verbose armc-05.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-07/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-T,rpi.x armc-07.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-07/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-T,rpi.x armc-07.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-1/armc-03/build-rpi-2.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g armc-03.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-1/armc-03/build-rpi-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g armc-03.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-04/build-rpi-2.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g armc-04.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-04/build-rpi-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g armc-04.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-1/armc-03/build-rpi-bplus.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-03.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-1/armc-03/build-rpi-bplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-03.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-04/build-rpi-bplus.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-04.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-04/build-rpi-bplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g armc-04.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-06/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-verbose -Wl,-T,rpi.x armc-06.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-06/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-verbose -Wl,-T,rpi.x armc-06.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-05/build-rpi-2.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g -Wl,-verbose armc-05.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-05/build-rpi-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g -Wl,-verbose armc-05.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-05/build-rpi-bplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-verbose armc-05.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-07/build-rpi-2.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g -Wl,-T,rpi.x armc-07.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-07/build-rpi-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g -Wl,-T,rpi.x armc-07.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-07/build-rpi-bplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-T,rpi.x armc-07.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-05/build-rpi-bplus.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-verbose armc-05.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-07/build-rpi-bplus.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-T,rpi.x armc-07.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-06/build-rpi-2.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g -Wl,-verbose -Wl,-T,rpi.x armc-06.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-06/build-rpi-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g -Wl,-verbose -Wl,-T,rpi.x armc-06.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-06/build-rpi-bplus.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-verbose -Wl,-T,rpi.x armc-06.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-06/build-rpi-bplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-verbose -Wl,-T,rpi.x armc-06.c -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-08/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-T,rpi.x armc-08.c armc-08-cstartup.c armc-08-start.S -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-08/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-T,rpi.x armc-08.c armc-08-cstartup.c armc-08-start.S -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-4/armc-013/rpi-gpio.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-gpio.h" 4 | 5 | static rpi_gpio_t* rpiGpio = (rpi_gpio_t*)RPI_GPIO_BASE; 6 | 7 | rpi_gpio_t* RPI_GetGpio(void) 8 | { 9 | return rpiGpio; 10 | } 11 | 12 | void RPI_GpioInit(void) 13 | { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /part-2/armc-08/build-rpi-2.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g -Wl,-T,rpi.x armc-08.c armc-08-cstartup.c armc-08-start.S -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-08/build-rpi-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g -Wl,-T,rpi.x armc-08.c armc-08-cstartup.c armc-08-start.S -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-08/build-rpi-bplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-T,rpi.x armc-08.c armc-08-cstartup.c armc-08-start.S -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-09/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-T,rpi.x armc-09.c armc-09-cstubs.c armc-09-cstartup.c armc-09-start.S -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-09/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-T,rpi.x armc-09.c armc-09-cstubs.c armc-09-cstartup.c armc-09-start.S -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-08/build-rpi-bplus.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-T,rpi.x armc-08.c armc-08-cstartup.c armc-08-start.S -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-09/build-rpi-2.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g -Wl,-T,rpi.x armc-09.c armc-09-cstubs.c armc-09-cstartup.c armc-09-start.S -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-09/build-rpi-2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPI2 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -g -Wl,-T,rpi.x armc-09.c armc-09-cstubs.c armc-09-cstartup.c armc-09-start.S -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-09/build-rpi-bplus.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-T,rpi.x armc-09.c armc-09-cstubs.c armc-09-cstartup.c armc-09-start.S -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-2/armc-09/build-rpi-bplus.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | arm-none-eabi-gcc -O0 -DRPIBPLUS -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -nostartfiles -g -Wl,-T,rpi.x armc-09.c armc-09-cstubs.c armc-09-cstartup.c armc-09-start.S -o kernel.elf 4 | arm-none-eabi-objcopy kernel.elf -O binary kernel.img 5 | -------------------------------------------------------------------------------- /part-3/arm011/rpi-base.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef RPI_BASE_H 3 | #define RPI_BASE_H 4 | 5 | #include 6 | 7 | typedef volatile uint32_t rpi_reg_rw_t; 8 | typedef volatile const uint32_t rpi_reg_ro_t; 9 | typedef volatile uint64_t rpi_wreg_rw_t; 10 | typedef volatile const uint64_t rpi_wreg_ro_t; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /part-3/arm012/rpi-base.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef RPI_BASE_H 3 | #define RPI_BASE_H 4 | 5 | #include 6 | 7 | typedef volatile uint32_t rpi_reg_rw_t; 8 | typedef volatile const uint32_t rpi_reg_ro_t; 9 | typedef volatile uint64_t rpi_wreg_rw_t; 10 | typedef volatile const uint64_t rpi_wreg_ro_t; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /part-4/armc-013/rpi-armtimer.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-armtimer.h" 4 | 5 | static rpi_arm_timer_t* rpiArmTimer = (rpi_arm_timer_t*)RPI_ARMTIMER_BASE; 6 | 7 | rpi_arm_timer_t* RPI_GetArmTimer(void) 8 | { 9 | return rpiArmTimer; 10 | } 11 | 12 | void RPI_ArmTimerInit(void) 13 | { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /part-5/armc-014/rpi-armtimer.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-armtimer.h" 4 | 5 | static rpi_arm_timer_t* rpiArmTimer = (rpi_arm_timer_t*)RPI_ARMTIMER_BASE; 6 | 7 | rpi_arm_timer_t* RPI_GetArmTimer(void) 8 | { 9 | return rpiArmTimer; 10 | } 11 | 12 | void RPI_ArmTimerInit(void) 13 | { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /part-5/armc-015/rpi-armtimer.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-armtimer.h" 4 | 5 | static rpi_arm_timer_t* rpiArmTimer = (rpi_arm_timer_t*)RPI_ARMTIMER_BASE; 6 | 7 | rpi_arm_timer_t* RPI_GetArmTimer(void) 8 | { 9 | return rpiArmTimer; 10 | } 11 | 12 | void RPI_ArmTimerInit(void) 13 | { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /part-5/armc-016/rpi-armtimer.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-armtimer.h" 4 | 5 | static rpi_arm_timer_t* rpiArmTimer = (rpi_arm_timer_t*)RPI_ARMTIMER_BASE; 6 | 7 | rpi_arm_timer_t* RPI_GetArmTimer(void) 8 | { 9 | return rpiArmTimer; 10 | } 11 | 12 | void RPI_ArmTimerInit(void) 13 | { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /part-3/arm011/rpi-systimer.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-systimer.h" 4 | 5 | static rpi_sys_timer_t* rpiSystemTimer = (rpi_sys_timer_t*)RPI_SYSTIMER_BASE; 6 | 7 | rpi_sys_timer_t* RPI_GetSystemTimer(void) 8 | { 9 | return rpiSystemTimer; 10 | } 11 | 12 | void RPI_WaitMicroSeconds( uint32_t us ) 13 | { 14 | volatile uint32_t ts = rpiSystemTimer->counter_lo; 15 | 16 | while( ( rpiSystemTimer->counter_lo - ts ) < us ) 17 | { 18 | /* BLANK */ 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /part-3/arm012/rpi-systimer.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-systimer.h" 4 | 5 | static rpi_sys_timer_t* rpiSystemTimer = (rpi_sys_timer_t*)RPI_SYSTIMER_BASE; 6 | 7 | rpi_sys_timer_t* RPI_GetSystemTimer(void) 8 | { 9 | return rpiSystemTimer; 10 | } 11 | 12 | void RPI_WaitMicroSeconds( uint32_t us ) 13 | { 14 | volatile uint32_t ts = rpiSystemTimer->counter_lo; 15 | 16 | while( ( rpiSystemTimer->counter_lo - ts ) < us ) 17 | { 18 | /* BLANK */ 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /part-4/armc-013/rpi-systimer.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-systimer.h" 4 | 5 | static rpi_sys_timer_t* rpiSystemTimer = (rpi_sys_timer_t*)RPI_SYSTIMER_BASE; 6 | 7 | rpi_sys_timer_t* RPI_GetSystemTimer(void) 8 | { 9 | return rpiSystemTimer; 10 | } 11 | 12 | void RPI_WaitMicroSeconds( uint32_t us ) 13 | { 14 | volatile uint32_t ts = rpiSystemTimer->counter_lo; 15 | 16 | while( ( rpiSystemTimer->counter_lo - ts ) < us ) 17 | { 18 | /* BLANK */ 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /part-5/armc-014/rpi-systimer.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-systimer.h" 4 | 5 | static rpi_sys_timer_t* rpiSystemTimer = (rpi_sys_timer_t*)RPI_SYSTIMER_BASE; 6 | 7 | rpi_sys_timer_t* RPI_GetSystemTimer(void) 8 | { 9 | return rpiSystemTimer; 10 | } 11 | 12 | void RPI_WaitMicroSeconds( uint32_t us ) 13 | { 14 | volatile uint32_t ts = rpiSystemTimer->counter_lo; 15 | 16 | while( ( rpiSystemTimer->counter_lo - ts ) < us ) 17 | { 18 | /* BLANK */ 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /part-5/armc-015/rpi-systimer.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-systimer.h" 4 | 5 | static rpi_sys_timer_t* rpiSystemTimer = (rpi_sys_timer_t*)RPI_SYSTIMER_BASE; 6 | 7 | rpi_sys_timer_t* RPI_GetSystemTimer(void) 8 | { 9 | return rpiSystemTimer; 10 | } 11 | 12 | void RPI_WaitMicroSeconds( uint32_t us ) 13 | { 14 | volatile uint32_t ts = rpiSystemTimer->counter_lo; 15 | 16 | while( ( rpiSystemTimer->counter_lo - ts ) < us ) 17 | { 18 | /* BLANK */ 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /part-5/armc-016/rpi-systimer.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-systimer.h" 4 | 5 | static rpi_sys_timer_t* rpiSystemTimer = (rpi_sys_timer_t*)RPI_SYSTIMER_BASE; 6 | 7 | rpi_sys_timer_t* RPI_GetSystemTimer(void) 8 | { 9 | return rpiSystemTimer; 10 | } 11 | 12 | void RPI_WaitMicroSeconds( uint32_t us ) 13 | { 14 | volatile uint32_t ts = rpiSystemTimer->counter_lo; 15 | 16 | while( ( rpiSystemTimer->counter_lo - ts ) < us ) 17 | { 18 | /* BLANK */ 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /part-3/arm011/rpi-systimer.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef RPI_SYSTIMER_H 3 | #define RPI_SYSTIMER_H 4 | 5 | #include 6 | 7 | #include "rpi-base.h" 8 | 9 | #ifdef RPI2 10 | #define RPI_SYSTIMER_BASE 0x3f003000 11 | #else 12 | #define RPI_SYSTIMER_BASE 0x20003000 13 | #endif 14 | 15 | typedef struct { 16 | volatile uint32_t control_status; 17 | volatile uint32_t counter_lo; 18 | volatile uint32_t counter_hi; 19 | volatile uint32_t compare0; 20 | volatile uint32_t compare1; 21 | volatile uint32_t compare2; 22 | volatile uint32_t compare3; 23 | } rpi_sys_timer_t; 24 | 25 | 26 | extern rpi_sys_timer_t* RPI_GetSystemTimer(void); 27 | extern void RPI_WaitMicroSeconds( uint32_t us ); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /part-3/arm012/rpi-systimer.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef RPI_SYSTIMER_H 3 | #define RPI_SYSTIMER_H 4 | 5 | #include 6 | 7 | #include "rpi-base.h" 8 | 9 | #ifdef RPI2 10 | #define RPI_SYSTIMER_BASE 0x3f003000 11 | #else 12 | #define RPI_SYSTIMER_BASE 0x20003000 13 | #endif 14 | 15 | typedef struct { 16 | volatile uint32_t control_status; 17 | volatile uint32_t counter_lo; 18 | volatile uint32_t counter_hi; 19 | volatile uint32_t compare0; 20 | volatile uint32_t compare1; 21 | volatile uint32_t compare2; 22 | volatile uint32_t compare3; 23 | } rpi_sys_timer_t; 24 | 25 | 26 | extern rpi_sys_timer_t* RPI_GetSystemTimer(void); 27 | extern void RPI_WaitMicroSeconds( uint32_t us ); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Raspberry-Pi Bare Metal Tutorial 2 | 3 | This repository contains the code for the Raspberry-Pi bare-metal programming 4 | in C series. The home of the tutorial and all of the articles relating to the 5 | code is at 6 | [valvers.com](http://www.valvers.com/open-software/raspberry-pi/step01-bare-metal-programming-in-cpt1/) 7 | 8 | You can build on linux, windows, or MAC - all you need is the 9 | [https://launchpad.net/gcc-arm-embedded](arm-none-eabi toolchain). 10 | 11 | For all platforms, you can get the required toolchain used in this tutorial 12 | from the [GCC-ARM-embedded](https://launchpad.net/gcc-arm-embedded) project - I 13 | recommend getting the 4.7 toolchain because I've had problems with the 4.9 14 | toolchain. 15 | 16 | Have fun, and remember to experiment! 17 | 18 | ## Tutorial links (online) 19 | 20 | [Step01 - Getting Started](http://www.valvers.com/open-software/raspberry-pi/step01-bare-metal-programming-in-cpt1/) 21 | 22 | [Step02 - C Runtime](http://www.valvers.com/open-software/raspberry-pi/step02-bare-metal-programming-in-c-pt2/) 23 | 24 | [Step03 - Introducing CMake](http://www.valvers.com/open-software/raspberry-pi/step03-bare-metal-programming-in-c-pt3/) 25 | 26 | [Step04 - Interrupts](http://www.valvers.com/open-software/raspberry-pi/step04-bare-metal-programming-in-c-pt4/) 27 | 28 | [Step05 - Graphics(Basic)](http://www.valvers.com/open-software/raspberry-pi/step05-bare-metal-programming-in-c-pt5/) 29 | 30 | ## Some interesting links: 31 | 32 | Original Cambridge Tutorial that inspired this tutorial series: 33 | http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/index.html 34 | 35 | ARM Instruction Reference: 36 | http://infocenter.arm.com/help/topic/com.arm.doc.qrc0001l/QRC0001_UAL.pdf 37 | 38 | GNU ARM Embedded Toolchain: 39 | https://launchpad.net/gcc-arm-embedded 40 | 41 | Newlib C-Library documentation: 42 | https://sourceware.org/newlib/libc.html 43 | -------------------------------------------------------------------------------- /part-4/armc-013/rpi-base.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013-2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_BASE_H 32 | #define RPI_BASE_H 33 | 34 | #include 35 | 36 | #ifdef RPI2 37 | #define PERIPHERAL_BASE 0x3F000000UL 38 | #else 39 | #define PERIPHERAL_BASE 0x20000000UL 40 | #endif 41 | 42 | typedef volatile uint32_t rpi_reg_rw_t; 43 | typedef volatile const uint32_t rpi_reg_ro_t; 44 | typedef volatile uint32_t rpi_reg_wo_t; 45 | 46 | typedef volatile uint64_t rpi_wreg_rw_t; 47 | typedef volatile const uint64_t rpi_wreg_ro_t; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /part-5/armc-014/rpi-base.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013-2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_BASE_H 32 | #define RPI_BASE_H 33 | 34 | #include 35 | 36 | #ifdef RPI2 37 | #define PERIPHERAL_BASE 0x3F000000UL 38 | #else 39 | #define PERIPHERAL_BASE 0x20000000UL 40 | #endif 41 | 42 | typedef volatile uint32_t rpi_reg_rw_t; 43 | typedef volatile const uint32_t rpi_reg_ro_t; 44 | typedef volatile uint32_t rpi_reg_wo_t; 45 | 46 | typedef volatile uint64_t rpi_wreg_rw_t; 47 | typedef volatile const uint64_t rpi_wreg_ro_t; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /part-5/armc-015/rpi-base.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013-2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_BASE_H 32 | #define RPI_BASE_H 33 | 34 | #include 35 | 36 | #ifdef RPI2 37 | #define PERIPHERAL_BASE 0x3F000000UL 38 | #else 39 | #define PERIPHERAL_BASE 0x20000000UL 40 | #endif 41 | 42 | typedef volatile uint32_t rpi_reg_rw_t; 43 | typedef volatile const uint32_t rpi_reg_ro_t; 44 | typedef volatile uint32_t rpi_reg_wo_t; 45 | 46 | typedef volatile uint64_t rpi_wreg_rw_t; 47 | typedef volatile const uint64_t rpi_wreg_ro_t; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /part-5/armc-016/rpi-base.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013-2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_BASE_H 32 | #define RPI_BASE_H 33 | 34 | #include 35 | 36 | #ifdef RPI2 37 | #define PERIPHERAL_BASE 0x3F000000UL 38 | #else 39 | #define PERIPHERAL_BASE 0x20000000UL 40 | #endif 41 | 42 | typedef volatile uint32_t rpi_reg_rw_t; 43 | typedef volatile const uint32_t rpi_reg_ro_t; 44 | typedef volatile uint32_t rpi_reg_wo_t; 45 | 46 | typedef volatile uint64_t rpi_wreg_rw_t; 47 | typedef volatile const uint64_t rpi_wreg_ro_t; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /part-2/armc-09/armc-09-start.S: -------------------------------------------------------------------------------- 1 | 2 | // Part of the Raspberry-Pi Bare Metal Tutorials 3 | // Copyright (c) 2013, Brian Sidebotham 4 | // All rights reserved. 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | .section ".text.startup" 30 | 31 | .global _start 32 | .global _get_stack_pointer 33 | 34 | _start: 35 | // Set it at 64MB which we know our application will not crash into 36 | // and we also know will be available to the ARM CPU. No matter what 37 | // settings we use to split the memory between the GPU and ARM CPU 38 | // ldr sp, =0x8000 39 | ldr sp, =(64 * 1024 * 1024) 40 | 41 | // Run the c startup function - should not return and will call kernel_main 42 | b _cstartup 43 | 44 | _inf_loop: 45 | b _inf_loop 46 | 47 | -------------------------------------------------------------------------------- /part-2/armc-08/armc-08-start.S: -------------------------------------------------------------------------------- 1 | 2 | // Part of the Raspberry-Pi Bare Metal Tutorials 3 | // Copyright (c) 2013, Brian Sidebotham 4 | // All rights reserved. 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | .section ".text.startup" 30 | 31 | .global _start 32 | .global _get_stack_pointer 33 | 34 | _start: 35 | // Set the stack pointer, which progresses downwards through memory 36 | // Set it at 64MB which we know our application will not crash into 37 | // and we also know will be available to the ARM CPU. No matter what 38 | // settings we use to split the memory between the GPU and ARM CPU 39 | ldr sp, =0x8000 40 | 41 | // Run the c startup function - should not return and will call kernel_main 42 | b _cstartup 43 | 44 | _inf_loop: 45 | b _inf_loop 46 | -------------------------------------------------------------------------------- /part-4/armc-013/rpi-systimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Raspberry-Pi Bare Metal Tutorials 3 | Copyright (c) 2013-2015, Brian Sidebotham 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | */ 29 | 30 | #ifndef RPI_SYSTIMER_H 31 | #define RPI_SYSTIMER_H 32 | 33 | #include 34 | 35 | #include "rpi-base.h" 36 | 37 | #define RPI_SYSTIMER_BASE ( PERIPHERAL_BASE + 0x3000 ) 38 | 39 | 40 | typedef struct { 41 | volatile uint32_t control_status; 42 | volatile uint32_t counter_lo; 43 | volatile uint32_t counter_hi; 44 | volatile uint32_t compare0; 45 | volatile uint32_t compare1; 46 | volatile uint32_t compare2; 47 | volatile uint32_t compare3; 48 | } rpi_sys_timer_t; 49 | 50 | 51 | extern rpi_sys_timer_t* RPI_GetSystemTimer(void); 52 | extern void RPI_WaitMicroSeconds( uint32_t us ); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /part-5/armc-014/rpi-systimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Raspberry-Pi Bare Metal Tutorials 3 | Copyright (c) 2013-2015, Brian Sidebotham 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | */ 29 | 30 | #ifndef RPI_SYSTIMER_H 31 | #define RPI_SYSTIMER_H 32 | 33 | #include 34 | 35 | #include "rpi-base.h" 36 | 37 | #define RPI_SYSTIMER_BASE ( PERIPHERAL_BASE + 0x3000 ) 38 | 39 | 40 | typedef struct { 41 | volatile uint32_t control_status; 42 | volatile uint32_t counter_lo; 43 | volatile uint32_t counter_hi; 44 | volatile uint32_t compare0; 45 | volatile uint32_t compare1; 46 | volatile uint32_t compare2; 47 | volatile uint32_t compare3; 48 | } rpi_sys_timer_t; 49 | 50 | 51 | extern rpi_sys_timer_t* RPI_GetSystemTimer(void); 52 | extern void RPI_WaitMicroSeconds( uint32_t us ); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /part-5/armc-015/rpi-systimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Raspberry-Pi Bare Metal Tutorials 3 | Copyright (c) 2013-2015, Brian Sidebotham 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | */ 29 | 30 | #ifndef RPI_SYSTIMER_H 31 | #define RPI_SYSTIMER_H 32 | 33 | #include 34 | 35 | #include "rpi-base.h" 36 | 37 | #define RPI_SYSTIMER_BASE ( PERIPHERAL_BASE + 0x3000 ) 38 | 39 | 40 | typedef struct { 41 | volatile uint32_t control_status; 42 | volatile uint32_t counter_lo; 43 | volatile uint32_t counter_hi; 44 | volatile uint32_t compare0; 45 | volatile uint32_t compare1; 46 | volatile uint32_t compare2; 47 | volatile uint32_t compare3; 48 | } rpi_sys_timer_t; 49 | 50 | 51 | extern rpi_sys_timer_t* RPI_GetSystemTimer(void); 52 | extern void RPI_WaitMicroSeconds( uint32_t us ); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /part-5/armc-016/rpi-systimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Part of the Raspberry-Pi Bare Metal Tutorials 3 | Copyright (c) 2013-2015, Brian Sidebotham 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | 28 | */ 29 | 30 | #ifndef RPI_SYSTIMER_H 31 | #define RPI_SYSTIMER_H 32 | 33 | #include 34 | 35 | #include "rpi-base.h" 36 | 37 | #define RPI_SYSTIMER_BASE ( PERIPHERAL_BASE + 0x3000 ) 38 | 39 | 40 | typedef struct { 41 | volatile uint32_t control_status; 42 | volatile uint32_t counter_lo; 43 | volatile uint32_t counter_hi; 44 | volatile uint32_t compare0; 45 | volatile uint32_t compare1; 46 | volatile uint32_t compare2; 47 | volatile uint32_t compare3; 48 | } rpi_sys_timer_t; 49 | 50 | 51 | extern rpi_sys_timer_t* RPI_GetSystemTimer(void); 52 | extern void RPI_WaitMicroSeconds( uint32_t us ); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /part-3/arm010/armc-010-start.S: -------------------------------------------------------------------------------- 1 | 2 | // Part of the Raspberry-Pi Bare Metal Tutorials 3 | // Copyright (c) 2013, Brian Sidebotham 4 | // All rights reserved. 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | .section ".text.startup" 30 | 31 | .global _start 32 | .global _get_stack_pointer 33 | 34 | _start: 35 | // Set the stack pointer at the end of RAM. 36 | // Keep it within the limits and also keep it aligned to a 32-bit 37 | // boundary! 38 | mov sp, #(128 * (1024 * 1024)) - 4 39 | //mov sp, #(256 * (1024 * 1024)) - 4 40 | //mov sp, #(512 * (1024 * 1024)) - 4 41 | 42 | // The c-startup 43 | b _cstartup 44 | 45 | _inf_loop: 46 | b _inf_loop 47 | 48 | 49 | _get_stack_pointer: 50 | // Return the stack pointer value 51 | str sp, [sp] 52 | ldr r0, [sp] 53 | 54 | // Return from the function 55 | mov pc, lr 56 | 57 | -------------------------------------------------------------------------------- /part-3/arm011/armc-011-start.S: -------------------------------------------------------------------------------- 1 | 2 | // Part of the Raspberry-Pi Bare Metal Tutorials 3 | // Copyright (c) 2013, Brian Sidebotham 4 | // All rights reserved. 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | .section ".text.startup" 30 | 31 | .global _start 32 | .global _get_stack_pointer 33 | 34 | _start: 35 | // Set the stack pointer at the end of RAM. 36 | // Keep it within the limits and also keep it aligned to a 32-bit 37 | // boundary! 38 | mov sp, #(128 * (1024 * 1024)) - 4 39 | //mov sp, #(256 * (1024 * 1024)) - 4 40 | //mov sp, #(512 * (1024 * 1024)) - 4 41 | 42 | // The c-startup 43 | b _cstartup 44 | 45 | _inf_loop: 46 | b _inf_loop 47 | 48 | 49 | _get_stack_pointer: 50 | // Return the stack pointer value 51 | str sp, [sp] 52 | ldr r0, [sp] 53 | 54 | // Return from the function 55 | mov pc, lr 56 | 57 | -------------------------------------------------------------------------------- /part-3/arm012/armc-012-start.S: -------------------------------------------------------------------------------- 1 | 2 | // Part of the Raspberry-Pi Bare Metal Tutorials 3 | // Copyright (c) 2013, Brian Sidebotham 4 | // All rights reserved. 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright notice, 13 | // this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | // POSSIBILITY OF SUCH DAMAGE. 27 | 28 | 29 | .section ".text.startup" 30 | 31 | .global _start 32 | .global _get_stack_pointer 33 | 34 | _start: 35 | // Set the stack pointer at the end of RAM. 36 | // Keep it within the limits and also keep it aligned to a 32-bit 37 | // boundary! 38 | mov sp, #(128 * (1024 * 1024)) - 4 39 | //mov sp, #(256 * (1024 * 1024)) - 4 40 | //mov sp, #(512 * (1024 * 1024)) - 4 41 | 42 | // The c-startup 43 | b _cstartup 44 | 45 | _inf_loop: 46 | b _inf_loop 47 | 48 | 49 | _get_stack_pointer: 50 | // Return the stack pointer value 51 | str sp, [sp] 52 | ldr r0, [sp] 53 | 54 | // Return from the function 55 | mov pc, lr 56 | 57 | -------------------------------------------------------------------------------- /part-3/arm010/armc-010-cstartup.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | extern int __bss_start__; 32 | extern int __bss_end__; 33 | 34 | extern void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ); 35 | 36 | void _cstartup( unsigned int r0, unsigned int r1, unsigned int r2 ) 37 | { 38 | int* bss = &__bss_start__; 39 | int* bss_end = &__bss_end__; 40 | 41 | /* 42 | Clear the BSS section 43 | 44 | See http://en.wikipedia.org/wiki/.bss for further information on the 45 | BSS section 46 | 47 | See https://sourceware.org/newlib/libc.html#Stubs for further 48 | information on the c-library stubs 49 | */ 50 | while( bss < bss_end ) 51 | *bss++ = 0; 52 | 53 | /* We should never return from main ... */ 54 | kernel_main( r0, r1, r2 ); 55 | 56 | /* ... but if we do, safely trap here */ 57 | while(1) 58 | { 59 | /* EMPTY! */ 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /part-3/arm011/armc-011-cstartup.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | extern int __bss_start__; 32 | extern int __bss_end__; 33 | 34 | extern void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ); 35 | 36 | void _cstartup( unsigned int r0, unsigned int r1, unsigned int r2 ) 37 | { 38 | int* bss = &__bss_start__; 39 | int* bss_end = &__bss_end__; 40 | 41 | /* 42 | Clear the BSS section 43 | 44 | See http://en.wikipedia.org/wiki/.bss for further information on the 45 | BSS section 46 | 47 | See https://sourceware.org/newlib/libc.html#Stubs for further 48 | information on the c-library stubs 49 | */ 50 | while( bss < bss_end ) 51 | *bss++ = 0; 52 | 53 | /* We should never return from main ... */ 54 | kernel_main( r0, r1, r2 ); 55 | 56 | /* ... but if we do, safely trap here */ 57 | while(1) 58 | { 59 | /* EMPTY! */ 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /part-3/arm012/armc-012-cstartup.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | extern int __bss_start__; 32 | extern int __bss_end__; 33 | 34 | extern void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ); 35 | 36 | void _cstartup( unsigned int r0, unsigned int r1, unsigned int r2 ) 37 | { 38 | int* bss = &__bss_start__; 39 | int* bss_end = &__bss_end__; 40 | 41 | /* 42 | Clear the BSS section 43 | 44 | See http://en.wikipedia.org/wiki/.bss for further information on the 45 | BSS section 46 | 47 | See https://sourceware.org/newlib/libc.html#Stubs for further 48 | information on the c-library stubs 49 | */ 50 | while( bss < bss_end ) 51 | *bss++ = 0; 52 | 53 | /* We should never return from main ... */ 54 | kernel_main( r0, r1, r2 ); 55 | 56 | /* ... but if we do, safely trap here */ 57 | while(1) 58 | { 59 | /* EMPTY! */ 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /part-5/armc-014/armc-cstartup.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | extern int __bss_start__; 32 | extern int __bss_end__; 33 | 34 | extern void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ); 35 | 36 | void _cstartup( unsigned int r0, unsigned int r1, unsigned int r2 ) 37 | { 38 | int* bss = &__bss_start__; 39 | int* bss_end = &__bss_end__; 40 | 41 | /* 42 | Clear the BSS section 43 | 44 | See http://en.wikipedia.org/wiki/.bss for further information on the 45 | BSS section 46 | 47 | See https://sourceware.org/newlib/libc.html#Stubs for further 48 | information on the c-library stubs 49 | */ 50 | while( bss < bss_end ) 51 | *bss++ = 0; 52 | 53 | /* We should never return from main ... */ 54 | kernel_main( r0, r1, r2 ); 55 | 56 | /* ... but if we do, safely trap here */ 57 | while(1) 58 | { 59 | /* EMPTY! */ 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /part-5/armc-015/armc-cstartup.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | extern int __bss_start__; 32 | extern int __bss_end__; 33 | 34 | extern void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ); 35 | 36 | void _cstartup( unsigned int r0, unsigned int r1, unsigned int r2 ) 37 | { 38 | int* bss = &__bss_start__; 39 | int* bss_end = &__bss_end__; 40 | 41 | /* 42 | Clear the BSS section 43 | 44 | See http://en.wikipedia.org/wiki/.bss for further information on the 45 | BSS section 46 | 47 | See https://sourceware.org/newlib/libc.html#Stubs for further 48 | information on the c-library stubs 49 | */ 50 | while( bss < bss_end ) 51 | *bss++ = 0; 52 | 53 | /* We should never return from main ... */ 54 | kernel_main( r0, r1, r2 ); 55 | 56 | /* ... but if we do, safely trap here */ 57 | while(1) 58 | { 59 | /* EMPTY! */ 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /part-5/armc-016/armc-cstartup.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | extern int __bss_start__; 32 | extern int __bss_end__; 33 | 34 | extern void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ); 35 | 36 | void _cstartup( unsigned int r0, unsigned int r1, unsigned int r2 ) 37 | { 38 | int* bss = &__bss_start__; 39 | int* bss_end = &__bss_end__; 40 | 41 | /* 42 | Clear the BSS section 43 | 44 | See http://en.wikipedia.org/wiki/.bss for further information on the 45 | BSS section 46 | 47 | See https://sourceware.org/newlib/libc.html#Stubs for further 48 | information on the c-library stubs 49 | */ 50 | while( bss < bss_end ) 51 | *bss++ = 0; 52 | 53 | /* We should never return from main ... */ 54 | kernel_main( r0, r1, r2 ); 55 | 56 | /* ... but if we do, safely trap here */ 57 | while(1) 58 | { 59 | /* EMPTY! */ 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /part-4/armc-013/armc-013-cstartup.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | extern int __bss_start__; 32 | extern int __bss_end__; 33 | 34 | extern void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ); 35 | 36 | void _cstartup( unsigned int r0, unsigned int r1, unsigned int r2 ) 37 | { 38 | int* bss = &__bss_start__; 39 | int* bss_end = &__bss_end__; 40 | 41 | /* 42 | Clear the BSS section 43 | 44 | See http://en.wikipedia.org/wiki/.bss for further information on the 45 | BSS section 46 | 47 | See https://sourceware.org/newlib/libc.html#Stubs for further 48 | information on the c-library stubs 49 | */ 50 | while( bss < bss_end ) 51 | *bss++ = 0; 52 | 53 | /* We should never return from main ... */ 54 | kernel_main( r0, r1, r2 ); 55 | 56 | /* ... but if we do, safely trap here */ 57 | while(1) 58 | { 59 | /* EMPTY! */ 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /part-2/armc-08/armc-08-cstartup.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | extern int __bss_start__; 32 | extern int __bss_end__; 33 | 34 | extern void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ); 35 | 36 | void _cstartup( unsigned int r0, unsigned int r1, unsigned int r2 ) 37 | { 38 | /*__bss_start__ and __bss_end__ are defined in the linker script */ 39 | int* bss = &__bss_start__; 40 | int* bss_end = &__bss_end__; 41 | 42 | /* 43 | Clear the BSS section 44 | 45 | See http://en.wikipedia.org/wiki/.bss for further information on the 46 | BSS section 47 | 48 | See https://sourceware.org/newlib/libc.html#Stubs for further 49 | information on the c-library stubs 50 | */ 51 | while( bss < bss_end ) 52 | *bss++ = 0; 53 | 54 | /* We should never return from main ... */ 55 | kernel_main( r0, r1, r2 ); 56 | 57 | /* ... but if we do, safely trap here */ 58 | while(1) 59 | { 60 | /* EMPTY! */ 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /part-2/armc-09/armc-09-cstartup.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | extern int __bss_start__; 32 | extern int __bss_end__; 33 | 34 | extern void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ); 35 | 36 | void _cstartup( unsigned int r0, unsigned int r1, unsigned int r2 ) 37 | { 38 | /*__bss_start__ and __bss_end__ are defined in the linker script */ 39 | int* bss = &__bss_start__; 40 | int* bss_end = &__bss_end__; 41 | 42 | /* 43 | Clear the BSS section 44 | 45 | See http://en.wikipedia.org/wiki/.bss for further information on the 46 | BSS section 47 | 48 | See https://sourceware.org/newlib/libc.html#Stubs for further 49 | information on the c-library stubs 50 | */ 51 | while( bss < bss_end ) 52 | *bss++ = 0; 53 | 54 | /* We should never return from main ... */ 55 | kernel_main( r0, r1, r2 ); 56 | 57 | /* ... but if we do, safely trap here */ 58 | while(1) 59 | { 60 | /* EMPTY! */ 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /part-5/armc-014/rpi-aux.c: -------------------------------------------------------------------------------- 1 | 2 | #include "rpi-aux.h" 3 | #include "rpi-base.h" 4 | #include "rpi-gpio.h" 5 | 6 | static aux_t* auxillary = (aux_t*)AUX_BASE; 7 | 8 | 9 | aux_t* RPI_GetAux( void ) 10 | { 11 | return auxillary; 12 | } 13 | 14 | /* Define the system clock frequency in MHz for the baud rate calculation. 15 | This is clearly defined on the BCM2835 datasheet errata page: 16 | http://elinux.org/BCM2835_datasheet_errata */ 17 | #define SYS_FREQ 250000000 18 | 19 | void RPI_AuxMiniUartInit( int baud, int bits ) 20 | { 21 | volatile int i; 22 | 23 | /* As this is a mini uart the configuration is complete! Now just 24 | enable the uart. Note from the documentation in section 2.1.1 of 25 | the ARM peripherals manual: 26 | 27 | If the enable bits are clear you will have no access to a 28 | peripheral. You can not even read or write the registers */ 29 | auxillary->ENABLES = AUX_ENA_MINIUART; 30 | 31 | /* Disable interrupts for now */ 32 | /* auxillary->IRQ &= ~AUX_IRQ_MU; */ 33 | 34 | auxillary->MU_IER = 0; 35 | 36 | /* Disable flow control,enable transmitter and receiver! */ 37 | auxillary->MU_CNTL = 0; 38 | 39 | /* Decide between seven or eight-bit mode */ 40 | if( bits == 8 ) 41 | auxillary->MU_LCR = AUX_MULCR_8BIT_MODE; 42 | else 43 | auxillary->MU_LCR = 0; 44 | 45 | auxillary->MU_MCR = 0; 46 | 47 | /* Disable all interrupts from MU and clear the fifos */ 48 | auxillary->MU_IER = 0; 49 | 50 | auxillary->MU_IIR = 0xC6; 51 | 52 | /* Transposed calculation from Section 2.2.1 of the ARM peripherals 53 | manual */ 54 | auxillary->MU_BAUD = ( SYS_FREQ / ( 8 * baud ) ) - 1; 55 | 56 | /* Setup GPIO 14 and 15 as alternative function 5 which is 57 | UART 1 TXD/RXD. These need to be set before enabling the UART */ 58 | RPI_SetGpioPinFunction( RPI_GPIO14, FS_ALT5 ); 59 | RPI_SetGpioPinFunction( RPI_GPIO15, FS_ALT5 ); 60 | 61 | RPI_GetGpio()->GPPUD = 0; 62 | for( i=0; i<150; i++ ) { } 63 | RPI_GetGpio()->GPPUDCLK0 = ( 1 << 14 ); 64 | for( i=0; i<150; i++ ) { } 65 | RPI_GetGpio()->GPPUDCLK0 = 0; 66 | 67 | /* Disable flow control,enable transmitter and receiver! */ 68 | auxillary->MU_CNTL = AUX_MUCNTL_TX_ENABLE; 69 | } 70 | 71 | 72 | void RPI_AuxMiniUartWrite( char c ) 73 | { 74 | /* Wait until the UART has an empty space in the FIFO */ 75 | while( ( auxillary->MU_LSR & AUX_MULSR_TX_EMPTY ) == 0 ) { } 76 | 77 | /* Write the character to the FIFO for transmission */ 78 | auxillary->MU_IO = c; 79 | } 80 | -------------------------------------------------------------------------------- /part-5/armc-015/rpi-aux.c: -------------------------------------------------------------------------------- 1 | 2 | #include "rpi-aux.h" 3 | #include "rpi-base.h" 4 | #include "rpi-gpio.h" 5 | 6 | static aux_t* auxillary = (aux_t*)AUX_BASE; 7 | 8 | 9 | aux_t* RPI_GetAux( void ) 10 | { 11 | return auxillary; 12 | } 13 | 14 | /* Define the system clock frequency in MHz for the baud rate calculation. 15 | This is clearly defined on the BCM2835 datasheet errata page: 16 | http://elinux.org/BCM2835_datasheet_errata */ 17 | #define SYS_FREQ 250000000 18 | 19 | void RPI_AuxMiniUartInit( int baud, int bits ) 20 | { 21 | volatile int i; 22 | 23 | /* As this is a mini uart the configuration is complete! Now just 24 | enable the uart. Note from the documentation in section 2.1.1 of 25 | the ARM peripherals manual: 26 | 27 | If the enable bits are clear you will have no access to a 28 | peripheral. You can not even read or write the registers */ 29 | auxillary->ENABLES = AUX_ENA_MINIUART; 30 | 31 | /* Disable interrupts for now */ 32 | /* auxillary->IRQ &= ~AUX_IRQ_MU; */ 33 | 34 | auxillary->MU_IER = 0; 35 | 36 | /* Disable flow control,enable transmitter and receiver! */ 37 | auxillary->MU_CNTL = 0; 38 | 39 | /* Decide between seven or eight-bit mode */ 40 | if( bits == 8 ) 41 | auxillary->MU_LCR = AUX_MULCR_8BIT_MODE; 42 | else 43 | auxillary->MU_LCR = 0; 44 | 45 | auxillary->MU_MCR = 0; 46 | 47 | /* Disable all interrupts from MU and clear the fifos */ 48 | auxillary->MU_IER = 0; 49 | 50 | auxillary->MU_IIR = 0xC6; 51 | 52 | /* Transposed calculation from Section 2.2.1 of the ARM peripherals 53 | manual */ 54 | auxillary->MU_BAUD = ( SYS_FREQ / ( 8 * baud ) ) - 1; 55 | 56 | /* Setup GPIO 14 and 15 as alternative function 5 which is 57 | UART 1 TXD/RXD. These need to be set before enabling the UART */ 58 | RPI_SetGpioPinFunction( RPI_GPIO14, FS_ALT5 ); 59 | RPI_SetGpioPinFunction( RPI_GPIO15, FS_ALT5 ); 60 | 61 | RPI_GetGpio()->GPPUD = 0; 62 | for( i=0; i<150; i++ ) { } 63 | RPI_GetGpio()->GPPUDCLK0 = ( 1 << 14 ); 64 | for( i=0; i<150; i++ ) { } 65 | RPI_GetGpio()->GPPUDCLK0 = 0; 66 | 67 | /* Disable flow control,enable transmitter and receiver! */ 68 | auxillary->MU_CNTL = AUX_MUCNTL_TX_ENABLE; 69 | } 70 | 71 | 72 | void RPI_AuxMiniUartWrite( char c ) 73 | { 74 | /* Wait until the UART has an empty space in the FIFO */ 75 | while( ( auxillary->MU_LSR & AUX_MULSR_TX_EMPTY ) == 0 ) { } 76 | 77 | /* Write the character to the FIFO for transmission */ 78 | auxillary->MU_IO = c; 79 | } 80 | -------------------------------------------------------------------------------- /part-5/armc-016/rpi-aux.c: -------------------------------------------------------------------------------- 1 | 2 | #include "rpi-aux.h" 3 | #include "rpi-base.h" 4 | #include "rpi-gpio.h" 5 | 6 | static aux_t* auxillary = (aux_t*)AUX_BASE; 7 | 8 | 9 | aux_t* RPI_GetAux( void ) 10 | { 11 | return auxillary; 12 | } 13 | 14 | /* Define the system clock frequency in MHz for the baud rate calculation. 15 | This is clearly defined on the BCM2835 datasheet errata page: 16 | http://elinux.org/BCM2835_datasheet_errata */ 17 | #define SYS_FREQ 250000000 18 | 19 | void RPI_AuxMiniUartInit( int baud, int bits ) 20 | { 21 | volatile int i; 22 | 23 | /* As this is a mini uart the configuration is complete! Now just 24 | enable the uart. Note from the documentation in section 2.1.1 of 25 | the ARM peripherals manual: 26 | 27 | If the enable bits are clear you will have no access to a 28 | peripheral. You can not even read or write the registers */ 29 | auxillary->ENABLES = AUX_ENA_MINIUART; 30 | 31 | /* Disable interrupts for now */ 32 | /* auxillary->IRQ &= ~AUX_IRQ_MU; */ 33 | 34 | auxillary->MU_IER = 0; 35 | 36 | /* Disable flow control,enable transmitter and receiver! */ 37 | auxillary->MU_CNTL = 0; 38 | 39 | /* Decide between seven or eight-bit mode */ 40 | if( bits == 8 ) 41 | auxillary->MU_LCR = AUX_MULCR_8BIT_MODE; 42 | else 43 | auxillary->MU_LCR = 0; 44 | 45 | auxillary->MU_MCR = 0; 46 | 47 | /* Disable all interrupts from MU and clear the fifos */ 48 | auxillary->MU_IER = 0; 49 | 50 | auxillary->MU_IIR = 0xC6; 51 | 52 | /* Transposed calculation from Section 2.2.1 of the ARM peripherals 53 | manual */ 54 | auxillary->MU_BAUD = ( SYS_FREQ / ( 8 * baud ) ) - 1; 55 | 56 | /* Setup GPIO 14 and 15 as alternative function 5 which is 57 | UART 1 TXD/RXD. These need to be set before enabling the UART */ 58 | RPI_SetGpioPinFunction( RPI_GPIO14, FS_ALT5 ); 59 | RPI_SetGpioPinFunction( RPI_GPIO15, FS_ALT5 ); 60 | 61 | RPI_GetGpio()->GPPUD = 0; 62 | for( i=0; i<150; i++ ) { } 63 | RPI_GetGpio()->GPPUDCLK0 = ( 1 << 14 ); 64 | for( i=0; i<150; i++ ) { } 65 | RPI_GetGpio()->GPPUDCLK0 = 0; 66 | 67 | /* Disable flow control,enable transmitter and receiver! */ 68 | auxillary->MU_CNTL = AUX_MUCNTL_TX_ENABLE; 69 | } 70 | 71 | 72 | void RPI_AuxMiniUartWrite( char c ) 73 | { 74 | /* Wait until the UART has an empty space in the FIFO */ 75 | while( ( auxillary->MU_LSR & AUX_MULSR_TX_EMPTY ) == 0 ) { } 76 | 77 | /* Write the character to the FIFO for transmission */ 78 | auxillary->MU_IO = c; 79 | } 80 | -------------------------------------------------------------------------------- /part-3/arm011/armc-011.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | /* 32 | C-Library stubs introduced for newlib 33 | */ 34 | 35 | #include 36 | #include 37 | 38 | #include "rpi-gpio.h" 39 | #include "rpi-systimer.h" 40 | 41 | /** GPIO Register set */ 42 | volatile unsigned int* gpio = (unsigned int*)GPIO_BASE; 43 | 44 | /** Main function - we'll never return from here */ 45 | void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ) 46 | { 47 | int loop; 48 | 49 | /* Write 1 to the GPIO init nibble in the Function Select GPIO peripheral register to enable 50 | the LED pin an output */ 51 | gpio[LED_GPFSEL] |= ( 1 << LED_GPFBIT ); 52 | 53 | /* Never exit as there is no OS to exit to! */ 54 | while(1) 55 | { 56 | 57 | /* Set the GPIO16 output high ( Turn OK LED off )*/ 58 | LED_OFF(); 59 | 60 | /* Wait half a second */ 61 | RPI_WaitMicroSeconds( 500000 ); 62 | 63 | /* Set the GPIO16 output low ( Turn OK LED on )*/ 64 | LED_ON(); 65 | 66 | /* Wait half a second */ 67 | RPI_WaitMicroSeconds( 500000 ); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /part-2/armc-08/armc-08.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #include "rpi-gpio.h" 32 | 33 | /** GPIO Register set */ 34 | volatile unsigned int* gpio = (unsigned int*)GPIO_BASE; 35 | 36 | /** Simple loop variable */ 37 | volatile unsigned int tim; 38 | 39 | /** Main function - we'll never return from here */ 40 | void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ) 41 | { 42 | /* Write 1 to the GPIO16 init nibble in the Function Select 1 GPIO 43 | peripheral register to enable GPIO16 as an output */ 44 | gpio[LED_GPFSEL] |= (1 << LED_GPFBIT); 45 | 46 | /* Never exit as there is no OS to exit to! */ 47 | while(1) 48 | { 49 | for(tim = 0; tim < 500000; tim++) 50 | ; 51 | 52 | /* Set the LED GPIO pin low ( Turn OK LED on for original Pi, and off 53 | for plus models )*/ 54 | gpio[LED_GPCLR] = (1 << LED_GPIO_BIT); 55 | 56 | for(tim = 0; tim < 500000; tim++) 57 | ; 58 | 59 | /* Set the LED GPIO pin high ( Turn OK LED off for original Pi, and on 60 | for plus models )*/ 61 | gpio[LED_GPSET] = (1 << LED_GPIO_BIT); 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /part-2/armc-04/armc-04.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013-2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #include "rpi-gpio.h" 32 | 33 | /** GPIO Register set */ 34 | volatile unsigned int* gpio = (unsigned int*)GPIO_BASE; 35 | 36 | /** Simple loop variable */ 37 | volatile unsigned int tim; 38 | 39 | /** Main function - we'll never return from here */ 40 | int main(void) __attribute__((naked)); 41 | int main(void) 42 | { 43 | /* Write 1 to the GPIO16 init nibble in the Function Select 1 GPIO 44 | peripheral register to enable GPIO16 as an output */ 45 | gpio[LED_GPFSEL] |= (1 << LED_GPFBIT); 46 | 47 | /* Never exit as there is no OS to exit to! */ 48 | while(1) 49 | { 50 | for(tim = 0; tim < 500000; tim++) 51 | ; 52 | 53 | /* Set the LED GPIO pin low ( Turn OK LED on for original Pi, and off 54 | for plus models )*/ 55 | gpio[LED_GPCLR] = (1 << LED_GPIO_BIT); 56 | 57 | for(tim = 0; tim < 500000; tim++) 58 | ; 59 | 60 | /* Set the LED GPIO pin high ( Turn OK LED off for original Pi, and on 61 | for plus models )*/ 62 | gpio[LED_GPSET] = (1 << LED_GPIO_BIT); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /part-2/armc-07/armc-07.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013-2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #include "rpi-gpio.h" 32 | 33 | /** GPIO Register set */ 34 | volatile unsigned int* gpio = (unsigned int*)GPIO_BASE; 35 | 36 | /** Simple loop variable */ 37 | volatile unsigned int tim; 38 | 39 | /** Main function - we'll never return from here */ 40 | int main(void) __attribute__((naked)); 41 | int main(void) 42 | { 43 | /* Write 1 to the GPIO16 init nibble in the Function Select 1 GPIO 44 | peripheral register to enable GPIO16 as an output */ 45 | gpio[LED_GPFSEL] |= (1 << LED_GPFBIT); 46 | 47 | /* Never exit as there is no OS to exit to! */ 48 | while(1) 49 | { 50 | for(tim = 0; tim < 500000; tim++) 51 | ; 52 | 53 | /* Set the LED GPIO pin low ( Turn OK LED on for original Pi, and off 54 | for plus models )*/ 55 | gpio[LED_GPCLR] = (1 << LED_GPIO_BIT); 56 | 57 | for(tim = 0; tim < 500000; tim++) 58 | ; 59 | 60 | /* Set the LED GPIO pin high ( Turn OK LED off for original Pi, and on 61 | for plus models )*/ 62 | gpio[LED_GPSET] = (1 << LED_GPIO_BIT); 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /part-3/arm010/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2013-2015, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # CMake build environment for the Valvers Raspberry-Pi bare metal tutorials 29 | 30 | # CMake 2.8.10 Documentation: http://www.cmake.org/cmake/help/v2.8.10/cmake.html 31 | 32 | cmake_minimum_required( VERSION 2.8 ) 33 | 34 | # Mark the language as C so that CMake doesn't try to test the C++ 35 | # cross-compiler's ability to compile a simple program because that will fail 36 | project( armc-010-tutorial C ASM ) 37 | 38 | # We had to adjust the CMAKE_C_FLAGS variable in the toolchain file to make sure 39 | # the compiler would work with CMake's simple program compilation test. So unset 40 | # it explicitly before re-setting it correctly for our system 41 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0" ) 42 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g" ) 43 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostartfiles" ) 44 | 45 | add_executable( armc-010 46 | armc-010.c 47 | armc-010-cstartup.c 48 | armc-010-cstubs.c 49 | armc-010-start.S ) 50 | 51 | add_custom_command( 52 | TARGET armc-010 POST_BUILD 53 | COMMAND ${CMAKE_OBJCOPY} ./armc-010${CMAKE_EXECUTABLE_SUFFIX} -O binary ./kernel.img 54 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 55 | COMMENT "Convert the ELF output file to a binary image" ) 56 | -------------------------------------------------------------------------------- /part-5/armc-014/rpi-gpio.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-gpio.h" 4 | 5 | static rpi_gpio_t* rpiGpio = (rpi_gpio_t*)RPI_GPIO_BASE; 6 | 7 | 8 | rpi_gpio_t* RPI_GetGpio(void) 9 | { 10 | return rpiGpio; 11 | } 12 | 13 | 14 | void RPI_SetGpioPinFunction( rpi_gpio_pin_t gpio, rpi_gpio_alt_function_t func ) 15 | { 16 | rpi_reg_rw_t* fsel_reg = &((rpi_reg_rw_t*)rpiGpio)[ gpio / 10 ]; 17 | rpi_reg_rw_t fsel_copy = *fsel_reg; 18 | fsel_copy &= ~( FS_MASK << ( ( gpio % 10 ) * 3 ) ); 19 | fsel_copy |= (func << ( ( gpio % 10 ) * 3 ) ); 20 | *fsel_reg = fsel_copy; 21 | } 22 | 23 | 24 | void RPI_SetGpioOutput( rpi_gpio_pin_t gpio ) 25 | { 26 | RPI_SetGpioPinFunction( gpio, FS_OUTPUT ); 27 | } 28 | 29 | 30 | void RPI_SetGpioInput( rpi_gpio_pin_t gpio ) 31 | { 32 | RPI_SetGpioPinFunction( gpio, FS_INPUT ); 33 | } 34 | 35 | 36 | rpi_gpio_value_t RPI_GetGpioValue( rpi_gpio_pin_t gpio ) 37 | { 38 | rpi_gpio_value_t result = RPI_IO_UNKNOWN; 39 | 40 | switch( gpio / 32 ) 41 | { 42 | case 0: 43 | result = rpiGpio->GPLEV0 & ( 1 << gpio ); 44 | break; 45 | 46 | case 1: 47 | result = rpiGpio->GPLEV1 & ( 1 << ( gpio - 32 ) ); 48 | break; 49 | 50 | default: 51 | break; 52 | } 53 | 54 | if( result != RPI_IO_UNKNOWN ) 55 | { 56 | if( result ) 57 | result = RPI_IO_HI; 58 | } 59 | 60 | return result; 61 | } 62 | 63 | 64 | void RPI_ToggleGpio( rpi_gpio_pin_t gpio ) 65 | { 66 | if( RPI_GetGpioValue( gpio ) ) 67 | RPI_SetGpioLo( gpio ); 68 | else 69 | RPI_SetGpioHi( gpio ); 70 | } 71 | 72 | 73 | void RPI_SetGpioHi( rpi_gpio_pin_t gpio ) 74 | { 75 | switch( gpio / 32 ) 76 | { 77 | case 0: 78 | rpiGpio->GPSET0 = ( 1 << gpio ); 79 | break; 80 | 81 | case 1: 82 | rpiGpio->GPSET1 = ( 1 << ( gpio - 32 ) ); 83 | break; 84 | 85 | default: 86 | break; 87 | } 88 | } 89 | 90 | 91 | void RPI_SetGpioLo( rpi_gpio_pin_t gpio ) 92 | { 93 | switch( gpio / 32 ) 94 | { 95 | case 0: 96 | rpiGpio->GPCLR0 = ( 1 << gpio ); 97 | break; 98 | 99 | case 1: 100 | rpiGpio->GPCLR1 = ( 1 << ( gpio - 32 ) ); 101 | break; 102 | 103 | default: 104 | break; 105 | } 106 | } 107 | 108 | 109 | void RPI_SetGpioValue( rpi_gpio_pin_t gpio, rpi_gpio_value_t value ) 110 | { 111 | if( ( value == RPI_IO_LO ) || ( value == RPI_IO_OFF ) ) 112 | RPI_SetGpioLo( gpio ); 113 | else if( ( value == RPI_IO_HI ) || ( value == RPI_IO_ON ) ) 114 | RPI_SetGpioHi( gpio ); 115 | } 116 | -------------------------------------------------------------------------------- /part-5/armc-015/rpi-gpio.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-gpio.h" 4 | 5 | static rpi_gpio_t* rpiGpio = (rpi_gpio_t*)RPI_GPIO_BASE; 6 | 7 | 8 | rpi_gpio_t* RPI_GetGpio(void) 9 | { 10 | return rpiGpio; 11 | } 12 | 13 | 14 | void RPI_SetGpioPinFunction( rpi_gpio_pin_t gpio, rpi_gpio_alt_function_t func ) 15 | { 16 | rpi_reg_rw_t* fsel_reg = &((rpi_reg_rw_t*)rpiGpio)[ gpio / 10 ]; 17 | rpi_reg_rw_t fsel_copy = *fsel_reg; 18 | fsel_copy &= ~( FS_MASK << ( ( gpio % 10 ) * 3 ) ); 19 | fsel_copy |= (func << ( ( gpio % 10 ) * 3 ) ); 20 | *fsel_reg = fsel_copy; 21 | } 22 | 23 | 24 | void RPI_SetGpioOutput( rpi_gpio_pin_t gpio ) 25 | { 26 | RPI_SetGpioPinFunction( gpio, FS_OUTPUT ); 27 | } 28 | 29 | 30 | void RPI_SetGpioInput( rpi_gpio_pin_t gpio ) 31 | { 32 | RPI_SetGpioPinFunction( gpio, FS_INPUT ); 33 | } 34 | 35 | 36 | rpi_gpio_value_t RPI_GetGpioValue( rpi_gpio_pin_t gpio ) 37 | { 38 | rpi_gpio_value_t result = RPI_IO_UNKNOWN; 39 | 40 | switch( gpio / 32 ) 41 | { 42 | case 0: 43 | result = rpiGpio->GPLEV0 & ( 1 << gpio ); 44 | break; 45 | 46 | case 1: 47 | result = rpiGpio->GPLEV1 & ( 1 << ( gpio - 32 ) ); 48 | break; 49 | 50 | default: 51 | break; 52 | } 53 | 54 | if( result != RPI_IO_UNKNOWN ) 55 | { 56 | if( result ) 57 | result = RPI_IO_HI; 58 | } 59 | 60 | return result; 61 | } 62 | 63 | 64 | void RPI_ToggleGpio( rpi_gpio_pin_t gpio ) 65 | { 66 | if( RPI_GetGpioValue( gpio ) ) 67 | RPI_SetGpioLo( gpio ); 68 | else 69 | RPI_SetGpioHi( gpio ); 70 | } 71 | 72 | 73 | void RPI_SetGpioHi( rpi_gpio_pin_t gpio ) 74 | { 75 | switch( gpio / 32 ) 76 | { 77 | case 0: 78 | rpiGpio->GPSET0 = ( 1 << gpio ); 79 | break; 80 | 81 | case 1: 82 | rpiGpio->GPSET1 = ( 1 << ( gpio - 32 ) ); 83 | break; 84 | 85 | default: 86 | break; 87 | } 88 | } 89 | 90 | 91 | void RPI_SetGpioLo( rpi_gpio_pin_t gpio ) 92 | { 93 | switch( gpio / 32 ) 94 | { 95 | case 0: 96 | rpiGpio->GPCLR0 = ( 1 << gpio ); 97 | break; 98 | 99 | case 1: 100 | rpiGpio->GPCLR1 = ( 1 << ( gpio - 32 ) ); 101 | break; 102 | 103 | default: 104 | break; 105 | } 106 | } 107 | 108 | 109 | void RPI_SetGpioValue( rpi_gpio_pin_t gpio, rpi_gpio_value_t value ) 110 | { 111 | if( ( value == RPI_IO_LO ) || ( value == RPI_IO_OFF ) ) 112 | RPI_SetGpioLo( gpio ); 113 | else if( ( value == RPI_IO_HI ) || ( value == RPI_IO_ON ) ) 114 | RPI_SetGpioHi( gpio ); 115 | } 116 | -------------------------------------------------------------------------------- /part-5/armc-016/rpi-gpio.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "rpi-gpio.h" 4 | 5 | static rpi_gpio_t* rpiGpio = (rpi_gpio_t*)RPI_GPIO_BASE; 6 | 7 | 8 | rpi_gpio_t* RPI_GetGpio(void) 9 | { 10 | return rpiGpio; 11 | } 12 | 13 | 14 | void RPI_SetGpioPinFunction( rpi_gpio_pin_t gpio, rpi_gpio_alt_function_t func ) 15 | { 16 | rpi_reg_rw_t* fsel_reg = &((rpi_reg_rw_t*)rpiGpio)[ gpio / 10 ]; 17 | rpi_reg_rw_t fsel_copy = *fsel_reg; 18 | fsel_copy &= ~( FS_MASK << ( ( gpio % 10 ) * 3 ) ); 19 | fsel_copy |= (func << ( ( gpio % 10 ) * 3 ) ); 20 | *fsel_reg = fsel_copy; 21 | } 22 | 23 | 24 | void RPI_SetGpioOutput( rpi_gpio_pin_t gpio ) 25 | { 26 | RPI_SetGpioPinFunction( gpio, FS_OUTPUT ); 27 | } 28 | 29 | 30 | void RPI_SetGpioInput( rpi_gpio_pin_t gpio ) 31 | { 32 | RPI_SetGpioPinFunction( gpio, FS_INPUT ); 33 | } 34 | 35 | 36 | rpi_gpio_value_t RPI_GetGpioValue( rpi_gpio_pin_t gpio ) 37 | { 38 | rpi_gpio_value_t result = RPI_IO_UNKNOWN; 39 | 40 | switch( gpio / 32 ) 41 | { 42 | case 0: 43 | result = rpiGpio->GPLEV0 & ( 1 << gpio ); 44 | break; 45 | 46 | case 1: 47 | result = rpiGpio->GPLEV1 & ( 1 << ( gpio - 32 ) ); 48 | break; 49 | 50 | default: 51 | break; 52 | } 53 | 54 | if( result != RPI_IO_UNKNOWN ) 55 | { 56 | if( result ) 57 | result = RPI_IO_HI; 58 | } 59 | 60 | return result; 61 | } 62 | 63 | 64 | void RPI_ToggleGpio( rpi_gpio_pin_t gpio ) 65 | { 66 | if( RPI_GetGpioValue( gpio ) ) 67 | RPI_SetGpioLo( gpio ); 68 | else 69 | RPI_SetGpioHi( gpio ); 70 | } 71 | 72 | 73 | void RPI_SetGpioHi( rpi_gpio_pin_t gpio ) 74 | { 75 | switch( gpio / 32 ) 76 | { 77 | case 0: 78 | rpiGpio->GPSET0 = ( 1 << gpio ); 79 | break; 80 | 81 | case 1: 82 | rpiGpio->GPSET1 = ( 1 << ( gpio - 32 ) ); 83 | break; 84 | 85 | default: 86 | break; 87 | } 88 | } 89 | 90 | 91 | void RPI_SetGpioLo( rpi_gpio_pin_t gpio ) 92 | { 93 | switch( gpio / 32 ) 94 | { 95 | case 0: 96 | rpiGpio->GPCLR0 = ( 1 << gpio ); 97 | break; 98 | 99 | case 1: 100 | rpiGpio->GPCLR1 = ( 1 << ( gpio - 32 ) ); 101 | break; 102 | 103 | default: 104 | break; 105 | } 106 | } 107 | 108 | 109 | void RPI_SetGpioValue( rpi_gpio_pin_t gpio, rpi_gpio_value_t value ) 110 | { 111 | if( ( value == RPI_IO_LO ) || ( value == RPI_IO_OFF ) ) 112 | RPI_SetGpioLo( gpio ); 113 | else if( ( value == RPI_IO_HI ) || ( value == RPI_IO_ON ) ) 114 | RPI_SetGpioHi( gpio ); 115 | } 116 | -------------------------------------------------------------------------------- /part-2/armc-09/armc-09.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | /* 32 | C-Library stubs introduced for newlib 33 | */ 34 | 35 | #include 36 | #include 37 | 38 | #include "rpi-gpio.h" 39 | 40 | /** GPIO Register set */ 41 | volatile unsigned int* gpio = (unsigned int*)GPIO_BASE; 42 | 43 | /** Main function - we'll never return from here */ 44 | void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ) 45 | { 46 | int loop; 47 | unsigned int* counters; 48 | 49 | /* Set the LED GPIO pin to an output to drive the LED */ 50 | gpio[LED_GPFSEL] |= ( 1 << LED_GPFBIT ); 51 | 52 | /* Allocate a block of memory for counters */ 53 | counters = malloc( 1024 * sizeof( unsigned int ) ); 54 | 55 | /* Failed to allocate memory! */ 56 | if( counters == NULL ) 57 | while(1) { LED_ON();/* Trap here */ } 58 | 59 | for( loop=0; loop<1024; loop++ ) 60 | counters[loop] = 0; 61 | 62 | /* Never exit as there is no OS to exit to! */ 63 | while(1) 64 | { 65 | /* Light the LED */ 66 | LED_ON(); 67 | 68 | for(counters[0] = 0; counters[0] < 500000; counters[0]++) 69 | ; 70 | 71 | /* Set the GPIO16 output low ( Turn OK LED on )*/ 72 | LED_OFF(); 73 | 74 | for(counters[1] = 0; counters[1] < 500000; counters[1]++) 75 | ; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /part-4/armc-013/armc-013.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | /* 32 | Interrupts example, show how to use the interrupt controller and to load 33 | the vector table at runtime. 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #include "rpi-gpio.h" 40 | #include "rpi-armtimer.h" 41 | #include "rpi-systimer.h" 42 | #include "rpi-interrupts.h" 43 | 44 | /** Main function - we'll never return from here */ 45 | void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ) 46 | { 47 | /* Write 1 to the LED init nibble in the Function Select GPIO 48 | peripheral register to enable LED pin as an output */ 49 | RPI_GetGpio()->LED_GPFSEL |= LED_GPFBIT; 50 | 51 | /* Enable the timer interrupt IRQ */ 52 | RPI_GetIrqController()->Enable_Basic_IRQs = RPI_BASIC_ARM_TIMER_IRQ; 53 | 54 | /* Setup the system timer interrupt */ 55 | /* Timer frequency = Clk/256 * 0x400 */ 56 | RPI_GetArmTimer()->Load = 0x400; 57 | 58 | /* Setup the ARM Timer */ 59 | RPI_GetArmTimer()->Control = 60 | RPI_ARMTIMER_CTRL_23BIT | 61 | RPI_ARMTIMER_CTRL_ENABLE | 62 | RPI_ARMTIMER_CTRL_INT_ENABLE | 63 | RPI_ARMTIMER_CTRL_PRESCALE_256; 64 | 65 | /* Enable interrupts! */ 66 | _enable_interrupts(); 67 | 68 | /* Never exit as there is no OS to exit to! */ 69 | while(1) 70 | { 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /part-2/armc-05/armc-05.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013-2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #include "rpi-gpio.h" 32 | 33 | /** GPIO Register set */ 34 | volatile unsigned int* gpio = (unsigned int*)GPIO_BASE; 35 | 36 | /** Simple loop variable */ 37 | volatile unsigned int tim; 38 | 39 | /** Main function - we'll never return from here */ 40 | int main(void) __attribute__((naked)); 41 | int main(void) 42 | { 43 | /* Write 1 to the GPIO16 init nibble in the Function Select 1 GPIO 44 | peripheral register to enable GPIO16 as an output */ 45 | gpio[LED_GPFSEL] |= (1 << LED_GPFBIT); 46 | 47 | /* Never exit as there is no OS to exit to! */ 48 | while(1) 49 | { 50 | for(tim = 0; tim < 500000; tim++) 51 | ; 52 | 53 | /* Set the LED GPIO pin low ( Turn OK LED on for original Pi, and off 54 | for plus models )*/ 55 | gpio[LED_GPCLR] = (1 << LED_GPIO_BIT); 56 | 57 | for(tim = 0; tim < 500000; tim++) 58 | ; 59 | 60 | /* Set the LED GPIO pin high ( Turn OK LED off for original Pi, and on 61 | for plus models )*/ 62 | gpio[LED_GPSET] = (1 << LED_GPIO_BIT); 63 | 64 | for(tim = 0; tim < 500000; tim++) 65 | ; 66 | 67 | /* Set the LED GPIO pin low ( Turn OK LED on for original Pi, and off 68 | for plus models )*/ 69 | gpio[LED_GPCLR] = (1 << LED_GPIO_BIT); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /part-2/armc-06/armc-06.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013-2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #include "rpi-gpio.h" 32 | 33 | /** GPIO Register set */ 34 | volatile unsigned int* gpio = (unsigned int*)GPIO_BASE; 35 | 36 | /** Simple loop variable */ 37 | volatile unsigned int tim; 38 | 39 | /** Main function - we'll never return from here */ 40 | int main(void) __attribute__((naked)); 41 | int main(void) 42 | { 43 | /* Write 1 to the GPIO16 init nibble in the Function Select 1 GPIO 44 | peripheral register to enable GPIO16 as an output */ 45 | gpio[LED_GPFSEL] |= (1 << LED_GPFBIT); 46 | 47 | /* Never exit as there is no OS to exit to! */ 48 | while(1) 49 | { 50 | for(tim = 0; tim < 500000; tim++) 51 | ; 52 | 53 | /* Set the LED GPIO pin low ( Turn OK LED on for original Pi, and off 54 | for plus models )*/ 55 | gpio[LED_GPCLR] = (1 << LED_GPIO_BIT); 56 | 57 | for(tim = 0; tim < 500000; tim++) 58 | ; 59 | 60 | /* Set the LED GPIO pin high ( Turn OK LED off for original Pi, and on 61 | for plus models )*/ 62 | gpio[LED_GPSET] = (1 << LED_GPIO_BIT); 63 | 64 | for(tim = 0; tim < 500000; tim++) 65 | ; 66 | 67 | /* Set the LED GPIO pin low ( Turn OK LED on for original Pi, and off 68 | for plus models )*/ 69 | gpio[LED_GPCLR] = (1 << LED_GPIO_BIT); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /part-3/arm011/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2013-2015, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # CMake build environment for the Valvers Raspberry-Pi bare metal tutorials 29 | 30 | # CMake 2.8.10 Documentation: http://www.cmake.org/cmake/help/v2.8.10/cmake.html 31 | 32 | cmake_minimum_required( VERSION 2.8 ) 33 | 34 | # Set the tutorial number so it's easier to re-use the CMakeLists.txt 35 | set( TUT 011 ) 36 | 37 | # Mark the language as C so that CMake doesn't try to test the C++ 38 | # cross-compiler's ability to compile a simple program because that will fail 39 | project( armc-${TUT}-tutorial C ASM ) 40 | 41 | # We had to adjust the CMAKE_C_FLAGS variable in the toolchain file to make sure 42 | # the compiler would work with CMake's simple program compilation test. So unset 43 | # it explicitly before re-setting it correctly for our system 44 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0" ) 45 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g" ) 46 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostartfiles" ) 47 | 48 | # Set the linker flags so that we use our "custom" linker script 49 | set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${PROJECT_SOURCE_DIR}/rpi.x" ) 50 | 51 | add_executable( armc-${TUT} 52 | armc-${TUT}.c 53 | armc-${TUT}-cstartup.c 54 | armc-${TUT}-cstubs.c 55 | armc-${TUT}-start.S 56 | rpi-systimer.c ) 57 | 58 | add_custom_command( 59 | TARGET armc-${TUT} POST_BUILD 60 | COMMAND ${CMAKE_OBJCOPY} ./armc-${TUT} -O binary ./kernel.img 61 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 62 | COMMENT "Convert the ELF output file to a binary image" ) 63 | -------------------------------------------------------------------------------- /part-3/arm012/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2013-2015, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # CMake build environment for the Valvers Raspberry-Pi bare metal tutorials 29 | 30 | # CMake 2.8.10 Documentation: http://www.cmake.org/cmake/help/v2.8.10/cmake.html 31 | 32 | cmake_minimum_required( VERSION 2.8 ) 33 | 34 | # Set the tutorial number so it's easier to re-use the CMakeLists.txt 35 | set( TUT 012 ) 36 | 37 | # Mark the language as C so that CMake doesn't try to test the C++ 38 | # cross-compiler's ability to compile a simple program because that will fail 39 | project( armc-${TUT}-tutorial C ASM ) 40 | 41 | # We had to adjust the CMAKE_C_FLAGS variable in the toolchain file to make sure 42 | # the compiler would work with CMake's simple program compilation test. So unset 43 | # it explicitly before re-setting it correctly for our system 44 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0" ) 45 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g" ) 46 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostartfiles" ) 47 | 48 | # Set the linker flags so that we use our "custom" linker script 49 | set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${PROJECT_SOURCE_DIR}/rpi.x" ) 50 | 51 | add_executable( armc-${TUT} 52 | armc-${TUT}.c 53 | armc-${TUT}-cstartup.c 54 | armc-${TUT}-cstubs.c 55 | armc-${TUT}-start.S 56 | rpi-systimer.c ) 57 | 58 | add_custom_command( 59 | TARGET armc-${TUT} POST_BUILD 60 | COMMAND ${CMAKE_OBJCOPY} ./armc-${TUT} -O binary ./kernel.img 61 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 62 | COMMENT "Convert the ELF output file to a binary image" ) 63 | -------------------------------------------------------------------------------- /part-3/arm010/armc-010.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | /* 32 | C-Library stubs introduced for newlib 33 | */ 34 | 35 | #include 36 | #include 37 | 38 | #include "rpi-gpio.h" 39 | 40 | /** GPIO Register set */ 41 | volatile unsigned int* gpio = (unsigned int*)GPIO_BASE; 42 | 43 | /** Main function - we'll never return from here */ 44 | void kernel_main( unsigned int r0, unsigned int r1, unsigned int atags ) 45 | { 46 | int loop; 47 | /* Allocate a block of memory for counters */ 48 | unsigned int* counters; 49 | 50 | counters = malloc( 1024 * sizeof( unsigned int ) ); 51 | 52 | /* Failed to allocate memory! */ 53 | if( counters == NULL ) 54 | { 55 | while(1) 56 | { 57 | /* Trap here */ 58 | } 59 | } 60 | 61 | for( loop=0; loop<1024; loop++ ) 62 | counters[loop] = 0; 63 | 64 | /* Write 1 to the GPIO16 init nibble in the Function Select 1 GPIO 65 | peripheral register to enable GPIO16 as an output */ 66 | gpio[LED_GPFSEL] |= ( 1 << LED_GPFBIT ); 67 | 68 | /* Never exit as there is no OS to exit to! */ 69 | while(1) 70 | { 71 | 72 | /* Set the GPIO16 output high ( Turn OK LED off )*/ 73 | LED_OFF(); 74 | 75 | for(counters[0] = 0; counters[0] < 500000; counters[0]++) 76 | ; 77 | 78 | /* Set the GPIO16 output low ( Turn OK LED on )*/ 79 | LED_ON(); 80 | 81 | for(counters[1] = 0; counters[1] < 500000; counters[1]++) 82 | ; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /part-4/armc-013/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2013, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # CMake build environment for the Valvers Raspberry-Pi bare metal tutorials 29 | 30 | # CMake 2.8.10 Documentation: http://www.cmake.org/cmake/help/v2.8.10/cmake.html 31 | 32 | cmake_minimum_required( VERSION 2.8 ) 33 | 34 | # Set the tutorial number so it's easier to re-use the CMakeLists.txt 35 | set( TUT 013 ) 36 | 37 | # Mark the language as C so that CMake doesn't try to test the C++ 38 | # cross-compiler's ability to compile a simple program because that will fail 39 | project( armc-${TUT}-tutorial C ASM ) 40 | 41 | # Add any C compiler flags here. The C flags concerned with processor tuning 42 | # are in the toolchain files toolchain-arm-none-eabi-bcm2835.cmake, etc. 43 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1" ) 44 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostartfiles" ) 45 | 46 | # Set the linker flags so that we use our "custom" linker script 47 | set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${PROJECT_SOURCE_DIR}/rpi.x" ) 48 | 49 | add_executable( armc-${TUT} 50 | armc-${TUT}.c 51 | armc-${TUT}-cstartup.c 52 | armc-${TUT}-cstubs.c 53 | armc-${TUT}-start.S 54 | rpi-armtimer.c 55 | rpi-armtimer.h 56 | rpi-base.h 57 | rpi-gpio.c 58 | rpi-gpio.h 59 | rpi-interrupts.c 60 | rpi-interrupts.h 61 | rpi-systimer.c 62 | rpi-systimer.h ) 63 | 64 | add_custom_command( 65 | TARGET armc-${TUT} POST_BUILD 66 | COMMAND ${CMAKE_OBJCOPY} ./armc-${TUT} -O binary ./kernel.img 67 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 68 | COMMENT "Convert the ELF output file to a binary image" ) 69 | -------------------------------------------------------------------------------- /part-5/armc-014/rpi-mailbox.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_MAILBOX_H 32 | #define RPI_MAILBOX_H 33 | 34 | #include "rpi-base.h" 35 | 36 | #define RPI_MAILBOX0_BASE ( PERIPHERAL_BASE + 0xB880 ) 37 | 38 | /* The available mailbox channels in the BCM2835 Mailbox interface. 39 | See https://github.com/raspberrypi/firmware/wiki/Mailboxes for 40 | information */ 41 | typedef enum { 42 | MB0_POWER_MANAGEMENT = 0, 43 | MB0_FRAMEBUFFER, 44 | MB0_VIRTUAL_UART, 45 | MB0_VCHIQ, 46 | MB0_LEDS, 47 | MB0_BUTTONS, 48 | MB0_TOUCHSCREEN, 49 | MB0_UNUSED, 50 | MB0_TAGS_ARM_TO_VC, 51 | MB0_TAGS_VC_TO_ARM, 52 | } mailbox0_channel_t; 53 | 54 | /* These defines come from the Broadcom Videocode driver source code, see: 55 | brcm_usrlib/dag/vmcsx/vcinclude/bcm2708_chip/arm_control.h */ 56 | enum mailbox_status_reg_bits { 57 | ARM_MS_FULL = 0x80000000, 58 | ARM_MS_EMPTY = 0x40000000, 59 | ARM_MS_LEVEL = 0x400000FF, 60 | }; 61 | 62 | /* Define a structure which defines the register access to a mailbox. 63 | Not all mailboxes support the full register set! */ 64 | typedef struct { 65 | volatile unsigned int Read; 66 | volatile unsigned int reserved1[((0x90 - 0x80) / 4) - 1]; 67 | volatile unsigned int Poll; 68 | volatile unsigned int Sender; 69 | volatile unsigned int Status; 70 | volatile unsigned int Configuration; 71 | volatile unsigned int Write; 72 | } mailbox_t; 73 | 74 | extern void RPI_Mailbox0Write( mailbox0_channel_t channel, int value ); 75 | extern int RPI_Mailbox0Read( mailbox0_channel_t channel ); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /part-5/armc-015/rpi-mailbox.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_MAILBOX_H 32 | #define RPI_MAILBOX_H 33 | 34 | #include "rpi-base.h" 35 | 36 | #define RPI_MAILBOX0_BASE ( PERIPHERAL_BASE + 0xB880 ) 37 | 38 | /* The available mailbox channels in the BCM2835 Mailbox interface. 39 | See https://github.com/raspberrypi/firmware/wiki/Mailboxes for 40 | information */ 41 | typedef enum { 42 | MB0_POWER_MANAGEMENT = 0, 43 | MB0_FRAMEBUFFER, 44 | MB0_VIRTUAL_UART, 45 | MB0_VCHIQ, 46 | MB0_LEDS, 47 | MB0_BUTTONS, 48 | MB0_TOUCHSCREEN, 49 | MB0_UNUSED, 50 | MB0_TAGS_ARM_TO_VC, 51 | MB0_TAGS_VC_TO_ARM, 52 | } mailbox0_channel_t; 53 | 54 | /* These defines come from the Broadcom Videocode driver source code, see: 55 | brcm_usrlib/dag/vmcsx/vcinclude/bcm2708_chip/arm_control.h */ 56 | enum mailbox_status_reg_bits { 57 | ARM_MS_FULL = 0x80000000, 58 | ARM_MS_EMPTY = 0x40000000, 59 | ARM_MS_LEVEL = 0x400000FF, 60 | }; 61 | 62 | /* Define a structure which defines the register access to a mailbox. 63 | Not all mailboxes support the full register set! */ 64 | typedef struct { 65 | volatile unsigned int Read; 66 | volatile unsigned int reserved1[((0x90 - 0x80) / 4) - 1]; 67 | volatile unsigned int Poll; 68 | volatile unsigned int Sender; 69 | volatile unsigned int Status; 70 | volatile unsigned int Configuration; 71 | volatile unsigned int Write; 72 | } mailbox_t; 73 | 74 | extern void RPI_Mailbox0Write( mailbox0_channel_t channel, int value ); 75 | extern int RPI_Mailbox0Read( mailbox0_channel_t channel ); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /part-5/armc-016/rpi-mailbox.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_MAILBOX_H 32 | #define RPI_MAILBOX_H 33 | 34 | #include "rpi-base.h" 35 | 36 | #define RPI_MAILBOX0_BASE ( PERIPHERAL_BASE + 0xB880 ) 37 | 38 | /* The available mailbox channels in the BCM2835 Mailbox interface. 39 | See https://github.com/raspberrypi/firmware/wiki/Mailboxes for 40 | information */ 41 | typedef enum { 42 | MB0_POWER_MANAGEMENT = 0, 43 | MB0_FRAMEBUFFER, 44 | MB0_VIRTUAL_UART, 45 | MB0_VCHIQ, 46 | MB0_LEDS, 47 | MB0_BUTTONS, 48 | MB0_TOUCHSCREEN, 49 | MB0_UNUSED, 50 | MB0_TAGS_ARM_TO_VC, 51 | MB0_TAGS_VC_TO_ARM, 52 | } mailbox0_channel_t; 53 | 54 | /* These defines come from the Broadcom Videocode driver source code, see: 55 | brcm_usrlib/dag/vmcsx/vcinclude/bcm2708_chip/arm_control.h */ 56 | enum mailbox_status_reg_bits { 57 | ARM_MS_FULL = 0x80000000, 58 | ARM_MS_EMPTY = 0x40000000, 59 | ARM_MS_LEVEL = 0x400000FF, 60 | }; 61 | 62 | /* Define a structure which defines the register access to a mailbox. 63 | Not all mailboxes support the full register set! */ 64 | typedef struct { 65 | volatile unsigned int Read; 66 | volatile unsigned int reserved1[((0x90 - 0x80) / 4) - 1]; 67 | volatile unsigned int Poll; 68 | volatile unsigned int Sender; 69 | volatile unsigned int Status; 70 | volatile unsigned int Configuration; 71 | volatile unsigned int Write; 72 | } mailbox_t; 73 | 74 | extern void RPI_Mailbox0Write( mailbox0_channel_t channel, int value ); 75 | extern int RPI_Mailbox0Read( mailbox0_channel_t channel ); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /part-5/armc-014/rpi-mailbox.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #include 32 | 33 | #include "rpi-gpio.h" 34 | #include "rpi-mailbox.h" 35 | 36 | /* Mailbox 0 mapped to it's base address */ 37 | static mailbox_t* rpiMailbox0 = (mailbox_t*)RPI_MAILBOX0_BASE; 38 | 39 | void RPI_Mailbox0Write( mailbox0_channel_t channel, int value ) 40 | { 41 | /* For information about accessing mailboxes, see: 42 | https://github.com/raspberrypi/firmware/wiki/Accessing-mailboxes */ 43 | 44 | /* Add the channel number into the lower 4 bits */ 45 | value &= ~(0xF); 46 | value |= channel; 47 | 48 | /* Wait until the mailbox becomes available and then write to the mailbox 49 | channel */ 50 | while( ( rpiMailbox0->Status & ARM_MS_FULL ) != 0 ) { } 51 | 52 | /* Write the modified value + channel number into the write register */ 53 | rpiMailbox0->Write = value; 54 | } 55 | 56 | 57 | int RPI_Mailbox0Read( mailbox0_channel_t channel ) 58 | { 59 | /* For information about accessing mailboxes, see: 60 | https://github.com/raspberrypi/firmware/wiki/Accessing-mailboxes */ 61 | int value = -1; 62 | 63 | /* Keep reading the register until the desired channel gives us a value */ 64 | while( ( value & 0xF ) != channel ) 65 | { 66 | /* Wait while the mailbox is empty because otherwise there's no value 67 | to read! */ 68 | while( rpiMailbox0->Status & ARM_MS_EMPTY ) { } 69 | 70 | /* Extract the value from the Read register of the mailbox. The value 71 | is actually in the upper 28 bits */ 72 | value = rpiMailbox0->Read; 73 | } 74 | 75 | /* Return just the value (the upper 28-bits) */ 76 | return value >> 4; 77 | } 78 | -------------------------------------------------------------------------------- /part-5/armc-015/rpi-mailbox.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #include 32 | 33 | #include "rpi-gpio.h" 34 | #include "rpi-mailbox.h" 35 | 36 | /* Mailbox 0 mapped to it's base address */ 37 | static mailbox_t* rpiMailbox0 = (mailbox_t*)RPI_MAILBOX0_BASE; 38 | 39 | void RPI_Mailbox0Write( mailbox0_channel_t channel, int value ) 40 | { 41 | /* For information about accessing mailboxes, see: 42 | https://github.com/raspberrypi/firmware/wiki/Accessing-mailboxes */ 43 | 44 | /* Add the channel number into the lower 4 bits */ 45 | value &= ~(0xF); 46 | value |= channel; 47 | 48 | /* Wait until the mailbox becomes available and then write to the mailbox 49 | channel */ 50 | while( ( rpiMailbox0->Status & ARM_MS_FULL ) != 0 ) { } 51 | 52 | /* Write the modified value + channel number into the write register */ 53 | rpiMailbox0->Write = value; 54 | } 55 | 56 | 57 | int RPI_Mailbox0Read( mailbox0_channel_t channel ) 58 | { 59 | /* For information about accessing mailboxes, see: 60 | https://github.com/raspberrypi/firmware/wiki/Accessing-mailboxes */ 61 | int value = -1; 62 | 63 | /* Keep reading the register until the desired channel gives us a value */ 64 | while( ( value & 0xF ) != channel ) 65 | { 66 | /* Wait while the mailbox is empty because otherwise there's no value 67 | to read! */ 68 | while( rpiMailbox0->Status & ARM_MS_EMPTY ) { } 69 | 70 | /* Extract the value from the Read register of the mailbox. The value 71 | is actually in the upper 28 bits */ 72 | value = rpiMailbox0->Read; 73 | } 74 | 75 | /* Return just the value (the upper 28-bits) */ 76 | return value >> 4; 77 | } 78 | -------------------------------------------------------------------------------- /part-5/armc-016/rpi-mailbox.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2015, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #include 32 | 33 | #include "rpi-gpio.h" 34 | #include "rpi-mailbox.h" 35 | 36 | /* Mailbox 0 mapped to it's base address */ 37 | static mailbox_t* rpiMailbox0 = (mailbox_t*)RPI_MAILBOX0_BASE; 38 | 39 | void RPI_Mailbox0Write( mailbox0_channel_t channel, int value ) 40 | { 41 | /* For information about accessing mailboxes, see: 42 | https://github.com/raspberrypi/firmware/wiki/Accessing-mailboxes */ 43 | 44 | /* Add the channel number into the lower 4 bits */ 45 | value &= ~(0xF); 46 | value |= channel; 47 | 48 | /* Wait until the mailbox becomes available and then write to the mailbox 49 | channel */ 50 | while( ( rpiMailbox0->Status & ARM_MS_FULL ) != 0 ) { } 51 | 52 | /* Write the modified value + channel number into the write register */ 53 | rpiMailbox0->Write = value; 54 | } 55 | 56 | 57 | int RPI_Mailbox0Read( mailbox0_channel_t channel ) 58 | { 59 | /* For information about accessing mailboxes, see: 60 | https://github.com/raspberrypi/firmware/wiki/Accessing-mailboxes */ 61 | int value = -1; 62 | 63 | /* Keep reading the register until the desired channel gives us a value */ 64 | while( ( value & 0xF ) != channel ) 65 | { 66 | /* Wait while the mailbox is empty because otherwise there's no value 67 | to read! */ 68 | while( rpiMailbox0->Status & ARM_MS_EMPTY ) { } 69 | 70 | /* Extract the value from the Read register of the mailbox. The value 71 | is actually in the upper 28 bits */ 72 | value = rpiMailbox0->Read; 73 | } 74 | 75 | /* Return just the value (the upper 28-bits) */ 76 | return value >> 4; 77 | } 78 | -------------------------------------------------------------------------------- /part-5/armc-014/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2015, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # CMake build environment for the Valvers Raspberry-Pi bare metal tutorials 29 | 30 | # CMake 2.8.10 Documentation: http://www.cmake.org/cmake/help/v2.8.10/cmake.html 31 | 32 | cmake_minimum_required( VERSION 2.8 ) 33 | 34 | # Set the tutorial number so it's easier to re-use the CMakeLists.txt 35 | set( TUT 014 ) 36 | 37 | # Mark the language as C so that CMake doesn't try to test the C++ 38 | # cross-compiler's ability to compile a simple program because that will fail 39 | project( armc-${TUT}-tutorial C ASM ) 40 | 41 | # Add any C compiler flags here. The C flags concerned with processor tuning 42 | # are in the toolchain files toolchain-arm-none-eabi-bcm2835.cmake, etc. 43 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1" ) 44 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" ) 45 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostartfiles" ) 46 | 47 | # Set the linker flags so that we use our "custom" linker script 48 | set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${PROJECT_SOURCE_DIR}/rpi.x" ) 49 | 50 | add_executable( armc-${TUT} 51 | armc-${TUT}.c 52 | armc-cstartup.c 53 | armc-cstubs.c 54 | armc-start.S 55 | rpi-armtimer.c 56 | rpi-armtimer.h 57 | rpi-aux.c 58 | rpi-aux.h 59 | rpi-base.h 60 | rpi-gpio.c 61 | rpi-gpio.h 62 | rpi-interrupts.c 63 | rpi-interrupts.h 64 | rpi-mailbox.c 65 | rpi-mailbox.h 66 | rpi-mailbox-interface.c 67 | rpi-mailbox-interface.h 68 | rpi-systimer.c 69 | rpi-systimer.h ) 70 | 71 | add_custom_command( 72 | TARGET armc-${TUT} POST_BUILD 73 | COMMAND ${CMAKE_OBJCOPY} ./armc-${TUT} -O binary ./kernel.img 74 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 75 | COMMENT "Convert the ELF output file to a binary image" ) 76 | -------------------------------------------------------------------------------- /part-5/armc-015/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2015, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # CMake build environment for the Valvers Raspberry-Pi bare metal tutorials 29 | 30 | # CMake 2.8.10 Documentation: http://www.cmake.org/cmake/help/v2.8.10/cmake.html 31 | 32 | cmake_minimum_required( VERSION 2.8 ) 33 | 34 | # Set the tutorial number so it's easier to re-use the CMakeLists.txt 35 | set( TUT 015 ) 36 | 37 | # Mark the language as C so that CMake doesn't try to test the C++ 38 | # cross-compiler's ability to compile a simple program because that will fail 39 | project( armc-${TUT}-tutorial C ASM ) 40 | 41 | # Add any C compiler flags here. The C flags concerned with processor tuning 42 | # are in the toolchain files toolchain-arm-none-eabi-bcm2835.cmake, etc. 43 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1" ) 44 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" ) 45 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostartfiles" ) 46 | 47 | # Set the linker flags so that we use our "custom" linker script 48 | set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${PROJECT_SOURCE_DIR}/rpi.x" ) 49 | 50 | add_executable( armc-${TUT} 51 | armc-${TUT}.c 52 | armc-cstartup.c 53 | armc-cstubs.c 54 | armc-start.S 55 | rpi-armtimer.c 56 | rpi-armtimer.h 57 | rpi-aux.c 58 | rpi-aux.h 59 | rpi-base.h 60 | rpi-gpio.c 61 | rpi-gpio.h 62 | rpi-interrupts.c 63 | rpi-interrupts.h 64 | rpi-mailbox.c 65 | rpi-mailbox.h 66 | rpi-mailbox-interface.c 67 | rpi-mailbox-interface.h 68 | rpi-systimer.c 69 | rpi-systimer.h ) 70 | 71 | add_custom_command( 72 | TARGET armc-${TUT} POST_BUILD 73 | COMMAND ${CMAKE_OBJCOPY} ./armc-${TUT} -O binary ./kernel.img 74 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 75 | COMMENT "Convert the ELF output file to a binary image" ) 76 | -------------------------------------------------------------------------------- /part-5/armc-016/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2015, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # CMake build environment for the Valvers Raspberry-Pi bare metal tutorials 29 | 30 | # CMake 2.8.10 Documentation: http://www.cmake.org/cmake/help/v2.8.10/cmake.html 31 | 32 | cmake_minimum_required( VERSION 2.8 ) 33 | 34 | # Set the tutorial number so it's easier to re-use the CMakeLists.txt 35 | set( TUT 016 ) 36 | 37 | # Mark the language as C so that CMake doesn't try to test the C++ 38 | # cross-compiler's ability to compile a simple program because that will fail 39 | project( armc-${TUT}-tutorial C ASM ) 40 | 41 | # Add any C compiler flags here. The C flags concerned with processor tuning 42 | # are in the toolchain files toolchain-arm-none-eabi-bcm2835.cmake, etc. 43 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O4" ) 44 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall" ) 45 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostartfiles" ) 46 | 47 | # Set the linker flags so that we use our "custom" linker script 48 | set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${PROJECT_SOURCE_DIR}/rpi.x" ) 49 | 50 | add_executable( armc-${TUT} 51 | armc-${TUT}.c 52 | armc-cstartup.c 53 | armc-cstubs.c 54 | armc-start.S 55 | rpi-armtimer.c 56 | rpi-armtimer.h 57 | rpi-aux.c 58 | rpi-aux.h 59 | rpi-base.h 60 | rpi-gpio.c 61 | rpi-gpio.h 62 | rpi-interrupts.c 63 | rpi-interrupts.h 64 | rpi-mailbox.c 65 | rpi-mailbox.h 66 | rpi-mailbox-interface.c 67 | rpi-mailbox-interface.h 68 | rpi-systimer.c 69 | rpi-systimer.h ) 70 | 71 | add_custom_command( 72 | TARGET armc-${TUT} POST_BUILD 73 | COMMAND ${CMAKE_OBJCOPY} ./armc-${TUT} -O binary ./kernel.img 74 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 75 | COMMENT "Convert the ELF output file to a binary image" ) 76 | -------------------------------------------------------------------------------- /part-4/armc-013/rpi-interrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_INTERRUPTS_H 32 | #define RPI_INTERRUPTS_H 33 | 34 | #include 35 | 36 | #include "rpi-base.h" 37 | 38 | /** @brief See Section 7.5 of the BCM2836 ARM Peripherals documentation, the base 39 | address of the controller is actually xxxxB000, but there is a 0x200 offset 40 | to the first addressable register for the interrupt controller, so offset the 41 | base to the first register */ 42 | #define RPI_INTERRUPT_CONTROLLER_BASE ( PERIPHERAL_BASE + 0xB200 ) 43 | 44 | /** @brief Bits in the Enable_Basic_IRQs register to enable various interrupts. 45 | See the BCM2835 ARM Peripherals manual, section 7.5 */ 46 | #define RPI_BASIC_ARM_TIMER_IRQ (1 << 0) 47 | #define RPI_BASIC_ARM_MAILBOX_IRQ (1 << 1) 48 | #define RPI_BASIC_ARM_DOORBELL_0_IRQ (1 << 2) 49 | #define RPI_BASIC_ARM_DOORBELL_1_IRQ (1 << 3) 50 | #define RPI_BASIC_GPU_0_HALTED_IRQ (1 << 4) 51 | #define RPI_BASIC_GPU_1_HALTED_IRQ (1 << 5) 52 | #define RPI_BASIC_ACCESS_ERROR_1_IRQ (1 << 6) 53 | #define RPI_BASIC_ACCESS_ERROR_0_IRQ (1 << 7) 54 | 55 | 56 | /** @brief The interrupt controller memory mapped register set */ 57 | typedef struct { 58 | volatile uint32_t IRQ_basic_pending; 59 | volatile uint32_t IRQ_pending_1; 60 | volatile uint32_t IRQ_pending_2; 61 | volatile uint32_t FIQ_control; 62 | volatile uint32_t Enable_IRQs_1; 63 | volatile uint32_t Enable_IRQs_2; 64 | volatile uint32_t Enable_Basic_IRQs; 65 | volatile uint32_t Disable_IRQs_1; 66 | volatile uint32_t Disable_IRQs_2; 67 | volatile uint32_t Disable_Basic_IRQs; 68 | } rpi_irq_controller_t; 69 | 70 | 71 | extern rpi_irq_controller_t* RPI_GetIrqController( void ); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /part-2/armc-04/rpi-gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_GPIO_H 32 | #define RPI_GPIO_H 33 | 34 | /* The base address of the GPIO peripheral (ARM Physical Address) */ 35 | #ifdef RPI2 36 | #define GPIO_BASE 0x3F200000UL 37 | #else 38 | #define GPIO_BASE 0x20200000UL 39 | #endif 40 | 41 | #if defined( RPIBPLUS ) || defined( RPI2 ) 42 | #define LED_GPFSEL GPIO_GPFSEL4 43 | #define LED_GPFBIT 21 44 | #define LED_GPSET GPIO_GPSET1 45 | #define LED_GPCLR GPIO_GPCLR1 46 | #define LED_GPIO_BIT 15 47 | #else 48 | #define LED_GPFSEL GPIO_GPFSEL1 49 | #define LED_GPFBIT 18 50 | #define LED_GPSET GPIO_GPSET0 51 | #define LED_GPCLR GPIO_GPCLR0 52 | #define LED_GPIO_BIT 16 53 | #endif 54 | 55 | #define GPIO_GPFSEL0 0 56 | #define GPIO_GPFSEL1 1 57 | #define GPIO_GPFSEL2 2 58 | #define GPIO_GPFSEL3 3 59 | #define GPIO_GPFSEL4 4 60 | #define GPIO_GPFSEL5 5 61 | 62 | #define GPIO_GPSET0 7 63 | #define GPIO_GPSET1 8 64 | 65 | #define GPIO_GPCLR0 10 66 | #define GPIO_GPCLR1 11 67 | 68 | #define GPIO_GPLEV0 13 69 | #define GPIO_GPLEV1 14 70 | 71 | #define GPIO_GPEDS0 16 72 | #define GPIO_GPEDS1 17 73 | 74 | #define GPIO_GPREN0 19 75 | #define GPIO_GPREN1 20 76 | 77 | #define GPIO_GPFEN0 22 78 | #define GPIO_GPFEN1 23 79 | 80 | #define GPIO_GPHEN0 25 81 | #define GPIO_GPHEN1 26 82 | 83 | #define GPIO_GPLEN0 28 84 | #define GPIO_GPLEN1 29 85 | 86 | #define GPIO_GPAREN0 31 87 | #define GPIO_GPAREN1 32 88 | 89 | #define GPIO_GPAFEN0 34 90 | #define GPIO_GPAFEN1 35 91 | 92 | #define GPIO_GPPUD 37 93 | #define GPIO_GPPUDCLK0 38 94 | #define GPIO_GPPUDCLK1 39 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /part-2/armc-05/rpi-gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_GPIO_H 32 | #define RPI_GPIO_H 33 | 34 | /* The base address of the GPIO peripheral (ARM Physical Address) */ 35 | #ifdef RPI2 36 | #define GPIO_BASE 0x3F200000UL 37 | #else 38 | #define GPIO_BASE 0x20200000UL 39 | #endif 40 | 41 | #if defined( RPIBPLUS ) || defined( RPI2 ) 42 | #define LED_GPFSEL GPIO_GPFSEL4 43 | #define LED_GPFBIT 21 44 | #define LED_GPSET GPIO_GPSET1 45 | #define LED_GPCLR GPIO_GPCLR1 46 | #define LED_GPIO_BIT 15 47 | #else 48 | #define LED_GPFSEL GPIO_GPFSEL1 49 | #define LED_GPFBIT 18 50 | #define LED_GPSET GPIO_GPSET0 51 | #define LED_GPCLR GPIO_GPCLR0 52 | #define LED_GPIO_BIT 16 53 | #endif 54 | 55 | #define GPIO_GPFSEL0 0 56 | #define GPIO_GPFSEL1 1 57 | #define GPIO_GPFSEL2 2 58 | #define GPIO_GPFSEL3 3 59 | #define GPIO_GPFSEL4 4 60 | #define GPIO_GPFSEL5 5 61 | 62 | #define GPIO_GPSET0 7 63 | #define GPIO_GPSET1 8 64 | 65 | #define GPIO_GPCLR0 10 66 | #define GPIO_GPCLR1 11 67 | 68 | #define GPIO_GPLEV0 13 69 | #define GPIO_GPLEV1 14 70 | 71 | #define GPIO_GPEDS0 16 72 | #define GPIO_GPEDS1 17 73 | 74 | #define GPIO_GPREN0 19 75 | #define GPIO_GPREN1 20 76 | 77 | #define GPIO_GPFEN0 22 78 | #define GPIO_GPFEN1 23 79 | 80 | #define GPIO_GPHEN0 25 81 | #define GPIO_GPHEN1 26 82 | 83 | #define GPIO_GPLEN0 28 84 | #define GPIO_GPLEN1 29 85 | 86 | #define GPIO_GPAREN0 31 87 | #define GPIO_GPAREN1 32 88 | 89 | #define GPIO_GPAFEN0 34 90 | #define GPIO_GPAFEN1 35 91 | 92 | #define GPIO_GPPUD 37 93 | #define GPIO_GPPUDCLK0 38 94 | #define GPIO_GPPUDCLK1 39 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /part-2/armc-06/rpi-gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_GPIO_H 32 | #define RPI_GPIO_H 33 | 34 | /* The base address of the GPIO peripheral (ARM Physical Address) */ 35 | #ifdef RPI2 36 | #define GPIO_BASE 0x3F200000UL 37 | #else 38 | #define GPIO_BASE 0x20200000UL 39 | #endif 40 | 41 | #if defined( RPIBPLUS ) || defined( RPI2 ) 42 | #define LED_GPFSEL GPIO_GPFSEL4 43 | #define LED_GPFBIT 21 44 | #define LED_GPSET GPIO_GPSET1 45 | #define LED_GPCLR GPIO_GPCLR1 46 | #define LED_GPIO_BIT 15 47 | #else 48 | #define LED_GPFSEL GPIO_GPFSEL1 49 | #define LED_GPFBIT 18 50 | #define LED_GPSET GPIO_GPSET0 51 | #define LED_GPCLR GPIO_GPCLR0 52 | #define LED_GPIO_BIT 16 53 | #endif 54 | 55 | #define GPIO_GPFSEL0 0 56 | #define GPIO_GPFSEL1 1 57 | #define GPIO_GPFSEL2 2 58 | #define GPIO_GPFSEL3 3 59 | #define GPIO_GPFSEL4 4 60 | #define GPIO_GPFSEL5 5 61 | 62 | #define GPIO_GPSET0 7 63 | #define GPIO_GPSET1 8 64 | 65 | #define GPIO_GPCLR0 10 66 | #define GPIO_GPCLR1 11 67 | 68 | #define GPIO_GPLEV0 13 69 | #define GPIO_GPLEV1 14 70 | 71 | #define GPIO_GPEDS0 16 72 | #define GPIO_GPEDS1 17 73 | 74 | #define GPIO_GPREN0 19 75 | #define GPIO_GPREN1 20 76 | 77 | #define GPIO_GPFEN0 22 78 | #define GPIO_GPFEN1 23 79 | 80 | #define GPIO_GPHEN0 25 81 | #define GPIO_GPHEN1 26 82 | 83 | #define GPIO_GPLEN0 28 84 | #define GPIO_GPLEN1 29 85 | 86 | #define GPIO_GPAREN0 31 87 | #define GPIO_GPAREN1 32 88 | 89 | #define GPIO_GPAFEN0 34 90 | #define GPIO_GPAFEN1 35 91 | 92 | #define GPIO_GPPUD 37 93 | #define GPIO_GPPUDCLK0 38 94 | #define GPIO_GPPUDCLK1 39 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /part-2/armc-07/rpi-gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_GPIO_H 32 | #define RPI_GPIO_H 33 | 34 | /* The base address of the GPIO peripheral (ARM Physical Address) */ 35 | #ifdef RPI2 36 | #define GPIO_BASE 0x3F200000UL 37 | #else 38 | #define GPIO_BASE 0x20200000UL 39 | #endif 40 | 41 | #if defined( RPIBPLUS ) || defined( RPI2 ) 42 | #define LED_GPFSEL GPIO_GPFSEL4 43 | #define LED_GPFBIT 21 44 | #define LED_GPSET GPIO_GPSET1 45 | #define LED_GPCLR GPIO_GPCLR1 46 | #define LED_GPIO_BIT 15 47 | #else 48 | #define LED_GPFSEL GPIO_GPFSEL1 49 | #define LED_GPFBIT 18 50 | #define LED_GPSET GPIO_GPSET0 51 | #define LED_GPCLR GPIO_GPCLR0 52 | #define LED_GPIO_BIT 16 53 | #endif 54 | 55 | #define GPIO_GPFSEL0 0 56 | #define GPIO_GPFSEL1 1 57 | #define GPIO_GPFSEL2 2 58 | #define GPIO_GPFSEL3 3 59 | #define GPIO_GPFSEL4 4 60 | #define GPIO_GPFSEL5 5 61 | 62 | #define GPIO_GPSET0 7 63 | #define GPIO_GPSET1 8 64 | 65 | #define GPIO_GPCLR0 10 66 | #define GPIO_GPCLR1 11 67 | 68 | #define GPIO_GPLEV0 13 69 | #define GPIO_GPLEV1 14 70 | 71 | #define GPIO_GPEDS0 16 72 | #define GPIO_GPEDS1 17 73 | 74 | #define GPIO_GPREN0 19 75 | #define GPIO_GPREN1 20 76 | 77 | #define GPIO_GPFEN0 22 78 | #define GPIO_GPFEN1 23 79 | 80 | #define GPIO_GPHEN0 25 81 | #define GPIO_GPHEN1 26 82 | 83 | #define GPIO_GPLEN0 28 84 | #define GPIO_GPLEN1 29 85 | 86 | #define GPIO_GPAREN0 31 87 | #define GPIO_GPAREN1 32 88 | 89 | #define GPIO_GPAFEN0 34 90 | #define GPIO_GPAFEN1 35 91 | 92 | #define GPIO_GPPUD 37 93 | #define GPIO_GPPUDCLK0 38 94 | #define GPIO_GPPUDCLK1 39 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /part-2/armc-08/rpi-gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Part of the Raspberry-Pi Bare Metal Tutorials 4 | Copyright (c) 2013, Brian Sidebotham 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | 29 | */ 30 | 31 | #ifndef RPI_GPIO_H 32 | #define RPI_GPIO_H 33 | 34 | /* The base address of the GPIO peripheral (ARM Physical Address) */ 35 | #ifdef RPI2 36 | #define GPIO_BASE 0x3F200000UL 37 | #else 38 | #define GPIO_BASE 0x20200000UL 39 | #endif 40 | 41 | #if defined( RPIBPLUS ) || defined( RPI2 ) 42 | #define LED_GPFSEL GPIO_GPFSEL4 43 | #define LED_GPFBIT 21 44 | #define LED_GPSET GPIO_GPSET1 45 | #define LED_GPCLR GPIO_GPCLR1 46 | #define LED_GPIO_BIT 15 47 | #else 48 | #define LED_GPFSEL GPIO_GPFSEL1 49 | #define LED_GPFBIT 18 50 | #define LED_GPSET GPIO_GPSET0 51 | #define LED_GPCLR GPIO_GPCLR0 52 | #define LED_GPIO_BIT 16 53 | #endif 54 | 55 | #define GPIO_GPFSEL0 0 56 | #define GPIO_GPFSEL1 1 57 | #define GPIO_GPFSEL2 2 58 | #define GPIO_GPFSEL3 3 59 | #define GPIO_GPFSEL4 4 60 | #define GPIO_GPFSEL5 5 61 | 62 | #define GPIO_GPSET0 7 63 | #define GPIO_GPSET1 8 64 | 65 | #define GPIO_GPCLR0 10 66 | #define GPIO_GPCLR1 11 67 | 68 | #define GPIO_GPLEV0 13 69 | #define GPIO_GPLEV1 14 70 | 71 | #define GPIO_GPEDS0 16 72 | #define GPIO_GPEDS1 17 73 | 74 | #define GPIO_GPREN0 19 75 | #define GPIO_GPREN1 20 76 | 77 | #define GPIO_GPFEN0 22 78 | #define GPIO_GPFEN1 23 79 | 80 | #define GPIO_GPHEN0 25 81 | #define GPIO_GPHEN1 26 82 | 83 | #define GPIO_GPLEN0 28 84 | #define GPIO_GPLEN1 29 85 | 86 | #define GPIO_GPAREN0 31 87 | #define GPIO_GPAREN1 32 88 | 89 | #define GPIO_GPAFEN0 34 90 | #define GPIO_GPAFEN1 35 91 | 92 | #define GPIO_GPPUD 37 93 | #define GPIO_GPPUDCLK0 38 94 | #define GPIO_GPPUDCLK1 39 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /part-3/arm010/toolchain-arm-none-eabi-rpi.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2013-2015, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # A CMake toolchain file so we can cross-compile for the Rapsberry-Pi bare-metal 29 | 30 | include(CMakeForceCompiler) 31 | 32 | # usage 33 | # cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi.cmake ../ 34 | 35 | # The Generic system name is used for embedded targets (targets without OS) in 36 | # CMake 37 | set( CMAKE_SYSTEM_NAME Generic ) 38 | set( CMAKE_SYSTEM_PROCESSOR BCM2835 ) 39 | 40 | # Set a toolchain path. You only need to set this if the toolchain isn't in 41 | # your system path. Don't forget a trailing path separator! 42 | set( TC_PATH "" ) 43 | 44 | # The toolchain prefix for all toolchain executables 45 | set( CROSS_COMPILE arm-none-eabi- ) 46 | 47 | # specify the cross compiler. We force the compiler so that CMake doesn't 48 | # attempt to build a simple test program as this will fail without us using 49 | # the -nostartfiles option on the command line 50 | CMAKE_FORCE_C_COMPILER( ${TC_PATH}${CROSS_COMPILE}gcc GNU ) 51 | 52 | # We must set the OBJCOPY setting into cache so that it's available to the 53 | # whole project. Otherwise, this does not get set into the CACHE and therefore 54 | # the build doesn't know what the OBJCOPY filepath is 55 | set( CMAKE_OBJCOPY ${TC_PATH}${CROSS_COMPILE}objcopy 56 | CACHE FILEPATH "The toolchain objcopy command " FORCE ) 57 | 58 | # Set the CMAKE C flags (which should also be used by the assembler! 59 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp" ) 60 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard" ) 61 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv6zk" ) 62 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=arm1176jzf-s" ) 63 | 64 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" ) 65 | set( CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" ) 66 | 67 | 68 | -------------------------------------------------------------------------------- /part-3/arm011/toolchain-arm-none-eabi-rpi.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2013-2015, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # A CMake toolchain file so we can cross-compile for the Rapsberry-Pi bare-metal 29 | 30 | include(CMakeForceCompiler) 31 | 32 | # usage 33 | # cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi.cmake ../ 34 | 35 | # The Generic system name is used for embedded targets (targets without OS) in 36 | # CMake 37 | set( CMAKE_SYSTEM_NAME Generic ) 38 | set( CMAKE_SYSTEM_PROCESSOR BCM2835 ) 39 | 40 | # Set a toolchain path. You only need to set this if the toolchain isn't in 41 | # your system path. Don't forget a trailing path separator! 42 | set( TC_PATH "" ) 43 | 44 | # The toolchain prefix for all toolchain executables 45 | set( CROSS_COMPILE arm-none-eabi- ) 46 | 47 | # specify the cross compiler. We force the compiler so that CMake doesn't 48 | # attempt to build a simple test program as this will fail without us using 49 | # the -nostartfiles option on the command line 50 | CMAKE_FORCE_C_COMPILER( ${TC_PATH}${CROSS_COMPILE}gcc GNU ) 51 | 52 | # We must set the OBJCOPY setting into cache so that it's available to the 53 | # whole project. Otherwise, this does not get set into the CACHE and therefore 54 | # the build doesn't know what the OBJCOPY filepath is 55 | set( CMAKE_OBJCOPY ${TC_PATH}${CROSS_COMPILE}objcopy 56 | CACHE FILEPATH "The toolchain objcopy command " FORCE ) 57 | 58 | # Set the CMAKE C flags (which should also be used by the assembler! 59 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp" ) 60 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard" ) 61 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv6zk" ) 62 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=arm1176jzf-s" ) 63 | 64 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" ) 65 | set( CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" ) 66 | 67 | 68 | -------------------------------------------------------------------------------- /part-3/arm012/toolchain-arm-none-eabi-rpi.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2013-2015, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # A CMake toolchain file so we can cross-compile for the Rapsberry-Pi bare-metal 29 | 30 | include(CMakeForceCompiler) 31 | 32 | # usage 33 | # cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi.cmake ../ 34 | 35 | # The Generic system name is used for embedded targets (targets without OS) in 36 | # CMake 37 | set( CMAKE_SYSTEM_NAME Generic ) 38 | set( CMAKE_SYSTEM_PROCESSOR BCM2835 ) 39 | 40 | # Set a toolchain path. You only need to set this if the toolchain isn't in 41 | # your system path. Don't forget a trailing path separator! 42 | set( TC_PATH "" ) 43 | 44 | # The toolchain prefix for all toolchain executables 45 | set( CROSS_COMPILE arm-none-eabi- ) 46 | 47 | # specify the cross compiler. We force the compiler so that CMake doesn't 48 | # attempt to build a simple test program as this will fail without us using 49 | # the -nostartfiles option on the command line 50 | CMAKE_FORCE_C_COMPILER( ${TC_PATH}${CROSS_COMPILE}gcc GNU ) 51 | 52 | # We must set the OBJCOPY setting into cache so that it's available to the 53 | # whole project. Otherwise, this does not get set into the CACHE and therefore 54 | # the build doesn't know what the OBJCOPY filepath is 55 | set( CMAKE_OBJCOPY ${TC_PATH}${CROSS_COMPILE}objcopy 56 | CACHE FILEPATH "The toolchain objcopy command " FORCE ) 57 | 58 | # Set the CMAKE C flags (which should also be used by the assembler! 59 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp" ) 60 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard" ) 61 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv6zk" ) 62 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=arm1176jzf-s" ) 63 | 64 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" ) 65 | set( CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" ) 66 | 67 | 68 | -------------------------------------------------------------------------------- /part-4/armc-013/toolchain-arm-none-eabi-rpi.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2013-2015, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # A CMake toolchain file so we can cross-compile for the Rapsberry-Pi bare-metal 29 | 30 | include(CMakeForceCompiler) 31 | 32 | # usage 33 | # cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi.cmake ../ 34 | 35 | # The Generic system name is used for embedded targets (targets without OS) in 36 | # CMake 37 | set( CMAKE_SYSTEM_NAME Generic ) 38 | set( CMAKE_SYSTEM_PROCESSOR BCM2835 ) 39 | 40 | # Set a toolchain path. You only need to set this if the toolchain isn't in 41 | # your system path. Don't forget a trailing path separator! 42 | set( TC_PATH "" ) 43 | 44 | # The toolchain prefix for all toolchain executables 45 | set( CROSS_COMPILE arm-none-eabi- ) 46 | 47 | # specify the cross compiler. We force the compiler so that CMake doesn't 48 | # attempt to build a simple test program as this will fail without us using 49 | # the -nostartfiles option on the command line 50 | CMAKE_FORCE_C_COMPILER( ${TC_PATH}${CROSS_COMPILE}gcc GNU ) 51 | 52 | # We must set the OBJCOPY setting into cache so that it's available to the 53 | # whole project. Otherwise, this does not get set into the CACHE and therefore 54 | # the build doesn't know what the OBJCOPY filepath is 55 | set( CMAKE_OBJCOPY ${TC_PATH}${CROSS_COMPILE}objcopy 56 | CACHE FILEPATH "The toolchain objcopy command " FORCE ) 57 | 58 | # Set the CMAKE C flags (which should also be used by the assembler! 59 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp" ) 60 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard" ) 61 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv6zk" ) 62 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=arm1176jzf-s" ) 63 | 64 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" ) 65 | set( CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" ) 66 | 67 | 68 | -------------------------------------------------------------------------------- /part-5/armc-014/toolchain-arm-none-eabi-rpi.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2013-2015, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # A CMake toolchain file so we can cross-compile for the Rapsberry-Pi bare-metal 29 | 30 | include(CMakeForceCompiler) 31 | 32 | # usage 33 | # cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi.cmake ../ 34 | 35 | # The Generic system name is used for embedded targets (targets without OS) in 36 | # CMake 37 | set( CMAKE_SYSTEM_NAME Generic ) 38 | set( CMAKE_SYSTEM_PROCESSOR BCM2835 ) 39 | 40 | # Set a toolchain path. You only need to set this if the toolchain isn't in 41 | # your system path. Don't forget a trailing path separator! 42 | set( TC_PATH "" ) 43 | 44 | # The toolchain prefix for all toolchain executables 45 | set( CROSS_COMPILE arm-none-eabi- ) 46 | 47 | # specify the cross compiler. We force the compiler so that CMake doesn't 48 | # attempt to build a simple test program as this will fail without us using 49 | # the -nostartfiles option on the command line 50 | CMAKE_FORCE_C_COMPILER( ${TC_PATH}${CROSS_COMPILE}gcc GNU ) 51 | 52 | # We must set the OBJCOPY setting into cache so that it's available to the 53 | # whole project. Otherwise, this does not get set into the CACHE and therefore 54 | # the build doesn't know what the OBJCOPY filepath is 55 | set( CMAKE_OBJCOPY ${TC_PATH}${CROSS_COMPILE}objcopy 56 | CACHE FILEPATH "The toolchain objcopy command " FORCE ) 57 | 58 | # Set the CMAKE C flags (which should also be used by the assembler! 59 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp" ) 60 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard" ) 61 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv6zk" ) 62 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=arm1176jzf-s" ) 63 | 64 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" ) 65 | set( CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" ) 66 | 67 | 68 | -------------------------------------------------------------------------------- /part-5/armc-015/toolchain-arm-none-eabi-rpi.cmake: -------------------------------------------------------------------------------- 1 | 2 | # Part of the Raspberry-Pi Bare Metal Tutorials 3 | # Copyright (c) 2013-2015, Brian Sidebotham 4 | # All rights reserved. 5 | 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | 9 | # 1. Redistributions of source code must retain the above copyright notice, 10 | # this list of conditions and the following disclaimer. 11 | 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the 14 | # documentation and/or other materials provided with the distribution. 15 | 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | # POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # A CMake toolchain file so we can cross-compile for the Rapsberry-Pi bare-metal 29 | 30 | include(CMakeForceCompiler) 31 | 32 | # usage 33 | # cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm-none-eabi.cmake ../ 34 | 35 | # The Generic system name is used for embedded targets (targets without OS) in 36 | # CMake 37 | set( CMAKE_SYSTEM_NAME Generic ) 38 | set( CMAKE_SYSTEM_PROCESSOR BCM2835 ) 39 | 40 | # Set a toolchain path. You only need to set this if the toolchain isn't in 41 | # your system path. Don't forget a trailing path separator! 42 | set( TC_PATH "" ) 43 | 44 | # The toolchain prefix for all toolchain executables 45 | set( CROSS_COMPILE arm-none-eabi- ) 46 | 47 | # specify the cross compiler. We force the compiler so that CMake doesn't 48 | # attempt to build a simple test program as this will fail without us using 49 | # the -nostartfiles option on the command line 50 | CMAKE_FORCE_C_COMPILER( ${TC_PATH}${CROSS_COMPILE}gcc GNU ) 51 | 52 | # We must set the OBJCOPY setting into cache so that it's available to the 53 | # whole project. Otherwise, this does not get set into the CACHE and therefore 54 | # the build doesn't know what the OBJCOPY filepath is 55 | set( CMAKE_OBJCOPY ${TC_PATH}${CROSS_COMPILE}objcopy 56 | CACHE FILEPATH "The toolchain objcopy command " FORCE ) 57 | 58 | # Set the CMAKE C flags (which should also be used by the assembler! 59 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp" ) 60 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard" ) 61 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv6zk" ) 62 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=arm1176jzf-s" ) 63 | 64 | set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" ) 65 | set( CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "" ) 66 | 67 | 68 | --------------------------------------------------------------------------------