Skip to content

Commit 41a7835

Browse files
committed
Merge remote-tracking branch 'upstream/master' into mcxa346-Rtduino
2 parents 2345544 + 17d026c commit 41a7835

File tree

127 files changed

+16611
-2685
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+16611
-2685
lines changed

.github/workflows/bsp_buildings.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ jobs:
234234
wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.7/arm-linux-musleabi_for_x86_64-pc-linux-gnu_stable.tar.bz2
235235
sudo tar xjf arm-linux-musleabi_for_x86_64-pc-linux-gnu_stable.tar.bz2 -C /opt
236236
/opt/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin/arm-linux-musleabi-gcc --version
237+
echo "RTT_EXEC_PATH=/opt/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin" >> $GITHUB_ENV
238+
echo "RTT_CC_PREFIX=arm-linux-musleabi-" >> $GITHUB_ENV
237239
238240
- name: Install Simulator Tools
239241
if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'gcc' && success() }}

bsp/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ This document is based on the RT-Thread mainline repository and categorizes the
8989
| [stm32f407-atk-explorer](stm32/stm32f407-atk-explorer) |||||| - ||||||| - | - || - ||| - || - | - | - | - || - ||
9090
| [stm32f407-fk407m2-zgt6](stm32/stm32f407-fk407m2-zgt6) |||| - || - | - |||||| - ||| - || - | - || - | - | - | - || - ||
9191
| [stm32f407-lckfb-skystar](stm32/stm32f407-lckfb-skystar) |||| - || - | - |||||| - ||| - || - | - || - | - | - ||| - | - |
92+
| [stm32f407-micu](stm32/stm32f407-micu) ||| - | - | - | - | - |||||| - ||| - | - | - | - | - |
9293
| [stm32f407-robomaster-c](stm32/stm32f407-robomaster-c) ||||| - | - | - | - ||| - || - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
9394
| [stm32f407-rt-spark](stm32/stm32f407-rt-spark) |||||| - | - |||||| - ||| - ||| - || - | - | - ||| - ||
9495
| [stm32f407-st-discovery](stm32/stm32f407-st-discovery) ||| - | - | - | - | - | - || - | - || - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
@@ -761,9 +762,9 @@ This document is based on the RT-Thread mainline repository and categorizes the
761762

762763
#### 🟢 K230 (RT-Smart)
763764

764-
| BSP Name | GPIO | UART | I2C | RTC | ADC | PWM | SDIO | HWTimer | WDT | SPI |
765-
|----------|------|------|-----|-----|-----|-----|------|---------|-----|-----|
766-
| [k230](k230) |||||||||||
765+
| BSP Name | GPIO | UART | I2C | RTC | ADC | PWM | SDIO | HWTimer | WDT | SPI | GNNE |
766+
|----------|------|------|-----|-----|-----|-----|------|---------|-----|-----|------|
767+
| [k230](k230) ||||||||||||
767768

768769
#### 🟢 Xuantie (RT-Smart)
769770

bsp/hpmicro/libraries/drivers/drv_sdio.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static hpm_stat_t hpm_sdmmc_transfer_polling(struct hpm_mmcsd *mmcsd, sdxc_adma_
9797
static hpm_stat_t hpm_sdmmc_transfer_interrupt_driven(struct hpm_mmcsd *mmcsd, sdxc_adma_config_t *dma_config, sdxc_xfer_t *xfer);
9898
static hpm_stat_t hpm_sdmmc_transfer(struct hpm_mmcsd *mmcsd, sdxc_adma_config_t *dma_config, sdxc_xfer_t *xfer);
9999
static rt_int32_t hpm_sdmmc_execute_tuning(struct rt_mmcsd_host *host, rt_int32_t opcode);
100-
static rt_int32_t hpm_sdmmc_switch_uhs_voltage(struct rt_mmcsd_host *host);
100+
static rt_err_t hpm_sdmmc_signal_voltage_switch(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg);
101101

102102
static void hpm_sdmmc_power_on_via_pin(struct hpm_mmcsd *mmcsd);
103103
static void hpm_sdmmc_power_off_via_pin(struct hpm_mmcsd *mmcsd);
@@ -152,7 +152,7 @@ static void hpm_sdmmc_switch_to_1v8_via_pin(struct hpm_mmcsd *mmcsd)
152152
}
153153

