当前位置:网站首页>1. Mx6u-alpha development board (LED drive experiment in C language version)
1. Mx6u-alpha development board (LED drive experiment in C language version)
2022-07-04 04:34:00 【*Ruthless*】
List of articles
One 、C Language runtime environment test
.global _start /* Global label */
_start:
/* Get into SVC Pattern */
mrs r0, cpsr
bic r0, r0, #0x1f /* take r0 Low in register 5 A reset , That is to say cpsr Of M0~M4*/
orr r0, r0, #0x13 /* r0 Or on the 0x13, Said the use of SVC Pattern */
msr cpsr, r0 /* take r0 Data written to cpsr_c in */
ldr sp, =0X80200000 /* Set the stack pointer */
b main /* Jump to main function */
One 、 Set processor mode
Set up 6ULL be in SVC Pattern Next . Set up CPSR The register of bit4-0, That is to say M[4:0] by 10011=0X13. Reading and writing the status register requires MRS and MSR Instructions .MRS take CPSR The register data is read into the general-purpose register ,MSR The instruction writes the value of the general-purpose register to CPSR Go inside the register .
Two 、 Set up sp The pointer
Sp Can point to the inside RAM, You can also point to DDR, We point it to DDR.Sp Where to set ?512MB The scope of the 0x80000000~0x9FFFFFFF. Stack size ,0x200000=2MB. Processor stack growth mode , about A7 In general, it is growing downward . Set up sp Point to 0x80200000.
3、 ... and 、 Jump to C Language
Use b Instructions , Jump to C Language functions , such as main function .
Two 、 Software writing
#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
#include "main.h"
/* Enable peripheral clock */
void clk_enable(void)
{
CCM_CCGR1 = 0xFFFFFFFF;
CCM_CCGR2 = 0xFFFFFFFF;
CCM_CCGR3 = 0xFFFFFFFF;
CCM_CCGR4 = 0xFFFFFFFF;
CCM_CCGR5 = 0xFFFFFFFF;
CCM_CCGR6 = 0xFFFFFFFF;
}
/* initialization LED*/
void led_init(void)
{
SW_PAD_GPIO1_IO03 = 0x5;/* Reuse as GPIO1-IO03*/
SW_PAD_GPIO1_IO03 = 0x10B0;/* Set up GPIO1——IO03 Electrical properties */
/*GPIO initialization */
GPIO1_GDIR = 0x8;/* Set as output */
GPIO1_DR = 0x0;/* open LED The lamp */
}
/* Short delay */
void delay_short(volatile unsigned int n)
{
while(n--){
}
}
void delay(volatile unsigned int n)
{
while(n--)
{
delay_short(0x77f); //1 millisecond (396MHZ)
}
}
void led_on(void)
{
GPIO1_DR &= ~(1<<3);
}
void led_off(void)
{
GPIO1_DR |= (1<<3);
}
int main(void)
{
clk_enable();
led_init();
while(1)
{
led_on();
delay(500);
led_off();
delay(500);
}
return 0;
}
3、 ... and 、 Link script
The link script describes the file to be connected , And link order , And the first address of the link
The syntax of the link script is simple , Is to write a series of commands , These commands make up the link script , Each command is a keyword with parameters or an assignment to symbols , You can use semicolons to separate commands . Strings such as file names can be typed directly , You can also use wildcards “*”. The simplest link script can contain only one command “SECTIONS”, We can be here “SECTIONS” Inside to describe the memory layout of the output file . Generally, the compiled code is included in text、data、bss and rodata In these four paragraphs ,
Our link script requirements for this experiment are as follows :
①、 The starting address of the link is 0X87800000
②、start.o To be linked to the beginning , because start.o It contains the first command to execute
According to the requirements , stay Makefile Create a new directory named “imx6ul.lds” The file of , Then enter the following code in this file :
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 = .;
}
The first 1 OK, let's write a keyword first “SECTIONS”, Followed by a brace , This brace and the second 14 The braces of the line are a pair , It's a must . It looks like C The functions in the language are the same .
The first 2 Line pair a special symbol “.” Assign a value ,“.” It is called location counter in link script , The default positioning counter is 0. We ask the code to link to 0X87800000 Where is the starting address , So this line gives “.” assignment 0X87800000, Said to 0X87800000 Start , Subsequent files or paragraphs will be marked with 0X87800000 Start the link for the starting address .
The first 3 Yes “.text” Is the segment name , The following colon is the syntax requirement , You can fill in the braces after the colon to link to “.text” All the files in this section ,“(.text)” Medium “” The wildcard , Representing all input files .text Put all the paragraphs in “.text” in .
The first 5 Line sets the file linked to the start location to start.o, because start.o It contains the first instruction to be executed , So be sure to link to the beginning . The first 6 Line is main.o This file , In fact, you don't have to write it out , because main.o It doesn't matter where you are , It is up to the compiler to determine the link location .
The first 10 Line defines a name called “.data” Section of , Then all the files “.data” Put all the paragraphs here .ALIGN(4) It's for the right “.data” The beginning of this paragraph
The starting address is byte aligned ,ALIGN(4) Express 4 Byte alignment . That is to say, paragraph “.data” The starting address should be able to be 4 to be divisible by , The common ones are ALIGN(4) perhaps ALIGN(8), That is to say 4 Byte or 8 Byte alignment .
In the 11、13 Yes __bss_start and __bss_end It's the sign , The first 11、13 These two lines are actually assigning values to these two symbols , Its value is the locator “.”, These two symbols are used to save .bss The starting and ending addresses of the segment ..bss A segment is a variable that is defined but not initialized , We need to do it manually .bss Segment variables are cleared , So we need to know .bss Start and end addresses of segments , In this way, we directly assign... To this memory 0 You can complete clearing . Pass the first 11、13 Line code ,.bss The start address and end address of the segment are saved in __bss_start and __bss_end in , We can directly compile or C These two symbols are used in the file .
After execution LED flashing 

