ESP32_C3 migrate to ESP-IDF package (#6427)

This commit is contained in:
tangzz98 2022-09-14 03:49:05 -04:00 committed by GitHub
parent 52e1d76254
commit cb7fd304ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 870 additions and 1131 deletions

View File

@ -19,7 +19,9 @@ CONFIG_RT_TICK_PER_SECOND=1000
# CONFIG_RT_USING_HOOK is not set
# CONFIG_RT_USING_IDLE_HOOK is not set
CONFIG_IDLE_THREAD_STACK_SIZE=256
# CONFIG_RT_USING_TIMER_SOFT is not set
CONFIG_RT_USING_TIMER_SOFT=y
CONFIG_RT_TIMER_THREAD_PRIO=4
CONFIG_RT_TIMER_THREAD_STACK_SIZE=512
#
# kservice optimization
@ -65,7 +67,7 @@ CONFIG_RT_USING_DEVICE=y
CONFIG_RT_USING_CONSOLE=y
CONFIG_RT_CONSOLEBUF_SIZE=256
CONFIG_RT_CONSOLE_DEVICE_NAME="uart"
CONFIG_RT_VER_NUM=0x40101
CONFIG_RT_VER_NUM=0x50000
# CONFIG_RT_USING_CPU_FFS is not set
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
@ -405,6 +407,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
# CONFIG_PKG_USING_HASH_MATCH is not set
# CONFIG_PKG_USING_FIRE_PID_CURVE is not set
# CONFIG_PKG_USING_ARMV7M_DWT_TOOL is not set
# CONFIG_PKG_USING_VOFA_PLUS is not set
#
# system packages
@ -440,7 +443,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
# CONFIG_PKG_USING_UC_CLK is not set
# CONFIG_PKG_USING_UC_COMMON is not set
# CONFIG_PKG_USING_UC_MODBUS is not set
# CONFIG_PKG_USING_RTDUINO is not set
CONFIG_PKG_USING_FREERTOS_WRAPPER=y
CONFIG_PKG_FREERTOS_WRAPPER_PATH="/packages/system/FreeRTOS_Wrapper"
CONFIG_PKG_USING_FREERTOS_WRAPPER_LATEST_VERSION=y
@ -478,6 +480,7 @@ CONFIG_PKG_FREERTOS_WRAPPER_VER="latest"
# CONFIG_PKG_USING_KMULTI_RTIMER is not set
# CONFIG_PKG_USING_TFDB is not set
# CONFIG_PKG_USING_QPC is not set
# CONFIG_PKG_USING_AGILE_UPGRADE is not set
#
# peripheral libraries and drivers
@ -646,6 +649,39 @@ CONFIG_PKG_ESP_IDF_VER="latest"
# CONFIG_PKG_USING_MFBD is not set
# CONFIG_PKG_USING_SLCAN2RTT is not set
# CONFIG_PKG_USING_SOEM is not set
# CONFIG_PKG_USING_QPARAM is not set
#
# Arduino libraries
#
# CONFIG_PKG_USING_RTDUINO is not set
#
# Sensor libraries
#
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SENSOR is not set
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BUSIO is not set
# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_AHTX0 is not set
# CONFIG_PKG_USING_ARDUINO_DHT_SENSOR is not set
# CONFIG_PKG_USING_ARDUINO_SEEED_BMP280 is not set
# CONFIG_PKG_USING_ARDUINO_SEEED_LIS3DHTR is not set
# CONFIG_PKG_USING_ARDUINO_CAPACITIVESENSOR is not set
#
# Display libraries
#
# CONFIG_PKG_USING_ARDUINO_U8G2 is not set
#
# Timing libraries
#
# CONFIG_PKG_USING_ARDUINO_MSTIMER2 is not set
#
# Project libraries
#
# CONFIG_PKG_USING_ARDUINO_ULTRASOUND_RADAR is not set
# CONFIG_PKG_USING_ARDUINO_SENSOR_KIT is not set
CONFIG_SOC_ESPRESSIF=y
CONFIG_SOC_ESP32_C3=y

View File

@ -1,6 +1,6 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.16)
set(COMPONENTS esptool_py main)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(rtthread)