154154

155-
static rt_int32_t hpm_sdmmc_switch_uhs_voltage(struct rt_mmcsd_host *host)
155+
static rt_err_t hpm_sdmmc_signal_voltage_switch(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg)
156156
{
157157
struct hpm_mmcsd *mmcsd = (struct hpm_mmcsd *) host->private_data;
158158
SDXC_Type *base = mmcsd->sdxc_base;
@@ -174,9 +174,17 @@ static rt_int32_t hpm_sdmmc_switch_uhs_voltage(struct rt_mmcsd_host *host)
174174
return -RT_ETIMEOUT;
175175
}
176176

177-
/* 3. Switch to 1.8V */
178-
hpm_sdmmc_switch_to_1v8_via_pin(mmcsd);
179-
sdxc_select_voltage(mmcsd->sdxc_base, sdxc_bus_voltage_sd_1v8);
177+
/* 3. Switch to 1.8V/3.3V */
178+
if (ios->signal_voltage == MMCSD_SIGNAL_VOLTAGE_330)
179+
{
180+
hpm_sdmmc_switch_to_3v3_via_pin(mmcsd);
181+
sdxc_select_voltage(mmcsd->sdxc_base, sdxc_bus_voltage_sd_3v3);
182+
}
183+
else
184+
{
185+
hpm_sdmmc_switch_to_1v8_via_pin(mmcsd);
186+
sdxc_select_voltage(mmcsd->sdxc_base, sdxc_bus_voltage_sd_1v8);
187+
}
180188

181189
/* 4. spec:host delay 5ms, host: give more delay time here */
182190
rt_thread_mdelay(10);
@@ -213,7 +221,7 @@ static const struct rt_mmcsd_host_ops hpm_mmcsd_host_ops =
213221
.get_card_status = NULL,
214222
.enable_sdio_irq = hpm_sdmmc_enable_sdio_irq,
215223
.execute_tuning = hpm_sdmmc_execute_tuning,
216-
.switch_uhs_voltage = hpm_sdmmc_switch_uhs_voltage,
224+
.signal_voltage_switch = hpm_sdmmc_signal_voltage_switch,
217225
};
218226

219227
void hpm_sdmmc_isr(struct hpm_mmcsd *mmcsd)

bsp/k230/.ci/attachconfig/ci.attachconfig.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
scons.args: &scons
22
scons_arg:
33
- '--strict'
4+
devices.gnee:
5+
<<: *scons
6+
kconfig:
7+
- CONFIG_BSP_USING_GNNE=y
48
devices.spi:
59
<<: *scons
610
kconfig:

bsp/k230/.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,7 @@ CONFIG_PKG_ZLIB_VER="latest"
16171617
#
16181618
# Drivers Configuration
16191619
#
1620+
# CONFIG_BSP_USING_GNNE is not set
16201621
# CONFIG_BSP_USING_SPI is not set
16211622
# CONFIG_BSP_USING_I2C is not set
16221623
# CONFIG_BSP_USING_RTC is not set

bsp/k230/board/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
menu "Drivers Configuration"
2+
3+
config BSP_USING_GNNE
4+
bool "Enable KPU and AI2D"
5+
default n
26

