当前位置:网站首页>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
边栏推荐
- 多位科技公司创始人向Entrepreneur First提供高达1.58亿美元的C轮融资,协助其投资下一代全球创新者
- Leetcode brush questions: binary tree 05 (flip binary tree)
- (指针)自己写一个比较字符串大小的函数,功能与strcmp类似。
- How to add custom API objects in kubernetes (1)
- MySQL 索引和事务
- R语言中如何查看已安装的R包
- B. All Distinct
- 【云原生】那些看起来很牛X,原理却很简单的一行代码
- 资深开发人员告诉你,怎样编写出优秀的代码?
- 仿《游戏鸟》源码 手游发号评测开服开测合集专区游戏下载网站模板
猜你喜欢
Architecture practice camp - graduation project of module 9 of phase 6
Graduation project: design seckill e-commerce system
Select function variable column name in dplyr of R language
[security attack and Defense] how much do you know about serialization and deserialization?
疫情远程办公经验分享| 社区征文
MySQL 索引和事务
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
旭化成首次参展第五届中国国际进口博览会(5th CIIE)
ModStartBlog 现代化个人博客系统 v5.2.0 源码下载
Flink learning 7: application structure
随机推荐
Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
多位科技公司创始人向Entrepreneur First提供高达1.58亿美元的C轮融资,协助其投资下一代全球创新者
Keysight N9320B射频频谱分析仪解决轮胎压力监测方案
Leetcode skimming: binary tree 07 (maximum depth of binary tree)
微信公众号无限回调授权系统源码
一个漂亮的API文档生成工具
一位毕业生的自我分享
Experience sharing of epidemic telecommuting | community essay solicitation
苹果CMS仿西瓜视频大气响应式视频模板源码
【安全攻防】序列化与反序列,你了解多少?
MySQL JDBC编程
虚拟商品帐号交易平台源码_支持个人二维码收款
C language bidirectional linked list first edition
Redis:集合Set类型数据的操作命令
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Wechat official account infinite callback authorization system source code
Redis: order collection Zset type data operation command
资深开发人员告诉你,怎样编写出优秀的代码?
Keysight n9320b RF spectrum analyzer solves tire pressure monitoring scheme
96% of the collected traffic is prevented by bubble mart of cloud hosting