当前位置:网站首页>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++6
download 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 :
边栏推荐
- Deep dive kotlin synergy (XXI): flow life cycle function
- Jarvis OJ shell流量分析
- Fleet tutorial 09 basic introduction to navigationrail (tutorial includes source code)
- File operation --i/o
- What else do you not know about new map()
- 【beanshell】数据写入本地多种方法
- PHP talent recruitment system development source code recruitment website source code secondary development
- Flet tutorial 12 stack overlapping to build a basic introduction to graphic and text mixing (tutorial includes source code)
- 【性能测试】全链路压测
- 如何安装mysql
猜你喜欢
精准防疫有“利器”| 芯讯通助力数字哨兵护航复市
PHP talent recruitment system development source code recruitment website source code secondary development
[brush questions] effective Sudoku
Learnopongl notes (II) - Lighting
China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users
Benji Banas membership pass holders' second quarter reward activities update list
干货!半监督预训练对话模型 SPACE
Jarvis OJ shell traffic analysis
Use JDBC technology and MySQL database management system to realize the function of course management, including adding, modifying, querying and deleting course information.
解决CMakeList find_package找不到Qt5,找不到ECM
随机推荐
【组队 PK 赛】本周任务已开启 | 答题挑战,夯实商品详情知识
File operation --i/o
Iphone14 with pill screen may trigger a rush for Chinese consumers
Detailed explanation of use scenarios and functions of polar coordinate sector diagram
中国广电正式推出5G服务,中国移动赶紧推出免费服务挽留用户
Use byte stream to read Chinese from file to console display
Jarvis OJ 远程登录协议
机器学习编译第2讲:张量程序抽象
Global Data Center released DC brain system, enabling intelligent operation and management through science and technology
Solve cmakelist find_ Package cannot find Qt5, ECM cannot be found
Enter a command with the keyboard
Benji Banas membership pass holders' second quarter reward activities update list
【刷題篇】鹅廠文化衫問題
【刷题篇】有效的数独
[team PK competition] the task of this week has been opened | question answering challenge to consolidate the knowledge of commodity details
【 brosser le titre 】 chemise culturelle de l'usine d'oies
China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users
Jarvis OJ Flag
飞桨EasyDL实操范例:工业零件划痕自动识别
Summary of PHP pseudo protocol of cisp-pte