From 22407f4b1fe83b89061f70e18dc66cac97a7bf4f Mon Sep 17 00:00:00 2001 From: liangkangnan Date: Sat, 20 Aug 2022 15:00:17 +0800 Subject: [PATCH] sdk:examples: add led_toggle Signed-off-by: liangkangnan --- sdk/examples/led_toggle/.gitignore | 8 ++++++++ sdk/examples/led_toggle/Makefile | 20 ++++++++++++++++++++ sdk/examples/led_toggle/README.md | 1 + sdk/examples/led_toggle/main.c | 20 ++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 sdk/examples/led_toggle/.gitignore create mode 100644 sdk/examples/led_toggle/Makefile create mode 100644 sdk/examples/led_toggle/README.md create mode 100644 sdk/examples/led_toggle/main.c diff --git a/sdk/examples/led_toggle/.gitignore b/sdk/examples/led_toggle/.gitignore new file mode 100644 index 0000000..485ec4b --- /dev/null +++ b/sdk/examples/led_toggle/.gitignore @@ -0,0 +1,8 @@ +# Object files +*.o +*.ko +*.obj +*.bin +*.dump +*.mem +gpio diff --git a/sdk/examples/led_toggle/Makefile b/sdk/examples/led_toggle/Makefile new file mode 100644 index 0000000..110d8bf --- /dev/null +++ b/sdk/examples/led_toggle/Makefile @@ -0,0 +1,20 @@ +RISCV_ARCH := rv32im +RISCV_ABI := ilp32 +RISCV_MCMODEL := medlow + + +TARGET = led_toggle + + +#CFLAGS += -DSIMULATION +#CFLAGS += -O2 +#ASM_SRCS += +#LDFLAGS += +#INCLUDES += -I. + +C_SRCS := \ + main.c \ + + +BSP_DIR = ../../bsp +include ../../bsp/bsp.mk diff --git a/sdk/examples/led_toggle/README.md b/sdk/examples/led_toggle/README.md new file mode 100644 index 0000000..f37d599 --- /dev/null +++ b/sdk/examples/led_toggle/README.md @@ -0,0 +1 @@ +每500ms翻转GPIO电平。 \ No newline at end of file diff --git a/sdk/examples/led_toggle/main.c b/sdk/examples/led_toggle/main.c new file mode 100644 index 0000000..5bce20f --- /dev/null +++ b/sdk/examples/led_toggle/main.c @@ -0,0 +1,20 @@ +#include + +#include "../../bsp/include/gpio.h" +#include "../../bsp/include/utils.h" +#include "../../bsp/include/pinmux.h" + +int main() +{ + // IO7用作GPIO7 + pinmux_set_io7_func(IO7_GPIO7); + // gpio7输出模式 + gpio_set_mode(GPIO7, GPIO_MODE_OUTPUT); + + while (1) { + gpio_set_output_data(GPIO7, 1); // GPIO7输出高 + busy_wait(500000); + gpio_set_output_data(GPIO7, 0); // GPIO7输出低 + busy_wait(500000); + } +}