当前位置:网站首页>Imx6ull bare metal development learning 2- use C language to light LED indicator
Imx6ull bare metal development learning 2- use C language to light LED indicator
2022-07-05 08:04:00 【Changjiang houlang blog】
This chapter follows the previous chapter <IMX6ULL Bare metal development learning 1- Assembly light up led> Upgrade the code .
Programming environment building :
Development board : Wildfire Imx6ull mini plate
Programming environment :Ubuntu18.04 + VScode
Start entering the code content :
C The language needs to run , There is no lack of an environment in which the assembly is ready to run .
Assembly code start.S as follows :
/*******************
* file name : start.S
* author : Guizhiwei
* mailbox : [email protected]
* date :2022 - 02 -13
* describe : Bare metal experimental test 2 C Words light up led
********************/
.global _start @ Global label
/*****
* describe : _start function
*/
_start :
/*****
*1. To configure CPU Get into SVC Pattern
*/
mrs r0, cpsr @ Copy CPSR Status register to R0 in
bic r0, r0, #0x1f @ clear CPU Mode bit BIT4-BIT0
orr r0, r0, #0x13 @ To configure BIT4-0 by SVC Pattern
msr cpsr, r0 @ Register R0 The data is written back to CPSR in
/*****
*2. Set the stack pointer and jump C Language main function
*/
ldr sp, =0x80200000 @ Set the stack 0x80200000->0x80000000 2M Space
b main @ Jump to C Language main function
With the above code , And stm32 Like writing code .
C Code part to a header file led.h, take CPU Relevant register address pointer is defined :
/*******************
* file name : led.h
* author : Guizhiwei
* mailbox : [email protected]
* date :2022 - 02 -13
* describe :led Lamp program header file , Store register pointer
********************/
#ifndef _H_LED_H
#define _H_LED_H
/**
* CCM Clock related register address definition
*/
#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 Reuse related register address definitions
* IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 Address 229_0014h
* IOMUXC_SNVS_SW_PAD_CTL_PAD_SNVS_TAMPER3 Address 229_0058h
*/
#define SW_MUX_GPIO5_IO3 *((volatile unsigned int *)0x02290014)
#define SW_PAD_GPIO5_IO3 *((volatile unsigned int *)0x02290058)
/**
* GPIO5 Related register address definition
*
*/
#define GPIO5_DR *((volatile unsigned int *)0x020AC000)
#define GPIO5_GDIR *((volatile unsigned int *)0x020AC004)
/**
* GPIO5_IO3 Related action macros
* Open drain output control
*/
#define LED_ON() (GPIO5_DR &= ~(1<<3))
#define LED_OFF() (GPIO5_DR |= (1<<3))
#endif // !_H_LED_H
Executable code snippets :
/*******************
* file name : led.c
* author : Guizhiwei
* mailbox : [email protected]
* date :2022 - 02 -13
* describe :led Lamp program executable program
********************/
#include "led.h"
/**
* Enable all peripherals to control the clock
*
*/
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 ;
}
/**
* Led Initialize the corresponding GPIO
*/
void led_Init(void)
{
/*****
*1.GPIO5_IO03 Reuse function configuration GPIO
*IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 Address 229_0014h
*/
SW_MUX_GPIO5_IO3 = 0x5; //AL5
/*****
*2.GPIO5_IO03 To configure IO Property function
*IOMUXC_SNVS_SW_PAD_CTL_PAD_SNVS_TAMPER3 Address 229_0058h
*BIT0 Swaying rate 0- Slow down
*BIT5-3 Driving ability R0/6 -110
*BIT7-6 Speed 100mhz-10
* BIT11 Open drain output enable 1- Turn on
*BIT12 The pull-down function is enabled 0- Close the pull-down button
*BIT13 Keep function 0
*BIT15-14 100K Up and down resistance -00
*BIT16 hys-0 close
* Set the configuration value :8B0-100010110000
*/
SW_PAD_GPIO5_IO3 = 0x08B0;
/*****
*3. Set up GPIO5_IO03 For export
*GPIO5_GDIR Address 20A_C004
*GPIO5_DR Address 20A_C000
*/
GPIO5_GDIR = 0x08;
/*****
*4 open GPIO LED
*/
LED_ON() ;
}
/****
* Time delay control operation procedure
* Achieve roughly 1ms Unit delay of
*/
void delay_ms(volatile unsigned int nms)
{
unsigned int nus;
while(nms--)
{
//1 ms Time delay
nus=0x7ff;
while(nus--)
{
}
}
}
/**
* Lord main Entry procedure
*/
int main(void)
{
clk_enable(); // Can make the clock
led_Init(); // initialization led The lamp
//led Flashing cycle
while(1)
{
LED_OFF();
delay_ms(500);
LED_ON();
delay_ms(500);
}
return 0;
}
The code part is ready , Next, prepare the link script , Used to specify the starting address and order of the compiler
SECTIONS{
. = 0x87800000;
.text :
{
start.o
led.o
*(.text)
}
.rodata ALIGN(4) : {*(.rodata*)}
.data ALIGN(4) : { *(.data) }
__bss_start = .;
.bss ALIGN(4) : { *(.bss) *(COMMON)}
__bss_end = .;
}
Get ready Makefile Take off compilation :
objs := start.o led.o
led.bin : $(objs)
arm-linux-gnueabihf-ld -Timxu.lds -o led.elf $^
arm-linux-gnueabihf-objcopy -O binary -S led.elf [email protected]
%.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 led.bin led.elf led.dis *.imx
dump:
arm-linux-gnueabihf-objdump -D -m arm led.elf > led.dis
dowmload:
./imxdownload led.bin /dev/sdb
Try compiling :
[email protected]:~/work/imxAss/Ledc$ make
arm-linux-gnueabihf-gcc -Wall -nostdlib -c -o start.o start.S
arm-linux-gnueabihf-gcc -Wall -nostdlib -c -o led.o led.c
arm-linux-gnueabihf-ld -Timxu.lds -o led.elf start.o led.o
arm-linux-gnueabihf-objcopy -O binary -S led.elf led.bin
边栏推荐
- Correlation based template matching based on Halcon learning [II] find_ ncc_ model_ defocused_ precision. hdev
- Ads learning record (lna_atf54143)
- Shape template matching based on Halcon learning [vi] find_ mirror_ dies. Hdev routine
- C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
- The firmware of the connected j-link does not support the following memory access
- 生产中影响滑环质量的因素
- .NET服务治理之限流中间件-FireflySoft.RateLimit
- Compilation warning solution sorting in Quartus II
- Class of color image processing based on Halcon learning_ ndim_ norm. hdev
- [trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
猜你喜欢
H264 (I) i/p/b frame gop/idr/ and other parameters
Extended application of single chip microcomputer-06 independent key
C language uses arrays to realize the intersection, union, difference and complement of sets
Arduino uses nrf24l01+ communication
UEFI development learning 2 - running ovmf in QEMU
Programming knowledge -- basis of C language
Use of orbbec Astra depth camera of OBI Zhongguang in ROS melody
Altium designer 19.1.18 - change the transparency of copper laying
A simple method to prove 1/t Fourier transform
Altium designer 19.1.18 - hide the fly line of a network
随机推荐
[professional literacy] core conferences and periodicals in the field of integrated circuits
Gradle composite construction
Sql Server的存储过程详解
1-stm32 operation environment construction
Ten thousand words detailed eight sorting must read (code + dynamic diagram demonstration)
Introduction of air gap, etc
Embedded composition and route
Altium designer 19.1.18 - Import frame
Halcon's practice based on shape template matching [2]
How to define guid in AMI code
Volatile of C language
Realization of binary relation of discrete mathematics with C language and its properties
solver. Learning notes of prototxt file parameters
Beijing Winter Olympics opening ceremony display equipment record 3
如何进行导电滑环选型
Ads learning record (lna_atf54143)
Detailed explanation of pragma usage
Adaptive filter
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
Relationship between line voltage and phase voltage, line current and phase current