IMX6ULL -- assembly led

assemble led

1. Schematic diagram

Schematic part:

 

 

It can be seen that DS0 is a light emitting diode, when LED0 is low, DS0 is on.

LED0 connected to GPIO1_IO3

GPIO IO initialization process:

1. Enable the GPIO clock. According to the imx6ull data sheet, it can be seen that CCGR0-CCGR7 has enabled the clocks of all peripherals. You can set all these 7 registers to 0xffffffff, which is equivalent to enabling all peripherals. CCM_CCRG: clock control module_clock gating register

2. Set the IO service, multiplex the register IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO03 as GPIO, and set bit0-bit3 to 0101

3. Configure the electrical properties of GPIO, IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO03 set the electrical properties

Including slew rate, speed, driving capability, open drain, pull-up and pull-down, etc.

4. Configure the GPIO function and set the input and output. Set GPIO1_DR register bit3 to 1, that is, set to output mode, bit3 is 1 for high level, and 0 for output low level

Two, GNU assembly syntax

The default entry label of the assembler is _start, but we can also use ENTRY in the link script to indicate other

The entry point, the following code is to use _start as the entry label:

.global _start      // 全局标号
_start: 
    ldr r0, =0x12 @r0=0x12

1. LDR command

LDR is mainly used to load data from storage to register Rx,

LDR can also load an immediate value into register Rx

In , LDR should use "=" instead of "#" when loading immediate data. In embedded development, the most commonly used LDR is to read

Take the CPU register value, for example, I.MX6UL has a register GPIO1_GDIR, its address is 0X0209C004, we

Now to read the data in this register, the sample code is as follows:

Example code 7.2.2.1 LDR instruction use

LDR R0, =0X0209C004 @将寄存器地址 0X0209C004 加载到 R0 中,即 R0=0X0209C004 
LDR R1, [R0] @读取地址 0X0209C004 中的数据到 R1 寄存器中 

The above code is to read the value in the register GPIO1_GDIR, and the read register value is saved in the R1 register.

The offset in the above code is 0, that is, the offset is not used.

R0-R7: Because the ARM instruction cannot directly read the data in the RAM, it is necessary to use registers such as R0

2. STR command

LDR is to read data from the memory, STR is to write data into the memory, also with I.MX6UL register

Take GPIO1_GDIR as an example, now we need to configure the value of the register GPIO1_GDIR to 0X20000002, the sample code is as follows:

Sample code 7.2.2.2 STR instruction use

LDR R0, =0X0209C004 @将寄存器地址 0X0209C004 加载到 R0 中,即 R0=0X0209C004 
LDR R1, =0X20000002 @R1 保存要写入到寄存器的值,即 R1=0X20000002 
STR R1, [R0] @将 R1 中的值写入到 R0 中所保存的地址中 

Both LDR and STR are read and written according to words, that is, 32-bit data to be operated. If you want to read and write according to bytes,

For half-word operations, you can add B or H after the instruction "LDR". For example, the instructions for byte operations are LDRB and

STRB, the half-word instructions are LDRH and STRH.

3. Assembly code

.global _start  /* 全局标号 */

/*
 * 描述:       _start函数,程序从此函数开始执行此函数完成时钟使能、
 *                GPIO初始化、最终控制GPIO输出低电平来点亮LED灯。
 */
_start:
        /* 例程代码 */
        /* 1、使能所有时钟 */
        ldr r0, =0X020C4068     /* CCGR0 */
        ldr r1, =0XFFFFFFFF
        str r1, [r0]

        ldr r0, =0X020C406C     /* CCGR1 */
        str r1, [r0]

        ldr r0, =0X020C4070     /* CCGR2 */
        str r1, [r0]

        ldr r0, =0X020C4074     /* CCGR3 */
        str r1, [r0]

        ldr r0, =0X020C4078     /* CCGR4 */
        str r1, [r0]

        ldr r0, =0X020C407C     /* CCGR5 */
        str r1, [r0]

        ldr r0, =0X020C4080     /* CCGR6 */
        str r1, [r0]


        /* 2、设置GPIO1_IO03复用为GPIO1_IO03 */
        ldr r0, =0X020E0068     /* 将寄存器SW_MUX_GPIO1_IO03_BASE加载到r0中 */
        ldr r1, =0X5            /* 设置寄存器SW_MUX_GPIO1_IO03_BASE的MUX_MODE为5 */
        str r1,[r0]

        /* 3、配置GPIO1_IO03的IO属性
         *bit 16:0 HYS关闭
         *bit [15:14]: 00 默认下拉
     *bit [13]: 0 kepper功能
     *bit [12]: 1 pull/keeper使能
     *bit [11]: 0 关闭开路输出
     *bit [7:6]: 10 速度100Mhz
     *bit [5:3]: 110 R0/6驱动能力
     *bit [0]: 0 低转换率
     */
    ldr r0, =0X020E02F4 /*寄存器SW_PAD_GPIO1_IO03_BASE */
    ldr r1, =0X10B0
    str r1,[r0]

        /* 4、设置GPIO1_IO03为输出 */
    ldr r0, =0X0209C004 /*寄存器GPIO1_GDIR */
    ldr r1, =0X0000008
    str r1,[r0]

        /* 5、打开LED0
         * 设置GPIO1_IO03输出低电平
         */
        ldr r0, =0X0209C000     /*寄存器GPIO1_DR */
   ldr r1, =0
   str r1,[r0]

/*
 * 描述:       loop死循环
 */
loop:
        b loop

4. Compiler

  1. Use arm-linux-gnueabihf-gcc to turn .c .s files into .o files

  2. Link all .o files into executable files in elf format. The link is to link all .o files together and link to the specified place

  3. Convert elf file to bin file for easy burning

When linking, you need to specify the link starting address, which is the starting address of the code running

For imx6ull, link start address should point to RAM address. RAM is divided into internal RAM and external RAM, that is, DDR. The internal RAM address of imx6ull is 0x900000-0x91ffff, and it can also be placed in external DDR. For the alpha512 byte development board, the DDR range is 0x80000000-0x9fffffff. To use DDR, DDR must be initialized. For IMX, the bin file cannot be run directly. A header needs to be added. This header information contains the initialization parameters of DDR. The internal boot rom of the IMX series SOC will be downloaded from the SD card, EMMC, etc. Read the header information in the storage, then initialize the DDR, and copy the bin file to the link address.

The running address of the bin file must be consistent with the starting address of the link, except for position-independent code

4. Burn the bin file

imx6ull supports SD card, EMMC, NAND, nor, spi flash, etc. to boot. Bare metal routines choose to burn to SD card

Burn the bare metal bin file to the SD card under ubuntu. Burning is not to copy the bin file to the SD card, but to burn the bin file to the absolute path of the SD card, you need to use the imxdownload tool

imxdownload will add a header to led.bin and generate a new load.imx file. This load.imx file is finally burned into the SD card

Guess you like

Origin blog.csdn.net/qq_58550520/article/details/132398772