当前位置:网站首页>ARM development (4) How to read the chip manual for novice Xiaobai, bare metal driver development steps and pure assembly to achieve lighting, assembly combined with c lighting, c to achieve lighting
ARM development (4) How to read the chip manual for novice Xiaobai, bare metal driver development steps and pure assembly to achieve lighting, assembly combined with c lighting, c to achieve lighting
2022-08-11 01:56:00 【fly to】
一.How to read the chip manual(datasheet)
as an embedded learner,How to read the chip manual is the top priority.No matter what the chip manual,How hype is written,Its essence is the instruction manual.
可是问题来了,它YThis is the manual in English,But friends who are not good at English should not be too anxious,We now have good translation software,And as long as we read more and read more,Accumulate at a point in the future,Reading the chip manual is no longer a problem for you.
Next, I will use a Samsung chip manual in a vivid image to lead you to read the chip manual together with how to carry out simple driver development,Learn how powerful it is.
二.Bare metal driver development steps
1.When we get a board,If you want to achieve specific functions,The first thing we must think about is to understand what kind of function we want to achieve.(Here, I will take the lighting of lamps that students are annoying to see as an example)
2.Now that we understand that our goal is to light up the lights,Then all we have to do next is find the little light bulb on the board(发光二极管)
如图:
然后我们看到了led【2-5】There are four small bulbs in total
After finding the small light bulb and the name, we officially opened the road to lighting our lights.
Bare metal driver development
(1)看电路图
--1.Find the device I want to control(Take the small light bulb hereled2来举例)
Open our peripheral hardware manual and search in the search barled2
如图
We know from this picture,这是一个npn三极管,The base is connectedcpuside control pinsCHG_COK,由cpuTo perform analog-to-digital conversion to control the high and low potentials,Determines the turn-on and turn-off of the transistor.Here we ignore the already marked onesGPX2_7.
(2)看芯片手册
搜索,The corresponding control module in the circuit diagram,然后如果有coreboardIf so, go there to find the corresponding oneGPX2-7.
看模块的overviewLearn about the approximate functionality of this module.
(3)Look at the control register
What should we do if there are more registers?
See sample programs provided by Technical Support,Find the register that needs to be modified(Often there are only a few).
Some manufacturers provide configuration software,Configure functions through the interface,We just need to use the value of the configured register.
Come to the chip manual,如图所示:
(4)编程
1.A macro that defines the register to be controlled(Corresponds to the register address in the manual)
2.设备初始化(如设置GPIO的输出状态) tips:GPIO就是与cpu相连的引脚
3.Break the functionality into the most basic pieces,逐个实现,如:点亮灯——灭灯——加延时——闪烁——跑马灯
The following code is in thiscpuand implemented on the development board:
cpu:samsung Exynos
开发板: FS4412
三.Pure assembly to achieve lighting
@ GPX2CON 寄存器地址: 0x11000000 + 0x0c40 .text ldr r0, =0x11000c40 @ 将GPX2CONThe register address is moved to r0,那么r0 就代表 GPX2CON ldr r1, [r0] bic r1, #0xf0000000 @ 将 28~31The number bit is cleared orr r1, #0x10000000 @ 28The number bit is set1,The other bits remain unchanged,设置GPX2_7输出功能 str r1, [r0] ldr r0, =0x114001e0 @ 将GPF3CONThe register address is moved to r0 GPF3_4 ldr r1, [r0] @ Get the contents of the address 4字节,相当于取出GPF3CON寄存器的内容 bic r1, #0xf0000 orr r1, #0x10000 str r1, [r0] while: ldr r2, =0x11000c44 @ 将GPX2DATThe address of the register is moved to r2 ldr r3, [r2] orr r3, #0x80 @ 将GPX2DAT的7号位置 1,亮灯 str r3, [r2] ldr r2, =0x114001e4 @ 将GPF3DAT ldr r3, [r2] orr r3, #0x10 @ 将GPF3DAT的4号位置 1,亮灯 str r3, [r2] bl delay_1s ldr r2, =0x11000c44 @ 将GPX2DATThe address of the register is moved to r2 ldr r3, [r2] bic r3, #0x80 str r3, [r2] ldr r2, =0x114001e4 @ 将GPF3DAT ldr r3, [r2] bic r3, #0x10 @ 将GPF3DAT的4号位置 0,灭灯 str r3, [r2] bl delay_1s b while delay_1s: ldr r10, =0x4ffffff loop: cmp r10, #0 subgt r10, #1 bgt loop mov pc, lr .end
makefile
CROSS=arm-linux- CC=gcc LD=ld OC=objcopy all: $(CROSS)$(CC) -c start.s $(CROSS)$(LD) start.o -Ttext 40008000 -o start.elf $(CROSS)$(OC) -O binary -S start.elf start.bin clean: rm *.o *.elf *.bin
四. assemblyc点灯
mian.c 实现延时
> Created Time: 2022年08月10日 星期三 15时43分06秒 ***********************************************************************/ void delay() { int i, j; for(i = 0; i < 10000; i++) for(j = 0; j < 256; j++); } /*******************************end of file*****************************/
@ GPX2CON 寄存器地址: 0x11000000 + 0x0c40 .text ldr r0, =0x11000c40 @ 将GPX2CONThe register address is moved to r0,那么r0 就代表 GPX2CON ldr r1, [r0] bic r1, #0xf0000000 @ 将 28~31The number bit is cleared orr r1, #0x10000000 @ 28The number bit is set1,The other bits remain unchanged,设置GPX2_7输出功能 str r1, [r0] ldr r0, =0x114001e0 @ 将GPF3CONThe register address is moved to r0 GPF3_4 ldr r1, [r0] @ Get the contents of the address 4字节,相当于取出GPF3CON寄存器的内容 bic r1, #0xf0000 orr r1, #0x10000 str r1, [r0] while: ldr r2, =0x11000c44 @ 将GPX2DATThe address of the register is moved to r2 ldr r3, [r2] orr r3, #0x80 @ 将GPX2DAT的7号位置 1,亮灯 str r3, [r2] ldr r2, =0x114001e4 @ 将GPF3DAT ldr r3, [r2] orr r3, #0x10 @ 将GPF3DAT的4号位置 1,亮灯 str r3, [r2] bl delay @ 调用main.c中的delay函数,进行延时 ldr r2, =0x11000c44 @ 将GPX2DATThe address of the register is moved to r2 ldr r3, [r2] bic r3, #0x80 str r3, [r2] ldr r2, =0x114001e4 @ 将GPF3DAT ldr r3, [r2] bic r3, #0x10 @ 将GPF3DAT的4号位置 0,灭灯 str r3, [r2] bl delay @ 调用main.c中的delay函数,进行延时 b while .end
makefile
CROSS=arm-linux- CC=gcc LD=ld OC=objcopy all: $(CROSS)$(CC) -c start.s $(CROSS)$(CC) -c main.c $(CROSS)$(LD) start.o main.o -Ttext 40008000 -o start.elf $(CROSS)$(OC) -O binary -S start.elf start.bin clean: rm *.o *.elf *.bin
五.c实现点灯,This method is what we use the most,Also the easiest
main.c
***********************************************************************/ void delay() { int i, j; for(i = 0; i < 10000; i++) for(j = 0; j < 256; j++); } #define GPX2CON *(volatile unsigned int *)0x11000c40 #define GPX2DAT *(volatile unsigned int *)0x11000c44 void led2_init() { // GPX2CON = GPX2CON & 0x0fffffff | (1 << 28) GPX2CON = GPX2CON & (~(0xf << 28)) | ( 0x1 << 28 ); } void led2_on() { GPX2DAT = GPX2DAT | (1 << 7); } void led2_off() { GPX2DAT = GPX2DAT & (~(1 << 7)); } int main() { led2_init(); while(1){ led2_on(); delay(); led2_off(); delay(); } } /*******************************end of file*****************************/
.text b main .end
makefile
CROSS=arm-linux- CC=gcc LD=ld OC=objcopy all: $(CROSS)$(CC) -c start.s $(CROSS)$(CC) -c main.c $(CROSS)$(LD) start.o main.o -Ttext 40008000 -o start.elf $(CROSS)$(OC) -O binary -S start.elf start.bin clean: rm *.o *.elf *.bin
六.Pure assembly to achieve marquee
@ GPX2CON 寄存器地址: 0x11000000 + 0x0c40 .text ldr r0, =0x11000c40 @ 将GPX2CONThe register address is moved to r0,那么r0 就代表 GPX2CON ldr r1, [r0] bic r1, #0xf0000000 @ 将 28~31The number bit is cleared orr r1, #0x10000000 @ 28The number bit is set1,The other bits remain unchanged,设置GPX2_7输出功能 str r1, [r0] ldr r0,=0x11000c20 ldr r1,[r0] bic r1,#0xf orr r1,#0x1 str r1,[r0] ldr r0, =0x114001e0 @ 将GPF3CONThe register address is moved to r0 GPF3_4 ldr r1, [r0] @ Get the contents of the address 4字节,相当于取出GPF3CON寄存器的内容 bic r1, #0xf0000 orr r1, #0x10000 str r1, [r0] ldr r0,=0x114001E0 ldr r1,[r0] bic r1,#0xf00000 orr r1,#0x100000 str r1,[r0] while: @开灯led2 ldr r2, =0x11000c44 @ 将GPX2DATThe address of the register is moved to r2 ldr r3, [r2] orr r3, #0x80 @ 将GPX2DAT的7号位置 1,亮灯 str r3, [r2] bl delay_1s @开灯led3 ldr r2,=0x11000c24 ldr r3,[r2] orr r3,#0x1 str r3,[r2] bl delay_1s @开灯led4 ldr r2, =0x114001e4 @ 将GPF3DAT ldr r3, [r2] orr r3, #0x10 @ 将GPF3DAT的4号位置 1,亮灯 str r3, [r2] bl delay_1s @开灯led5 ldr r2,=0x114001E4 ldr r3,[r2] orr r3,#0x20 str r3,[r2] bl delay_1s @关灯led2 ldr r2, =0x11000c44 @ 将GPX2DATThe address of the register is moved to r2 ldr r3, [r2] bic r3, #0x80 str r3, [r2] bl delay_1s @关灯led3 ldr r2,=0x11000c24 ldr r3,[r2] bic r3,#0x1 str r3,[r2] bl delay_1s @关灯led4 ldr r2, =0x114001e4 @ 将GPF3DAT ldr r3, [r2] bic r3, #0x10 @ 将GPF3DAT的4号位置 0,灭灯 str r3, [r2] bl delay_1s @关灯led5 ldr r2,=0x114001E4 ldr r3,[r2] bic r3,#0x20 str r3,[r2] bl delay_1s b while delay_1s: ldr r10, =0x4ffffff loop: cmp r10, #0 subgt r10, #1 bgt loop mov pc, lr .end
makefile
CROSS=arm-linux- CC=gcc LD=ld OC=objcopy all: $(CROSS)$(CC) -c start.s $(CROSS)$(LD) start.o -Ttext 40008000 -o start.elf $(CROSS)$(OC) -O binary -S start.elf start.bin clean: rm *.o *.elf *.bin
边栏推荐
- 通过微透镜阵列的传播
- Fatal error in launcher: Unable to create process using xxx --logdir logs(tensorboard使用)
- 22. Inventory service
- 惨遭面试官吊打高并发系统设计,回来学习 2400 小时后成功复仇
- SystemVerilog: Verifying knowledge bits and pieces
- 项目构建工具-Gradle入门
- Experiment record of Shengxin (part3)--scipy.spatial.distance_matrix
- 单面PCB布线阻抗的工程设计
- The concept of services
- 【Video】Report Sharing | 2021 Insurance Industry Digital Insights
猜你喜欢
2022英伟达显卡排名天梯图
漏洞管理计划的未来趋势
SyntaxError: invalid syntax
最新国产电源厂家及具体型号pin-to-pin替代手册发布
联盛德W801系列6-从微信小程序的角度来分析W801的蓝牙通信源码(indicate方式)
划分字母区间[贪心->空间换时间->数组hash优化]
通过微透镜阵列的传播
The statistical data analysis, interview manual"
Is container technology really the savior of environmental management?
【oops-framework】模板项目【oops-game-kit】使用简介
随机推荐
生信实验记录(part2)--tf.reduce_sum()用法介绍
《QA离业务代码能有多近?》轻量级单元测试方案
安装dlib库
How to convert url to obj or obj to url
络达开发---UI定义+自定义按钮事件
#yyds Dry Goods Inventory#[Yugong Series] August 2022 Go Teaching Course 008-Integer of Data Types
最新国产电源厂家及具体型号pin-to-pin替代手册发布
ora-00001违反唯一约束
软件测试面试题:缺陷等级应如何划分?
MySQL - 一条SQL在MySQL中是如何被执行的?
软件测试面试题:什么是数据的对立性,有几个层次?
软件测试面试题:性能测试工作?
C # - delegate detailed usage
0图中等 LeetCode565. 数组嵌套
Vim take on a window.
阿里亿级并发册 + 机器学习算法 + 面试册 + 优化册 + 代码册 笔记!!!
WinForm (5) control and its members
微服务概念
Update chromedriver driver programming skills │ selenium
FPGA学习专栏-串口通信(xinlinx)