37
menuconfig BSP_USING_SPI
48
bool "Enable SPI"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# RT-Thread building script for gnne component
2+
3+
from building import *
4+
5+
cwd = GetCurrentDir()
6+
src = Glob('*.c')
7+
CPPPATH = [cwd]
8+
9+
group = DefineGroup('Gnne', src, depend = ['BSP_USING_GNNE'], CPPPATH = CPPPATH)
10+
11+
objs = [group]
12+
13+
list = os.listdir(cwd)
14+
15+
for item in list:
16+
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
17+
objs = objs + SConscript(os.path.join(item, 'SConscript'))
18+
19+
Return('objs')
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
/* Copyright (c) 2023, Canaan Bright Sight Co., Ltd
2+
*
3+
* Redistribution and use in source and binary forms, with or without
4+
* modification, are permitted provided that the following conditions are met:
5+
* 1. Redistributions of source code must retain the above copyright
6+
* notice, this list of conditions and the following disclaimer.
7+
* 2. Redistributions in binary form must reproduce the above copyright
8+
* notice, this list of conditions and the following disclaimer in the
9+
* documentation and/or other materials provided with the distribution.
10+
*
11+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
12+
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
13+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
16+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
/*
27+
* Copyright (c) 2006-2025 RT-Thread Development Team
28+
*
29+
* SPDX-License-Identifier: Apache-2.0
30+
*/
31+
32+
#include <rtthread.h>
33+
#include <rthw.h>
34+
#include "drv_hardlock.h"
35+
#include "board.h"
36+
37+
#if defined(RT_USING_POSIX_DEVIO)
38+
#include <dfs_posix.h>
39+
#include <poll.h>
40+
#include <termios.h>
41+
#endif
42+
43+
#define AI2D_CMD_LOCK 0
44+
#define AI2D_CMD_TRYLOCK 1
45+
#define AI2D_CMD_UNLOCK 2
46+
static hardlock_type g_ai2d_lock = HARDLOCK_MAX;
47+
48+
struct ai_2d_dev_handle
49+
{
50+
rt_wqueue_t *wait;
51+
rt_bool_t is_lock;
52+
};
53+
54+
55+
#define ai_2d_log(s...) rt_kprintf(s)
56+
57+
#define ai_2d_err(s...) do { \
58+
ai_2d_log("<err>[%s:%d] ", __func__, __LINE__); \
59+
ai_2d_log(s); \
60+
ai_2d_log("\r\n"); \
61+
} while (0)
62+
63+
static struct rt_device g_ai_2d_device = {0};
64+
static struct rt_event g_ai_2d_event = {0};
65+
extern void *gnne_base_addr;
66+
67+
static int ai_2d_device_open(struct dfs_file *file)
68+
{
69+
struct ai_2d_dev_handle *handle;
70+
rt_device_t device;
71+
72+
handle = rt_malloc(sizeof(struct ai_2d_dev_handle));
73+
if (handle == RT_NULL)
74+
{
75+
ai_2d_err("malloc failed\n");
76+
return -1;
77+
}
78+
device = (rt_device_t)file->vnode->data;
79+
handle->wait = &device->wait_queue;
80+
handle->is_lock = RT_FALSE;
81+
file->data = (void *)handle;
82+
return RT_EOK;
83+
}
84+
85+
static int ai_2d_device_close(struct dfs_file *file)
86+
{
87+
struct ai_2d_dev_handle *handle;
88+
89+
handle = (struct ai_2d_dev_handle *)file->data;
90+
if (handle == RT_NULL)
91+
{
92+
ai_2d_err("try to close a invalid handle");
93+
return -RT_EINVAL;
94+
}
95+
if (handle->is_lock)
96+
{
97+
kd_hardlock_unlock(g_ai2d_lock);
98+
}
99+
rt_free(handle);
100+
file->data = RT_NULL;
101+
return RT_EOK;
102+
}
103+
104+
static int ai_2d_device_ioctl(struct dfs_file *file, int cmd, void *args)
105+
{
106+
struct ai_2d_dev_handle *handle;
107+
int ret = -1;
108+
109+
handle = (struct ai_2d_dev_handle *)file->data;
110+
if (g_ai2d_lock == HARDLOCK_MAX)
111+
return ret;
112+
113+
if (cmd == AI2D_CMD_LOCK)
114+
{
115+
if (handle->is_lock == RT_TRUE)
116+
{
117+
return 0;
118+
}
119+
while (kd_hardlock_lock(g_ai2d_lock));
120+
handle->is_lock = RT_TRUE;
121+
ret = 0;
122+
}
123+
else if (cmd == AI2D_CMD_UNLOCK)
124+
{
125+
if (handle->is_lock == RT_FALSE)
126+
{
127+
return 0;
128+
}
129+
kd_hardlock_unlock(g_ai2d_lock);
130+
handle->is_lock = RT_FALSE;
131+
ret = 0;
132+
}
133+
else if (cmd == AI2D_CMD_TRYLOCK)
134+
{
135+
if (handle->is_lock == RT_TRUE)
136+
{
137+
return 0;
138+
}
139+
if (!kd_hardlock_lock(g_ai2d_lock))
140+
{
141+
handle->is_lock = RT_TRUE;
142+
ret = 0;
143+
}
144+
}
145+
return ret;
146+
}
147+
148+
int ai_2d_device_poll(struct dfs_file *file, struct rt_pollreq *req)
149+
{
150+
struct ai_2d_dev_handle *handle;
151+
unsigned int flags;
152+
handle = (struct ai_2d_dev_handle *)file->data;
153+
if (!handle)
154+
{
155+
ai_2d_err("ai_2d_dev_handle NULL!");
156+
return -EINVAL;
157+
}
158+
rt_event_recv(&g_ai_2d_event, 0x01, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, NULL);
159+
rt_poll_add(handle->wait, req);
160+
return POLLIN;
161+
}
162+
163+
static const struct dfs_file_ops ai_2d_input_fops =
164+
{
165+
.open = ai_2d_device_open,
166+
.close = ai_2d_device_close,
167+
.ioctl = ai_2d_device_ioctl,
168+
.poll = ai_2d_device_poll,
169+
};
170+
171+
static void irq_callback(int irq, void *data)
172+
{
173+
rt_wqueue_t *wait = (rt_wqueue_t *)data;
174+
volatile rt_uint32_t *write_addr = (rt_uint32_t *)((char *)gnne_base_addr + 0xca0);
175+
if (gnne_base_addr == RT_NULL)
176+
{
177+
ai_2d_err("ai2d interrupts while the hardware is not yet initialized\n");
178+
}
179+
write_addr[0] = 1;
180+
write_addr[1] = 0;
181+
write_addr[2] = 0;
182+
write_addr[3] = 0;
183+
rt_wqueue_wakeup(wait, (void *)POLLIN);
184+
rt_event_send(&g_ai_2d_event, 0x1);
185+
}
186+
187+
int ai_2d_device_init(void)
188+
{
189+
int ret = 0;
190+
rt_isr_handler_t old_handler;
191+
rt_device_t ai_2d_device = &g_ai_2d_device;
192+
193+
ret = rt_event_init(&g_ai_2d_event, "ai_2d_event", RT_IPC_FLAG_PRIO);
194+
if (ret)
195+
{
196+
ai_2d_err("event init failed\n");
197+
return -ENOMEM;
198+
}
199+
200+
ret = rt_device_register(ai_2d_device, "ai_2d_device", RT_DEVICE_FLAG_RDWR);
201+
if (ret)
202+
{
203+
ai_2d_err("ai_2d_device register fail\n");
204+
return ret;
205+
}
206+
207+
rt_wqueue_init(&ai_2d_device->wait_queue);
208+
old_handler = rt_hw_interrupt_install(K230_IRQ_AI_2D, irq_callback, &ai_2d_device->wait_queue, "ai_2d_irq");
209+
if (old_handler == RT_NULL)
210+
{
211+
ai_2d_err("ai_2d_device interrupt install fail\n");
212+
return -RT_ERROR;
213+
}
214+
rt_hw_interrupt_umask(K230_IRQ_AI_2D);
215+
216+
ai_2d_device->fops = &ai_2d_input_fops;
217+
218+
if (kd_request_lock(HARDLOCK_AI2D))
219+
{
220+
ai_2d_err("fail to request hardlock-%d\n", HARDLOCK_AI2D);
221+
}
222+
else
223+
{
224+
g_ai2d_lock = HARDLOCK_AI2D;
225+
}
226+
return RT_EOK;
227+
}

0 commit comments

Comments
 (0)