当前位置:网站首页>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边栏推荐
- Semiconductor devices (I) PN junction
- A simple method to prove 1/t Fourier transform
- Global and Chinese market of urban rail connectors 2022-2028: Research Report on technology, participants, trends, market size and share
- Altium designer 19.1.18 - hide the fly line of a network
- General makefile (I) single C language compilation template
- Adaptive filter
- About yolov3, conduct map test directly
- Global and Chinese markets for anesthesia, breathing and sleep apnea devices 2022-2028: Research Report on technology, participants, trends, market size and share
- 研究發現,跨境電商客服系統都有這五點功能!
- Altium designer 19.1.18 - change the transparency of copper laying
猜你喜欢

Summary -st2.0 Hall angle estimation

Software designer: 03 database system
![Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine](/img/a1/d13b37955b044b6be5f1fd10263c5e.jpg)
Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine

Network communication process

Record the opening ceremony of Beijing Winter Olympics with display equipment

Reasons for rapid wear of conductive slip rings
![C WinForm [view status bar -- statusstrip] - Practice 2](/img/40/63065e6c4dc4e9fcb3e898981f518a.jpg)
C WinForm [view status bar -- statusstrip] - Practice 2

Altium designer learning (I)

Consul installation

C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
随机推荐
[professional literacy] specific direction of analog integrated circuits
Screen record of the opening ceremony of the Beijing winter olympics 2
Shape template matching based on Halcon learning [vi] find_ mirror_ dies. Hdev routine
Win10 shortcut key
Extern keyword function
After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update
IEEE access personal contribution experience record
生产中影响滑环质量的因素
Programming knowledge -- basis of C language
My-basic application 2: my-basic installation and operation
Scm-05 basis of independent keyboard
Detailed explanation of pragma usage
Connection mode - bridge and net
UEFI development learning 6 - creation of protocol
Altium designer 19.1.18 - Import frame
UEFI development learning 2 - running ovmf in QEMU
Wifi-802.11 negotiation rate table
Verilog -- state machine coding method
Global and Chinese markets of large aperture scintillators 2022-2028: Research Report on technology, participants, trends, market size and share
H264 (I) i/p/b frame gop/idr/ and other parameters