(exynos4412) Tiny4412 bare metal development - lighting up LED lights

1 Introduction

Tiny4412 development is an Android and Linux learning development board launched by Friendly Arm. The CPU adopts Samsung's EXYNOS4412, a 32-bit chip, belonging to the Cortex-A series, with a main frequency of 1.5GHZ, and can run ubuntu, Android5.0, pure Linux and other operating systems .

This article introduces the use of this development board to complete bare metal development, without involving the operating system, directly as a microcontroller, 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:

image-20220124143413952

The following is a physical map of the development board:

image-20220124143157723

Development board configuration:

image-20220124143510661

2. Build a cross-compilation environment

Before performing bare metal programming, you need to build a cross-compilation environment and install the arm-linux-gcc cross-compiler, so that the cross-compiled program can run on the development board.

What is cross compilation? PC compilation and running on the embedded development board are called cross compilation.

The cross compiler is provided in the CD-ROM of the development board, which can be directly copied to the PC to decompress under Linux, and configure the environment variable interface.

The detailed operation steps are as follows:

1.	在Linux用户目录下创建一个目录:  mkdir work/arm-linux-gcc -p

2.	将交叉编译器拷贝到Linux系统共享目录。再解压到arm-linux-gcc目录下。
tar xvf arm-linux-gcc-4.5.1-v6-vfp-20120301.tgz -C /home/wbyq/work/arm-linux-gcc/

3.	添加系统环境变量
 (1). root用户: 需要将代码写在/etc/profile文件中
 (2). 普通用户: 需要将代码写在 用户目录下的.bash_profile文件中
profile文件系统上电的时候会自动执行。
添加环境变量的命令:
export PATH=/home/wbyq/work/arm-linux-gcc/opt/FriendlyARM/toolschain/4.5.1/bin:$PATH
参数:
export  导出--全局声明
PATH  系统环境变量的名称. 作用: 保存Linux系统可执行文件的搜索路径.

输出环境变量的值:
[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
参数:
LD_LIBRARY_PATH 系统环境变量的名称. 作用: 保存Linux系统动态库的搜索路径. xxx.so

4.	生效环境变量
(1). 立即生效:  当前终端有效
[wbyq@wbyq ~]$ source .bash_profile 
(2). 退出用户、重新登录系统,实现永久生效

5.	测试交叉编译器. 学习基本用法

[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 light

If you have studied single-chip (51, STM32, MSP430, AVR, etc.) programming, 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. 查看原理图

2. 配置GPIO口  

3. 控制GPIO口输出电平控制LED

4. 编译程序:
xxx.lds 链接文件
设备: 字符设备、块设备、网络设备
SD卡设备: /dev/sdb
查看块大小: cat /sys/block/sdb/size    单位是块(1块512字节)

5. 烧写到开发板测试
dd iflag=dsync oflag=dsync if=./E4412_N.bl1.bin of=/dev/sdb seek=1
参数:
if=./E4412_N.bl1.bin  要写到SD卡上的文件
of=/dev/sdb   SD卡设备
seek=1  跳过的块.  一个块==512字节

执行烧写命令:
[wbyq@wbyq sd_fuse]$ sudo ./sd_write.sh /dev/sdb ../main.bin 

(1) Check the schematic diagram to find the wiring position of the LED

The tiny4412 development board is designed in two layers, a core board and a bottom board. The LED lights are soldered on the core board, and the schematic diagram has to open the core board.

image-20220124144707586

image-20220124144724303

(2) Check the chip manual to understand how the GPIO port is configured

image-20220124144846728

The configuration method is also well understood, and it is described in detail in the manual. LED is an output control device, and the GPIO port needs to be configured as output mode.

The mode configuration of the GPIO is done by the CON register, and the output control is done by the DAT register.

image-20220124144957228

(3) write code

/* LED的寄存器  GPM4_0 1 2 3*/
#define GPM4CON     (*(volatile unsigned int *)0x110002E0)
#define GPM4DAT     (*(volatile unsigned int *)0x110002E4)

int main(void)
{
    
    
	/*配置GPIO口模式--配置LED灯*/
	GPM4CON&=0xFFFF0000;
	GPM4CON|=0x00001111;

	/*3. 配置GPIO口模式--配置按键*/
	GPX3CON&=0xFF0000FF;

    GPM4DAT&=~(1<<0);
    GPM4DAT&=~(1<<1);
	GPM4DAT&=~(1<<2);
    GPM4DAT&=~(1<<3);
    while(1)
    {
    
    
        
    }
    return 0;
}

(4) Makefile writing

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 programming 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 ]  #检查传入的第三个参数长度是否为 0
then
    echo "传参数顺序: ./脚本.sh  <SD卡设备>  <要烧录的文件>"
    exit 0
fi

if [ -b $1 ]   #检查第二个参数是否是块设备
then
    echo "$1 SD卡设备正常!"
else
    echo "$1 SD卡设备错误!"
    exit 0   #退出脚本
fi

if [ -e $2 ]   #检查第三个参数(就是要烧录的文件是否存在)
then
    echo "$2 文件存在."
else
    echo "$2 文件不存在."
    exit 0    #退出脚本
fi


BDEV_NAME=`basename $1`   #变量赋值--块设备名称
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 #将要烧录文件赋值给变量E4412_UBOOT
MKBL2=./mkbl2  #需要当前路径下有一个mkbl2文件


if [ ! -f ${E4412_UBOOT} ]; then  #检测文件是否是普通文件,非目录和设备文件
	echo "$2 文件非普通文件!请检查文件是否正确!"
	exit -1  #退出脚本文件
fi

if [ ! -f ${MKBL2} ]; then       #检测文件是否是普通文件,非目录和设备文件
	echo "当前目录下缺少 mkbl2 文件!"
	exit -1 #退出脚本文件
fi

${MKBL2} ${E4412_UBOOT} bl2.bin 14336    #14K 通过mkbl2文件烧录程序 地址是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"

#烧录命令 ./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"
#烧录命令
dd iflag=dsync oflag=dsync if=./bl2.bin of=$1 seek=$bl2_position

sync


#输出信息
echo "---------------------------------------"
echo "程序烧录成功!"
echo "请拔出SD卡,放入开发板运行!!"

Guess you like

Origin blog.csdn.net/xiaolong1126626497/article/details/123162252