[bsp][esp][esp32c3] add the bsp of esp32c3 (#5869)

* add the ESP32_C3 first version

* add the blinky ok version

* fix the code

* format file

* add the readme

* fix the formate

* Update README.md

* Update main.c

* fix the readme

* fix rtconfig.h

* remove cpp config
This commit is contained in:
supperthomas authored and GitHub committed 2022-04-29 09:01:44 +08:00
1 parent 62d2403ebe
commit ee1e0a0df0
15 files changed
+2472

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "espidf",
"name": "Launch",
"request": "launch"
}
]
}
+26
View File
@@ -0,0 +1,26 @@
{
"C_Cpp.intelliSenseEngine": "Tag Parser",
"idf.adapterTargetName": "esp32c3",
"idf.openOcdConfigs": [
"board/esp32c3-builtin.cfg"
],
"idf.portWin": "COM7",
"idf.flashType": "UART",
"files.associations": {
"panic_internal.h": "c",
"rtthread.h": "c",
"bitset": "c",
"chrono": "c",
"algorithm": "c",
"rtdebug.h": "c",
"rtservice.h": "c",
"rtdef.h": "c",
"rtconfig.h": "c",
"thread": "c",
"rthw.h": "c",
"typeinfo": "c",
"serial.h": "c",
"timer.h": "c"
},
"RTT_Studio.Build.Parallel_Jobs": "4"
}
+300
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+6
View File
@@ -0,0 +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)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(rtthread)
+8
View File
@@ -0,0 +1,8 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#
PROJECT_NAME := rtthread
include $(IDF_PATH)/make/project.mk
+89
View File
@@ -0,0 +1,89 @@
# ESP32-C3 BSP 说明
## 简介
本文档为 乐鑫ESP32-C3 开发板的[ESP32C3](http://luatos.com/t/esp32c3) BSP (板级支持包) 说明。
主要内容如下:
- 开发板资源介绍
- BSP 快速上手
通过阅读快速上手章节开发者可以快速地上手该 BSP,将 RT-Thread 运行在开发板上。
## 开发板介绍
目前测试了两款开发板,运行都正常,由于两款开发板LED小灯引脚不同,请根据自己开发板修改GPIO引脚,目前默认使用的开发板是LUATOS_ESP32C3。已测开发板外观如下图所示:
- [LUATOS_ESP32C3](https://wiki.luatos.com/chips/esp32c3/board.html)
![LUATOS_ESP32C3](images/luatos_esp32c3.png)
- [HX-DK-商](https://docs.wireless-tech.cn/doc/7/)
![hongxu](images/hx_shang.png)
该LUATOS_ESP32C3开发板常用 **板载资源** 如下:
- MCU:[esp32-c3](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf),主频 160MHz, 407.22 CoreMark; 2.55 CoreMark/MHz
- 芯片内置:384KB ROM, 400KB SRAM,
- 常用外设
- 红色LED:2个,D4 (IO12), D5(IO13)
- 按键:2个,K1(BOOT) K2(RST)
- SPI FLASH: 2M
- 常用接口:USB UART等
开发板更多详细信息请参考 [ESP32-C3开发板介绍](https://wiki.luatos.com/chips/esp32c3/board.html)。
## 外设支持
本 BSP 目前对外设的支持情况如下:
| **片上外设** | **支持情况** | **备注** |
| :----------------- | :----------: | :------------------------------------- |
| GPIO | 待支持 | |
| UART | 待支持 | |
## 使用说明
### 快速上手
说先要搭建IDE开发环境,乐鑫官方推荐使用IDF开发。
IDF的搭建方法有很多种,尝试了很多种方法之后,总结了一个最快速的方法,并且可以使用vscode跨平台安装,非常简单方便,具体方法见链接[ESP-IDF 一键式搭建环境基于VSCODE](https://blog.csdn.net/lt6210925/article/details/123699249)。 安装的时候IDF版本请选择IDF 4.4版本。如果你对官方IDF命令行的方式熟悉的话,你也可以使用命令行的方式,这边已经测试过,是可以使用的。
### IDF patch加载
由于IDF使用的是FREERTOS需要修改一些文件,将`0001-add-fixed-of-rtthread.patch` 这个文件拷贝到安装的时候的IDF的代码目录,执行命令 `git apply 0001-add-fixed-of-rtthread.patch` 打上patch
#### 编译下载
编译选择最下面的按钮:
![build](images/build.png)
这边通常采用串口下载,需要根据你自己开发板选择对应的串口(如果有JTAG的,也可以用JTAG下载和调试)
![burn](images/burn.png)
#### 运行结果
下载程序成功之后,系统会运行,红色的 D4以 1S 周期闪烁。
刚接触ESP32, 目前仅实现LED小灯闪烁,可以print打印,后续计划将pin设备和console对接上去,也欢迎大家一起来贡献,感兴趣的可以通过公众号`Thomas的小火车`来联系
## 注意事项
- 目前RTTHREAD支持起来了,后续会需要继续完善一些其他功能,刚开始使用ESP32,欢迎小伙伴一起来讨论和贡献。
## 联系人信息
维护人:
- [supperthomas](https://github.com/supperthomas) 邮箱:<78900636@qq.com>
## 特别感谢
- 感谢[chenyingchun0312](https://github.com/chenyingchun0312) 提供了RISCV的强力支持
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 KiB

+23
View File
@@ -0,0 +1,23 @@
idf_component_register(SRCS "main.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"
INCLUDE_DIRS
"../../../include"
"../../../libcpu/risc-v/common"
"../")
ADD_DEFINITIONS(
-D__RTTHREAD__
)
+133
View File
@@ -0,0 +1,133 @@
/*
* Copyright (c) 2021-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-04-24 supperthomas first version
*/
#include <stdio.h>
#include "driver/gpio.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"
void main_thread_entry(void *parameter)
{
#define BLINK_GPIO 12
gpio_reset_pin(BLINK_GPIO);
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
while (1)
{
gpio_set_level(BLINK_GPIO, 1);
rt_thread_mdelay(1000);
gpio_set_level(BLINK_GPIO, 0);
rt_thread_mdelay(1000);
}
}
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();
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__);
}
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();
/* timer thread initialization */
rt_system_timer_thread_init();
/* idle thread initialization */
rt_thread_idle_init();
/* start scheduler */
rt_system_scheduler_start();
/* init scheduler system */
/* never reach here */
return ;
}
void app_main(void)
{
/* startup RT-Thread RTOS */
rtthread_startup();
return;
}
+151
View File
@@ -0,0 +1,151 @@
#ifndef RT_CONFIG_H__
#define RT_CONFIG_H__
/* Automatically generated file; DO NOT EDIT. */
/* RT-Thread Configuration */
/* RT-Thread Kernel */
#define RT_NAME_MAX 8
#define RT_ALIGN_SIZE 4
#define RT_THREAD_PRIORITY_32
#define RT_THREAD_PRIORITY_MAX 32
#define RT_TICK_PER_SECOND 1000
#define IDLE_THREAD_STACK_SIZE 256
/* kservice optimization */
/* Inter-Thread communication */
#define RT_USING_SEMAPHORE
/* Memory Management */
#define RT_USING_MEMPOOL
#define RT_USING_SMALL_MEM
#define RT_USING_SMALL_MEM_AS_HEAP
#define RT_USING_HEAP
/* Kernel Device Object */
#define RT_VER_NUM 0x40004
/* RT-Thread Components */
/* C++ features */
/* Command shell */
/* Device virtual file system */
/* Device Drivers */
/* Using USB */
/* POSIX layer and C standard library */
/* Network */
/* Socket abstraction layer */
/* Network interface device */
/* light weight TCP/IP stack */
/* AT commands */
/* VBUS(Virtual Software BUS) */
/* Utilities */
/* RT-Thread Utestcases */
/* RT-Thread online packages */
/* IoT - internet of things */
/* Wi-Fi */
/* Marvell WiFi */
/* Wiced WiFi */
/* IoT Cloud */
/* security packages */
/* language packages */
/* JSON: JavaScript Object Notation, a lightweight data-interchange format */
/* XML: Extensible Markup Language */
/* multimedia packages */
/* LVGL: powerful and easy-to-use embedded GUI library */
/* u8g2: a monochrome graphic library */
/* PainterEngine: A cross-platform graphics application framework written in C language */
/* tools packages */
/* system packages */
/* enhanced kernel services */
/* POSIX extension functions */
/* acceleration: Assembly language or algorithmic acceleration packages */
/* CMSIS: ARM Cortex-M Microcontroller Software Interface Standard */
/* Micrium: Micrium software products porting for RT-Thread */
/* peripheral libraries and drivers */
/* AI packages */
/* miscellaneous packages */
/* project laboratory */
/* samples: kernel and components samples */
/* entertainment: terminal games and other interesting software packages */
#endif
File diff suppressed because it is too large. Load diff