[feat] add uart_interrupt demo

This commit is contained in:
zhji 2025-06-02 20:37:44 +08:00
parent 96d31a0df1
commit 8bc6f6d5db
5 changed files with 72 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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;
}

View File

@ -0,0 +1 @@
# set(CONFIG_COMPONENT1 1)