当前位置:网站首页>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
边栏推荐
- Some thoughts on extracting perspectives from ealfa and Ebeta
- Bluetooth hc-05 pairing process and precautions
- Hardware 1 -- relationship between gain and magnification
- Live555 push RTSP audio and video stream summary (I) cross compilation
- Verilog -- state machine coding method
- Communication standard -- communication protocol
- 研究發現,跨境電商客服系統都有這五點功能!
- 软件设计师:03-数据库系统
- Ads usage skills
- Solutions to compilation warnings in Quartus II
猜你喜欢
Shape template matching based on Halcon learning [vi] find_ mirror_ dies. Hdev routine
C language enhancement -- pointer
C WinForm [view status bar -- statusstrip] - Practice 2
Altium designer 19.1.18 - clear information generated by measuring distance
UEFI development learning 3 - create UEFI program
UEFI development learning 2 - running ovmf in QEMU
Halcon's practice based on shape template matching [2]
Drive LED -- GPIO control
Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine
Summary -st2.0 Hall angle estimation
随机推荐
Some errors in configuring the environment
C language # and #
Makefile application
After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update
Development tools -- gcc compiler usage
Can't find real-time chat software? Recommend to you what e-commerce enterprises are using!
Compilation warning solution sorting in Quartus II
Global and Chinese market of urban rail connectors 2022-2028: Research Report on technology, participants, trends, market size and share
Acwing - the collection of pet elves - (multidimensional 01 Backpack + positive and reverse order + two forms of DP for the answer)
Realization of binary relation of discrete mathematics with C language and its properties
生产中影响滑环质量的因素
[trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement
C WinForm [get file path -- traverse folder pictures] - practical exercise 6
Count and sort the occurrence times of specific fields through SQL statements
MLPerf Training v2.0 榜单发布,在同等GPU配置下百度飞桨性能世界第一
Ads usage skills
Pointnet++ classification practice
Shell script basic syntax
Some thoughts on extracting perspectives from ealfa and Ebeta
Cadence simulation encountered "input.scs": can not open input file change path problem