个人是小白,手动烧写了linux系统。按照
william hill官网
里很牛的大神的帖子,熟悉烧写代码的流程,代码还是参考大神的,代码如下:
main.c文件
#include "stdint.h"
// IO port for controling LEDs
#define GPM04_BASE 0xE0200340 // GPM04 Base Address
#define GPD0_BASE 0xE02000A0
#define GPCON_OFS 0x00 // Control Register Offset
#define GPDAT_OFS 0x04 // Data Register Offset
#define MP0_4CON_REG (*(vola
tile uint32_t *)(GPM04_BASE+GPCON_OFS))
#define MP0_4DAT_REG (*(volatile uint32_t *)(GPM04_BASE+GPDAT_OFS))
#define GPD0CON_REG (*(volatile uint32_t *)(GPD0_BASE+GPCON_OFS))
#define GPD0DAT_REG (*(volatile uint32_t *)(GPD0_BASE+GPDAT_OFS))
#define LED1 4 // GPM0_4->LED1
#define LED2 5 // GPM0_5->LED2
#define LED3 6 // GPM0_6->LED3
#define LED4 7 // GPM0_7->LED4
#define BEEP 0 // GPD0_0->BEEP
void Delay_ms(uint32_t Count)
{
//延时1ms,共延时nCountms
// Arm clock为400M,循环体每次30个Arm clock
int32_t temp1 = 13333;
int32_t temp2 = 0;
asm volatile (
"Delay_ms_0:n"
"mov %0, %2n"
"Delay_ms_1:n"
"subs %0, %0, #1n" // 单发射 cycle 1
// 跳转清流水线,以下指令均只用作填充流水线
"mov %1, %1n" // 双发射 cycle 1
"mov %1, %1n" // 单发射 cycle 2
"mov %1, %1n" // 单发射 cycle 3
"mov %1, %1n" // 单发射 cycle 4
"mov %1, %1n" // 单发射 cycle 5
"mov %1, %1n" // 单发射 cycle 6
"mov %1, %1n" // 单发射 cycle 7
"mov %1, %1n" // 单发射 cycle 8
"mov %1, %1n" // 单发射 cycle 9
"mov %1, %1n" // 单发射 cycle 10
"mov %1, %1n" // 单发射 cycle 11
"mov %1, %1n" // 单发射 cycle 12
"mov %1, %1n" // 单发射 cycle 13
"mov %1, %1n" // 单发射 cycle 14
"mov %1, %1n" // 单发射 cycle 15
"mov %1, %1n" // 单发射 cycle 16
"mov %0, %0n" // 单发射 cycle 17
"bne.w Delay_ms_1n" // 跳转会清流水线,13级流水线,cycle 30
"subs %1, %1, #1n" // 调用者确保nCount不为0
"bne.w Delay_ms_0n"
: "+r"(temp2), "+r"(Count): "r"(temp1): "cc"
);
}
void Gpio_LED1(uint8_t On)
{
if (On) {
MP0_4DAT_REG &= ~(1<
} else {
MP0_4DAT_REG |= (1<
}
}
void Gpio_LED2(uint8_t On)
{
if (On) {
MP0_4DAT_REG &= ~(1<
} else {
MP0_4DAT_REG |= (1<
}
}
void Gpio_LED3(uint8_t On)
{
if (On) {
MP0_4DAT_REG &= ~(1<
} else {
MP0_4DAT_REG |= (1<
}
}
void Gpio_LED4(uint8_t On)
{
if (On) {
MP0_4DAT_REG &= ~(1<
} else {
MP0_4DAT_REG |= (1<
}
}
void Gpio_Beep(uint8_t On)
{
if (On) {
GPD0DAT_REG |= (1<
} else {
GPD0DAT_REG &= ~(1<
}
}
void Gpio_Init(void)
{
// GPM04_4 output led1, off
MP0_4CON_REG = (MP0_4CON_REG & (~(0xf<<(LED1<<2)))) | (0x1<<(LED1<<2));
MP0_4DAT_REG |= (1<
// GPM04_5 output led2, off
MP0_4CON_REG = (MP0_4CON_REG & (~(0xf<<(LED2<<2)))) | (0x1<<(LED2<<2));
MP0_4DAT_REG |= (1<
// GPM04_6 output led3, off
MP0_4CON_REG = (MP0_4CON_REG & (~(0xf<<(LED3<<2)))) | (0x1<<(LED3<<2));
MP0_4DAT_REG |= (1<
// GPM04_7 output led4, off
MP0_4CON_REG = (MP0_4CON_REG & (~(0xf<<(LED4<<2)))) | (0x1<<(LED4<<2));
MP0_4DAT_REG |= (1<
// Beep output, off
GPD0CON_REG = (GPD0CON_REG & (~(0xf<<(BEEP<<2)))) | (0x1<<(BEEP<<2));
GPD0DAT_REG &= ~(1<
}
void main(void)
{
Gpio_Init();
while (1) {
Gpio_LED1(1);
Delay_ms(1000);
Gpio_LED1(0);
Gpio_LED2(1);
Delay_ms(1000);
Gpio_LED2(0);
Gpio_LED3(1);
Delay_ms(1000);
Gpio_LED3(0);
Gpio_LED4(1);
Gpio_Beep(1);
Delay_ms(1000);
Gpio_LED4(0);
Gpio_Beep(0);
}
}
led.s文件
SECTION .intvec:CODE:NOROOT(2)
PUBLIC __iar_program_start
ARM
__iar_program_start
EXTERN main
BLX main
END
下载工具使用的是sdboot.exe这个软件还是很好用的,手动用dnw1.01.EXE,可是没有找到OK210的驱动
实验现象
感谢帖友的分享。努力学习中,。。。