当前位置:网站首页>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)
#endifmain.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.disstart.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
边栏推荐
- SQL programming task04 job - set operation
- 崔鹏团队:万字长文梳理「稳定学习」全景图
- Time complexity
- Debian10 configuring rsyslog+loganalyzer log server
- Game (sanziqi & minesweeping)
- Foundation Consolidation - Flex width is content width
- 魔王冷饭||#099 魔王说西游;老板的本质;再答中年危机;专业选择
- JS prototype and prototype chain Paramecium can understand
- [cmake command notes]find_ path
- Random decoding NLP
猜你喜欢

SQL programming task03 job - more complex query

4. functions and inline functions with default values for formal parameters

Network module packaging

Module 8 job

Epoll introduction and principle explanation

Questions not written in the monthly contest

Error reported when compiling basalt

Foundation Consolidation - Flex width is content width

office2016+visio2016

Constexpr keyword
随机推荐
[hdu] p2087 cut cloth strip
4. functions and inline functions with default values for formal parameters
You can be what you want to be
fatal: refusing to merge unrelated histories
//1.9 char character variable operation
Openvino CPU acceleration survey
How are pub and sub connected in ros1?
Overview of visual object detection technology based on deep learning
Score and loop statements (including goto statements) -part3
You can also do NLP (classification)
[hdu] p1466 calculate the number of intersections of straight lines
7.new, delete, OOP, this pointer
Up the Strip
[learning notes] roll back Mo team
Uint8 serializing and deserializing pits using stringstream
JS to paste pictures into web pages
9. class and object practice and initialization list
//1.11 basic operators
You can also do NLP (classification)
Exercise analysis summary