[feat] add uart_interrupt demo
This commit is contained in:
parent
96d31a0df1
commit
8bc6f6d5db
@ -19,10 +19,6 @@ isr_reset:
|
|||||||
ldr r0, =0xE000E280
|
ldr r0, =0xE000E280
|
||||||
ldr r1, =0xFFFFFFFF
|
ldr r1, =0xFFFFFFFF
|
||||||
str r1, [r0]
|
str r1, [r0]
|
||||||
/* relocate VTOR, vector table offset register */
|
|
||||||
ldr r0, =0xE000ED08
|
|
||||||
ldr r1, =_vector_load
|
|
||||||
str r1, [r0]
|
|
||||||
/* set MSP, main stack point */
|
/* set MSP, main stack point */
|
||||||
ldr r0, =_stack_top
|
ldr r0, =_stack_top
|
||||||
msr msp, r0
|
msr msp, r0
|
||||||
@ -52,7 +48,7 @@ isr_reset:
|
|||||||
cmp r1, r2
|
cmp r1, r2
|
||||||
blo 1b
|
blo 1b
|
||||||
2:
|
2:
|
||||||
; bl SystemInit
|
bl irq_init
|
||||||
bl main
|
bl main
|
||||||
b .
|
b .
|
||||||
.size isr_reset, .-isr_reset
|
.size isr_reset, .-isr_reset
|
||||||
|
|||||||
9
example/peripherals/uart/uart_interrupt/CMakeLists.txt
Normal file
9
example/peripherals/uart/uart_interrupt/CMakeLists.txt
Normal 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)
|
||||||
18
example/peripherals/uart/uart_interrupt/Makefile
Normal file
18
example/peripherals/uart/uart_interrupt/Makefile
Normal 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
|
||||||
43
example/peripherals/uart/uart_interrupt/main.c
Normal file
43
example/peripherals/uart/uart_interrupt/main.c
Normal 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;
|
||||||
|
}
|
||||||
1
example/peripherals/uart/uart_interrupt/proj.conf
Normal file
1
example/peripherals/uart/uart_interrupt/proj.conf
Normal file
@ -0,0 +1 @@
|
|||||||
|
# set(CONFIG_COMPONENT1 1)
|
||||||
Loading…
Reference in New Issue
Block a user