裸机开发_L3_仿STM32库函数开发LED实验
1. 硬件层电路
1.1 正点原子 i.MX6ULL ALPHA V2.2 开发板
查看底板原理图可知:
功能管脚 | 芯片引脚 |
---|---|
LED0 | GPIO1_IO03 |
1.2 飞凌i.MX6UL-C开发板
2. 软件编写
2.1 正点原子 i.MX6ULL ALPHA V2.2 开发板
2.1.1 imx6ull.lds
链接脚本
SECTIONS{
. = 0x87800000;
.text : {
start.o
*(.text)
}
.rodata ALIGN(4) : {
*(.rodata) }
.data ALIGN(4) : {
*(.data) }
__bss_start = .;
.bss ALIGN(4) : {
*(.bss) *(COMMON) }
__bss_end = .;
}
2.1.2 start.S
初始化BSS段
.global _start
.global _bss_start
_bss_start:
.word __bss_start
.global _bss_end
_bss_end:
.word __bss_end
_start :
/**
设置处理器进入SVC模式
*/
mrs r0, cpsr
bic r0, r0, #0x1f
orr r0, r0, #0x13
msr cpsr, r0
/**
清除BSS段 */
ldr r0, _bss_start
ldr r1, _bss_end
mov r2, #0
bss_loop:
stmia r0!, {
r2}
cmp r0, r1
ble bss_loop
/**
设置sp指针
*/
ldr sp, =0x80200000
/**
跳转至C语言main函数
*/
b main
2.1.3 imx6ull.h
“结构体”封装寄存器
【注意】地址的连续性,如果寄存器地址不连续,需要添加“占位”。
/*
* 外设寄存器组的基地址
*/
#define CCM_BASE (0x020C4000)
#define CCM_ANALOG_BASE (0x020C8000)
#define IOMUX_SW_MUX_BASE (0x020E0014)
#define IOMUX_SW_PAD_BASE (0x020E0204)
#define GPIO1_BASE (0x0209C000)
#define GPIO2_BASE (0x020A0000)
#define GPIO3_BASE (0x020A4000)
#define GPIO4_BASE (0x020A8000)
#define GPIO5_BASE (0x020AC000)
/* CCM 外设 */
typedef struct
{
volatile unsigned int CCR;
volatile unsigned int CCDR;
volatile unsigned int CSR;
volatile unsigned int CCSR;
volatile unsigned int CACRR;
volatile unsigned int CBCDR;
volatile unsigned int CBCMR;
volatile unsigned int CSCMR1;
volatile unsigned int CSCMR2;
volatile unsigned int CSCDR1;
volatile unsigned int CS1CDR;
volatile unsigned int CS2CDR;
volatile unsigned int CDCDR;
volatile unsigned int CHSCCDR;
volatile unsigned int CSCDR2;
volatile unsigned int CSCDR3;
volatile unsigned int RESERVED_1[2];
volatile unsigned int CDHIPR;
volatile unsigned int RESERVED_2[2];
volatile unsigned int CLPCR;
volatile unsigned int CISR;
volatile unsigned int CIMR;
volatile unsigned int CCOSR;
volatile unsigned int CGPR;
volatile unsigned int CCGR0;
volatile unsigned int CCGR1;
volatile unsigned int CCGR2;
volatile unsigned int CCGR3;
volatile unsigned int CCGR4;
volatile unsigned int CCGR5;
volatile unsigned int CCGR6;
volatile unsigned int RESERVED_3[1];
volatile unsigned int CMEOR;
}CCM_TypeDef;
typedef struct
{
volatile unsigned int PLL_ARM;
volatile unsigned int PLL_ARM_SET;
volatile unsigned int PLL_ARM_CLR;
volatile unsigned int PLL_ARM_TOG;
volatile unsigned int PLL_USB1;
volatile unsigned int PLL_USB1_SET;
volatile unsigned int PLL_USB1_CLR;
volatile unsigned int PLL_USB1_TOG;
volatile unsigned int PLL_USB2;
volatile unsigned int PLL_USB2_SET;
volatile unsigned int PLL_USB2_CLR;
volatile unsigned int PLL_USB2_TOG;
volatile unsigned int PLL_SYS;
volatile unsigned int PLL_SYS_SET;
volatile unsigned int PLL_SYS_CLR;
volatile unsigned int PLL_SYS_TOG;
volatile unsigned int PLL_SYS_SS;
volatile unsigned int RESERVED_1[3];
volatile unsigned int PLL_SYS_NUM;
volatile unsigned int RESERVED_2[3];
volatile unsigned int PLL_SYS_DENOM;
volatile unsigned int RESERVED_3[3];
volatile unsigned int PLL_AUDIO;
volatile unsigned int PLL_AUDIO_SET;
volatile unsigned int PLL_AUDIO_CLR;
volatile unsigned int PLL_AUDIO_TOG;
volatile unsigned int PLL_AUDIO_DENOM;
volatile