当前位置:网站首页>Embedded -arm (bare board development) -2
Embedded -arm (bare board development) -2
2022-07-05 17:04:00 【Orange peel does not stop school】
One 、LED drive
1. For example, we need to control a LED On and off , According to this circuit diagram , We can know , Give Way LED1 On or off is the control wire GPIOC12 Low on / High level .

2. And find GPIOC12 and CPU Connected pins , It can be further understood as , control LED1 On or off , In fact, it is control CPU W15 Pin output low / High level .

3. In the data book , We learned that ,W15 If the pin wants to control GPIOC12 Pin , Need to switch to function 1 Can only be .

4. How to switch functions , You need to check the GPIOxALTFUN0 This table (x On behalf of all kinds of GPIO type , such as A、B、C、D、E), We can see ,GPIOC12 The occupied bit is 24 And the 25 position , By changing the bits of these two bits , To achieve the effect of switching functions .

5. How can I know this GPIO Is it input or output mode , You need to check the following table , Then do the corresponding bit operation , We see , Each type has 32 position , So we can know , Need to put C Group No 12 Location 1, Because I want you to GPIOC12 Output .

6. After configuring the I / O mode , We also need to specify whether the output is high level or low level , Used to decide LED On and off .

namely :
GPIOCALTFN0 0xc001c020
take [25:24] Configure to 01, take W15 The pins are configured to function 1 (GPIO)
GPIOCOUTENB 0xc001c004
[12] Configure to 1, take W15 The pin is further configured to output mode
GPIOCOUT 0xc001c000
[12] To configure 0/1 representative W15 Low output / High level
Two 、 Code writing
1. First review the pointer
int i = 0;
&i: take i The first address of the variable
*(&i) = 100;// i=100
So the operations on addresses we learned today can be equivalent to :
constant : 0xc001c020
Address : (int *)0xc001c020
visit : *((int *)0xc001c020)
Standard writing for accessing special function registers :
*((volatile unsigned int *)0xc001c020)
2. Bit operation
Principles for operating special function registers : Change only relevant bit, Other bit Keep the original value unchanged
The wrong sample :
// FALSE Change the functions of other pins to functions 0
*((volatile unsigned int *)0xc001c020) = 0x01000000;
// Yes BUG If bit25 It turned out to be 1
*((volatile unsigned int *)0xc001c020) |= 0x01000000;
The correct sample :
*((volatile unsigned int *)0xc001c020) &= 0xfcffffff;
*((volatile unsigned int *)0xc001c020) |= 0x01000000;
Standard writing :
*((volatile unsigned int *)0xc001c020) &= ~(3<<24);
*((volatile unsigned int *)0xc001c020) |= (1<<24);
The actual code is as follows :

But at this time, it is only finished .c Compilation of documents , Links cannot be compiled directly and are used by development boards .
Because in the current PC Next ,x86 Of CPU Next , Compile the program directly , A program that can run ( Or library files ), It can be directly in the current environment , namely x86 Of CPU Next , The current computer is running . But we will ARM Of CPU Run under , You can't do this directly , Need to be in x86 On the platform ,( With the cross compiler ) To compile the code you have written , Compile generated ( The executable ) Program , It is put on the target development board ,arm Of CPU Running on . So called : stay x86 Compile on platform , stay ARM Run on the platform .
3、 ... and 、 Cross compilation
1. Why cross compile
The reason for cross compilation , The main reason is : There are too few resources in the embedded system . The specific explanation is : Cross compiled programs , In the target environment to run , Various resources , Are relatively limited , So it is difficult to compile directly locally .
2. Construction of cross compilation environment
because ARM yes 32 position , And I used Ubuntu yes 64 Bit , So install 32 Bit Library .
sudo apt-get install lib32ncurses5 lib32z1 lib32stdc++6download ARM-Linux GCC 4.4.3
I use what is provided by friendly Electronics
Guangzhou Youyi Electronic Technology Co., Ltd (arm9.net)
http://www.arm9.net/download.asp
Create your own folder , Used to store downloaded compressed packages , And extract the :
tar xf arm-cortex_a9-eabi-4.7-eglibc-2.18.tar.gz
Add to environment variables :
vi ~/.bashrc
Add
export PATH=$PATH:/opt/arm-cortex_a9-eabi-4.7-eglibc-2.18/bin/
Immediate effect environment variable ( You can also close the window , Open it again )
source ~/.bashrc
Check out the version , Check that the installation was successful :
arm-linux-gcc -v
A similar interface means success :

3. Compile operation
arm-none-linux-gnueabi-gcc -c -nostdlib led.c -o led.o
arm-none-linux-gnueabi-ld -nostdlib -nostartfiles -Ttext=0x48000000 -eled_test led.o -o led
arm-none-linux-gnueabi-objcopy -O binary led led.bin
The above knowledge points involved in the compilation process
-nostdlib: compile Standard library files are not used in the linking process
-nostartfiles: Link use without adding standard startup code
-Ttext=0x48000000: Specify the starting link address of the code segment , The link address and running address should be consistent , Otherwise, the program is likely to run away .
-e: Specify the entry point .( The entry point found by the default linker is _start function )
arm-cortex_a9-linux-gnueabi-objcopy: be stripped ELF Additional information in
Run the code in the target board :cp led.bin /tftpboot/
Execute... On the development board ( A serial port ):
tftp 48000000 led.bin
go 48000000

After running the command , Of the board LED The light will start flashing :

边栏推荐
猜你喜欢

Machine learning compilation lesson 2: tensor program abstraction

ECU introduction

PHP人才招聘系统开发 源代码 招聘网站源码二次开发

Deep dive kotlin synergy (XXI): flow life cycle function

Deeply cultivate 5g, and smart core continues to promote 5g applications

Use JDBC technology and MySQL database management system to realize the function of course management, including adding, modifying, querying and deleting course information.

Jarvis OJ Webshell分析

Summary of methods for finding intersection of ordered linked list sets

如何将mysql卸载干净

PHP talent recruitment system development source code recruitment website source code secondary development
随机推荐
Cs231n notes (bottom) - applicable to 0 Foundation
Raspberry pie 4B installation pytorch1.11
Twig数组合并的写法
[brush title] goose factory shirt problem
Jarvis OJ 远程登录协议
采用药丸屏的iPhone14或引发中国消费者的热烈抢购
【微信小程序】一文读懂小程序的生命周期和路由跳转
Games101 notes (I)
Jarvis OJ Flag
Iphone14 with pill screen may trigger a rush for Chinese consumers
Binary tree related OJ problems
Little knowledge about C language (array and string)
Application of threshold homomorphic encryption in privacy Computing: Interpretation
Wsl2.0 installation
How to install MySQL
Allusions of King Xuan of Qi Dynasty
WR | 西湖大学鞠峰组揭示微塑料污染对人工湿地菌群与脱氮功能的影响
【剑指 Offer】61. 扑克牌中的顺子
Etcd 构建高可用Etcd集群
[61dctf]fm