1.在common文件夹下新建cmd_led_test.c
2.修改common/Makefile ,添加一行COBJS-y += cmd_led_test.o ,将cmd_led_test编译进uboot
3.编译
4.下载测试
U-Boot# led on
argc = 2
argv[0] is: led
argv[1] is: on
输入led on,可以发现led被亮了,我使用的是am335x GPIO3_16
U-Boot# led off
argc = 2
argv[0] is: led
argv[1] is: off
输入led off,可以发现led被熄灭
附源码cmd_led_test.c
//======================================
-
#define AM335X_GPIO3_BASE 0x481AE000
-
-
#define GPIO3_16_PIN 0x00010000
-
-
#define GPIO_OE 0x481AE134
-
-
#define GPIO_CLEARDATAOUT 0x481AE190
-
-
#define GPIO_SETDATAOUT 0x481AE194
-
-
-
#include <common.h>
-
-
#include <command.h>
-
-
-
static void led_on(){
-
-
int * gpio_SETDATAOUT = (int *) GPIO_SETDATAOUT ;
-
-
int * gpio_CLEARDATAOUT = (int *) GPIO_CLEARDATAOUT;
-
-
int * gpio_OE = (int *) GPIO_OE;
-
-
-
-
*gpio_OE = ~GPIO3_16_PIN;
-
-
*gpio_SETDATAOUT = GPIO3_16_PIN;
-
-
}
-
-
static void led_off(){
-
-
int * gpio_SETDATAOUT = (int *) GPIO_SETDATAOUT ;
-
-
int * gpio_CLEARDATAOUT = (int *) GPIO_CLEARDATAOUT;
-
-
-
-
int * gpio_OE = (int *) GPIO_OE;
-
-
*gpio_OE = ~GPIO3_16_PIN;
-
-
*gpio_CLEARDATAOUT = GPIO3_16_PIN;
-
-
-
-
}
-
-
static int do_led(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-
-
{
-
-
int i = 0;
-
-
printf("argc = %d\n",argc);
-
-
for( i = 0; i < argc ; i++){
-
-
printf("argv[%d] is: %s\n",i,argv[i]);
-
-
}
-
-
if( argc == 2){
-
-
if( strcmp(argv[1],"on") == 0 ){
-
-
led_on();
-
-
}else{
-
-
led_off();
-
-
}
-
-
}
-
-
return 0;
-
-
}
-
-
-
-
U_BOOT_CMD(
-
-
led, 2, 0, do_led,
-
-
"led - this is a led command, light ON or OFF led2 ,which control by GPIO3_16",
-
-
"- led - this is a led command, light ON or OFF led2 ,which control by GPIO3_16"
-
-
);
阅读(9385) | 评论(0) | 转发(0) |