From 8bc6f6d5db73e18ddf12c4c97db1ea14485247b7 Mon Sep 17 00:00:00 2001 From: zhji Date: Mon, 2 Jun 2025 20:37:44 +0800 Subject: [PATCH] [feat] add uart_interrupt demo --- driver/start.S | 6 +-- .../uart/uart_interrupt/CMakeLists.txt | 9 ++++ .../peripherals/uart/uart_interrupt/Makefile | 18 ++++++++ .../peripherals/uart/uart_interrupt/main.c | 43 +++++++++++++++++++ .../peripherals/uart/uart_interrupt/proj.conf | 1 + 5 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 example/peripherals/uart/uart_interrupt/CMakeLists.txt create mode 100644 example/peripherals/uart/uart_interrupt/Makefile create mode 100644 example/peripherals/uart/uart_interrupt/main.c create mode 100644 example/peripherals/uart/uart_interrupt/proj.conf diff --git a/driver/start.S b/driver/start.S index e117874..183eefa 100644 --- a/driver/start.S +++ b/driver/start.S @@ -19,10 +19,6 @@ isr_reset: ldr r0, =0xE000E280 ldr r1, =0xFFFFFFFF str r1, [r0] - /* relocate VTOR, vector table offset register */ - ldr r0, =0xE000ED08 - ldr r1, =_vector_load - str r1, [r0] /* set MSP, main stack point */ ldr r0, =_stack_top msr msp, r0 @@ -52,7 +48,7 @@ isr_reset: cmp r1, r2 blo 1b 2: -; bl SystemInit + bl irq_init bl main b . .size isr_reset, .-isr_reset diff --git a/example/peripherals/uart/uart_interrupt/CMakeLists.txt b/example/peripherals/uart/uart_interrupt/CMakeLists.txt new file mode 100644 index 0000000..e07dfed --- /dev/null +++ b/example/peripherals/uart/uart_interrupt/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.10) + +include(proj.conf) + +project(${EXAMPLE_NAME} VERSION 0.1) +add_executable(${EXAMPLE_NAME}.elf main.c) + +add_subdirectory(${SDK_BASE_DIR} sdk) +target_link_libraries(${EXAMPLE_NAME}.elf sdk) diff --git a/example/peripherals/uart/uart_interrupt/Makefile b/example/peripherals/uart/uart_interrupt/Makefile new file mode 100644 index 0000000..df5330b --- /dev/null +++ b/example/peripherals/uart/uart_interrupt/Makefile @@ -0,0 +1,18 @@ +EXAMPLE_BASE_DIR ?= $(shell realpath .) +EXAMPLE_NAME := $(notdir $(patsubst %/,%,$(CURDIR))) +SDK_BASE_DIR ?= $(shell realpath ./../../../..) + +export SDK_BASE_DIR +export EXAMPLE_NAME +export EXAMPLE_BASE_DIR + +GCC_PATH := $(shell which arm-none-eabi-gcc) +CROSS_COMPILE := $(patsubst %gcc,%,$(GCC_PATH)) +ifeq ($(GCC_PATH),) +$(error arm-none-eabi-gcc not found in PATH. Please install the ARM toolchain.) +endif + +# add custom cmake definition +#cmake_definition+=-Dxxx=sss + +include $(SDK_BASE_DIR)/project.build diff --git a/example/peripherals/uart/uart_interrupt/main.c b/example/peripherals/uart/uart_interrupt/main.c new file mode 100644 index 0000000..44c1574 --- /dev/null +++ b/example/peripherals/uart/uart_interrupt/main.c @@ -0,0 +1,43 @@ +#include "gpio.h" +#include "uart.h" +#include "resets.h" +#include "irq.h" +#include "stdio.h" + +#define UART_ID uart0_hw + +void uart_isr(void) +{ + int c, r; + + while (1) { + c = uart_get_char(UART_ID); + if (c < 0) { + break; + } else { + while (1) { + r = uart_put_char(UART_ID, (uint8_t)c); + if (r < 0) { + continue; + } else { + break; + } + } + } + } +} + +int main(void) +{ + reset_unreset_blocks_wait(RESETS_BLOCK_IO_BANK0 | RESETS_BLOCK_UART0); + + gpio_init(0, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_DRIVE_4MA); /* UART_TX pin */ + gpio_init(1, GPIO_FUNC_UART | GPIO_PULL_UP | GPIO_SCHMITT | GPIO_PAD_IE | GPIO_PAD_OD); /* UART_RX pin */ + uart_init(UART_ID, 6 * 1000 * 1000, UART_DATABITS_8 | UART_PARITY_NONE | UART_STOPBITS_1); + printf("uart_interrupt example\r\n"); + uart_int_enable(UART_ID, UART_INT_RX | UART_INT_RTO); + irq_attach(UART0_IRQ, uart_isr); + irq_enable(UART0_IRQ); + + return 0; +} diff --git a/example/peripherals/uart/uart_interrupt/proj.conf b/example/peripherals/uart/uart_interrupt/proj.conf new file mode 100644 index 0000000..7d2ef31 --- /dev/null +++ b/example/peripherals/uart/uart_interrupt/proj.conf @@ -0,0 +1 @@ +# set(CONFIG_COMPONENT1 1)