边栏推荐
- Redis: hash type data operation command
- 沃博联结束战略评估,决定保留表现优异的博姿业务
- UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence
- Exercises in quantum mechanics
- RHCSA 07 - 用户与群组管理
- 【愚公系列】2022年7月 Go教学课程 001-Go语言前提简介
- R语言dplyr中的Select函数变量列名
- Redis: operation command for collecting set type data
- tdk-lambda电源主要应用
- 毕业设计项目
猜你喜欢

【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装

分布式CAP理论

Graduation project: design seckill e-commerce system

Many founders of technology companies provided enterpriser first with a round C financing of up to US $158million to help it invest in the next generation of global innovators

UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence

戳气球和布尔运算问题(巨难)

Ppt tutorial, how to save a presentation as a PDF file in PowerPoint?

两万字带你掌握多线程
![[security attack and Defense] how much do you know about serialization and deserialization?](/img/cd/cc7d53b818e9a45dec22eada11bb24.png)
[security attack and Defense] how much do you know about serialization and deserialization?

普源DS1000Z系列数字示波器在通信原理实验中的应用方案
随机推荐
AcWing第 58 场周赛
Touch and take you to implement an EventEmitter
leetcode:1314. 矩阵区域和【二维前缀和模板】
架构实战营 - 第 6 期 模块九之毕业设计
Leetcode brush questions: binary tree 05 (flip binary tree)
Rhcsa 03 - Basic permissions for documents
Exploration and practice of eventbridge in the field of SaaS enterprise integration
ROS2中CMake编译选项的设置
【安全攻防】序列化与反序列,你了解多少?
y55.第三章 Kubernetes从入门到精通 -- HPA控制器及metrics-server(二八)
B. All Distinct
Leetcode 121 best time to buy and sell stock (simple)
Keysight n9320b RF spectrum analyzer solves tire pressure monitoring scheme
Graduation project
C语言单向链表练习
Rhcsa 08 - automount configuration
One click compilation and deployment of MySQL
GUI 应用:socket 网络聊天室
资深开发人员告诉你,怎样编写出优秀的代码?
5张图告诉你:同样是职场人,差距怎么这么大?