当前位置:网站首页>1. Mx6u bare metal program (1) - Lighting master

1. Mx6u bare metal program (1) - Lighting master

2022-06-23 01:48:00 Chongyou research Sen

Workflow :

1. Configuration environment

2. Ready to file

3. Compile

4. Burn to the board

5. Observe the phenomenon


This experimental document :main.c   main.h    Makefile   start.s      imx6ul.lds Link script


main.h The code is as follows :

#ifndef _MAIN_H
#define _MAIN_H

/*
 * CCM  Related register address 
*/
#define CCM_CCGR0 *((volatile unsigned int *)0X020C4068)
#define CCM_CCGR1 *((volatile unsigned int *)0X020C406C)
#define CCM_CCGR2 *((volatile unsigned int *)0X020C4070)
#define CCM_CCGR3 *((volatile unsigned int *)0X020C4074)
#define CCM_CCGR4 *((volatile unsigned int *)0X020C4078)
#define CCM_CCGR5 *((volatile unsigned int *)0X020C407C)
#define CCM_CCGR6 *((volatile unsigned int *)0X020C4080)

/* 
* IOMUX  Related register address 
*/
#define SW_MUX_GPIO1_IO03 *((volatile unsigned int *)0X020E0068)
#define SW_PAD_GPIO1_IO03 *((volatile unsigned int *)0X020E02F4)

/* 
* GPIO1  Related register address 
*/
#define GPIO1_DR *((volatile unsigned int *)0X0209C000)
#define GPIO1_GDIR *((volatile unsigned int *)0X0209C004)
#define GPIO1_PSR *((volatile unsigned int *)0X0209C008)
#define GPIO1_ICR1 *((volatile unsigned int *)0X0209C00C)
#define GPIO1_ICR2 *((volatile unsigned int *)0X0209C010)
#define GPIO1_IMR *((volatile unsigned int *)0X0209C014)
#define GPIO1_ISR *((volatile unsigned int *)0X0209C018)
#define GPIO1_EDGE_SEL *((volatile unsigned int *)0X0209C01C)



#endif

main.c The code is as follows :

#include "main.h"

// Enable all peripheral clocks 
void clk_enable(void)
{
    CCM_CCGR0 = 0xffffffff;
    CCM_CCGR1 = 0xffffffff;
    CCM_CCGR2 = 0xffffffff;
    CCM_CCGR3 = 0xffffffff;
    CCM_CCGR4 = 0xffffffff;
    CCM_CCGR5 = 0xffffffff;
    CCM_CCGR6 = 0xffffffff;
}

// initialization LED Of GPIO
void led_init(void)
{
    SW_MUX_GPIO1_IO03 = 0x5;// initialization IO complex GPIO_IO0303   
    SW_PAD_GPIO1_IO03 = 0X10B0; // To configure GPIO_Io03 Properties of 
    GPIO1_GDIR = 0X0000008;// initialization GPOIO,GPIO_IO03 For output mode 
    GPIO1_DR = 0X0;// Set up IO The mouth is low potential , open led
}

// open LED The lamp 
void led_on(void)
{
    GPIO1_DR &= ~(1<<3);
}

// close LED
void led_off(void)
{
    GPIO1_DR |= (1<<3);
}

// Short time delay function 
void delay_short(volatile unsigned int n)
{
    while(n--){}
}
//1ms The time delay function 
void delay(volatile unsigned int n)
{
    while(n--)
        {
            delay_short(0x7ff);
        }
}


int main(void)
{
    clk_enable(); /*  Enable all clocks  */
    led_init(); /*  initialization  led */
    while(1) /*  Dead cycle  */
    { 
        led_off(); /*  close  LED */
        delay(500); /*  The delay is about  500ms */
        led_on(); /*  open  LED */
        delay(500); /*  The delay is about  500ms */
    }
    return 0;
}

Makefile The code is as follows :

objs := start.o main.o
 
ledc.bin:$(objs)
    arm-linux-gnueabihf-ld -Timx6ul.lds -o ledc.elf $^
    arm-linux-gnueabihf-objcopy -O binary -S ledc.elf [email protected]
    arm-linux-gnueabihf-objdump -D -m arm ledc.elf > ledc.dis

%.o:%.s
    arm-linux-gnueabihf-gcc -Wall -nostdlib -c -o [email protected] $<
 
%.o:%.S
    arm-linux-gnueabihf-gcc -Wall -nostdlib -c -o [email protected] $<
 
%.o:%.c
    arm-linux-gnueabihf-gcc -Wall -nostdlib -c -o [email protected] $<
 
clean:
    rm -rf *.o ledc.bin ledc.elf ledc.dis

start.s The code is as follows :

.global _start 

_start:

    mrs r0, cpsr
    bic r0, r0, #0x1f /*  take  r0  It's low  5  A reset , That is to say  cpsr  Of  M0~M4 */
    orr r0, r0, #0x13 
    msr cpsr, r0 /*  take  r0  Data written to  cpsr_c  in  */

    ldr sp, =0X80200000 /*  Set the stack pointer  */
    b main 

  imx6ul.lds The code is as follows ( For link addresses )

SECTIONS{
    . = 0X87800000;
    .text :
    {
        start.o 
        main.o 
        *(.text)
    }
    .rodata ALIGN(4) : {*(.rodata*)} 
    .data ALIGN(4) : { *(.data) } 
    __bss_start = .; 
    .bss ALIGN(4) : { *(.bss) *(COMMON) } 
    __bss_end = .;
    }

Code reading :main.h

Through the parameter manual , Find the address of each register , First of all (1) The clock ,(2) Reuse settings (3) Feature set (4)DR Set up (5)GDIR Set up

The clock : Turn on the peripheral clock .

Reuse settings : Reuse this pin as GPIO Or other types of

Feature set : set speed , Pull down and other functions

DR Set up : Set up GPIO Oral potential

GDIR Set up : Set up GPIO Port input or output

Code reading :main.c

clk_enable: Turn on all clocks

led_init: Inside GDIR yes 0X00000008 Because this experiment is 3 mouth , amount to (0123) Decimal corresponds to (0001) Binary system , So it is 8

led_on: Set up DR The low potential is & Take the opposite , High potential is | No negation

Code reading :Makefile

$^: A collection of all dependent files , That is to say objs The value of the variable

[email protected]: Target file collection , That is to say led.bin

$<: The first file that depends on the file

Code reading : Compile the script

. = 0x0000000  Put the address 0x000000 to .

.text:{}    Put the things in curly braces in .text paragraph

*(.text) Representing all input files .text Put all the paragraphs in .text in

ALIGN(4) Indicates progress 4 Byte alignment  


Compile : Get burn file led.bin

Burn to the board :

  functional verification :

Twinkle, twinkle, crystal ( Not at all ),LED Press 0.5m flashing

matters needing attention :Makefile Indentation may be a problem !!!


The experiment is over

原网站

版权声明
本文为[Chongyou research Sen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202220512168709.html