View File

@ -43,37 +43,33 @@ Each peripheral supporting condition for this BSP is as follows:
| UART | Support | Using LUATOS_ESP32C3 development board requires connecting serial port to USB chip UART0_TX and UART0_RX (such as CP2102) |
| JTAG debug | Support | ESP32C3 usb-linked development boards can be debugged |
## Quickly Get Started
First of all, we'll need to build the IDE, Espressif officially recommends the IDF.
When installing the IDF, please select version 4.4. If you are familiar with the official IDF command line, you can also use the command line to perform the `idf.py build` directly in the `bsp/esp32_c3`, which has been tested and proved that it's functional
### ESP-IDF Adds RT-Thread patch
The IDF was running the FreeRTOS, so we'll need a few modifications to get to RT-Thread.
Copy the `rtt.patch` file to the IDF code directory, and then execute the next few commands on the `git bash` command line to mark the patch.
## Quick Start Guide
1. Download ESP-IDF package
```
cd esp/esp-idf
git checkout v4.4
git am rtt.patch
pkgs --update
```
If you don't want to use the patch file and have uploaded the code to GitHub, you can now go to [tangzz98/esp-idf](tangzz98/esp-idf) to download the latest `freertos_wrapper` branch code. After the modification, the original IDF example is still kept in normal use, they won't interfere with each other.
#### Compile and Download
Right-click `bsp/ESP32_C3` and use vscode to open the project
Compile and select the button at the bottom:
![build](images/build.png)
Here we usually use the serial port to download, you need to choose the corresponding serial port according to your own development board (if there is JTAG, you can also use JTAG to download and debug)
![](images/burn.png)
Once the project is successfully downloaded, the system runs automatically, the red LED will blink in 1s on cycles.
2. Go to ESP-IDF package directory and install IDF tools. This command only needs to be run once after the package is downloaded for the first time.
```
cd packages/ESP-IDF-latest
./install.sh
# Use install.bat in Windows environment
```
3. Under the ESP-IDF package directory, export IDF environment variables. This commands need to be run every time when the BSP is built in a new terminal.
```
. export.sh
# Use export.bat in Windows environment
```
4. Configure RT-Thread under the BSP directory
```
scons --menuconfig
```
5. Whenever RT-Thread configuration is changed with `scons --menuconfig`, a new `CMakeLists.txt` needs to be generated with the command below
```
scons --target=esp-idf
```
6. Use `idf.py` to compile and upload the program. Refer to [Espressif official documents](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/get-started/index.html#build-your-first-project) for reference.
7. Once the project is successfully downloaded, the system runs automatically, the red LED will blink in 1s on cycles.
## Notes
@ -83,6 +79,7 @@ Once the project is successfully downloaded, the system runs automatically, the
Maintainer:
- [supperthomas](https://github.com/supperthomas) email address: [78900636@qq.com](mailto:78900636@qq.com)
- [tangzz98](https://github.com/tangzz98) email address: [tangz98@outlook.com](tangz98@outlook.com)
Special thanks to [chenyingchun0312](https://github.com/chenyingchun0312) for providing support on the RISC-V part working.

View File

@ -52,50 +52,42 @@
## 使用说明
### 快速上手
先要搭建IDE开发环境乐鑫官方推荐使用IDF开发这边建议使用vscode插件。
IDF的搭建方法有很多种尝试了很多种方法之后总结了一个比较好用的方法并且可以使用vscode跨平台安装非常简单方便具体方法见链接[ESP-IDF 一键式搭建环境基于VSCODE](https://blog.csdn.net/lt6210925/article/details/123699249)。 安装的时候IDF版本请选择IDF 4.4版本。如果你对官方IDF命令行的方式熟悉的话你也可以使用命令行的方式直接在`bsp/esp32_c3`中执行`idf.py build`即可,这边已经测试过,是可以使用的。
### ESP-IDF 添加RT-THREAD patch
由于IDF使用的是FREERTOS如果需要使用rt-thread就需要修改一些文件。将`rtt.patch` 这个文件拷贝到IDF的代码目录下面然后在`git bash`命令行内执行命令下面几条命令就可以打上patch
1. 下载ESP-IDF软件包
```
cd esp/esp-idf
git checkout v4.4
git am rtt.patch
pkgs --update
```
如果不想用patch文件已经将代码上传到github上面可以进入[tangzz98/esp-idf](https://github.com/tangzz98/esp-idf/tree/freertos_wrapper) 下载最新的freertos_wrapper分支代码即可。修改之后的IDF原来的IDF的example还是正常使用互不干扰可以放心使用。
#### 编译下载
在`bsp/ESP32_C3`中右击然后使用vscode打开工程
编译选择最下面的按钮即可:
![build](images/build.png)
这边通常采用串口下载需要根据你自己开发板选择对应的串口如果有JTAG的也可以用JTAG下载和调试
![burn](images/burn.png)
#### 运行结果
下载程序成功之后,系统会运行,红色的 LED灯以 1S 周期闪烁。
感兴趣的可以通过公众号`Thomas的小火车`来联系
2. 进入到ESP-IDF软件包路径安装IDf工具链。此命令只需要在下载完软件包后执行一次。
```
cd packages/ESP-IDF-latest
./install.sh
# Windows环境下使用install.bat
```
3. 在软件包路径下设置IDF路径。每当在新的命令行编译BSP时需要执行此命令。
```
. export.sh
# Windows环境下使用export.bat
```
4. 在BSP路径下配置RT-Thread
```
scons --menuconfig
```
5. 每当使用`scons --menuconfig`更改RT-Thread配置后需要重新生成`CMakeLists.txt`。
```
scons --target=esp-idf
```
6. 使用`idf.py`命令编译,烧录。具体参考[乐鑫官网](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/get-started/index.html#build-your-first-project)
7. 下载程序成功之后,系统会运行,红色的 LED灯以 1S 周期闪烁。
## 注意事项
- 目前RTTHREAD支持起来了后续会需要继续完善一些其他功能刚开始使用ESP32欢迎小伙伴一起来讨论和贡献。
- 目前RTTHREAD支持起来了后续会需要继续完善一些其他功能刚开始使用ESP32欢迎小伙伴一起来讨论和贡献。感兴趣的可以通过公众号`Thomas的小火车`来联系
## 联系人信息
维护人:
- [supperthomas](https://github.com/supperthomas) 邮箱:<78900636@qq.com>
- [tangzz98](https://github.com/tangzz98) 邮箱:<tangz98@outlook.com>
## 特别感谢

14
bsp/ESP32_C3/SConscript Normal file
View File

@ -0,0 +1,14 @@
# for module compiling
import os
Import('RTT_ROOT')
cwd = str(Dir('#'))
objs = []
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
Return('objs')

32
bsp/ESP32_C3/SConstruct Normal file
View File

@ -0,0 +1,32 @@
import os
import sys
import rtconfig
if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
else:
RTT_ROOT = os.path.join(os.getcwd(), '..', '..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *
TARGET = 'rtthread.' + rtconfig.TARGET_EXT
DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS,
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
env['ASCOM'] = env['ASPPCOM']
Export('RTT_ROOT')
Export('rtconfig')
# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, remove_components = ['libc'])
# make a building
DoBuilding(TARGET, objs)

View File

@ -0,0 +1,11 @@
import os
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = [cwd]
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2021-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-06-02 supperthomas first version
*/
#include <rtthread.h>
#include "hal/systimer_hal.h"
#include "hal/systimer_ll.h"
#include "esp_private/panic_internal.h"
#include "esp_private/systimer.h"
#include "esp_private/periph_ctrl.h"
#include "esp_intr_alloc.h"
#include "esp_attr.h"
static systimer_hal_context_t systimer_hal;
IRAM_ATTR void rt_SysTickIsrHandler(void *arg)
{
systimer_ll_clear_alarm_int(systimer_hal.dev, SYSTIMER_LL_ALARM_OS_TICK_CORE0);
rt_interrupt_enter();
rt_tick_increase();
rt_interrupt_leave();
}
void rt_hw_systick_init(void)
{
esp_intr_alloc(ETS_SYSTIMER_TARGET0_EDGE_INTR_SOURCE, ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL1, rt_SysTickIsrHandler, &systimer_hal, NULL);
periph_module_enable(PERIPH_SYSTIMER_MODULE);
systimer_hal_init(&systimer_hal);
systimer_hal_tick_rate_ops_t ops = {
.ticks_to_us = systimer_ticks_to_us,
.us_to_ticks = systimer_us_to_ticks,
};
systimer_hal_set_tick_rate_ops(&systimer_hal, &ops);
systimer_ll_set_counter_value(systimer_hal.dev, SYSTIMER_LL_COUNTER_OS_TICK, 0);
systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_LL_COUNTER_OS_TICK);
systimer_hal_connect_alarm_counter(&systimer_hal, SYSTIMER_LL_ALARM_OS_TICK_CORE0, SYSTIMER_LL_COUNTER_OS_TICK);
systimer_hal_set_alarm_period(&systimer_hal, SYSTIMER_LL_ALARM_OS_TICK_CORE0, 1000000UL / RT_TICK_PER_SECOND);
systimer_hal_select_alarm_mode(&systimer_hal, SYSTIMER_LL_ALARM_OS_TICK_CORE0, SYSTIMER_ALARM_MODE_PERIOD);
systimer_hal_counter_can_stall_by_cpu(&systimer_hal, 1, 0, true);
systimer_hal_enable_alarm_int(&systimer_hal, SYSTIMER_LL_ALARM_OS_TICK_CORE0);
systimer_hal_enable_counter(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK);
}
void rt_hw_board_init(void)
{
rt_hw_systick_init();
/* 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
}

View File

@ -11,13 +11,13 @@
#ifndef __BOARD_H__
#define __BOARD_H__
#include <rtthread.h>
#include "drv_gpio.h"
#include <rtconfig.h>
#ifdef __cplusplus
extern "C" {
#endif
void rt_hw_board_init(void);
#ifdef __cplusplus
}

View File

@ -9,15 +9,12 @@
*
*/
#include "drv_gpio.h"
#include <stdio.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "driver/gpio.h"
#ifdef RT_USING_PIN
#define DBG_LEVEL DBG_LOG
#define LOG_TAG "drv.gpio"
#include <rtdbg.h>
static void mcu_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
{
gpio_set_level(pin, value);
@ -97,5 +94,4 @@ int rt_hw_pin_init(void)
}
INIT_BOARD_EXPORT(rt_hw_pin_init);
#endif /* RT_USING_PIN */

View File

@ -12,16 +12,10 @@
#ifndef __DRV_GPIO_H__
#define __DRV_GPIO_H__
#include <rtthread.h>
#include <rthw.h>
#include <rtconfig.h>
#ifdef RT_USING_DEVICE
#include <rtdevice.h>
#ifdef RT_USING_PIN
int rt_hw_pin_init(void);
#endif
#include "driver/gpio.h"
int rt_hw_pin_init(void);
#endif /* __DRV_GPIO_H__ */

View File

@ -9,7 +9,11 @@
*
*/
#include "drv_uart.h"
#include <rtthread.h>
#include <rtdevice.h>
#include "driver/uart.h"
#include "hal/uart_hal.h"
#include "sdkconfig.h"
#ifdef RT_USING_SERIAL_V1

View File

@ -12,17 +12,10 @@
#ifndef __DRV_UART_H__
#define __DRV_UART_H__
#include <rtthread.h>
#include <rthw.h>
#include <rtconfig.h>
#ifdef RT_USING_DEVICE
#include <rtdevice.h>
#ifdef RT_USING_SERIAL_V1
int rt_hw_uart_init(void);
#endif
#include "driver/uart.h"
#include "hal/uart_hal.h"
#include "sdkconfig.h"
int rt_hw_uart_init(void);
#endif /* __DRV_UART_H__ */

View File

@ -1,49 +1,50 @@
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"
"../../../src/scheduler.c"
"../../../src/device.c"
"../../../src/clock.c"
"../../../src/irq.c"
"../../../src/thread.c"
"../../../src/mempool.c"
"../../../src/ipc.c"
"../../../src/mem.c"
"../../../src/object.c"
"../../../src/idle.c"
"../../../src/timer.c"
"../../../src/kservice.c"
"../../../src/device.c"
"../../../components/drivers/misc/pin.c"
"../../../components/drivers/ipc/pipe.c"
"../../../components/drivers/ipc/ringblk_buf.c"
"../../../components/drivers/ipc/waitqueue.c"
"../../../components/drivers/ipc/completion.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"
idf_component_register(
SRCS
../../../libcpu/risc-v/common/cpuport.c
../../../libcpu/risc-v/common/context_gcc.S
../../../components/drivers/ipc/completion.c
../../../components/drivers/ipc/dataqueue.c
../../../components/drivers/ipc/pipe.c
../../../components/drivers/ipc/ringblk_buf.c
../../../components/drivers/ipc/ringbuffer.c
../../../components/drivers/ipc/waitqueue.c
../../../components/drivers/ipc/workqueue.c
../../../components/drivers/misc/pin.c
../../../components/drivers/serial/serial.c
../drivers/drv_uart.c
../drivers/board.c
../drivers/drv_gpio.c
../../../components/finsh/shell.c
../../../components/finsh/msh.c
../../../components/finsh/msh_parse.c
../../../components/finsh/cmd.c
../../../src/clock.c
../../../src/components.c
../../../src/device.c
../../../src/idle.c
../../../src/ipc.c
../../../src/irq.c
../../../src/kservice.c
../../../src/mem.c
../../../src/mempool.c
../../../src/object.c
../../../src/scheduler.c
../../../src/thread.c
../../../src/timer.c
main.c
INCLUDE_DIRS
"../../../components/drivers/include/drivers"
"../../../components/drivers/include"
"../../../components/finsh"
"."
"../../../include"
"../../../libcpu/risc-v/common"
"../")
ADD_DEFINITIONS(
-D__RTTHREAD__
INCLUDE_DIRS
../../../libcpu/risc-v/common
../../../components/drivers/include
../drivers
../../../components/finsh
..
../../../include
)
target_link_libraries(${COMPONENT_LIB}
INTERFACE "-u __rt_init_rt_work_sys_workqueue_init"
INTERFACE "-u __rt_init_rt_hw_uart_init"
INTERFACE "-u __rt_init_rt_hw_pin_init"
INTERFACE "-u __rt_init_finsh_system_init"
)
#TODO
#list(APPEND LINK_FLAGS "-u __rt_init_desc_rt_hw_pin_init")
#set(compile_options "-u __rt_init_desc_rt_hw_pin_init")

View File

@ -0,0 +1,11 @@
import os
from building import *
cwd = GetCurrentDir()
src = Glob('*.c')
CPPPATH = []
group = DefineGroup('Main', src, depend = [''], CPPPATH = CPPPATH)
Return('group')

View File

@ -1,235 +0,0 @@
/*
* Copyright (c) 2021-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-06-02 supperthomas first version
*/
#include <stdio.h>
#include "esp_private/panic_internal.h"
#include "hal/uart_hal.h"
#include "driver/timer.h"
#include "soc/periph_defs.h"
#include "hal/systimer_hal.h"
#include "hal/systimer_ll.h"
#include "esp_intr_alloc.h"
#include "rtthread.h"
#include "rthw.h"
#include "drv_gpio.h"
#include "drv_uart.h"
#include "shell.h"
#ifdef RT_USING_COMPONENTS_INIT
/*
* Components Initialization will initialize some driver and components as following
* order:
* rti_start --> 0
* BOARD_EXPORT --> 1
* rti_board_end --> 1.end
*
* DEVICE_EXPORT --> 2
* COMPONENT_EXPORT --> 3
* FS_EXPORT --> 4
* ENV_EXPORT --> 5
* APP_EXPORT --> 6
*
* rti_end --> 6.end
*
* These automatically initialization, the driver or component initial function must
* be defined with:
* INIT_BOARD_EXPORT(fn);
* INIT_DEVICE_EXPORT(fn);
* ...
* INIT_APP_EXPORT(fn);
* etc.
*/
static int rti_start(void)
{
return 0;
}
INIT_EXPORT(rti_start, "0");
static int rti_board_start(void)
{
return 0;
}
INIT_EXPORT(rti_board_start, "0.end");
static int rti_board_end(void)
{
return 0;
}
INIT_EXPORT(rti_board_end, "1.end");
static int rti_end(void)
{
return 0;
}
INIT_EXPORT(rti_end, "6.end");
/**
* @brief Onboard components initialization. In this function, the board-level
* initialization function will be called to complete the initialization
* of the on-board peripherals.
*/
void rt_components_board_init(void)
{
#if RT_DEBUG_INIT
int result;
const struct rt_init_desc *desc;
for (desc = &__rt_init_desc_rti_board_start; desc < &__rt_init_desc_rti_board_end; desc ++)
{
rt_kprintf("rt_components_board_init initialize %s", desc->fn_name);
result = desc->fn();
rt_kprintf(":%d done\n", result);
}
#else
volatile const init_fn_t *fn_ptr;
for (fn_ptr = &__rt_init_rti_board_start; fn_ptr < &__rt_init_rti_board_end; fn_ptr++)
{
(*fn_ptr)();
}
#endif /* RT_DEBUG_INIT */
}
/**
* @brief RT-Thread Components Initialization.
*/
void rt_components_init(void)
{
#if RT_DEBUG_INIT
int result;
const struct rt_init_desc *desc;
rt_kprintf("do components initialization.\n");
for (desc = &__rt_init_desc_rti_board_end; desc < &__rt_init_desc_rti_end; desc ++)
{
rt_kprintf("rt_components_init initialize %s", desc->fn_name);
result = desc->fn();
rt_kprintf(":%d done\n", result);
}
#else
volatile const init_fn_t *fn_ptr;
for (fn_ptr = &__rt_init_rti_board_end; fn_ptr < &__rt_init_rti_end; fn_ptr ++)
{
(*fn_ptr)();
}
#endif /* RT_DEBUG_INIT */
}
#endif /* RT_USING_COMPONENTS_INIT */
void main_thread_entry(void *parameter)
{
#ifdef RT_USING_COMPONENTS_INIT
/* RT-Thread components initialization */
rt_components_init();
#endif /* RT_USING_COMPONENTS_INIT */
extern int rtt_main();
rtt_main();
}
void rt_application_init(void)
{
rt_thread_t tid;
#define RT_MAIN_THREAD_STACK_SIZE 2048
#define RT_MAIN_THREAD_PRIORITY 10
tid = rt_thread_create("main", main_thread_entry, RT_NULL,
RT_MAIN_THREAD_STACK_SIZE, RT_MAIN_THREAD_PRIORITY, 20);
RT_ASSERT(tid != RT_NULL);
rt_thread_startup(tid);
}
//component
static uint32_t uwTick = 0;
static systimer_hal_context_t systimer_hal;
IRAM_ATTR void rt_SysTickIsrHandler(void *arg)
{
systimer_ll_clear_alarm_int(systimer_hal.dev, 1);
rt_interrupt_enter();
rt_tick_increase();
uwTick++;
/* leave interrupt */
rt_interrupt_leave();
systimer_ll_is_alarm_int_fired(systimer_hal.dev, 1);
}
void rt_hw_systick_init(void)
{
uint8_t system_timer_counter=1;
//rt_hw_interrupt_enable(0);
esp_intr_alloc(ETS_SYSTIMER_TARGET1_EDGE_INTR_SOURCE, ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL1, rt_SysTickIsrHandler, &systimer_hal, NULL);
systimer_hal_init(&systimer_hal);
systimer_ll_set_counter_value(systimer_hal.dev, system_timer_counter, 0);
systimer_ll_apply_counter_value(systimer_hal.dev, system_timer_counter);
uint32_t alarm_id = 1 ;
systimer_hal_connect_alarm_counter(&systimer_hal, alarm_id, system_timer_counter);
systimer_hal_set_alarm_period(&systimer_hal, alarm_id, 1000000UL / 1000);
systimer_hal_select_alarm_mode(&systimer_hal, alarm_id, SYSTIMER_ALARM_MODE_PERIOD);
systimer_hal_counter_can_stall_by_cpu(&systimer_hal, 1, 0, true);
systimer_hal_enable_alarm_int(&systimer_hal, alarm_id);
systimer_hal_enable_counter(&systimer_hal, SYSTIMER_LL_COUNTER_OS_TICK);
}
void rt_hw_board_init(void)
{
rt_hw_systick_init();
/* 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)
{
rt_hw_interrupt_disable();
/* init board */
rt_hw_board_init();
/* timer system initialization */
rt_system_timer_init();
/* create init_thread */
rt_application_init();
/* timer thread initialization */
rt_system_timer_thread_init();
/* idle thread initialization */
rt_thread_idle_init();
/* start scheduler */
rt_system_scheduler_start();
/* init scheduler system */
rt_hw_pin_init();
rt_hw_uart_init();
finsh_system_init();
/* never reach here */
return ;
}
void app_main(void)
{
/* startup RT-Thread RTOS */
rtthread_startup();
return;
}

View File

@ -13,10 +13,8 @@
#include <rtdevice.h>
#include <board.h>
int rtt_main(void)
int 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)

View File

@ -12,6 +12,9 @@
#define RT_THREAD_PRIORITY_MAX 32
#define RT_TICK_PER_SECOND 1000
#define IDLE_THREAD_STACK_SIZE 256
#define RT_USING_TIMER_SOFT
#define RT_TIMER_THREAD_PRIO 4
#define RT_TIMER_THREAD_STACK_SIZE 512
/* kservice optimization */
@ -37,7 +40,7 @@
#define RT_USING_CONSOLE
#define RT_CONSOLEBUF_SIZE 256
#define RT_CONSOLE_DEVICE_NAME "uart"
#define RT_VER_NUM 0x40101
#define RT_VER_NUM 0x50000
/* RT-Thread Components */
@ -62,9 +65,10 @@
/* Device Drivers */
#define RT_USING_DEVICE_IPC
#define RT_USING_PIN
#define RT_USING_SERIAL
#define RT_USING_SERIAL_V1
#define RT_SERIAL_RB_BUFSZ 64
#define RT_USING_PIN
/* Using USB */
@ -168,6 +172,21 @@
/* entertainment: terminal games and other interesting software packages */
/* Arduino libraries */
/* Sensor libraries */
/* Display libraries */
/* Timing libraries */
/* Project libraries */
#define SOC_ESPRESSIF
#define SOC_ESP32_C3

42
bsp/ESP32_C3/rtconfig.py Normal file
View File

@ -0,0 +1,42 @@
import os
# toolchains options
ARCH ='risc-v'
CPU =''
CROSS_TOOL ='gcc'
if os.getenv('RTT_CC'):
CROSS_TOOL = os.getenv('RTT_CC')
if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
EXEC_PATH = r'~/.espressif/tools/riscv32-esp-elf/esp-2022r1-11.2.0/riscv32-esp-elf/bin'
else:
print('Please make sure your toolchains is GNU GCC!')
exit(0)
if os.getenv('RTT_EXEC_PATH'):
EXEC_PATH = os.getenv('RTT_EXEC_PATH')
BUILD = 'debug'
if PLATFORM == 'gcc':
# toolchains
PREFIX = 'riscv32-esp-elf-'
CC = PREFIX + 'gcc'
CXX = PREFIX + 'g++'
AS = PREFIX + 'gcc'
AR = PREFIX + 'ar'
LINK = PREFIX + 'gcc'
TARGET_EXT = 'elf'
SIZE = PREFIX + 'size'
OBJDUMP = PREFIX + 'objdump'
OBJCPY = PREFIX + 'objcopy'
STRIP = PREFIX + 'strip'
CFLAGS = ''
AFLAGS = ''
LFLAGS = ''
CXXFLAGS = ''
POST_ACTION = ''

File diff suppressed because it is too large Load Diff

View File

@ -186,7 +186,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
'cmake':('gcc', 'gcc'),
'cmake-armclang':('keil', 'armclang'),
'xmake':('gcc', 'gcc'),
'codelite' : ('gcc', 'gcc')}
'codelite' : ('gcc', 'gcc'),
'esp-idf': ('gcc', 'gcc')}
tgt_name = GetOption('target')
if tgt_name:
@ -857,10 +858,16 @@ def GenTargetProject(program = None):
if GetOption('target') == 'cmake' or GetOption('target') == 'cmake-armclang':
from cmake import CMakeProject
CMakeProject(Env,Projects)
if GetOption('target') == 'xmake':
from xmake import XMakeProject
XMakeProject(Env, Projects)
if GetOption('target') == 'esp-idf':
from esp_idf import ESPIDFProject
ESPIDFProject(Env, Projects)
exit(0)
def EndBuilding(target, program = None):
need_exit = False

48
tools/esp_idf.py Normal file
View File

@ -0,0 +1,48 @@
import os
import re
import utils
from utils import _make_path_relative
def GenerateCFiles(env,project):
"""
Generate CMakeLists.txt files
"""
info = utils.ProjectInfo(env)
init_export = []
main_component_dir = os.path.join(os.getcwd(), 'main')
cm_file = open(os.path.join(main_component_dir, 'CMakeLists.txt'), 'w')
if cm_file:
cm_file.write("idf_component_register(\n")
cm_file.write("\tSRCS\n")
for group in project:
for f in group['src']:
path = _make_path_relative(main_component_dir, os.path.normpath(f.rfile().abspath))
cm_file.write( "\t" + path.replace("\\", "/") + "\n" )
src = open(f.rfile().abspath, 'r')
for line in src.readlines():
if re.match('INIT_(BOARD|PREV|DEVICE|COMPONENT|ENV|APP)_EXPORT\(.+\)', line):
init_export.append(re.search('\(.+\)', line).group(0)[1:-1])
src.close()
cm_file.write("\n")
cm_file.write("\tINCLUDE_DIRS\n")
for i in info['CPPPATH']:
path = _make_path_relative(main_component_dir, i)
cm_file.write( "\t" + path.replace("\\", "/") + "\n")
cm_file.write(")\n\n")
print(init_export)
n = len(init_export)
if n:
cm_file.write("target_link_libraries(${COMPONENT_LIB}\n")
for i in range(n):
cm_file.write("\tINTERFACE \"-u __rt_init_" + init_export[i] + "\"\n")
cm_file.write(")\n")
def ESPIDFProject(env,project):
print('Update setting files for CMakeLists.txt...')
GenerateCFiles(env,project)
print('Done!')