[bsp][esp32] adapt C3/C6 to ESP-IDF v6.1 and bump RISC-V toolchain to gcc 15.2 (#11870)

* [bsp][esp32] adapt C3/C6 to ESP-IDF v6.1 and bump RISC-V toolchain to gcc 15.2

- Adapt ESP32-C3/C6 BSP to ESP-IDF v6.1; bump RISC-V toolchain to gcc 15.2
- C6: re-enable SPI with board-local drv_spi.c; add devices.spi to CI
  attachconfig; drop shared drv_spi.c spi_command_t hack
- C6: fix ADC oneshot multi-channel unit handle and mutex
- C3: fix portTRY_ENTER_CRITICAL_SAFE expansion in portmacro.h
- Compat with RT-Thread-packages/esp-idf rtt-dev used by CI: map
  SYSTIMER_* to SYSTIMER_LL_* (C3 and C6 board.c), accept uart_periph.h
  from hal/ or soc/
- Fix clang-format and cppcheck issues in the compat code

Signed-off-by: seteiro <chenmoushun@163.com>
Co-Authored-By: Grok <seteiro@mail.grokbot.com>

* ci: retrigger after esp-idf#18 merged

* bsp: ESP: fix C6 ADC for IDF 6.1 (adc_ll bus clock)

Replace removed PERIPH_SARADC_MODULE with adc_ll_enable_bus_clock /
adc_ll_reset_register when ESP_IDF_VERSION >= 6.0.0.

---------

Signed-off-by: seteiro <chenmoushun@163.com>
Co-authored-by: Grok <seteiro@mail.grokbot.com>
This commit is contained in:
Chen MoushunandGrok authored and GitHub committed 2026-10-22 15:42:35 +08:00
1 parent 1c801efabc
commit dff75f072f
55 files changed
+4564 -333

No files matched your search

+2 -2
View File
@@ -288,8 +288,8 @@ jobs:
- name: Install riscv32-esp-elf ToolChains
if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-riscv32-esp32' && success() }}
run: |
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
sudo tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz -C /opt
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz
sudo tar xf riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz -C /opt
/opt/riscv32-esp-elf/bin/riscv32-esp-elf-gcc --version
pip3 install esptool
echo "RTT_EXEC_PATH=/opt/riscv32-esp-elf/bin" >> $GITHUB_ENV
+2 -2
View File
@@ -128,8 +128,8 @@ jobs:
- name: Install riscv32-esp-elf ToolChains
if: ${{ github.event.inputs.bsp_tool_chain == 'sourcery-riscv32-esp32' && success() }}
run: |
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
sudo tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz -C /opt
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz
sudo tar xf riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz -C /opt
/opt/riscv32-esp-elf/bin/riscv32-esp-elf-gcc --version
pip3 install esptool
echo "RTT_EXEC_PATH=/opt/riscv32-esp-elf/bin" >> $GITHUB_ENV
@@ -371,8 +371,8 @@ jobs:
- name: Install riscv32-esp-elf ToolChains
if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-riscv32-esp32' && success() }}
run: |
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
sudo tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz -C /opt
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz
sudo tar xf riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz -C /opt
/opt/riscv32-esp-elf/bin/riscv32-esp-elf-gcc --version
pip3 install esptool
echo "RTT_EXEC_PATH=/opt/riscv32-esp-elf/bin" >> $GITHUB_ENV
@@ -117,8 +117,8 @@ jobs:
- name: Install riscv32-esp-elf ToolChains
if: ${{ github.event.inputs.bsp_tool_chain == 'sourcery-riscv32-esp32' && success() }}
run: |
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
sudo tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz -C /opt
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz
sudo tar xf riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz -C /opt
/opt/riscv32-esp-elf/bin/riscv32-esp-elf-gcc --version
pip3 install esptool
echo "RTT_EXEC_PATH=/opt/riscv32-esp-elf/bin" >> $GITHUB_ENV
+2 -2
View File
@@ -89,8 +89,8 @@ jobs:
echo "TOOLCHAIN_PATH=/opt/Xuantie-900-gcc-elf-newlib-x86_64-V3.2.0/bin" >> $GITHUB_ENV
;;
riscv32-esp-elf)
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
sudo tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz -C /opt
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz
sudo tar xf riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz -C /opt
pip3 install --user esptool
echo "TOOLCHAIN_PATH=/opt/riscv32-esp-elf/bin" >> $GITHUB_ENV
;;
+2 -2
View File
@@ -133,8 +133,8 @@ jobs:
echo "TOOLCHAIN_PATH=/opt/Xuantie-900-gcc-elf-newlib-x86_64-V3.2.0/bin" >> $GITHUB_ENV
;;
riscv32-esp-elf)
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
sudo tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz -C /opt
wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz
sudo tar xf riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz -C /opt
echo "TOOLCHAIN_PATH=/opt/riscv32-esp-elf/bin" >> $GITHUB_ENV
;;
riscv64-linux-musl-k230)
+8
View File
@@ -0,0 +1,8 @@
# clang-format ignore file
/ESP32_C3/idf_port/include/freertos/portmacro.h
/ESP32_C3/idf_port/src/port.c
/ESP32_C6/idf_port/include/freertos/portmacro.h
/ESP32_C6/libraries/drivers/sdkconfig.h
/ESP32_C6/libraries/drivers/sdkconfig_c6.h
/libraries/drivers/sdkconfig.h
/libraries/drivers/sdkconfig_c6.h
+3 -3
View File
@@ -71,7 +71,7 @@ int main(void) {
```sh
wcx@tim  ~/rt-thread/bsp/ESP32_C3   esp32 ±  sudo riscv32-esp-elf-gdb # Enter gdb debugging
GNU gdb (crosstool-NG esp-2022r1-RC1) 9.2.90.20200913-git
GNU gdb (esp-gdb) 17.1_20260402
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
@@ -138,8 +138,8 @@ If you want to lightly experiment with the ESP32-C3, it is recommended to quickl
1. Download the RISC-V toolchain:
```sh
wget https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
wget https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz
tar xf riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz
```
2. Configure the path of the toolchain:
+3 -3
View File
@@ -78,7 +78,7 @@ int main(void) {
```sh
wcx@tim  ~/rt-thread/bsp/ESP32_C3   esp32 ±  sudo riscv32-esp-elf-gdb # 进入gdb调试
GNU gdb (crosstool-NG esp-2022r1-RC1) 9.2.90.20200913-git
GNU gdb (esp-gdb) 17.1_20260402
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
@@ -147,8 +147,8 @@ Type "apropos word" to search for commands related to "word".
1. 下载 RISC-V 工具链:
```sh
wget https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
tar xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
wget https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz
tar xf riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz
```
2. 配置工具链的路径:
+2 -2
View File
@@ -22,8 +22,8 @@ USER dev
WORKDIR /home/dev
# 3. Install esp-idf toolchains
RUN wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz && \
sudo tar -xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz -C /opt
RUN wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz && \
sudo tar -xf riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz -C /opt
# 4. Clone RT-Thread and switch master
RUN git clone https://github.com/RT-Thread/rt-thread.git && \
@@ -86,6 +86,39 @@ typedef rt_ubase_t UBaseType_t;
typedef rt_tick_t TickType_t;
#define portMAX_DELAY (TickType_t) RT_TICK_MAX
/*
* FreeRTOS V11 definitions that ESP-IDF v6.1 headers expect but the
* FreeRTOS-Wrapper kernel (FreeRTOS V10.4.6) does not provide.
*/
/* RISC-V has no privilege levels, so the annotation expands to nothing. */
#ifndef PRIVILEGED_FUNCTION
#define PRIVILEGED_FUNCTION
#endif
/* FreeRTOS V11 renamed nothing here: `StaticList_t` is just an alias of
`struct xLIST`. Used by components/esp_ringbuf/include/freertos/ringbuf.h. */
#ifndef RT_FREERTOS_WRAPPER_STATIC_LIST_T
#define RT_FREERTOS_WRAPPER_STATIC_LIST_T
#include "freertos/list.h"
typedef List_t StaticList_t;
#endif
/*
* ESP-IDF v6.1's components/esp_ringbuf blocks on the FreeRTOS task event
* lists, which FreeRTOS V11 provides and FreeRTOS-Wrapper does not.
* components/rtthread/scons/event_list.c implements the two functions below on
* top of the wrapper's list implementation; the declarations have to be visible
* here because esp_ringbuf calls them after a plain <freertos/FreeRTOS.h>.
* vTaskInternalSetTimeOutState() already exists in the wrapper's tasks.c but is
* not declared in its task.h.
*/
void vTaskPlaceOnEventList(List_t *const pxEventList, TickType_t xTicksToWait);
BaseType_t xTaskRemoveFromEventList(List_t *const pxEventList);
/* The wrapper's tasks.c defines this with TimeOut_t, which is a typedef of
`struct xTIME_OUT` in its freertos/task.h. Spell the tag out, because
task.h is not included here and a different tag would be a different type. */
struct xTIME_OUT;
void vTaskInternalSetTimeOutState(struct xTIME_OUT *const pxTimeOut);
struct rt_semaphore_wrapper
{
struct rt_semaphore sem;
@@ -245,6 +278,32 @@ FORCE_INLINE_ATTR BaseType_t xPortGetCoreID(void)
return (BaseType_t) esp_cpu_get_core_id();
}
/*
* The ESP-IDF v6.1 <freertos/stream_buffer.h> refers to StaticStreamBuffer_t,
* which FreeRTOS V11 defines in its FreeRTOS.h. The FreeRTOS-Wrapper kernel
* is V10.4.6 and provides no stream buffers, so nothing in the RT-Thread
* scons build can allocate one; the type only has to exist for the headers
* to parse. Same layout as ESP-IDF's components/freertos/FreeRTOS-Kernel.
*/
#ifndef RT_FREERTOS_WRAPPER_STATIC_STREAM_BUFFER_T
#define RT_FREERTOS_WRAPPER_STATIC_STREAM_BUFFER_T
typedef struct xSTATIC_STREAM_BUFFER
{
size_t uxDummy1[4];
void * pvDummy2[3];
uint8_t ucDummy3;
#if ( configUSE_TRACE_FACILITY == 1 )
UBaseType_t uxDummy4;
#endif
#if ( configUSE_SB_COMPLETED_CALLBACK == 1 )
void * pvDummy5[2];
#endif
portMUX_TYPE xDummyStreamBufferLock;
} StaticStreamBuffer_t;
/* Message buffers are built on stream buffers. */
typedef StaticStreamBuffer_t StaticMessageBuffer_t;
#endif
/* ------------------------------------------- FreeRTOS Porting Interface ----------------------------------------------
@@ -290,7 +349,7 @@ FORCE_INLINE_ATTR BaseType_t xPortGetCoreID(void)
portEXIT_CRITICAL(mux); \
} \
})
#define portTRY_ENTER_CRITICAL_SAFE(mux, timeout) portENTER_CRITICAL_SAFE(mux, timeout)
#define portTRY_ENTER_CRITICAL_SAFE(mux, timeout) portTRY_ENTER_CRITICAL(mux, timeout)
// ---------------------- Yielding -------------------------
+20
View File
@@ -17,6 +17,14 @@ SECTIONS
* RTC fast memory holds RTC wake stub code,
* including from any source file named rtc_wake_stub*.c
*/
.rtc_reserved (NOLOAD):
{
. = ALIGN(4);
_rtc_reserved_start = ABSOLUTE(.);
KEEP(*(.rtc_reserved*))
_rtc_reserved_end = ABSOLUTE(.);
} > rtc_iram_seg
.rtc.text :
{
. = ALIGN(4);
@@ -134,6 +142,8 @@ SECTIONS
_iram_start = ABSOLUTE(.);
/* Vectors go to start of IRAM */
ASSERT(ABSOLUTE(.) % 0x100 == 0, "vector address must be 256 byte aligned");
_vector_table_start = ABSOLUTE(.);
KEEP(*(.exception_vectors_table.text));
KEEP(*(.exception_vectors.text));
. = ALIGN(4);
@@ -201,6 +211,8 @@ SECTIONS
*libpp.a:(.wifiorslpiram .wifiorslpiram.*)
*libpp.a:(.wifirxiram .wifirxiram.*)
*libpp.a:(.wifislprxiram .wifislprxiram.*)
*libpp.a:(.wifiextrairam .wifiextrairam.*)
*libnet80211.a:(.wifiextrairam .wifiextrairam.*)
*riscv?interrupt.*(.literal .literal.* .text .text.*)
*riscv?vectors.*(.literal .literal.* .text .text.*)
*librtc.a:(.literal .literal.* .text .text.*)
@@ -519,8 +531,16 @@ SECTIONS
soc_reserved_memory_region_end = ABSOLUTE(.);
/* System init functions registered via ESP_SYSTEM_INIT_FN */
_esp_system_init_fn_array_start = ABSOLUTE(.);
_esp_sys_init_fn_start = ABSOLUTE(.);
KEEP (*(SORT_BY_INIT_PRIORITY(.esp_system_init_fn.*)))
KEEP (*(SORT_BY_INIT_PRIORITY(.esp_sys_init_fn.*)))
_esp_system_init_fn_array_end = ABSOLUTE(.);
_esp_sys_init_fn_end = ABSOLUTE(.);
. = ALIGN(4);
_esp_libc_clock_array_start = ABSOLUTE(.);
KEEP (*(.esp_libc_clock_desc))
_esp_libc_clock_array_end = ABSOLUTE(.);
/* section information for initial. */
. = ALIGN(4);
__rt_init_start = .;
-1
View File
@@ -44,7 +44,6 @@
#include "hal/systimer_hal.h"
#include "hal/systimer_ll.h"
#include "riscv/rvruntime-frames.h"
#include "riscv/riscv_interrupts.h"
#include "riscv/interrupt.h"
#include "esp_private/crosscore_int.h"
#include "esp_attr.h"
+4 -2
View File
@@ -13,13 +13,15 @@
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
/* esp_timer_init() is called under BSP_USING_BLE; ESP-IDF v6.1's header
* chain no longer declares it implicitly. */
#include "esp_timer.h"
#ifdef BSP_USING_BLE
void app_main()
{
while(1)
while (1)
{
}
}
#endif /* BSP_USING_BLE */
+11 -3
View File
@@ -16,7 +16,7 @@ if 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'
EXEC_PATH = r'~/.espressif/tools/riscv32-esp-elf/esp-15.2.0_20251204/riscv32-esp-elf/bin'
else:
print('Please make sure your toolchains is GNU GCC!')
exit(0)
@@ -41,8 +41,16 @@ if PLATFORM == 'gcc':
OBJCPY = PREFIX + 'objcopy'
STRIP = PREFIX + 'strip'
DEVICE = ' -nostartfiles -march=rv32imc --specs=nosys.specs -fasynchronous-unwind-tables '
CFLAGS = DEVICE + '-include ../../components/libc/compilers/common/include/sys/ioctl.h -gdwarf-4 -ggdb -Og '
# ESP-IDF v6.1 / binutils >= 2.41 no longer imply the Zicsr/Zifencei
# extensions in `-march=rv32imc`, so spell them out.
DEVICE = ' -nostartfiles -march=rv32imc_zicsr_zifencei --specs=nosys.specs -fasynchronous-unwind-tables '
# RT-Thread's rt_uint32_t/rt_tick_t are layout compatible with the
# toolchain's uint32_t but not the same type (`unsigned int` vs
# `long unsigned int` on riscv32 with GCC 15). ESP-IDF v6.1 sources
# mix both, and GCC >= 14 promotes incompatible-pointer-types and
# int-conversion from warnings to errors.
CFLAGS = DEVICE + '-Wno-error=incompatible-pointer-types -Wno-error=int-conversion '
CFLAGS += '-include ../../components/libc/compilers/common/include/sys/ioctl.h -gdwarf-4 -ggdb -Og '
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
idf_path = find_package_path(BSP_ROOT, 'ESP-IDF-latest', relative_to=BSP_ROOT, pathsep='/')
LFLAGS = DEVICE + ' -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32C3=0 -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,_start -T idf_port/ld/memory.ld -T idf_port/ld/sections.ld -T ' + idf_path + '/components/esp_rom/esp32c3/ld/esp32c3.rom.ld -T ' + idf_path + '/components/esp_rom/esp32c3/ld/esp32c3.rom.api.ld -T ' + idf_path + '/components/esp_rom/esp32c3/ld/esp32c3.rom.libgcc.ld -T ' + idf_path + '/components/esp_rom/esp32c3/ld/esp32c3.rom.newlib.ld -T ' + idf_path + '/components/esp_rom/esp32c3/ld/esp32c3.rom.version.ld -T ' + idf_path + '/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld -T ' + idf_path + '/components/soc/esp32c3/ld/esp32c3.peripherals.ld -Wl,--wrap=_Unwind_SetEnableExceptionFdeSorting -Wl,--wrap=__register_frame_info_bases -Wl,--wrap=__register_frame_info -Wl,--wrap=__register_frame -Wl,--wrap=__register_frame_info_table_bases -Wl,--wrap=__register_frame_info_table -Wl,--wrap=__register_frame_table -Wl,--wrap=__deregister_frame_info_bases -Wl,--wrap=__deregister_frame_info -Wl,--wrap=_Unwind_Find_FDE -Wl,--wrap=_Unwind_GetGR -Wl,--wrap=_Unwind_GetCFA -Wl,--wrap=_Unwind_GetIP -Wl,--wrap=_Unwind_GetIPInfo -Wl,--wrap=_Unwind_GetRegionStart -Wl,--wrap=_Unwind_GetDataRelBase -Wl,--wrap=_Unwind_GetTextRelBase -Wl,--wrap=_Unwind_SetIP -Wl,--wrap=_Unwind_SetGR -Wl,--wrap=_Unwind_GetLanguageSpecificData -Wl,--wrap=_Unwind_FindEnclosingFunction -Wl,--wrap=_Unwind_Resume -Wl,--wrap=_Unwind_RaiseException -Wl,--wrap=_Unwind_DeleteException -Wl,--wrap=_Unwind_ForcedUnwind -Wl,--wrap=_Unwind_Resume_or_Rethrow -Wl,--wrap=_Unwind_Backtrace -Wl,--wrap=__cxa_call_unexpected -Wl,--eh-frame-hdr -Wl,--wrap=__gxx_personality_v0 -Wl,--cref -Wl,--defsym=IDF_TARGET_ESP32C3=0'
@@ -12,3 +12,9 @@ devices.uart:
- CONFIG_RT_USING_SERIAL=y
- CONFIG_RT_USING_SERIAL_V1=y
- CONFIG_BSP_USING_UART=y
devices.spi:
<<: *scons
kconfig:
- CONFIG_RT_USING_SPI=y
- CONFIG_BSP_USING_SPI=y
- CONFIG_BSP_USING_SPI2=y
+2 -2
View File
@@ -44,7 +44,7 @@ ESP32-C6-DevKitC-1 是乐鑫推出的一款基于 RISC-V 内核的开发板,
| IDE/编译器 | 已测试版本 |
| ---------- | ---------- |
| GCC | Espressif riscv32-esp-elf GCC 11.2.0 |
| GCC | Espressif riscv32-esp-elf GCC 15.2.0 |
## 3 使用说明
@@ -52,7 +52,7 @@ ESP32-C6-DevKitC-1 是乐鑫推出的一款基于 RISC-V 内核的开发板,
### 3.1 使用 Env 编译 BSP
1. 下载 [riscv32-esp-elf GCC 11.2.0](https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-win64.zip)(Windows)。Linux 用同版本的 `linux-amd64` 包。
1. 下载 [riscv32-esp-elf GCC 15.2.0](https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-w64-mingw32.zip)(Windows)。Linux 用同版本的 `linux-amd64` 包。
2. 下载 Env 工具 [最新版本](https://github.com/RT-Thread/env-windows/releases)
3. 将 [esp-idf 提交 `4fa003074a73774369d38123749fe64b7b4acbd3`](https://github.com/cms19859230182-lang/esp-idf/commit/4fa003074a73774369d38123749fe64b7b4acbd3)(`bsp/esp32c6-scons`)放到 `packages/ESP-IDF-latest`。官方 `RT-Thread-packages/esp-idf` 里还没有这些 C6 源码,`pkgs --update` 下到的包编不过。SConstruct 发现包里没有 C6 时,拉取的也是这一次提交,不跟分支尖走。
4. 在当前 BSP 目录下执行 `scons --exec-path=工具链的bin目录`
+2 -2
View File
@@ -152,8 +152,8 @@ def _match_idf_spi_lock_stub_to_spi_config():
if spi_selected:
marker = b'skip_name = ('
if marker not in text:
raise RuntimeError('%s has no %s to skip spi_lock_stub.c in'
% (sc, marker.decode()))
# In ESP-IDF v6.1+, spi_lock_stub is no longer present; spi_common.c is built directly.
return
text = text.replace(marker, marker + entry, 1)
else:
text = text.replace(entry, b'', 1)
+3 -3
View File
@@ -15,9 +15,9 @@ RUN apt update && \
USER dev
WORKDIR /home/dev
RUN wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz && \
sudo tar -xf riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz -C /opt && \
rm riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
RUN wget -q https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz && \
sudo tar -xf riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz -C /opt && \
rm riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz
ENV PATH="/opt/riscv32-esp-elf/bin:${PATH}"
-118
View File
@@ -16,122 +16,4 @@ CPPPATH = Split(
group = DefineGroup('idf_port', src, depend = [''], CPPPATH = CPPPATH)
# bsp/ESP/libraries/drivers/drv_spi.c calls the ESP-IDF master mode SPI driver:
# spi_bus_initialize() lives in components/driver/spi_common.c and
# spi_bus_add_device()/spi_device_acquire_bus()/spi_device_polling_transmit()/
# spi_device_release_bus() in components/driver/spi_master.c. The package's own
# driver group drops both for C6 (packages/ESP-IDF-latest/SConscript:999 keeps
# only gpio.c, rtc_io.c, uart.c and spi_bus_lock.c out of components/driver), so
# they are compiled here -- and only with BSP_USING_SPI selected, so a default
# build adds nothing.
if GetDepend(['BSP_USING_SPI']):
from env_package import find_package_path
bsp_root = os.path.normpath(os.path.join(GetCurrentDir(), '..'))
idf = find_package_path(bsp_root, 'ESP-IDF-latest',
relative_to=bsp_root, pathsep='/')
wrapper = find_package_path(bsp_root, 'FreeRTOS-Wrapper-latest',
relative_to=bsp_root, pathsep='/')
# scons resolves these against the BSP root (the variant dir 'build' mirrors
# them), so '..' steps out of this idf_port directory; the include
# directories below are absolute to stay independent of that.
spi_src = [
'../%s/components/driver/spi_common.c' % idf,
'../%s/components/driver/spi_master.c' % idf,
# spi_common.c and spi_master.c are written against the HAL layer, and
# this package's C6 hal group drops spi_hal.c; without it the ten
# spi_hal_* calls those two files make have no definition.
'../%s/components/hal/spi_hal.c' % idf,
# spi_common.c reaches GDMA through its own SOC_GDMA_SUPPORTED section
# (soc/esp32c6/include/soc/soc_caps.h defines it as 1), and that code is
# compiled into the object no matter what the third argument of
# spi_bus_initialize() is. The package drops every path containing
# 'gdma' from its C6 source list, so the driver and its hal wrapper are
# compiled here instead. The package's gdma.c is written against the C3
# generation of hal/gdma_ll.h and that tree is shared with the C3 BSP,
# so this BSP carries its own C6-correct copy (src/gdma.c) instead of
# rewriting the package file at build time.
'src/gdma.c',
'../%s/components/hal/gdma_hal.c' % idf,
# gdma.c reads gdma_periph_signals (gdma.c:541 and on) to map a
# GDMA_TRIG_PERIPH_* onto the signal slots of a channel; the one object
# file defining it is this SoC table, which the package drops for the
# same 'gdma' reason as the two files above.
'../%s/components/soc/esp32c6/gdma_periph.c' % idf,
# this gcc has no __atomic_compare_exchange_1 (see the file); the byte
# sized compare-exchange of spi_common.c's atomic_bool needs one.
'src/rt_atomic_cas_stub.c',
]
# headers the two files include. freertos/queue.h and freertos/task.h come
# from the RT-Thread FreeRTOS wrapper, like everywhere else in this BSP: the
# kernel copy inside the package wants an IDF sdkconfig this BSP does not
# carry.
spi_path = [os.path.join(bsp_root, idf, 'components', p) for p in (
'driver/include',
'esp_common/include',
'esp_hw_support/include',
'esp_hw_support/port/esp32c6/include',
'esp_rom/include',
'esp_system/include',
'esp_system/port/include',
'esp_system/port/include/private',
'esp_timer/include',
'hal/include',
'hal/esp32c6/include',
'hal/platform_port/include',
'heap/include',
'log/include',
'newlib/platform_include',
'riscv/include',
'soc/include',
'soc/esp32c6/include',
)] + [os.path.join(bsp_root, wrapper, 'FreeRTOS/include')]
# hal/esp32c6/include/hal/spi_ll.h names SPI_CLK_SRC_XTAL/SPI_CLK_SRC_RC_FAST
# (enumerators of soc/clk_tree_defs.h) and spi_command_t with its
# SPI_CMD_HD_* values, and this package snapshot defines neither of the
# latter anywhere -- only spi_ll.h uses them, hal/include/hal/spi_types.h has
# no spi_command_t. drv_spi.c carries the declarations for its own
# translation unit; these flags give the package's own sources the same
# thing. The real home of both is the package's hal/include/hal/spi_types.h.
# One string, because building.py appends LOCAL_CFLAGS to a CFLAGS string.
spi_flags = (
'-include soc/clk_tree_defs.h'
' -Dspi_command_t=int'
' -DSPI_CMD_HD_WRBUF=0x01'
' -DSPI_CMD_HD_RDBUF=0x02'
' -DSPI_CMD_HD_WRDMA=0x03'
' -DSPI_CMD_HD_RDDMA=0x04'
' -DSPI_CMD_HD_SEG_END=0x05'
' -DSPI_CMD_HD_EN_QPI=0x06'
' -DSPI_CMD_HD_WR_END=0x07'
' -DSPI_CMD_HD_INT0=0x08'
' -DSPI_CMD_HD_INT1=0x09'
' -DSPI_CMD_HD_INT2=0x0A'
)
group += DefineGroup('idf_port_spi', spi_src, depend = ['BSP_USING_SPI'],
LOCAL_CPPPATH = spi_path, LOCAL_CFLAGS = spi_flags)
# spi_hal.c is only init/deinit/cal_clock. spi_hal_setup_device,
# spi_hal_setup_trans, spi_hal_prepare_data, spi_hal_user_start and
# spi_hal_fetch_result -- everything spi_master.c drives a transfer with --
# are in spi_hal_iram.c, the second file of that pair, which this package's
# C6 drop_hal list removes as well.
#
# It is a group of its own because it is the only source that may see
# include/spi_ll_master_start_compat.h: that header defines a macro named
# spi_ll_master_user_start, and giving it to spi_common.c, spi_master.c or
# gdma.c would only shadow the C6 header's own helpers in files that never
# ask for that name.
iram_path = [os.path.join(bsp_root, 'idf_port', 'include')] + spi_path
group += DefineGroup('idf_port_spi_iram',
['../%s/components/hal/spi_hal_iram.c' % idf],
depend = ['BSP_USING_SPI'],
LOCAL_CPPPATH = iram_path,
LOCAL_CFLAGS = spi_flags +
' -include spi_ll_master_start_compat.h')
Return('group')
File diff suppressed because it is too large. Load diff
+11
View File
@@ -147,6 +147,8 @@ SECTIONS
_iram_start = ABSOLUTE(.);
/* Vectors go to start of IRAM */
ASSERT(ABSOLUTE(.) % 0x100 == 0, "vector address must be 256 byte aligned");
_vector_table_start = ABSOLUTE(.);
KEEP(*(.exception_vectors_table.text));
KEEP(*(.exception_vectors.text));
. = ALIGN(4);
@@ -386,8 +388,17 @@ SECTIONS
soc_reserved_memory_region_end = ABSOLUTE(.);
/* System init functions registered via ESP_SYSTEM_INIT_FN */
_esp_system_init_fn_array_start = ABSOLUTE(.);
_esp_sys_init_fn_start = ABSOLUTE(.);
KEEP (*(SORT_BY_INIT_PRIORITY(.esp_system_init_fn.*)))
KEEP (*(SORT_BY_INIT_PRIORITY(.esp_sys_init_fn.*)))
_esp_system_init_fn_array_end = ABSOLUTE(.);
_esp_sys_init_fn_end = ABSOLUTE(.);
. = ALIGN(4);
_esp_libc_clock_array_start = ABSOLUTE(.);
KEEP (*(.esp_libc_clock_desc))
_esp_libc_clock_array_end = ABSOLUTE(.);
/* section information for initial. */
. = ALIGN(4);
__rt_init_start = .;
KEEP(*(SORT(.rti_fn*)));
-1
View File
@@ -44,7 +44,6 @@
#include "hal/systimer_hal.h"
#include "hal/systimer_ll.h"
#include "riscv/rvruntime-frames.h"
#include "riscv/riscv_interrupts.h"
#include "riscv/interrupt.h"
#include "esp_private/crosscore_int.h"
#include "esp_attr.h"
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,39 @@
import os
from building import *
cwd = GetCurrentDir()
src = ['board.c']
# This directory is built through a scons variant dir (duplicate=0), so the
# hand maintained sdkconfig.h that the ESP-IDF sources include is not copied
# next to the objects. Add the real directory to the include path.
CPPPATH = [cwd, Dir('.').srcnode().abspath]
if GetDepend('BSP_USING_GPIO'):
src += ['drv_gpio.c']
if GetDepend('BSP_USING_UART'):
src += ['drv_uart.c']
if GetDepend('BSP_USING_ADC'):
src += ['drv_adc.c']
if GetDepend('BSP_USING_I2C'):
src += ['drv_hw_i2c.c']
if GetDepend('BSP_USING_PWM'):
src += ['drv_pwm.c']
if GetDepend('BSP_USING_CLOCK_TIMER'):
src += ['drv_timer.c']
if GetDepend('BSP_USING_WIFI'):
src += ['drv_wifi.c']
if GetDepend('BSP_USING_SPI'):
src += ['drv_spi.c']
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
+127
View File
@@ -0,0 +1,127 @@
/*
* Copyright (c) 2021-2024 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-06-02 supperthomas first version
* 2024-12-08 wumingzi support rt_hw_us_delay
*/
#include <rtthread.h>
#include "rttypes.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"
#include "esp_timer.h"
#include "driver/gptimer.h"
/* CI pulls RT-Thread-packages/esp-idf rtt-dev, where OS-tick IDs live only as SYSTIMER_LL_*.
* IDF v6.1 / package PR #18 reintroduces the non-LL names in esp_private/systimer.h. */
#ifndef SYSTIMER_COUNTER_OS_TICK
#define SYSTIMER_COUNTER_OS_TICK SYSTIMER_LL_COUNTER_OS_TICK
#endif
#ifndef SYSTIMER_ALARM_OS_TICK_CORE0
#define SYSTIMER_ALARM_OS_TICK_CORE0 SYSTIMER_LL_ALARM_OS_TICK_CORE0
#endif
static systimer_hal_context_t systimer_hal;
IRAM_ATTR void rt_SysTickIsrHandler(void *arg)
{
systimer_ll_clear_alarm_int(systimer_hal.dev, SYSTIMER_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_COUNTER_OS_TICK, 0);
systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_OS_TICK);
systimer_hal_connect_alarm_counter(&systimer_hal, SYSTIMER_ALARM_OS_TICK_CORE0, SYSTIMER_COUNTER_OS_TICK);
systimer_hal_set_alarm_period(&systimer_hal, SYSTIMER_ALARM_OS_TICK_CORE0, 1000000UL / RT_TICK_PER_SECOND);
systimer_hal_select_alarm_mode(&systimer_hal, SYSTIMER_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_ALARM_OS_TICK_CORE0);
systimer_hal_enable_counter(&systimer_hal, SYSTIMER_COUNTER_OS_TICK);
}
#ifdef SOC_ESP32_C6
#include "riscv/csr.h"
static void c6_reserve_broken_intr(void)
{
/* CPU lines 3 and 4 do not latch an enable on this chip. Reserve them
* before esp_intr_alloc so the chosen line, its non-IRAM mask and the
* matrix route are written together. Copying the handler afterwards
* leaves non_iram_int_mask on the old line. */
ESP_ERROR_CHECK(esp_intr_reserve(3, 0));
ESP_ERROR_CHECK(esp_intr_reserve(4, 0));
}
#endif
void rt_hw_board_init(void)
{
#ifdef SOC_ESP32_C6
RV_WRITE_CSR(mideleg, 0);
c6_reserve_broken_intr();
#endif
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
}
#ifdef SOC_ESP32_C6
#include "esp_rom_sys.h"
void rt_hw_us_delay(rt_uint32_t us)
{
esp_rom_delay_us(us);
}
#else
static gptimer_handle_t gptimer_hw_us = NULL;
static int delay_us_init(void)
{
gptimer_config_t timer_config = {
.clk_src = GPTIMER_CLK_SRC_DEFAULT,
.direction = GPTIMER_COUNT_UP,
.resolution_hz = 1 * 1000 * 1000, /* 1MHz, 1 tick = 1us*/
};
ESP_ERROR_CHECK(gptimer_new_timer(&timer_config, &gptimer_hw_us));
ESP_ERROR_CHECK(gptimer_enable(gptimer_hw_us));
return RT_EOK;
}
INIT_DEVICE_EXPORT(delay_us_init);
void rt_hw_us_delay(rt_uint32_t us)
{
uint64_t count = 0;
ESP_ERROR_CHECK(gptimer_start(gptimer_hw_us));
ESP_ERROR_CHECK(gptimer_set_raw_count(gptimer_hw_us, 0));
/* Retrieve the timestamp at anytime*/
while (count < (uint64_t)us)
{
ESP_ERROR_CHECK(gptimer_get_raw_count(gptimer_hw_us, &count));
}
ESP_ERROR_CHECK(gptimer_stop(gptimer_hw_us));
}
#endif
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2021-2024 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-06-02 supperthomas first version
* 2024-12-08 wumingzi support rt_hw_us_delay
*/
#ifndef __BOARD_H__
#define __BOARD_H__
#include <rtconfig.h>
#include "rttypes.h"
#ifdef __cplusplus
extern "C" {
#endif
void rt_hw_board_init(void);
void rt_hw_us_delay(rt_uint32_t us);
#ifdef __cplusplus
}
#endif
#endif
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-11-23 Chushicheng first version
*/
#ifndef __DRV_ADC_H__
#define __DRV_ADC_H__
#include <rtconfig.h>
#if defined BSP_USING_ADC
/* esp config class */
static struct esp_adc_config
{
rt_uint8_t adc_id;
const char *device_name;
};
int rt_hw_adc_init(void);
#endif /* BSP_USING_ADC */
#endif /* __DRV_ADC_H__ */
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2021-2024 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-06-03 supperthomas first version
* 2024-12-08 wumingzi support open drain mode for soft i2c
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "driver/gpio.h"
#ifdef RT_USING_PIN
static void mcu_pin_write(rt_device_t dev, rt_base_t pin, rt_uint8_t value)
{
gpio_set_level(pin, value);
/*TODO:set gpio out put mode */
}
static rt_ssize_t mcu_pin_read(rt_device_t dev, rt_base_t pin)
{
rt_ssize_t value;
value = gpio_get_level(pin);
return value;
}
static void mcu_pin_mode(rt_device_t dev, rt_base_t pin, rt_uint8_t mode)
{
gpio_config_t io_conf;
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1ULL << pin);
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0;
gpio_config(&io_conf);
switch (mode)
{
case PIN_MODE_INPUT:
gpio_set_direction(pin, GPIO_MODE_INPUT);
break;
case PIN_MODE_OUTPUT:
gpio_set_direction(pin, GPIO_MODE_OUTPUT);
break;
case PIN_MODE_OUTPUT_OD:
gpio_set_direction(pin, GPIO_MODE_INPUT_OUTPUT_OD);
break;
default:
break;
}
/*TODO:set gpio out put mode */
}
static rt_err_t mcu_pin_attach_irq(struct rt_device *device, rt_base_t pin,
rt_uint8_t irq_mode, void (*hdr)(void *args), void *args)
{
/*TODO: start irq handle */
return -RT_ENOSYS;
}
static rt_err_t mcu_pin_detach_irq(struct rt_device *device, rt_base_t pin)
{
/*TODO:disable gpio irq handle */
return RT_EOK;
}
static rt_err_t mcu_pin_irq_enable(struct rt_device *device, rt_base_t pin,
rt_uint8_t enabled)
{
/*TODO:start irq handle */
return RT_EOK;
}
const static struct rt_pin_ops _mcu_pin_ops = {
mcu_pin_mode,
mcu_pin_write,
mcu_pin_read,
mcu_pin_attach_irq,
mcu_pin_detach_irq,
mcu_pin_irq_enable,
RT_NULL,
};
int rt_hw_pin_init(void)
{
/*TODO: INIT THE GPIO CLOCK AND OTHER */
return rt_device_pin_register("pin", &_mcu_pin_ops, RT_NULL);
}
INIT_BOARD_EXPORT(rt_hw_pin_init);
#endif /* RT_USING_PIN */
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2021-2024 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-06-03 supperthomas first version
*
*/
#ifndef __DRV_GPIO_H__
#define __DRV_GPIO_H__
#include <rtconfig.h>
#ifdef RT_USING_PIN
int rt_hw_pin_init(void);
#endif
#endif /* __DRV_GPIO_H__ */
@@ -0,0 +1,135 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*2023-03-28 Zxy first version
*/
#include "drv_hw_i2c.h"
#include "driver/i2c.h"//bsp/ESP32_C3/packages/ESP-IDF-latest/components/driver/include/driver/i2c.h
#include "hal/i2c_types.h"//bsp/ESP32_C3/packages/ESP-IDF-latest/tools/mocks/hal/include/hal/i2c_types.h
#include "esp_err.h"
//#include "portmacro.h"//bsp/ESP32_C3/packages/FreeRTOS_Wrapper-latest/FreeRTOS/portable/rt-thread/portmacro.h
#ifdef BSP_USING_HW_I2C
struct esp32_i2c
{
struct rt_i2c_bus_device bus;
i2c_config_t *base;
char *device_name;
};
// #if defined(BSP_USING_I2C0)
static struct esp32_i2c i2c0 = { 0 };
// #endif
static rt_size_t _master_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num)
{
i2c_cmd_handle_t cmd;//创建流程
rt_size_t ret = (0);
rt_uint32_t index = 0;
// struct esp32_i2c *esp32_i2c = RT_NULL;
struct rt_i2c_msg *msg = RT_NULL;
i2c_rw_t direction;//w-0 r-1
esp_err_t result = ESP_OK;
RT_ASSERT(bus != RT_NULL);
// esp32_i2c = (struct esp32_i2c *)bus;
for (index = 0; index < num; index++)
{
msg = &msgs[index];
direction = ((msg->flags & RT_I2C_RD) ? I2C_MASTER_READ : I2C_MASTER_WRITE);
if (!(msg->flags & RT_I2C_NO_START))
{
/* Start condition and slave address. */
cmd = i2c_cmd_link_create();//创建流程
i2c_master_start(cmd);//启动流程录入
result = i2c_master_write_byte(cmd, msg->addr << 1 | WRITE_BIT, ACK_CHECK_EN);//发送起始信号和从设备地址
i2c_master_stop(cmd);//流程录入完毕
ret = i2c_master_cmd_begin(I2C_NUMBER(0), cmd, 1000 / portTICK_PERIOD_MS);//执行流程
i2c_cmd_link_delete(cmd);//删除流程任务
if (ret != ESP_OK)
{
return ret;
}
}
if (result == ESP_OK)
{
if (direction == I2C_MASTER_WRITE)
{
/* Transmit data. */
cmd = i2c_cmd_link_create();//创建流程
i2c_master_start(cmd);//启动流程录入
result = i2c_master_write_byte(cmd, msg->buf, ACK_CHECK_EN);
i2c_master_stop(cmd);//流程录入完毕
ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_PERIOD_MS);//执行流程
i2c_cmd_link_delete(cmd);//删除流程任务
}
else
{
/* Receive Data. */
cmd = i2c_cmd_link_create();//创建流程
i2c_master_start(cmd);//启动流程录入
result = i2c_master_read_byte(cmd, msg->buf, ACK_VAL);
i2c_master_stop(cmd);//流程录入完毕
ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_PERIOD_MS);//执行流程
i2c_cmd_link_delete(cmd);//删除流程任务
}
}
}
if (result == ESP_OK)
{
ret = index;
}
return ret;
}
static rt_size_t _slave_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num)
{
return -RT_ENOSYS;
}
static rt_err_t _i2c_bus_control(struct rt_i2c_bus_device *bus, int cmd, void *args)
{
return -RT_EINVAL;
}
static const struct rt_i2c_bus_device_ops i2c_ops = {
_master_xfer,
_slave_xfer,
_i2c_bus_control,
};
int rt_hw_i2c_init(void)
{
i2c0.base = &i2c0;
i2c0.device_name = "i2c0";
i2c0.bus.ops = &i2c_ops;
int i2c_master_port = I2C_MASTER_NUM;//iic0
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_io_num = I2C_MASTER_SCL_IO,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = 100000,
// .clk_flags = 0, /*!< Optional, you can use I2C_SCLK_SRC_FLAG_* flags to choose i2c source clock here. */
};
i2c_param_config(i2c_master_port, &conf);//配置完成
i2c_driver_install(i2c_master_port, conf.mode, 0, 0, 0);// I2C 设备的初始化
rt_i2c_bus_device_register(&i2c0.bus, i2c0.device_name);
return RT_EOK;
}
INIT_BOARD_EXPORT(rt_hw_i2c_init);
#endif /* RT_USING_I2C */
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*2023-03-28 Zxy first version
*/
#ifndef __DRV_HW_I2C_H__
#define __DRV_HW_I2C_H__
#include <rtthread.h>
#include <rtdevice.h>
#include "sdkconfig.h"
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
#define READ_BIT I2C_MASTER_READ /*!< I2C master read */
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
#define ACK_VAL 0x0 /*!< I2C ack value */
#define NACK_VAL 0x1 /*!< I2C nack value */
#define _I2C_NUMBER(num) I2C_NUM_##num
#define I2C_NUMBER(num) _I2C_NUMBER(num)
#define I2C_MASTER_NUM I2C_NUMBER(0) /*!< I2C port number for master dev */
#define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL /*!< gpio number for I2C master clock */
#define I2C_MASTER_SDA_IO CONFIG_I2C_MASTER_SDA /*!< gpio number for I2C master data */
#define CONFIG_I2C_MASTER_SCL 6
#define CONFIG_I2C_MASTER_SDA 5
int rt_hw_i2c_init(void);
#endif /* __DRV_HW_I2C_H__ */
@@ -0,0 +1,176 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-11-26 ChuShicheng first version
*/
#include <rtdevice.h>
#include "drv_pwm.h"
#include "driver/ledc.h"
#ifdef BSP_USING_PWM
#define DBG_LEVEL DBG_LOG
#include <rtdbg.h>
#define LOG_TAG "DRV.PWM"
#define LEDC_MODE LEDC_LOW_SPEED_MODE
#define LEDC_DUTY_DEFAULT (4095) // Set duty to 50%. ((2 ** 13) - 1) * 50% = 4095
#define LEDC_FREQUENCY_DEFAULT (5000) // Frequency in Hertz. Set frequency at 5 kHz
struct esp_pwm
{
struct rt_device_pwm pwm_device;
rt_uint8_t timer_num;
char *name;
};
static struct esp_pwm esp_pwm_obj[] = {
#ifdef BSP_USING_PWM0
{
.name = "pwm0",
.timer_num = 0,
}
#endif /* BSP_USING_PWM0 */
};
static rt_err_t _pwm_set(struct esp_pwm *obj, struct rt_pwm_configuration *configuration)
{
float period = configuration->period;
float pulse = configuration->pulse;
float duty = 8191 * (pulse / period); // ((2 ** 13) - 1) * (pulse / period_hz)
float period_hz = 1000000000 / configuration->period;
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_MODE,
.timer_num = obj->timer_num,
.duty_resolution = LEDC_TIMER_13_BIT,
.freq_hz = (uint32_t)period_hz, // Set output frequency at 5 kHz
.clk_cfg = LEDC_AUTO_CLK
};
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, configuration->channel, (uint32_t)duty));
// Update duty to apply the new value
ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, configuration->channel));
return RT_EOK;
}
static rt_err_t _pwm_get(struct esp_pwm *obj, struct rt_pwm_configuration *configuration)
{
uint32_t period_hz = ledc_get_freq(LEDC_MODE, obj->timer_num);
LOG_W("period_hz:%d", period_hz);
uint32_t duty = ledc_get_duty(LEDC_MODE, configuration->channel);
LOG_W("duty:%d", duty);
configuration->period = 1000000000 / period_hz;
configuration->pulse = duty * configuration->period / 8191;
LOG_W("pulse:%d", configuration->pulse);
return RT_EOK;
}
static void pwm_enabled(struct esp_pwm *obj, struct rt_pwm_configuration *configuration, rt_uint8_t enable)
{
if (enable)
{
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_MODE,
.timer_num = obj->timer_num,
.duty_resolution = LEDC_TIMER_13_BIT,
.freq_hz = LEDC_FREQUENCY_DEFAULT, // Set output frequency at 5 kHz
.clk_cfg = LEDC_AUTO_CLK
};
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
// Prepare and then apply the LEDC PWM channel configuration
ledc_channel_config_t ledc_channel = {
.speed_mode = LEDC_MODE,
.channel = configuration->channel,
.timer_sel = obj->timer_num,
.intr_type = LEDC_INTR_DISABLE,
.duty = LEDC_DUTY_DEFAULT, // ((2 ** 13) - 1) * (pulse / period_hz)
.hpoint = 0
};
switch (configuration->channel)
{
case LEDC_CHANNEL_0:
ledc_channel.gpio_num = BSP_LEDC_CH0_GPIO;
break;
case LEDC_CHANNEL_1:
ledc_channel.gpio_num = BSP_LEDC_CH1_GPIO;
break;
case LEDC_CHANNEL_2:
ledc_channel.gpio_num = BSP_LEDC_CH2_GPIO;
break;
case LEDC_CHANNEL_3:
ledc_channel.gpio_num = BSP_LEDC_CH3_GPIO;
break;
case LEDC_CHANNEL_4:
ledc_channel.gpio_num = BSP_LEDC_CH4_GPIO;
break;
case LEDC_CHANNEL_5:
ledc_channel.gpio_num = BSP_LEDC_CH5_GPIO;
break;
default:
break;
}
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
}
else
{
ESP_ERROR_CHECK(ledc_stop(LEDC_MODE, configuration->channel, 0));
}
}
static rt_err_t _pwm_control(struct rt_device_pwm *device, int cmd, void *arg)
{
struct esp_pwm *_pwm = rt_container_of(device, struct esp_pwm, pwm_device);
struct rt_pwm_configuration *configuration = (struct rt_pwm_configuration *)arg;
switch (cmd)
{
case PWM_CMD_ENABLE:
pwm_enabled(_pwm, configuration, RT_TRUE);
return RT_EOK;
case PWM_CMD_DISABLE:
pwm_enabled(_pwm, configuration, RT_FALSE);
return RT_EOK;
case PWM_CMD_SET:
return _pwm_set(_pwm, configuration);
case PWM_CMD_GET:
return _pwm_get(_pwm, configuration);
default:
return -RT_EINVAL;
}
}
static struct rt_pwm_ops _pwm_ops = {
_pwm_control
};
int rt_hw_pwm_init(void)
{
int result = RT_EOK;
for (int i = 0; i < sizeof(esp_pwm_obj) / sizeof(esp_pwm_obj[0]); i++)
{
esp_pwm_obj[i].timer_num = i;
result = rt_device_pwm_register(&esp_pwm_obj[i].pwm_device, esp_pwm_obj[i].name, &_pwm_ops, 0);
if (result != RT_EOK)
{
LOG_E("%s register fail.", esp_pwm_obj[i].name);
}
}
return result;
}
INIT_DEVICE_EXPORT(rt_hw_pwm_init);
#endif /* BSP_USING_PWM */
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-10-20 ChuShicheng first version
*/
#ifndef __DRV_PWM_H__
#define __DRV_PWM_H__
#include <rtconfig.h>
int rt_hw_pwm_init(void);
#endif /* __DRV_PWM_H__ */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2006-2024 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2024-10-08 wumingzi first implementation
*/
#ifndef __DRV_SPI_H__
#define __DRV_SPI_H__
#include <rthw.h>
#include <rtthread.h>
#include <board.h>
#include "driver/spi_common.h" /*bsp/ESP32_C3/packages/ESP-IDF-latest/components/driver/include/driver/spi_common.h*/
#ifdef __cplusplus
extern "C" {
#endif
/* esp32 spi dirver class */
struct esp32_spi
{
char *bus_name;
struct rt_spi_bus *spi_bus;
spi_bus_config_t *esp32_spi_bus_cfg;
};
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin);
#ifdef __cplusplus
}
#endif
#endif /* __DRV_SPI_H__ */
@@ -0,0 +1,162 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-11-15 BetMul first version
*/
#include "drv_timer.h"
#include <rtthread.h>
#include <rtdevice.h>
#include "driver/gptimer.h"
#include "sdkconfig.h"
#ifdef RT_USING_CLOCK_TIME
/**
* handle interrupt for clock_timer.
*/
static bool mcu_clock_timer_intr_handler(gptimer_handle_t gptimer, const gptimer_alarm_event_data_t *edata, void *user_ctx)
{
rt_interrupt_enter();
rt_clock_timer_t *clock_timer = (rt_clock_timer_t *)user_ctx;
rt_clock_timer_isr(clock_timer);
rt_interrupt_leave();
return 0;
}
/**
* init the clock_timer
*/
static void mcu_clock_timer_init(rt_clock_timer_t *timer, rt_uint32_t state)
{
gptimer_handle_t gptimer = (gptimer_handle_t)timer->parent.user_data;
// let the gptimer into enable status
ESP_ERROR_CHECK(gptimer_enable(gptimer));
}
/**
* start the clock_timer, change status into running
*/
static rt_err_t mcu_clock_timer_start(rt_clock_timer_t *timer, rt_uint32_t cnt, rt_clock_timer_mode_t mode)
{
gptimer_handle_t gptimer = (gptimer_handle_t)timer->parent.user_data;
gptimer_alarm_config_t alarm_config = {
.alarm_count = cnt,
};
if (mode == CLOCK_TIMER_MODE_ONESHOT)
{
}
else
{
alarm_config.reload_count = 0;
alarm_config.flags.auto_reload_on_alarm = true;
}
ESP_ERROR_CHECK(gptimer_set_alarm_action(gptimer, &alarm_config));
ESP_ERROR_CHECK(gptimer_start(gptimer));
return RT_EOK;
}
/**
* stop the clock_timer, change the status from running into enable
*/
static void mcu_clock_timer_stop(rt_clock_timer_t *timer)
{
gptimer_handle_t gptimer = (gptimer_handle_t)timer->parent.user_data;
ESP_ERROR_CHECK(gptimer_stop(gptimer));
}
/**
* get count
*/
static rt_uint32_t mcu_clock_timer_count_get(rt_clock_timer_t *timer)
{
gptimer_handle_t gptimer = (gptimer_handle_t)timer->parent.user_data;
// get count number
uint64_t value;
ESP_ERROR_CHECK(gptimer_get_raw_count(gptimer, &value));
return (rt_uint32_t)value;
}
/**
* control the clock_timer
*/
static rt_err_t mcu_clock_timer_control(rt_clock_timer_t *timer, rt_uint32_t cmd, void *args)
{
rt_err_t err = RT_EOK;
switch (cmd)
{
case CLOCK_TIMER_CTRL_FREQ_SET:
err = -RT_ERROR;
break;
case CLOCK_TIMER_CTRL_INFO_GET:
err = -RT_ERROR;
break;
case CLOCK_TIMER_CTRL_MODE_SET:
timer->mode = *(rt_uint32_t *)args;
break;
case CLOCK_TIMER_CTRL_STOP:
mcu_clock_timer_stop(timer);
break;
}
return err;
}
static struct rt_clock_timer_device _clock_timer;
static const struct rt_clock_timer_ops _clock_timer_ops = {
.init = mcu_clock_timer_init,
.start = mcu_clock_timer_start,
.stop = mcu_clock_timer_stop,
.count_get = mcu_clock_timer_count_get,
.control = mcu_clock_timer_control
};
static const struct rt_clock_timer_info _clock_timer_info = {
// TODO:what is the true max and min?
.maxfreq = 1000000UL,
.minfreq = 1000000UL,
.maxcnt = 0xFFFF,
.cntmode = CLOCK_TIMER_MODE_ONESHOT
};
int rt_hw_clock_timer_init(void)
{
char *name = "timer0";
gptimer_handle_t gptimer = NULL;
gptimer_config_t timer_config = {
.clk_src = GPTIMER_CLK_SRC_DEFAULT,
.direction = GPTIMER_COUNT_UP,
.resolution_hz = 1 * 1000 * 1000,
};
gptimer_event_callbacks_t cbs = {
.on_alarm = mcu_clock_timer_intr_handler,
};
ESP_ERROR_CHECK(gptimer_new_timer(&timer_config, &gptimer));
ESP_ERROR_CHECK(gptimer_register_event_callbacks(gptimer, &cbs, &_clock_timer));
_clock_timer.info = &_clock_timer_info;
_clock_timer.ops = &_clock_timer_ops;
return rt_clock_timer_register(&_clock_timer, name, (void *)gptimer);
}
INIT_DEVICE_EXPORT(rt_hw_clock_timer_init);
#endif /* RT_USING_CLOCK_TIME */
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-11-15 BetMul first version
*/
#ifndef __DRV_CLOCK_TIMER_H__
#define __DRV_CLOCK_TIMER_H__
#include <rtconfig.h>
#ifdef RT_USING_CLOCK_TIME
int rt_hw_clock_timer_init(void);
#endif
#endif /* __DRV_CLOCK_TIMER_H__ */
@@ -0,0 +1,140 @@
/*
* 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 <rtthread.h>
#include <rtdevice.h>
#include "driver/uart.h"
#include "hal/uart_hal.h"
#include "hal/uart_periph.h"
#include "sdkconfig.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,
#ifdef SOC_ESP32_C6
.source_clk = UART_SCLK_DEFAULT,
#else
.source_clk = UART_SCLK_APB,
#endif
};
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,21 @@
/*
* 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 <rtconfig.h>
#ifdef RT_USING_SERIAL_V1
int rt_hw_uart_init(void);
#endif
#endif /* __DRV_UART_H__ */
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2019 Winner Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-07-25 WCX1024979076 1st version
*/
#ifndef __DRV_WIFI_H__
#define __DRV_WIFI_H__
#ifdef RT_USING_WIFI
int rt_hw_wifi_init(void);
#endif /* RT_USING_WIFI */
#endif /* __DRV_WIFI_H__ */
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+8 -5
View File
@@ -16,7 +16,7 @@ if 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'
EXEC_PATH = r'~/.espressif/tools/riscv32-esp-elf/esp-15.2.0_20251204/riscv32-esp-elf/bin'
else:
print('Please make sure your toolchains is GNU GCC!')
exit(0)
@@ -40,8 +40,11 @@ if PLATFORM == 'gcc':
OBJCPY = PREFIX + 'objcopy'
STRIP = PREFIX + 'strip'
DEVICE = ' -nostartfiles -march=rv32imac --specs=nosys.specs -fasynchronous-unwind-tables '
CFLAGS = DEVICE + '-include ../../components/libc/compilers/common/include/sys/ioctl.h -gdwarf-4 -ggdb -Og '
# GCC 15 no longer enables the Zicsr/Zifencei extensions through the base
# `-march=rv32imac`, so spell them out.
DEVICE = ' -nostartfiles -march=rv32imac_zicsr_zifencei --specs=nosys.specs -fasynchronous-unwind-tables '
CFLAGS = DEVICE + '-Wno-error=incompatible-pointer-types -Wno-error=int-conversion '
CFLAGS += '-include ../../components/libc/compilers/common/include/sys/ioctl.h -gdwarf-4 -ggdb -Og '
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
idf_path = find_package_path(BSP_ROOT, 'ESP-IDF-latest', relative_to=BSP_ROOT, pathsep='/')
rom = idf_path + '/components/esp_rom/esp32c6/ld/'
@@ -52,9 +55,9 @@ if PLATFORM == 'gcc':
'esp32c6.rom.libgcc.ld',
'esp32c6.rom.newlib.ld',
'esp32c6.rom.version.ld',
'esp32c6.rom.heap.ld',
# ESP-IDF v6.1 folded the heap and watchdog ROM symbols into
# esp32c6.rom.ld, so these two scripts no longer ship.
'esp32c6.rom.spiflash.ld',
'esp32c6.rom.wdt.ld',
]
link_scripts = [' -T idf_port/ld/memory.ld -T idf_port/ld/sections.ld']
link_scripts += [' -T ' + rom + name for name in rom_scripts]
+17 -8
View File
@@ -21,10 +21,19 @@
#include "esp_timer.h"
#include "driver/gptimer.h"
/* CI pulls RT-Thread-packages/esp-idf rtt-dev, where OS-tick IDs live only as SYSTIMER_LL_*.
* IDF v6.1 / package PR #18 reintroduces the non-LL names in esp_private/systimer.h. */
#ifndef SYSTIMER_COUNTER_OS_TICK
#define SYSTIMER_COUNTER_OS_TICK SYSTIMER_LL_COUNTER_OS_TICK
#endif
#ifndef SYSTIMER_ALARM_OS_TICK_CORE0
#define SYSTIMER_ALARM_OS_TICK_CORE0 SYSTIMER_LL_ALARM_OS_TICK_CORE0
#endif
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);
systimer_ll_clear_alarm_int(systimer_hal.dev, SYSTIMER_ALARM_OS_TICK_CORE0);
rt_interrupt_enter();
rt_tick_increase();
rt_interrupt_leave();
@@ -40,14 +49,14 @@ void rt_hw_systick_init(void)
.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_ll_set_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_OS_TICK, 0);
systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_OS_TICK);
systimer_hal_connect_alarm_counter(&systimer_hal, SYSTIMER_ALARM_OS_TICK_CORE0, SYSTIMER_COUNTER_OS_TICK);
systimer_hal_set_alarm_period(&systimer_hal, SYSTIMER_ALARM_OS_TICK_CORE0, 1000000UL / RT_TICK_PER_SECOND);
systimer_hal_select_alarm_mode(&systimer_hal, SYSTIMER_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);
systimer_hal_enable_alarm_int(&systimer_hal, SYSTIMER_ALARM_OS_TICK_CORE0);
systimer_hal_enable_counter(&systimer_hal, SYSTIMER_COUNTER_OS_TICK);
}
#ifdef SOC_ESP32_C6
+30 -11
View File
@@ -22,19 +22,31 @@
#include "esp_rom_sys.h"
#include "esp_private/periph_ctrl.h"
#include "esp_private/sar_periph_ctrl.h"
#include "hal/adc_ll.h"
#else
#include "esp_adc/adc_oneshot.h"
#include "esp_adc/adc_cali.h"
#include "esp_adc/adc_cali_scheme.h"
#endif
/* ESP-IDF v6.1 renamed the maximum attenuation for the ESP32-C3 from
* 11 dB to 12 dB (ADC_ATTEN_DB_11 -> ADC_ATTEN_DB_12). Both are enum
* constants, so the preprocessor cannot tell them apart with #ifdef; use the
* IDF version macro to keep 5.1 builds working. */
#include "esp_idf_version.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
#define ADC_DEV_ATTEN ADC_ATTEN_DB_12
#else
#define ADC_DEV_ATTEN ADC_ATTEN_DB_11
#endif
#ifdef BSP_USING_ADC
#define DBG_TAG "drv.adc"
#define DBG_LVL DBG_INFO
#define DBG_TAG "drv.adc"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#define EXAMPLE_READ_LEN 256
#define GET_UNIT(x) ((x>>3) & 0x1)
#define EXAMPLE_READ_LEN 256
#define GET_UNIT(x) ((x >> 3) & 0x1)
/* esp i2c dirver class */
struct esp_adc
@@ -49,8 +61,7 @@ struct esp_adc
#endif
};
static struct esp_adc_config adc_config[] =
{
static struct esp_adc_config adc_config[] = {
#ifdef BSP_USING_ADC1
{
.adc_id = ADC_UNIT_1,
@@ -86,13 +97,22 @@ static rt_err_t _adc_enabled(struct rt_adc_device *device, rt_int8_t channel, rt
{
adc_on--;
sar_periph_ctrl_adc_oneshot_power_release();
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
adc_ll_enable_bus_clock(false);
#else
periph_module_disable(PERIPH_SARADC_MODULE);
#endif
}
rt_mutex_release(&adc_lock);
return RT_EOK;
}
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
adc_ll_enable_bus_clock(true);
adc_ll_reset_register();
#else
periph_module_enable(PERIPH_SARADC_MODULE);
#endif
sar_periph_ctrl_adc_oneshot_power_acquire();
adc_on++;
@@ -128,7 +148,7 @@ static rt_err_t _adc_enabled(struct rt_adc_device *device, rt_int8_t channel, rt
#else
struct esp_adc *_adc = rt_container_of(device, struct esp_adc, adc_device);
if(enabled)
if (enabled)
{
//-------------ADC Init---------------//
adc_oneshot_unit_init_cfg_t init_config = {
@@ -138,14 +158,14 @@ static rt_err_t _adc_enabled(struct rt_adc_device *device, rt_int8_t channel, rt
//-------------ADC Config---------------//
adc_oneshot_chan_cfg_t config = {
.bitwidth = ADC_BITWIDTH_DEFAULT,
.atten = ADC_ATTEN_DB_11,
.atten = ADC_DEV_ATTEN,
};
ESP_ERROR_CHECK(adc_oneshot_config_channel(_adc->handle, channel, &config));
#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
adc_cali_curve_fitting_config_t cali_config = {
.unit_id = _adc->adc_id,
.atten = ADC_ATTEN_DB_11,
.atten = ADC_DEV_ATTEN,
.bitwidth = ADC_BITWIDTH_DEFAULT,
};
if (adc_cali_create_scheme_curve_fitting(&cali_config, &_adc->cali_handle) == ESP_OK)
@@ -241,8 +261,7 @@ static rt_err_t _adc_get_value(struct rt_adc_device *device, rt_int8_t channel,
#endif
}
static const struct rt_adc_ops esp_adc_ops =
{
static const struct rt_adc_ops esp_adc_ops = {
.enabled = _adc_enabled,
.convert = _adc_get_value,
.get_resolution = RT_NULL,
File diff suppressed because it is too large. Load diff
+10
View File
@@ -13,6 +13,16 @@
#include <rtdevice.h>
#include "driver/uart.h"
#include "hal/uart_hal.h"
/* hal/uart_periph.h on IDF v6.1, soc/uart_periph.h on the rtt-dev package */
#if defined(__has_include)
#if __has_include("hal/uart_periph.h")
#include "hal/uart_periph.h"
#else
#include "soc/uart_periph.h"
#endif
#else
#include "soc/uart_periph.h"
#endif
#include "sdkconfig.h"
#ifdef RT_USING_SERIAL_V1
+37
View File
@@ -4,6 +4,17 @@
*/
#include "rtconfig.h"
#pragma once
/*
* ESP-IDF v6.1 moved the newlib compatibility shims into esp_libc. They are
* only enabled when CONFIG_LIBC_NEWLIB is set, otherwise esp_libc declares an
* empty `struct _reent` and the toolchain's <stdio.h> fails to compile.
* The scons build links against the toolchain's newlib, so enable it.
*/
#define CONFIG_LIBC_NEWLIB 1
/* new in ESP-IDF v6.1 (components/esp_libc/Kconfig), default 200 */
#define CONFIG_LIBC_ASSERT_BUFFER_SIZE 200
/* ESP-IDF v6.1 split esp_log into V1/V2 variants (components/log/Kconfig). */
#define CONFIG_LOG_VERSION 1
#ifdef SOC_ESP32_C6
#include "sdkconfig_c6.h"
#else
@@ -223,7 +234,17 @@
#define CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE 1
#define CONFIG_BOOTLOADER_LOG_LEVEL_INFO 1
#define CONFIG_BOOTLOADER_LOG_LEVEL 3
/* new in ESP-IDF v6.1 (components/bootloader/Kconfig.projbuild), default 80 */
#define CONFIG_BOOTLOADER_CPU_CLK_FREQ_MHZ 80
/*
* ESP-IDF v6.1 only offers the VDDSDIO boost on chips with a configurable
* VDDSDIO regulator (choice BOOTLOADER_VDDSDIO_BOOST depends on
* SOC_CONFIGURABLE_VDDSDIO_SUPPORTED). The ESP32-C3 has none and its
* soc/rtc.h no longer declares rtc_vddsdio_*_config().
*/
#if !defined(SOC_ESP32_C3)
#define CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V 1
#endif
#define CONFIG_BOOTLOADER_REGION_PROTECTION_ENABLE 1
#define CONFIG_BOOTLOADER_WDT_ENABLE 1
#define CONFIG_BOOTLOADER_WDT_TIME_MS 9000
@@ -247,6 +268,11 @@
#define CONFIG_ESPTOOLPY_FLASHMODE_DIO 1
#define CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_STR 1
#define CONFIG_ESPTOOLPY_FLASHMODE "dio"
#define CONFIG_ESPTOOLPY_FLASHMODE_VAL 3
/* new in ESP-IDF v6.1: eFuse block revision range checked by the 2nd stage
bootloader (components/esp_hw_support/port/esp32c3/Kconfig.hw_support) */
#define CONFIG_ESP_EFUSE_BLOCK_REV_MIN_FULL 0
#define CONFIG_ESP_EFUSE_BLOCK_REV_MAX_FULL 199
#define CONFIG_ESPTOOLPY_FLASHFREQ_80M 1
#define CONFIG_ESPTOOLPY_FLASHFREQ "80m"
#define CONFIG_ESPTOOLPY_FLASHSIZE_2MB 1
@@ -406,9 +432,18 @@
#define CONFIG_ESP_PHY_REDUCE_TX_POWER 1
#define CONFIG_ESP_PHY_ENABLE_USB 1
#endif
/* ESP-IDF v6.1's sleep_modes.c reaches for the PAU-only
sleep_enable_cpu_retention() when the CPU is powered down in light sleep,
which the ESP32-C3 has no support for (SOC_PAU_SUPPORTED is 0 there).
The RT-Thread port does its own tick/sleep handling, so leave the
ESP-IDF power management off. */
#ifdef CONFIG_PM_ENABLE
#define CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP 1
#endif
#define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_160 1
#define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ 160
/* new in ESP-IDF v6.1 (components/esp_hw_support/Kconfig), default 0 */
#define CONFIG_ESP_SLEEP_WAIT_FLASH_READY_EXTRA_DELAY 0
#ifdef BSP_ENABLE_GDBSTUB
#define CONFIG_ESP_SYSTEM_PANIC_GDBSTUB 1
#else
@@ -421,6 +456,7 @@
#define CONFIG_ESP_SYSTEM_USE_EH_FRAME 1
#endif
#define CONFIG_ESP_SYSTEM_MEMPROT_FEATURE 1
#define CONFIG_ESP_SYSTEM_MEMPROT_PMS 1
#define CONFIG_ESP_SYSTEM_MEMPROT_FEATURE_LOCK 1
#define CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE 32
#define CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE 2304
@@ -686,6 +722,7 @@
#define CONFIG_WPA_MBEDTLS_TLS_CLIENT 1
#endif
/* List of deprecated options */
#define CONFIG_ESP_SYSTEM_MEMPROT CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#define CONFIG_BROWNOUT_DET CONFIG_ESP_BROWNOUT_DET
#define CONFIG_BROWNOUT_DET_LVL CONFIG_ESP_BROWNOUT_DET_LVL
#define CONFIG_BROWNOUT_DET_LVL_SEL_7 CONFIG_ESP_BROWNOUT_DET_LVL_SEL_7
+17
View File
@@ -921,3 +921,20 @@
#define CONFIG_SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND (1)
#define CONFIG_SOC_PHY_COMBO_MODULE (1) /*!< Support Wi-Fi, BLE and 15.4*/
#define CONFIG_SOC_CAPS_NO_RESET_BY_ANA_BOD (1)
/* --------------------------------------------------------------------------
* ESP-IDF v6.1 additions the scons build needs. The C3 side of the hand
* written sdkconfig.h carries these; the C6 includes this header instead, so
* repeat the SoC independent ones here.
* -------------------------------------------------------------------------- */
/* new in v6.1 (components/bootloader/Kconfig.projbuild), default 80 */
#define CONFIG_BOOTLOADER_CPU_CLK_FREQ_MHZ 80
/* new in v6.1: eFuse block revision range checked by the 2nd stage bootloader */
#define CONFIG_ESP_EFUSE_BLOCK_REV_MIN_FULL 0
#define CONFIG_ESP_EFUSE_BLOCK_REV_MAX_FULL 199
/* new in v6.1 (components/esp_hw_support/Kconfig), default 0 */
#define CONFIG_ESP_SLEEP_WAIT_FLASH_READY_EXTRA_DELAY 0
/* new in v6.1: the PMS memory protection mode symbol */
#define CONFIG_ESP_SYSTEM_MEMPROT_PMS 1
#define CONFIG_ESP_SYSTEM_MEMPROT CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
#define CONFIG_ESPTOOLPY_FLASHMODE_VAL 3
+1 -1
View File
@@ -28,7 +28,7 @@ download_urls = {
'riscv32-unknown-elf-gcc': 'https://github.com/hpmicro/riscv-gnu-toolchain/releases/download/2022.05.15/riscv32-unknown-elf-newlib-multilib_2022.05.15_linux.tar.gz',
'llvm-arm': 'https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-16.0.0/LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64.tar.gz',
'riscv-none-embed-gcc': 'https://github.com/RT-Thread/toolchains-ci/releases/download/v1.5/xpack-riscv-none-embed-gcc-8.3.0-2.3-linux-x64.tar.gz',
'riscv32-esp-elf-gcc': 'https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz',
'riscv32-esp-elf-gcc': 'https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz',
'clang': 'https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-16.0.0/LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64.tar.gz',
# 添加其他工具链的下载地址
}
+1 -1
View File
@@ -7,7 +7,7 @@ declare -A download_urls=(
["riscv64-unknown-elf-gcc"]="https://github.com/RT-Thread/toolchains-ci/releases/download/v1.4/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14.tar.gz"
["riscv32-unknown-elf-gcc"]="https://github.com/hpmicro/riscv-gnu-toolchain/releases/download/2022.05.15/riscv32-unknown-elf-newlib-multilib_2022.05.15_linux.tar.gz"
["riscv-none-embed-gcc"]="https://github.com/RT-Thread/toolchains-ci/releases/download/v1.5/xpack-riscv-none-embed-gcc-8.3.0-2.3-linux-x64.tar.gz"
["riscv32-esp-elf-gcc"]="https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz"
["riscv32-esp-elf-gcc"]="https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz"
["clang"]="https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-16.0.0/LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64.tar.gz"
["i686-atxhua-newlib-elf-gcc"]="https://github.com/atxhua/i686-atxhua-newlib-elf/releases/download/15.2.0/i686-atxhua-newlib-elf-linux.tar.gz"
["i686-atxhua-picolib-elf-gcc"]="https://github.com/atxhua/i686-atxhua-picolib-elf/releases/download/15.2.0/i686-atxhua-picolib-elf-linux.tar.gz"
+1 -1
View File
@@ -389,7 +389,7 @@ riscv32-esp-elf-gcc:
- ESP32_C3
- ESP32_C6
count: 2
download_url: https://github.com/espressif/crosstool-NG/releases/download/esp-2022r1-RC1/riscv32-esp-elf-gcc11_2_0-esp-2022r1-RC1-linux-amd64.tar.xz
download_url: https://github.com/espressif/crosstool-NG/releases/download/esp-15.2.0_20251204/riscv32-esp-elf-15.2.0_20251204-x86_64-linux-gnu.tar.xz
riscv32-unknown-elf-gcc:
bsp:
- core-v-mcu/core-v-cv32e40p