1. Preface
Tiny4412 development is an Android and Linux learning development board launched by the arm of friendship. The CPU adopts Samsung's EXYNOS4412, 32-bit chip, belongs to Cortex-A series, the main frequency is 1.5GHZ, and can run ubuntu and Android 5 0. Pure Linux and other operating systems.
This article introduces how to use this development board to complete the bare metal development without involving the operating system. It can be directly used as a single chip microcomputer to complete the programming of LED lights and buzzers, and understand the difference between this chip and the conventional Cortex-M series chip programming.
The core board is shown in the figure:
The following is the physical drawing of the development board:
Configuration of development board:
2. Build a cross compilation environment
Before bare metal programming, you need to build a cross compilation environment and install arm linux GCC cross compiler. The cross compiled program can run on the development board.
What is cross compilation? The mode of compiling on PC and running on embedded development board is called cross compilation.
The cross compiler is provided in the CD-ROM of the development board, which can be directly copied to the PC under Linux, decompressed and configured with the environment variable interface.
The detailed operation steps are as follows:
1. stay Linux Create a directory under the user directory: mkdir work/arm-linux-gcc -p 2. Copy cross compiler to Linux System shared directory. Then unzip to arm-linux-gcc Directory. tar xvf arm-linux-gcc-4.5.1-v6-vfp-20120301.tgz -C /home/wbyq/work/arm-linux-gcc/ 3. Add system environment variable (1). root user: You need to write the code in/etc/profile In the file (2). Ordinary users: You need to write the code in the user directory.bash_profile In the file profile When the file system is powered on, it will execute automatically. Commands for adding environment variables: export PATH=/home/wbyq/work/arm-linux-gcc/opt/FriendlyARM/toolschain/4.5.1/bin:$PATH Parameters: export export--Global declaration PATH The name of the system environment variable. effect: preservation Linux Search path for system executable. Output the value of the environment variable: [wbyq@wbyq ~]$ echo $PATH /home/wbyq/work/arm-linux-gcc/opt/FriendlyARM/toolschain/4.5.1/bin:/usr/lib/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wbyq/bin export LD_LIBRARY_PATH=/mnt/hgfs/linux-share-dir/sum:$LD_LIBRARY_PATH parameter: LD_LIBRARY_PATH The name of the system environment variable. effect: preservation Linux Search path of system dynamic library. xxx.so 4. Effective environment variable (1). Effective immediately: The current terminal is valid [wbyq@wbyq ~]$ source .bash_profile (2). Exit the user and log in to the system again to achieve permanent effect 5. Test cross compiler. Learn basic usage [wbyq@wbyq linux_2021]$ arm-linux-gcc app.c [wbyq@wbyq linux_2021]$ ls a.out app.c [wbyq@wbyq linux_2021]$ ./a.out bash: ./a.out: cannot execute binary file [wbyq@wbyq linux_2021]$ gcc app.c -o app1 [wbyq@wbyq linux_2021]$ arm-linux-gcc app.c -o app2 [wbyq@wbyq linux_2021]$ ls a.out app1 app2 app.c [wbyq@wbyq linux_2021]$ file app1 app1: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped [wbyq@wbyq linux_2021]$ file app2 app2: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.27, not stripped
3. Turn on the LED
If you have studied the programming of single chip microcomputer (51, STM32, MSP430, AVR, etc.), it should be easy to complete the content of the current chapter.
To complete the control of LED lights, the following steps need to be completed:
1. View schematic 2. to configure GPIO mouth 3. control GPIO Port output level control LED 4. Compiler: xxx.lds Link file equipment: Character device, block device, network device SD Card device: /dev/sdb View block size: cat /sys/block/sdb/size The unit is block(1 Block 512 bytes) 5. Burn to development board test dd iflag=dsync oflag=dsync if=./E4412_N.bl1.bin of=/dev/sdb seek=1 parameter: if=./E4412_N.bl1.bin To write SD File on card of=/dev/sdb SD Card device seek=1 Skipped block. A block==512 byte Execute burn command: [wbyq@wbyq sd_fuse]$ sudo ./sd_write.sh /dev/sdb ../main.bin
(1) Check the schematic diagram and find the wiring position of the LED
tiny4412 development board is designed in two layers, one core board and one bottom board. LED lights are welded on the core board, and the core board must be opened for the schematic diagram.
(2) Check the chip manual to understand how to configure the GPIO port
The configuration method is also well understood and is described in detail in the manual. LED belongs to output control device, and GPIO port needs to be configured into output mode.
The configuration of DAT register is completed by GPIO.
(3) Write code
/* LED Register GPM4_0 1 2 3*/ #define GPM4CON (*(volatile unsigned int *)0x110002E0) #define GPM4DAT (*(volatile unsigned int *)0x110002E4) int main(void) { /*Configure GPIO port mode -- configure LED light*/ GPM4CON&=0xFFFF0000; GPM4CON|=0x00001111; /*3. Configure GPIO port mode -- configure key*/ GPX3CON&=0xFF0000FF; GPM4DAT&=~(1<<0); GPM4DAT&=~(1<<1); GPM4DAT&=~(1<<2); GPM4DAT&=~(1<<3); while(1) { } return 0; }
(4) Written by Makefile
CC=arm-linux-gcc main_sp.bin:start.o main.o arm-linux-ld -Tmain.lds -o main_sp.elf $^ arm-linux-objcopy -O binary main_sp.elf main.bin arm-linux-objdump -D main_sp.elf > main_sp_elf.dis %.o : %.S $(CC) -o $@ $< -c %.o : %.c $(CC) -o $@ $< -c clean: rm *.o *.elf *.bin *.dis -f
(5) Code burning script
# # Copyright (C) 2011 Samsung Electronics Co., Ltd. # http://www.samsung.com/ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. #modify by zth # #################################### if [ -z $2 ] #Check whether the length of the third parameter passed in is 0 then echo "Transmission parameter sequence: ./script.sh <SD Card device> <File to burn>" exit 0 fi if [ -b $1 ] #Check whether the second parameter is a block device then echo "$1 SD The card device is normal!" else echo "$1 SD Card device error!" exit 0 #Exit script fi if [ -e $2 ] #Check the third parameter (that is, whether the file to be burned exists) then echo "$2 File exists." else echo "$2 file does not exist." exit 0 #Exit script fi BDEV_NAME=`basename $1` #Variable assignment -- block device name BDEV_SIZE=`cat /sys/block/${BDEV_NAME}/size` if [ ${BDEV_SIZE} -le 0 ]; then echo "Error: NO media found in card reader." exit 1 fi if [ ${BDEV_SIZE} -gt 32000000 ]; then echo "Error: Block device size (${BDEV_SIZE}) is too large" exit 1 fi E4412_UBOOT=$2 #Assign the file to be burned to the variable E4412_UBOOT MKBL2=./mkbl2 #A mkbl2 file is required under the current path if [ ! -f ${E4412_UBOOT} ]; then #Check whether the file is an ordinary file, not a directory and device file echo "$2 File is not an ordinary file! Please check whether the file is correct!" exit -1 #Exit script file fi if [ ! -f ${MKBL2} ]; then #Check whether the file is an ordinary file, not a directory and device file echo "Missing in current directory mkbl2 File!" exit -1 #Exit script file fi ${MKBL2} ${E4412_UBOOT} bl2.bin 14336 #14K burning program through mkbl2 file. The address is 14336 #./mkbl2 main.bin bl2.bin 14336 #################################### # fusing images signed_bl1_position=1 bl2_position=17 uboot_position=49 tzsw_position=705 #<BL1 fusing> echo "---------------------------------------" echo "BL1 fusing" #Burn command/ xx.sh /dev/sdb main.bin dd iflag=dsync oflag=dsync if=./E4412_N.bl1.bin of=$1 seek=$signed_bl1_position #<BL2 fusing> echo "---------------------------------------" echo "BL2 fusing" #Burn command dd iflag=dsync oflag=dsync if=./bl2.bin of=$1 seek=$bl2_position sync #Output information echo "---------------------------------------" echo "Program burning succeeded!" echo "Please pull it out SD Card, put it into the development board to run!!"