Esp32 C3 UART driver (#6214)
* Use FreeRTOS wrapper * Add console driver * Add patch, .config. Update readme. * Change date
This commit is contained in:
parent
a8581ac8a4
commit
3c3bd647f7
|
@ -62,7 +62,9 @@ CONFIG_RT_USING_HEAP=y
|
|||
CONFIG_RT_USING_DEVICE=y
|
||||
# CONFIG_RT_USING_DEVICE_OPS is not set
|
||||
# CONFIG_RT_USING_INTERRUPT_INFO is not set
|
||||
# CONFIG_RT_USING_CONSOLE is not set
|
||||
CONFIG_RT_USING_CONSOLE=y
|
||||
CONFIG_RT_CONSOLEBUF_SIZE=256
|
||||
CONFIG_RT_CONSOLE_DEVICE_NAME="uart"
|
||||
CONFIG_RT_VER_NUM=0x40101
|
||||
# CONFIG_RT_USING_CPU_FFS is not set
|
||||
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
|
||||
|
@ -73,7 +75,21 @@ CONFIG_RT_VER_NUM=0x40101
|
|||
CONFIG_RT_USING_COMPONENTS_INIT=y
|
||||
# CONFIG_RT_USING_USER_MAIN is not set
|
||||
# CONFIG_RT_USING_LEGACY is not set
|
||||
# CONFIG_RT_USING_MSH is not set
|
||||
CONFIG_RT_USING_MSH=y
|
||||
CONFIG_RT_USING_FINSH=y
|
||||
CONFIG_FINSH_USING_MSH=y
|
||||
CONFIG_FINSH_THREAD_NAME="tshell"
|
||||
CONFIG_FINSH_THREAD_PRIORITY=20
|
||||
CONFIG_FINSH_THREAD_STACK_SIZE=4096
|
||||
CONFIG_FINSH_USING_HISTORY=y
|
||||
CONFIG_FINSH_HISTORY_LINES=5
|
||||
CONFIG_FINSH_USING_SYMTAB=y
|
||||
CONFIG_FINSH_CMD_SIZE=80
|
||||
CONFIG_MSH_USING_BUILT_IN_COMMANDS=y
|
||||
CONFIG_FINSH_USING_DESCRIPTION=y
|
||||
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
|
||||
# CONFIG_FINSH_USING_AUTH is not set
|
||||
CONFIG_FINSH_ARG_MAX=10
|
||||
# CONFIG_RT_USING_DFS is not set
|
||||
# CONFIG_RT_USING_FAL is not set
|
||||
|
||||
|
@ -82,7 +98,11 @@ CONFIG_RT_USING_COMPONENTS_INIT=y
|
|||
#
|
||||
CONFIG_RT_USING_DEVICE_IPC=y
|
||||
# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set
|
||||
# CONFIG_RT_USING_SERIAL is not set
|
||||
CONFIG_RT_USING_SERIAL=y
|
||||
CONFIG_RT_USING_SERIAL_V1=y
|
||||
# CONFIG_RT_USING_SERIAL_V2 is not set
|
||||
# CONFIG_RT_SERIAL_USING_DMA is not set
|
||||
CONFIG_RT_SERIAL_RB_BUFSZ=64
|
||||
# CONFIG_RT_USING_CAN is not set
|
||||
# CONFIG_RT_USING_HWTIMER is not set
|
||||
# CONFIG_RT_USING_CPUTIME is not set
|
||||
|
@ -620,9 +640,12 @@ CONFIG_BSP_BOARD_LUATOS_ESP32C3=y
|
|||
# Onboard Peripheral Drivers
|
||||
#
|
||||
CONFIG_RT_BSP_LED_PIN=12
|
||||
CONFIG_RT_BSP_UART_PORT=0
|
||||
CONFIG_RT_BSP_UART_TX_PIN=21
|
||||
CONFIG_RT_BSP_UART_RX_PIN=20
|
||||
|
||||
#
|
||||
# On-chip Peripheral Drivers
|
||||
#
|
||||
CONFIG_BSP_USING_GPIO=y
|
||||
# CONFIG_BSP_USING_UART is not set
|
||||
CONFIG_BSP_USING_UART=y
|
||||
|
|
|
@ -1,393 +0,0 @@
|
|||
From 317ee995e9d530587bfb14439b3b1ee38d1afe77 Mon Sep 17 00:00:00 2001
|
||||
From: supperthomas <78900636@qq.com>
|
||||
Date: Fri, 6 May 2022 23:06:28 +0800
|
||||
Subject: [PATCH] add the config of RTTHREAD
|
||||
|
||||
add the init link file
|
||||
---
|
||||
Kconfig | 4 +
|
||||
.../esp_system/ld/esp32c3/sections.ld.in | 26 +++
|
||||
components/freertos/port/port_common.c | 5 +
|
||||
components/freertos/port/port_systick.c | 3 +
|
||||
components/riscv/vectors.S | 220 ++++++++++++++++--
|
||||
5 files changed, 239 insertions(+), 19 deletions(-)
|
||||
|
||||
diff --git a/Kconfig b/Kconfig
|
||||
index 928d274106..d368adaa37 100644
|
||||
--- a/Kconfig
|
||||
+++ b/Kconfig
|
||||
@@ -61,6 +61,10 @@ mainmenu "Espressif IoT Development Framework Configuration"
|
||||
bool
|
||||
default "y" if IDF_TARGET="linux"
|
||||
|
||||
+ config IDF_RTOS_RTTHREAD
|
||||
+ bool "RT-THREAD SELECT"
|
||||
+ default "n"
|
||||
+
|
||||
config IDF_FIRMWARE_CHIP_ID
|
||||
hex
|
||||
default 0x0000 if IDF_TARGET_ESP32
|
||||
diff --git a/components/esp_system/ld/esp32c3/sections.ld.in b/components/esp_system/ld/esp32c3/sections.ld.in
|
||||
index 0ebeda06c1..8215237fff 100644
|
||||
--- a/components/esp_system/ld/esp32c3/sections.ld.in
|
||||
+++ b/components/esp_system/ld/esp32c3/sections.ld.in
|
||||
@@ -183,6 +183,32 @@ SECTIONS
|
||||
_noinit_end = ABSOLUTE(.);
|
||||
} > dram0_0_seg
|
||||
|
||||
+ .stack_dummy (COPY):
|
||||
+ {
|
||||
+ . = ALIGN(8);
|
||||
+ __STACKSIZE__ = 40960;
|
||||
+ __stack_start__ = .;
|
||||
+ *(.stack*)
|
||||
+ . += __STACKSIZE__;
|
||||
+ __stack_cpu0 = .;
|
||||
+ __stack_end__ = .;
|
||||
+ } > dram0_0_seg
|
||||
+
|
||||
+ .stack_dummy (COPY):
|
||||
+ {
|
||||
+ . = ALIGN(8);
|
||||
+ __HEAPSIZE__ = 40960;
|
||||
+ __heap_start__ = .;
|
||||
+ . += __STACKSIZE__;
|
||||
+ __heap_end__ = .;
|
||||
+ /* section information for initial. */
|
||||
+ . = ALIGN(4);
|
||||
+ __rt_init_start = .;
|
||||
+ KEEP(*(SORT(.rti_fn*)))
|
||||
+ __rt_init_end = .;
|
||||
+
|
||||
+ . = ALIGN(4);
|
||||
+ } > dram0_0_seg
|
||||
/* Shared RAM */
|
||||
.dram0.bss (NOLOAD) :
|
||||
{
|
||||
diff --git a/components/freertos/port/port_common.c b/components/freertos/port/port_common.c
|
||||
index ffca3d5429..9d8159f588 100644
|
||||
--- a/components/freertos/port/port_common.c
|
||||
+++ b/components/freertos/port/port_common.c
|
||||
@@ -74,11 +74,16 @@ void esp_startup_start_app_common(void)
|
||||
esp_gdbstub_init();
|
||||
#endif // CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
|
||||
|
||||
+#ifdef CONFIG_IDF_RTOS_RTTHREAD
|
||||
+ app_main();
|
||||
+#else
|
||||
portBASE_TYPE res = xTaskCreatePinnedToCore(&main_task, "main",
|
||||
ESP_TASK_MAIN_STACK, NULL,
|
||||
ESP_TASK_MAIN_PRIO, NULL, ESP_TASK_MAIN_CORE);
|
||||
assert(res == pdTRUE);
|
||||
(void)res;
|
||||
+#endif
|
||||
+
|
||||
}
|
||||
|
||||
static void main_task(void* args)
|
||||
diff --git a/components/freertos/port/port_systick.c b/components/freertos/port/port_systick.c
|
||||
index 0c14a155a1..0fa203574b 100644
|
||||
--- a/components/freertos/port/port_systick.c
|
||||
+++ b/components/freertos/port/port_systick.c
|
||||
@@ -116,6 +116,8 @@ void vPortSetupTimer(void)
|
||||
*/
|
||||
IRAM_ATTR void SysTickIsrHandler(void *arg)
|
||||
{
|
||||
+#ifdef CONFIG_IDF_RTOS_RTTHREAD
|
||||
+#else
|
||||
uint32_t cpuid = xPortGetCoreID();
|
||||
systimer_hal_context_t *systimer_hal = (systimer_hal_context_t *)arg;
|
||||
#ifdef CONFIG_PM_TRACE
|
||||
@@ -144,6 +146,7 @@ IRAM_ATTR void SysTickIsrHandler(void *arg)
|
||||
#ifdef CONFIG_PM_TRACE
|
||||
ESP_PM_TRACE_EXIT(TICK, cpuid);
|
||||
#endif
|
||||
+#endif
|
||||
}
|
||||
|
||||
#endif // CONFIG_FREERTOS_SYSTICK_USES_CCOUNT
|
||||
diff --git a/components/riscv/vectors.S b/components/riscv/vectors.S
|
||||
index 1006d5bea5..963494fcb3 100644
|
||||
--- a/components/riscv/vectors.S
|
||||
+++ b/components/riscv/vectors.S
|
||||
@@ -17,6 +17,9 @@
|
||||
#include "soc/soc_caps.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
+#define STORE sw
|
||||
+#define LOAD lw
|
||||
+#define REGBYTES 4
|
||||
|
||||
.equ SAVE_REGS, 32
|
||||
.equ CONTEXT_SIZE, (SAVE_REGS * 4)
|
||||
@@ -218,25 +221,27 @@ _call_panic_handler:
|
||||
*/
|
||||
.global _interrupt_handler
|
||||
.type _interrupt_handler, @function
|
||||
+#ifndef CONFIG_IDF_RTOS_RTTHREAD
|
||||
+
|
||||
_interrupt_handler:
|
||||
/* entry */
|
||||
- save_regs
|
||||
- save_mepc
|
||||
+ save_regs /* 保存寄存器 */
|
||||
+ save_mepc /* 保存MEPC */
|
||||
|
||||
/* Before doing anythig preserve the stack pointer */
|
||||
/* It will be saved in current TCB, if needed */
|
||||
- mv a0, sp
|
||||
+ mv a0, sp /* 保存SP a0 = sp */
|
||||
call rtos_int_enter
|
||||
|
||||
/* Before dispatch c handler, restore interrupt to enable nested intr */
|
||||
- csrr s1, mcause
|
||||
- csrr s2, mstatus
|
||||
+ csrr s1, mcause /* 保存mcause s1 = mcause */
|
||||
+ csrr s2, mstatus /* 保存mstatus s2 = mstatus */
|
||||
|
||||
- /* Save the interrupt threshold level */
|
||||
- la t0, INTERRUPT_CORE0_CPU_INT_THRESH_REG
|
||||
- lw s3, 0(t0)
|
||||
+ /* Save the interrupt threshold level 保存中断嵌套层数? */
|
||||
+ la t0, INTERRUPT_CORE0_CPU_INT_THRESH_REG /* 保存mstatus t0 = &INTERRUPT_CORE0_CPU_INT_THRESH_REG */
|
||||
+ lw s3, 0(t0) /* s3 = mstatus */
|
||||
|
||||
- /* Increase interrupt threshold level */
|
||||
+ /* Increase interrupt threshold level 增加中断嵌套层数*/
|
||||
li t2, 0x7fffffff
|
||||
and t1, s1, t2 /* t1 = mcause & mask */
|
||||
slli t1, t1, 2 /* t1 = mcause * 4 */
|
||||
@@ -247,8 +252,8 @@ _interrupt_handler:
|
||||
sw t2, 0(t0) /* INTERRUPT_CORE0_CPU_INT_THRESH_REG = t2 */
|
||||
fence
|
||||
|
||||
- li t0, 0x8
|
||||
- csrrs t0, mstatus, t0
|
||||
+ li t0, 0x8 /* t0 = 8 */
|
||||
+ csrrs t0, mstatus, t0 /*设置状态MIE寄存器,开总中断*/
|
||||
|
||||
#ifdef CONFIG_PM_TRACE
|
||||
li a0, 0 /* = ESP_PM_TRACE_IDLE */
|
||||
@@ -269,34 +274,211 @@ _interrupt_handler:
|
||||
/* call the C dispatcher */
|
||||
mv a0, sp /* argument 1, stack pointer */
|
||||
mv a1, s1 /* argument 2, interrupt number (mcause) */
|
||||
- /* mask off the interrupt flag of mcause */
|
||||
+ /* mask off the interrupt flag of mcause 屏幕异常中断*/
|
||||
li t0, 0x7fffffff
|
||||
and a1, a1, t0
|
||||
jal _global_interrupt_handler
|
||||
|
||||
- /* After dispatch c handler, disable interrupt to make freertos make context switch */
|
||||
+ /* After dispatch c handler, disable interrupt to make freertos make context switch
|
||||
+ 在调用c函数之后,disable 中断让freertos能够做内容切换
|
||||
+ */
|
||||
|
||||
li t0, 0x8
|
||||
- csrrc t0, mstatus, t0
|
||||
+ csrrc t0, mstatus, t0 /*清状态MIE寄存器 关总中断*/
|
||||
|
||||
- /* restore the interrupt threshold level */
|
||||
+
|
||||
+ /* restore the interrupt threshold level 中断嵌套 */
|
||||
la t0, INTERRUPT_CORE0_CPU_INT_THRESH_REG
|
||||
sw s3, 0(t0)
|
||||
fence
|
||||
|
||||
/* Yield to the next task is needed: */
|
||||
- mv a0, sp
|
||||
+ mv a0, sp /* a0 = sp*/
|
||||
call rtos_int_exit
|
||||
|
||||
/* The next (or current) stack pointer is returned in a0 */
|
||||
- mv sp, a0
|
||||
+ mv sp, a0 /* sp = a0*/
|
||||
|
||||
/* restore the rest of the registers */
|
||||
- csrw mcause, s1
|
||||
- csrw mstatus, s2
|
||||
+ csrw mcause, s1 /* mcause = s1 */
|
||||
+ csrw mstatus, s2 /* mstatus = s2 */
|
||||
restore_mepc
|
||||
restore_regs
|
||||
|
||||
/* exit, this will also re-enable the interrupts */
|
||||
mret
|
||||
.size _interrupt_handler, .-_interrupt_handler
|
||||
+#else
|
||||
+_interrupt_handler:
|
||||
+ /* 此时CPU的sp = from_thread->sp */
|
||||
+ /* 注意: 在这里,并没有将mepc的值赋值为from_thread栈中的epc,但后面会赋值 */
|
||||
+ addi sp, sp, -32 * REGBYTES /* sp = sp - 32 * 4 栈指针向下偏移32个寄存器长度,用来将CPU的寄存器保存到from_thread的栈中*/
|
||||
+ STORE x1, 1 * REGBYTES(sp) /* 将CPU的x1寄存器,即ra寄存器,保存到from_thread->栈中 */
|
||||
+
|
||||
+ li t0, 0x80 /* t0 = 0x80 */
|
||||
+ STORE t0, 2 * REGBYTES(sp) /* mstatus = t0, 即关闭全局中断 */
|
||||
+
|
||||
+ /* 将 CPU 的其他寄存器的值,保存到from_thread的任务栈中 */
|
||||
+ STORE x4, 4 * REGBYTES(sp)
|
||||
+ STORE x5, 5 * REGBYTES(sp)
|
||||
+ STORE x6, 6 * REGBYTES(sp)
|
||||
+ STORE x7, 7 * REGBYTES(sp)
|
||||
+ STORE x8, 8 * REGBYTES(sp)
|
||||
+ STORE x9, 9 * REGBYTES(sp)
|
||||
+ STORE x10, 10 * REGBYTES(sp)
|
||||
+ STORE x11, 11 * REGBYTES(sp)
|
||||
+ STORE x12, 12 * REGBYTES(sp)
|
||||
+ STORE x13, 13 * REGBYTES(sp)
|
||||
+ STORE x14, 14 * REGBYTES(sp)
|
||||
+ STORE x15, 15 * REGBYTES(sp)
|
||||
+ STORE x16, 16 * REGBYTES(sp)
|
||||
+ STORE x17, 17 * REGBYTES(sp)
|
||||
+ STORE x18, 18 * REGBYTES(sp)
|
||||
+ STORE x19, 19 * REGBYTES(sp)
|
||||
+ STORE x20, 20 * REGBYTES(sp)
|
||||
+ STORE x21, 21 * REGBYTES(sp)
|
||||
+ STORE x22, 22 * REGBYTES(sp)
|
||||
+ STORE x23, 23 * REGBYTES(sp)
|
||||
+ STORE x24, 24 * REGBYTES(sp)
|
||||
+ STORE x25, 25 * REGBYTES(sp)
|
||||
+ STORE x26, 26 * REGBYTES(sp)
|
||||
+ STORE x27, 27 * REGBYTES(sp)
|
||||
+ STORE x28, 28 * REGBYTES(sp)
|
||||
+ STORE x29, 29 * REGBYTES(sp)
|
||||
+ STORE x30, 30 * REGBYTES(sp)
|
||||
+ STORE x31, 31 * REGBYTES(sp)
|
||||
+
|
||||
+ /* 备份 CPU 的 sp (这时,CPU的sp其实就是from thread的sp指针) 寄存器的值到 s0 寄存器中,下面会使用s0,恢复 CPU 的寄存器 */
|
||||
+ move s0, sp /* s0 = sp */
|
||||
+
|
||||
+ /* 在中断函数中,中断函数中调用的C函数,需要使用 sp, 这里,在中断函数中,使用的 sp 为,系统的栈资源 */
|
||||
+ /* switch to interrupt stack */
|
||||
+ la sp, __stack_end__ /* sp = _sp */
|
||||
+
|
||||
+ /* interrupt handle */
|
||||
+ /* 注意: 在调用C函数之前,比如sp的值为0x30001000, 在执行完C函数后,sp的值还是会变成 0x30001000 */
|
||||
+ call rt_interrupt_enter /* 执行所有的中断函数前,调用该函数 */
|
||||
+
|
||||
+ csrr s1, mcause
|
||||
+ csrr s2, mstatus
|
||||
+
|
||||
+ /* Save the interrupt threshold level */
|
||||
+ la t0, INTERRUPT_CORE0_CPU_INT_THRESH_REG
|
||||
+ lw s3, 0(t0)
|
||||
+
|
||||
+ li t2, 0x7fffffff
|
||||
+ and t1, s1, t2 /* t1 = mcause & mask */
|
||||
+ slli t1, t1, 2 /* t1 = mcause * 4 */
|
||||
+ la t2, INTC_INT_PRIO_REG(0)
|
||||
+ add t1, t2, t1 /* t1 = INTC_INT_PRIO_REG + 4 * mcause */
|
||||
+ lw t2, 0(t1) /* t2 = INTC_INT_PRIO_REG[mcause] */
|
||||
+ addi t2, t2, 1 /* t2 = t2 +1 */
|
||||
+ sw t2, 0(t0) /* INTERRUPT_CORE0_CPU_INT_THRESH_REG = t2 */
|
||||
+ fence
|
||||
+
|
||||
+ li t0, 0x8
|
||||
+ csrrs t0, mstatus, t0
|
||||
+
|
||||
+ /* call the C dispatcher */
|
||||
+ mv a0, sp /* argument 1, stack pointer */
|
||||
+ mv a1, s1 /* argument 2, interrupt number (mcause) */
|
||||
+ /* mask off the interrupt flag of mcause */
|
||||
+ li t0, 0x7fffffff
|
||||
+ and a1, a1, t0
|
||||
+ jal _global_interrupt_handler
|
||||
+
|
||||
+ li t0, 0x8
|
||||
+ csrrc t0, mstatus, t0
|
||||
+
|
||||
+ /* restore the interrupt threshold level */
|
||||
+ la t0, INTERRUPT_CORE0_CPU_INT_THRESH_REG
|
||||
+ sw s3, 0(t0)
|
||||
+ fence
|
||||
+
|
||||
+ call rt_interrupt_leave /* 执行所有的中断函数后,调用该函数 */
|
||||
+
|
||||
+ /* 上面,将保存执行中断服务函数之前的CPU的sp寄存器到了s0所指向的位置处,当执行完中断服务函数,需要将之前的CPU寄存器,恢复一下,此时sp又变成了from thread的sp了 */
|
||||
+ move sp, s0 /* sp = s0 */
|
||||
+
|
||||
+ /* 下面两句话,相当于将 rt_thread_switch_interrupt_flag 值,赋值给了s2 */
|
||||
+ /* 将 rt_thread_switch_interrupt_flag 的地址值,赋值给 s0 寄存器*/
|
||||
+ la s0, rt_thread_switch_interrupt_flag /* s0 = &rt_thread_switch_interrupt_flag */
|
||||
+ /* 将 s0 所指向的地址处的内容,取出来,赋值给 s2 寄存器,其实就是将 rt_thread_switch_interrupt_flag 的值,赋值给了 s2 寄存器*/
|
||||
+ lw s2, 0(s0) /* s2 = *s0 = rt_thread_switch_interrupt_flag */
|
||||
+
|
||||
+ /* 如果 s2的值,即 rt_thread_switch_interrupt_flag 值,如果不为0,则需要继续执行下一条指令,如果为0,则需要跳转到 spurious_interrupt 标号处 执行 */
|
||||
+ /* 如果 s2的值等于0,rt_thread_switch_interrupt_flag等于0, 则不需要在中断处理函数中,进行上下文切换,反之则需要 */
|
||||
+ /* 如果不需要上下文切换, */
|
||||
+
|
||||
+ /* 在这里,跳转到 spurious_interrupt的话,是不会进行上下文切换的,因为,此时CPU的sp指针还是from线程的*/
|
||||
+ beqz s2, spurious_interrupt /* if (s2 == 0) goto spurious_interrupt; else 执行下一条语句*/
|
||||
+
|
||||
+ /* 需要上下文切换: 主要目的是将CPU的sp指针,赋值为to_thread的sp */
|
||||
+
|
||||
+ /* 将 s0 所执向的地址的内容设置为0, 也就是,将变量 rt_thread_switch_interrupt_flag 赋值为了 0 */
|
||||
+ /* s0存放的值是 rt_thread_switch_interrupt_flag 变量的地址*/
|
||||
+ sw zero, 0(s0) /* *s0 = 0; 也就是 rt_thread_switch_interrupt_flag = 0 */
|
||||
+ /* 将 mepc 的值,赋值给 a0 寄存器,mepc 的值是,跳转到中断函数执行之前的 PC 指针 */
|
||||
+ /* 这时的mpec其实,还是from线程,在跳转到中断执行前的一个PC地址 */
|
||||
+ csrr a0, mepc /* a0 = mepc */
|
||||
+
|
||||
+ /* 将 mpec 的值写回到freom thread任务栈中的 epc 中,待后续,恢复from线程时,使用 */
|
||||
+ STORE a0, 0 * REGBYTES(sp) /* from_thread->sp->epc = a0 ,中断入口处*/
|
||||
+
|
||||
+ /* 将from_thread的sp指针,赋值为CPU的sp指针 */
|
||||
+ la s0, rt_interrupt_from_thread /* s0 = &rt_interrupt_from_thread 注意: rt_interrupt_from_thread = &(from_thread->sp) */
|
||||
+ LOAD s1, 0(s0) /* s1 = rt_interrupt_from_thread,也就是s1 = &(from_thread->sp) */
|
||||
+ STORE sp, 0(s1) /* from_thread->sp = sp*/
|
||||
+
|
||||
+ /* 接下来,需要开始恢复CPU的sp为to_thread的sp了 */
|
||||
+ la s0, rt_interrupt_to_thread /* s0 = &rt_interrupt_to_thread 注意: rt_interrupt_to_thread = &(to_thred->sp)*/
|
||||
+ LOAD s1, 0(s0) /* s1 = rt_interrupt_to_thread, 也就是s1 = &(to_thred->sp) */
|
||||
+ LOAD sp, 0(s1) /* sp = (to_thred->sp)*/
|
||||
+
|
||||
+ /* 将CPU的 mepc设置为to_thred的mepc,待中断退出,执行mret指令后,将从该地址开始执行 */
|
||||
+ LOAD a0, 0 * REGBYTES(sp) /* a0 = to_thread的mepc的值*/
|
||||
+ csrw mepc, a0 /* mepc = a0 */
|
||||
+
|
||||
+
|
||||
+spurious_interrupt:
|
||||
+ LOAD x1, 1 * REGBYTES(sp)
|
||||
+
|
||||
+ /* Remain in M-mode after mret */
|
||||
+ li t0, 0x00001800
|
||||
+ csrs mstatus, t0
|
||||
+ LOAD t0, 2 * REGBYTES(sp)
|
||||
+ csrs mstatus, t0
|
||||
+
|
||||
+ LOAD x4, 4 * REGBYTES(sp)
|
||||
+ LOAD x5, 5 * REGBYTES(sp)
|
||||
+ LOAD x6, 6 * REGBYTES(sp)
|
||||
+ LOAD x7, 7 * REGBYTES(sp)
|
||||
+ LOAD x8, 8 * REGBYTES(sp)
|
||||
+ LOAD x9, 9 * REGBYTES(sp)
|
||||
+ LOAD x10, 10 * REGBYTES(sp)
|
||||
+ LOAD x11, 11 * REGBYTES(sp)
|
||||
+ LOAD x12, 12 * REGBYTES(sp)
|
||||
+ LOAD x13, 13 * REGBYTES(sp)
|
||||
+ LOAD x14, 14 * REGBYTES(sp)
|
||||
+ LOAD x15, 15 * REGBYTES(sp)
|
||||
+ LOAD x16, 16 * REGBYTES(sp)
|
||||
+ LOAD x17, 17 * REGBYTES(sp)
|
||||
+ LOAD x18, 18 * REGBYTES(sp)
|
||||
+ LOAD x19, 19 * REGBYTES(sp)
|
||||
+ LOAD x20, 20 * REGBYTES(sp)
|
||||
+ LOAD x21, 21 * REGBYTES(sp)
|
||||
+ LOAD x22, 22 * REGBYTES(sp)
|
||||
+ LOAD x23, 23 * REGBYTES(sp)
|
||||
+ LOAD x24, 24 * REGBYTES(sp)
|
||||
+ LOAD x25, 25 * REGBYTES(sp)
|
||||
+ LOAD x26, 26 * REGBYTES(sp)
|
||||
+ LOAD x27, 27 * REGBYTES(sp)
|
||||
+ LOAD x28, 28 * REGBYTES(sp)
|
||||
+ LOAD x29, 29 * REGBYTES(sp)
|
||||
+ LOAD x30, 30 * REGBYTES(sp)
|
||||
+ LOAD x31, 31 * REGBYTES(sp)
|
||||
+
|
||||
+ addi sp, sp, 32 * REGBYTES
|
||||
+ mret
|
||||
+ .size _interrupt_handler, .-_interrupt_handler
|
||||
+#endif
|
||||
--
|
||||
2.35.1.windows.2
|
||||
|
|
@ -45,7 +45,7 @@
|
|||
| **片上外设** | **支持情况** | **备注** |
|
||||
| :----------------- | :----------: | :------------------------------------- |
|
||||
| GPIO | 支持 | |
|
||||
| UART | 支持中 | |
|
||||
| UART | 支持 | 使用LUATOS_ESP32C3开发板需要在UART0_TX和UART0_RX连接串口转USB芯片(如CP2102)|
|
||||
| JTAG调试 | 支持 | ESP32C3采用USB方式和PC链接的开发板可以调试 |
|
||||
|
||||
## 使用说明
|
||||
|
@ -58,15 +58,15 @@ IDF的搭建方法有很多种,尝试了很多种方法之后,总结了一
|
|||
|
||||
### ESP-IDF 添加RT-THREAD patch
|
||||
|
||||
由于IDF使用的是FREERTOS,如果需要使用rt-thread就需要修改一些文件。将`0001-add-the-config-of-RTTHREAD.patch` 这个文件拷贝到IDF的代码目录下面,然后在`git bash`命令行内执行命令下面几条命令就可以打上patch
|
||||
由于IDF使用的是FREERTOS,如果需要使用rt-thread就需要修改一些文件。将`rtt.patch` 这个文件拷贝到IDF的代码目录下面,然后在`git bash`命令行内执行命令下面几条命令就可以打上patch
|
||||
|
||||
```
|
||||
cd esp/esp-idf
|
||||
git checkout v4.4
|
||||
git am 0001-add-the-config-of-RTTHREAD.patch
|
||||
git am rtt.patch
|
||||
```
|
||||
|
||||
如果不想用patch文件,已经将代码上传到github上面,可以进入[supperthomas/esp-idf](https://github.com/supperthomas/esp-idf) 下载最新的master分支代码即可。修改之后的IDF,原来的IDF的example还是正常使用,互不干扰,可以放心使用。
|
||||
如果不想用patch文件,已经将代码上传到github上面,可以进入[tangzz98/esp-idf](https://github.com/tangzz98/esp-idf/tree/freertos_wrapper) 下载最新的freertos_wrapper分支代码即可。修改之后的IDF,原来的IDF的example还是正常使用,互不干扰,可以放心使用。
|
||||
|
||||
#### 编译下载
|
||||
|
||||
|
|
|
@ -27,6 +27,21 @@ menu "Onboard Peripheral Drivers"
|
|||
default 8 if BSP_BOARD_HX_EXP32C3
|
||||
depends on BSP_USING_GPIO
|
||||
|
||||
config RT_BSP_UART_PORT
|
||||
int "UART PORT SET"
|
||||
default 0
|
||||
depends on BSP_USING_UART
|
||||
|
||||
config RT_BSP_UART_TX_PIN
|
||||
int "UART TX PIN SET"
|
||||
default 21 if BSP_BOARD_LUATOS_ESP32C3
|
||||
depends on BSP_USING_UART
|
||||
|
||||
config RT_BSP_UART_RX_PIN
|
||||
int "UART RX PIN SET"
|
||||
default 20 if BSP_BOARD_LUATOS_ESP32C3
|
||||
depends on BSP_USING_UART
|
||||
|
||||
endmenu
|
||||
|
||||
|
||||
|
@ -38,7 +53,9 @@ menu "On-chip Peripheral Drivers"
|
|||
|
||||
config BSP_USING_UART
|
||||
bool "Enable UART"
|
||||
default n
|
||||
select RT_USING_SERIAL
|
||||
select RT_USING_SERIAL_V1
|
||||
default y
|
||||
endmenu
|
||||
|
||||
endmenu
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
idf_component_register(SRCS "board.c" "main.c"
|
||||
"drv_gpio.c"
|
||||
"drv_uart.c"
|
||||
"../../../libcpu/risc-v/common/cpuport.c"
|
||||
"../../../libcpu/risc-v/common/context_gcc.S"
|
||||
"../../../src/components.c"
|
||||
|
@ -24,11 +25,18 @@ idf_component_register(SRCS "board.c" "main.c"
|
|||
"../../../components/drivers/ipc/dataqueue.c"
|
||||
"../../../components/drivers/ipc/ringbuffer.c"
|
||||
"../../../components/drivers/ipc/workqueue.c"
|
||||
"../../../components/drivers/serial/serial.c"
|
||||
"../../../components/finsh/cmd.c"
|
||||
"../../../components/finsh/msh_file.c"
|
||||
"../../../components/finsh/msh_parse.c"
|
||||
"../../../components/finsh/msh.c"
|
||||
"../../../components/finsh/shell.c"
|
||||
|
||||
INCLUDE_DIRS
|
||||
"../../../components/drivers/include/drivers"
|
||||
|
||||
"../../../components/drivers/include"
|
||||
"../../../components/finsh"
|
||||
"."
|
||||
"../../../include"
|
||||
"../../../libcpu/risc-v/common"
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include "rtthread.h"
|
||||
#include "rthw.h"
|
||||
#include "drv_gpio.h"
|
||||
|
||||
#define rt_kprintf printf
|
||||
#include "drv_uart.h"
|
||||
#include "shell.h"
|
||||
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
/*
|
||||
|
@ -190,16 +190,13 @@ void rt_hw_systick_init(void)
|
|||
void rt_hw_board_init(void)
|
||||
{
|
||||
rt_hw_systick_init();
|
||||
#if defined(RT_USING_HEAP)
|
||||
extern int __heap_start__;
|
||||
extern int __heap_end__;
|
||||
printf("%s:%d__heap_start__:%p,__heap_end__:%p\n",__func__,__LINE__,&__heap_start__,&__heap_end__);
|
||||
rt_system_heap_init((void *)&__heap_start__, (void *)&__heap_end__);
|
||||
#endif
|
||||
/* Board underlying hardware initialization */
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
rt_components_board_init();
|
||||
#endif
|
||||
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
|
||||
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void rtthread_startup(void)
|
||||
|
@ -207,15 +204,10 @@ static void rtthread_startup(void)
|
|||
rt_hw_interrupt_disable();
|
||||
/* init board */
|
||||
rt_hw_board_init();
|
||||
/* show RT-Thread version */
|
||||
rt_show_version();
|
||||
|
||||
/* timer system initialization */
|
||||
rt_system_timer_init();
|
||||
|
||||
/* scheduler system initialization */
|
||||
rt_system_scheduler_init();
|
||||
|
||||
/* create init_thread */
|
||||
rt_application_init();
|
||||
|
||||
|
@ -229,6 +221,8 @@ static void rtthread_startup(void)
|
|||
rt_system_scheduler_start();
|
||||
/* init scheduler system */
|
||||
rt_hw_pin_init();
|
||||
rt_hw_uart_init();
|
||||
finsh_system_init();
|
||||
/* never reach here */
|
||||
return ;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-08-04 tangzz98 first version
|
||||
*
|
||||
*/
|
||||
|
||||
#include "drv_uart.h"
|
||||
|
||||
#ifdef RT_USING_SERIAL_V1
|
||||
|
||||
#ifdef CONFIG_UART_ISR_IN_IRAM
|
||||
#define UART_ISR_ATTR IRAM_ATTR
|
||||
#else
|
||||
#define UART_ISR_ATTR
|
||||
#endif
|
||||
|
||||
uart_hal_context_t hal[] = {
|
||||
{
|
||||
.dev = &UART0,
|
||||
},
|
||||
{
|
||||
.dev = &UART1,
|
||||
},
|
||||
};
|
||||
|
||||
static struct rt_serial_device _serial;
|
||||
|
||||
static void mcu_uart_rx_intr_handler(void *param)
|
||||
{
|
||||
uint32_t uart_intr_status;
|
||||
struct rt_serial_device *serial;
|
||||
uart_port_t port;
|
||||
rt_interrupt_enter();
|
||||
serial = (struct rt_serial_device *)param;
|
||||
port = (uart_port_t)serial->parent.user_data;
|
||||
uart_intr_status = uart_hal_get_intsts_mask(&hal[port]);
|
||||
if (uart_intr_status != 0)
|
||||
{
|
||||
if (uart_intr_status & UART_INTR_RXFIFO_FULL)
|
||||
{
|
||||
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
|
||||
}
|
||||
uart_hal_clr_intsts_mask(&hal[port], uart_intr_status);
|
||||
}
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
|
||||
static rt_err_t mcu_uart_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t mcu_uart_control(struct rt_serial_device *serial, int cmd, void *arg)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static int mcu_uart_putc(struct rt_serial_device *serial, char c)
|
||||
{
|
||||
uart_port_t port = (uart_port_t)serial->parent.user_data;
|
||||
uint32_t write_size = 0;
|
||||
do
|
||||
{
|
||||
uart_hal_write_txfifo(&hal[port], (const uint8_t *)&c, 1, &write_size);
|
||||
} while (write_size == 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int mcu_uart_getc(struct rt_serial_device *serial)
|
||||
{
|
||||
uart_port_t port = (uart_port_t)serial->parent.user_data;
|
||||
uint8_t c;
|
||||
int len = uart_hal_get_rxfifo_len(&hal[port]);
|
||||
if (len == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = 1;
|
||||
uart_hal_read_rxfifo(&hal[port], &c, &len);
|
||||
return (int)c;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct rt_uart_ops _uart_ops =
|
||||
{
|
||||
mcu_uart_configure,
|
||||
mcu_uart_control,
|
||||
mcu_uart_putc,
|
||||
mcu_uart_getc,
|
||||
RT_NULL,
|
||||
};
|
||||
|
||||
int rt_hw_uart_init(void)
|
||||
{
|
||||
uart_intr_config_t uart_intr = {
|
||||
.intr_enable_mask = UART_INTR_RXFIFO_FULL,
|
||||
.rxfifo_full_thresh = 1,
|
||||
};
|
||||
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
|
||||
uart_config_t uart_config = {
|
||||
.baud_rate = BAUD_RATE_115200,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||
.source_clk = UART_SCLK_APB,
|
||||
};
|
||||
int intr_alloc_flags = 0;
|
||||
|
||||
#if CONFIG_UART_ISR_IN_IRAM
|
||||
intr_alloc_flags = ESP_INTR_FLAG_IRAM;
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(uart_param_config(RT_BSP_UART_PORT, &uart_config));
|
||||
ESP_ERROR_CHECK(uart_set_pin(RT_BSP_UART_PORT, RT_BSP_UART_TX_PIN, RT_BSP_UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
|
||||
ESP_ERROR_CHECK(esp_intr_alloc(uart_periph_signal[RT_BSP_UART_PORT].irq, intr_alloc_flags, mcu_uart_rx_intr_handler, (void *)&_serial, NULL));
|
||||
ESP_ERROR_CHECK(uart_intr_config(RT_BSP_UART_PORT, &uart_intr));
|
||||
_serial.ops = &_uart_ops;
|
||||
_serial.config = config;
|
||||
|
||||
return rt_hw_serial_register(&_serial, "uart", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, (void *)RT_BSP_UART_PORT);
|
||||
}
|
||||
INIT_BOARD_EXPORT(rt_hw_uart_init);
|
||||
|
||||
#endif /* RT_USING_SERIAL_V1 */
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-08-04 tangzz98 first version
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __DRV_UART_H__
|
||||
#define __DRV_UART_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
|
||||
#ifdef RT_USING_DEVICE
|
||||
#include <rtdevice.h>
|
||||
#endif
|
||||
|
||||
#include "driver/uart.h"
|
||||
#include "hal/uart_hal.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
int rt_hw_uart_init(void);
|
||||
|
||||
#endif /* __DRV_UART_H__ */
|
|
@ -15,10 +15,12 @@
|
|||
|
||||
int rtt_main(void)
|
||||
{
|
||||
/* show RT-Thread version */
|
||||
rt_show_version();
|
||||
rt_kprintf("Hello!RT-THREAD!\r\n");
|
||||
rt_pin_mode(RT_BSP_LED_PIN, PIN_MODE_OUTPUT);
|
||||
while (1)
|
||||
{
|
||||
printf("Hello!RT-THREAD!\r\n");
|
||||
rt_pin_write(RT_BSP_LED_PIN, PIN_HIGH);
|
||||
rt_thread_mdelay(1000);
|
||||
rt_pin_write(RT_BSP_LED_PIN, PIN_LOW);
|
||||
|
|
|
@ -34,16 +34,34 @@
|
|||
/* Kernel Device Object */
|
||||
|
||||
#define RT_USING_DEVICE
|
||||
#define RT_USING_CONSOLE
|
||||
#define RT_CONSOLEBUF_SIZE 256
|
||||
#define RT_CONSOLE_DEVICE_NAME "uart"
|
||||
#define RT_VER_NUM 0x40101
|
||||
|
||||
/* RT-Thread Components */
|
||||
|
||||
#define RT_USING_COMPONENTS_INIT
|
||||
#define RT_USING_MSH
|
||||
#define RT_USING_FINSH
|
||||
#define FINSH_USING_MSH
|
||||
#define FINSH_THREAD_NAME "tshell"
|
||||
#define FINSH_THREAD_PRIORITY 20
|
||||
#define FINSH_THREAD_STACK_SIZE 4096
|
||||
#define FINSH_USING_HISTORY
|
||||
#define FINSH_HISTORY_LINES 5
|
||||
#define FINSH_USING_SYMTAB
|
||||
#define FINSH_CMD_SIZE 80
|
||||
#define MSH_USING_BUILT_IN_COMMANDS
|
||||
#define FINSH_USING_DESCRIPTION
|
||||
#define FINSH_ARG_MAX 10
|
||||
|
||||
/* Device Drivers */
|
||||
|
||||
#define RT_USING_DEVICE_IPC
|
||||
#define RT_USING_PIN
|
||||
#define RT_USING_SERIAL
|
||||
#define RT_USING_SERIAL_V1
|
||||
|
||||
/* Using USB */
|
||||
|
||||
|
@ -150,9 +168,13 @@
|
|||
/* Onboard Peripheral Drivers */
|
||||
|
||||
#define RT_BSP_LED_PIN 12
|
||||
#define RT_BSP_UART_PORT 0
|
||||
#define RT_BSP_UART_TX_PIN 21
|
||||
#define RT_BSP_UART_RX_PIN 20
|
||||
|
||||
/* On-chip Peripheral Drivers */
|
||||
|
||||
#define BSP_USING_GPIO
|
||||
#define BSP_USING_UART
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -600,7 +600,7 @@ CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL1=y
|
|||
# CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL3 is not set
|
||||
CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER=y
|
||||
CONFIG_FREERTOS_OPTIMIZED_SCHEDULER=y
|
||||
CONFIG_FREERTOS_HZ=100
|
||||
CONFIG_FREERTOS_HZ=1000
|
||||
CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
|
||||
# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set
|
||||
# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL is not set
|
||||
|
@ -628,8 +628,7 @@ CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y
|
|||
# CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set
|
||||
# CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH is not set
|
||||
CONFIG_FREERTOS_DEBUG_OCDAWARE=y
|
||||
CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT=y
|
||||
# CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH is not set
|
||||
# CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT is not set
|
||||
# end of FreeRTOS
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue