当前位置:网站首页>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边栏推荐
- Step motor generates S-curve upper computer
- 1-stm32 operation environment construction
- How to select conductive slip ring
- The browser cannot access Baidu
- Drive LED -- GPIO control
- Connection mode - bridge and net
- C WinForm [realize the previous and next selection pictures] - practice 7
- Some errors in configuring the environment
- Cadence learning records
- Baiwen 7-day smart home learning experience of Internet of things
猜你喜欢
![C WinForm [display real-time time in the status bar] - practical exercise 1](/img/9f/d193cbb488542cc4c439efd79c4963.jpg)
C WinForm [display real-time time in the status bar] - practical exercise 1

Improve lighting C program

Matlab2018b problem solving when installing embedded coder support package for stmicroelectronic

Acwing - the collection of pet elves - (multidimensional 01 Backpack + positive and reverse order + two forms of DP for the answer)

The research found that the cross-border e-commerce customer service system has these five functions!

Makefile application

Altium designer 19.1.18 - clear information generated by measuring distance

Hardware 1 -- relationship between gain and magnification

Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
![Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine](/img/13/22a1915329f58acd54c40176f6f301.jpg)
Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
随机推荐
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
About the problem that MySQL connector net cannot be cleared in MySQL
Network communication process
Wifi-802.11 negotiation rate table
Basic embedded concepts
Fundamentals of C language
C WinForm [exit application] - practice 3
Realization of binary relation of discrete mathematics with C language and its properties
Global and Chinese market for blood typing 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets for recycled boilers 2022-2028: Research Report on technology, participants, trends, market size and share
Hardware 1 -- relationship between gain and magnification
Shell script basic syntax
Extended application of single chip microcomputer-06 independent key
Sql Server的存储过程详解
Detailed explanation of pragma usage
C # joint configuration with Halcon
[untitled] record the visual shock of the Winter Olympics and the introduction of the display screen
About yolov3, conduct map test directly
C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update