[Beijing Xunwei] i.MX6ULL Terminator LED Assembler

According to the previous introduction, we need to make the following settings for GPIO1_IO03:
1. Enable the clock of
GPIO1. The clock of GPIO1 is controlled by bits 27 and 26 of the CCM_CCGR1 register. If we set these two bits to 1, the clock of GPIO1 will be enabled. .

2. Configure the multiplexing function of
GPIO1_IO03. The IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO03 register is the multiplexing register of GPIO1_IO03. The address is 0x20e0068. Set this register as a GPIO function.

3. Configure GPIO1_IO03 pull-up and pull-down
IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO03 register is the configuration register of GPIO1_IO03, configure GPIO1_IO03 as the pull-up and pull-down of GPIO through this register.

4. Set GPIO1_IO03 output

In the second step, we have multiplexed GPIO1_IO03 into GPIO, and then we need to configure GPIO as output, as well as the high and low levels of output. On page 1357 of the "IMX6ULL Reference Manual" we can see the GPIO register group corresponding to GPIO1_IO03, As shown in Figure 1:
Insert picture description here

figure 1

By setting bit3 of register GPIO1_GDIR to 1, GPIO1_IO03 can be set as output. Then by setting bit3 of the GPIO1_DR register to 0, you can control GPIO1_IO03 to output low level, and the LED will light up. Bit3 of GPIO1_DR is set to 1, which can control GPIO1_IO03 to output high level, and the LED will be off.

The source code of this experiment is in the "i.MX6UL Terminator CD-ROM data\04_bare-metal routine source code\1_leds\1_leds" in the CD-ROM of the development board. We can copy this folder to UBuntu and compile it with a cross-compiler.

Let's start to implement the LED experiment step by step. First log in to the Ubuntu system, create an led folder in the work folder under the user's root directory, and then create a new assembly file "led.s" under the led directory, as shown in Figure 2:
Insert picture description here

figure 2

Then use the "vi led.s" command to open the led.s file, and enter the following code in the led.s file:

1	.global _start  /* 全局标号 */                                     

2	/*                                                          
3	 * 	_start函数,程序从此函数开始执行此函数完成时钟使能、              
4	 *	GPIO初始化、最终控制GPIO输出低电平来点亮LED灯。               
5	 */                                                             
6	_start:                                                       
7		/* 1、使能所有时钟 */                                        
8		ldr r0, =0X020C4068 	/* CCGR0 */                   
9		ldr r1, =0XFFFFFFFF                                 
10		str r1, [r0]		                                        
	                                                                                  
11		ldr r0, =0X020C406C  	/* CCGR1 */                                                
12		str r1, [r0]                                                                    
                                                                                        
13		ldr r0, =0X020C4070  	/* CCGR2 */                                                   
14		str r1, [r0]                                                                        
	                                                                                    
15		ldr r0, =0X020C4074  	/* CCGR3 */                                               
16		str r1, [r0]                                                                     
	                                                                                    
17		ldr r0, =0X020C4078  	/* CCGR4 */                                                 
18		str r1, [r0]                                                                      
	                                                                                 
19		ldr r0, =0X020C407C  	/* CCGR5 */                                                 
20		str r1, [r0]                                                                       
	                                                                                   
21		ldr r0, =0X020C4080  	/* CCGR6 */                                                 
22		str r1, [r0]                                                                      
	                                                                                
                                                                                        
23		/* 设置GPIO1_IO03为GPIO模式 */                                                    
24		ldr r0, =0X020E0068	/* 把寄存器SW_MUX_GPIO1_IO03_BASE加载到r0中 */                   
25		ldr r1, =0X5	/* 设置寄存器SW_MUX_GPIO1_IO03_BASE的MUX_MODE为5 */             
26		str r1,[r0]                                                                         
                                                                                       
27		/* 配置GPIO1_IO03的IO属性	                                                        
28		 		*bit 16:0 HYS关闭                                                         
29		 		*bit [15:14]: 00 默认下拉                                                  
30	     	*bit [13]: 0 kepper功能                                                       
31	     	*bit [12]: 1 pull/keeper使能                                                    
32	     	*bit [11]: 0 关闭开路输出                                                      
33	     	*bit [7:6]: 10 速度100Mhz                                                   
34	     	*bit [5:3]: 110 R0/6驱动能力                                                 
35	     	*bit [0]: 0 低转换率                                                          
36	   */                                                                                
37	    ldr r0, =0X020E02F4	/*寄存器SW_PAD_GPIO1_IO03_BASE */          
38	    ldr r1, =0X10B0                                                                    
39	    str r1,[r0]                                                                       

40		/* 设置GPIO1_IO03为输出 */                                                        
41	    ldr r0, =0X0209C004	/*寄存器GPIO1_GDIR */                                       
42	    ldr r1, =0X0000008		                                                         
43	    str r1,[r0]                                                                     
                                                                                      
44		/* 点亮LED0                                                                     
45		 * 设置GPIO1_IO03输出低电平                                                      
46		 */                                                                                 
47		ldr r0, =0X0209C000	/*寄存器GPIO1_DR */                                       
48	   	ldr r1, =0		                                                                 
49	   	str r1,[r0]                                                                            
                                                                     
50	/*                                                                
51	 * 描述:	loop死循环                                        
52	 */                                                                
53	loop:                                                 
54		b loop 				                                              

In line 2, we define the global label _start, and the program is executed sequentially from the _start label.
Line 8 uses ldr to write 0x020c4068 to register r0, which is the register address of CCM_CCGR0.
Line 9 uses ldr to write 0xffffffff to register r1 to turn on the clocks of all peripherals.
Line 10 uses the str command to write the value in r1 to the address saved in r0, which is equivalent to writing 0xffffffff to the address 0x20c4068, that is, setting the CCM_CCGR0 register to 0xffffffff, enabling all peripheral clocks controlled by the CCM_CCGR0 register.
From line 11 to line 22, write 0xffffffff to the CCM_CCGR1-CCM_CCGR6 register to enable all peripheral clocks.
Lines 24 to 26 are to set the IO of GPIO1_IO03 to GPIO mode. The multiplexing register of GPIO1_IO03 is 0x20e0068. Set the MUX_MODE of this register to 5 (GPIO mode)
. Lines 37 to 39 set the IOMUX_SW_PAD_CTL_PAD_GPIO1_IO03 configuration register of GPIO1_IO03
. Line 40 to line 43 is to set GPIO as output function.
The 47th to 49th is to set GPIO output 0 (low level)
. The 53rd to 54th lines are infinite loops. Using the b jump instruction, the program continuously jumps to loop execution.

Insert picture description here

Guess you like

Origin blog.csdn.net/BeiJingXunWei/article/details/108545107