当前位置:网站首页>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
边栏推荐
- NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
- Kivy教程之 更改背景颜色(教程含源码)
- Boutique website navigation theme whole station source code WordPress template adaptive mobile terminal
- [microservices openfeign] two degradation methods of feign | fallback | fallbackfactory
- The "functional art" jointly created by Bolang and Virgil abloh in 2021 to commemorate the 100th anniversary of Bolang brand will debut during the exhibition of abloh's works in the museum
- Leetcode skimming: binary tree 07 (maximum depth of binary tree)
- Virtual commodity account trading platform source code_ Support personal QR code collection
- Asynchronous development process - touch your hand and lead you to realize a promise
- 什么是上下文?
- Redis:有序集合zset类型数据操作命令
猜你喜欢
Kivy教程之 格式化文本 (教程含源码)
Main applications of TDK lambda power supply
tdk-lambda电源主要应用
Flink learning 7: application structure
架构训练毕业设计+总结
Redis: hash type data operation command
【微信小程序】好看的轮播图组件
Virtual commodity account trading platform source code_ Support personal QR code collection
96% of the collected traffic is prevented by bubble mart of cloud hosting
Distributed cap theory
随机推荐
Unity draws the trajectory of pinball and billiards
更优雅地远程操作服务器:Paramiko库的实践
Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
Unity资源路径
Common methods of threads
统计遗传学:第三章,群体遗传
微信脑力比拼答题小程序_支持流量主带最新题库文件
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence
(pointeur) Écrivez - vous une fonction qui compare la taille de la chaîne et fonctionne comme strcmp.
Detailed explanation of event cycle
博朗与Virgil Abloh于2021年为纪念博朗品牌100周年而联合打造的“功能性艺术”将在博物馆展出Abloh作品期间首次亮相
Rhcsa 01 - create partitions and file systems
Krypton saikr daily question - CTF
Kivy教程之 更改背景颜色(教程含源码)
Kivy教程之 格式化文本 (教程含源码)
RHCSA 01 - 创建分区与文件系统
Experience sharing of epidemic telecommuting | community essay solicitation
Leetcode brush questions: binary tree 05 (flip binary tree)
Flink learning 6: programming model
I.MX6U-ALPHA开发板(C语言版本LED驱动实验)