Skip to content

Commit e399fea

Browse files
author
Ironside
committed
bsp/spacemit/k1:first version
1 parent 138c888 commit e399fea

File tree

32 files changed

+4617
-0
lines changed

32 files changed

+4617
-0
lines changed

bsp/spacemit/k1/.config

Lines changed: 1431 additions & 0 deletions
Large diffs are not rendered by default.

bsp/spacemit/k1/.defconfig

Lines changed: 1463 additions & 0 deletions
Large diffs are not rendered by default.

bsp/spacemit/k1/Kconfig

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
mainmenu "RT-Thread SpacemiT K1 Configuration"
2+
3+
BSP_DIR := .
4+
RTT_DIR := ../../..
5+
PKGS_DIR := packages
6+
7+
source "$(RTT_DIR)/Kconfig"
8+
osource "$PKGS_DIR/Kconfig"
9+
#rsource "board/Kconfig"
10+
rsource "drivers/Kconfig"
11+
12+
config SOC_SPACEMIT_K1
13+
bool
14+
select ARCH_RISCV64
15+
select RT_USING_COMPONENTS_INIT
16+
select RT_USING_USER_MAIN
17+
default y
18+
19+
choice BOARD_NAME
20+
prompt "Select Your Board"
21+
default BOARD_MUSE_PI_PRO
22+
23+
config BOARD_MUSE_PI_PRO
24+
bool "SpacemiT MUSE Pi Pro"
25+
select SOC_SPACEMIT_K1
26+
default y
27+
endchoice
28+
29+
config ENABLE_FPU
30+
bool "Enable FPU"
31+
select ARCH_RISCV_FPU
32+
default y
33+
34+
config __STACKSIZE__
35+
int "stack size for interrupt"
36+
default 16384

bsp/spacemit/k1/README.md

Whitespace-only changes.

bsp/spacemit/k1/SConscript

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# for module compiling
2+
import os
3+
from building import *
4+
5+
objs = []
6+
7+
# ------------------- libcpu -------------------
8+
RTT_ROOT = os.path.normpath(os.path.join(GetCurrentDir(), '..', '..', '..'))
9+
10+
common64_path = os.path.join(RTT_ROOT, 'libcpu/risc-v/common64')
11+
libcpu_src = [
12+
os.path.join(common64_path, 'sbi.c'),
13+
os.path.join(common64_path, 'trap.c'),
14+
os.path.join(common64_path, 'cpuport.c'),
15+
os.path.join(common64_path, 'context_gcc.S'),
16+
os.path.join(common64_path, 'interrupt_gcc.S'),
17+
os.path.join(common64_path, 'startup_gcc.S'),
18+
]
19+
20+
k1_libcpu_path = os.path.join(RTT_ROOT, 'libcpu/risc-v/spacemit/x60')
21+
libcpu_src += Glob(os.path.join(k1_libcpu_path, '*.c'))
22+
23+
libcpu_cpppath = [
24+
common64_path,
25+
k1_libcpu_path,
26+
os.path.join(RTT_ROOT, 'libcpu/risc-v/vector/rvv-1.0'),
27+
]
28+
29+
group = DefineGroup('libcpu', libcpu_src, depend=[''], CPPPATH=libcpu_cpppath)
30+
objs += group
31+
32+
33+
# ------------------- bsp -------------------
34+
cwd = GetCurrentDir()
35+
list = os.listdir(cwd)
36+
37+
for d in list:
38+
path = os.path.join(cwd, d)
39+
if os.path.isfile(os.path.join(path, 'SConscript')):
40+
objs = objs + SConscript(os.path.join(d, 'SConscript'))
41+
42+
43+
Return('objs')

bsp/spacemit/k1/SConstruct

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
import sys
3+
import rtconfig
4+
5+
from rtconfig import RTT_ROOT
6+
7+
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
8+
from building import *
9+
10+
TARGET = 'rtthread.' + rtconfig.TARGET_EXT
11+
12+
DefaultEnvironment(tools=[])
13+
env = Environment(tools = ['mingw'],
14+
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
15+
CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS,
16+
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
17+
AR = rtconfig.AR, ARFLAGS = '-rc',
18+
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
19+
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
20+
env['ASCOM'] = env['ASPPCOM']
21+
22+
Export('RTT_ROOT')
23+
Export('rtconfig')
24+
25+
26+
# prepare building environment
27+
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = True)
28+
29+
stack_size = 8192
30+
stack_lds = open('link_stacksize.lds', 'w')
31+
if GetDepend('__STACKSIZE__'):
32+
stack_size = GetDepend('__STACKSIZE__')
33+
stack_lds.write('__STACKSIZE__ = %d;' % stack_size)
34+
stack_lds.close()
35+
36+
DoBuilding(TARGET, objs)
37+
38+
Clean(TARGET, 'link.lds.generated')
39+
Clean(TARGET, 'build')
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from building import *
2+
3+
cwd = GetCurrentDir()
4+
src = Glob('*.c')
5+
CPPPATH = [cwd]
6+
7+
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
8+
9+
Return('group')
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2006-2020, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-10-15 IronsideZhang first version
9+
*/
10+
11+
#include <rtthread.h>
12+
#include <rthw.h>
13+
#include <stdio.h>
14+
#include <string.h>
15+
16+
int main(void)
17+
{
18+
printf("Hello RISC-V\n");
19+
20+
return 0;
21+
}

bsp/spacemit/k1/board/SConscript

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from building import *
2+
3+
cwd = GetCurrentDir()
4+
src = Glob('*.c') + Glob('*.cpp') + Glob('*.S')
5+
CPPPATH = [cwd]
6+
7+
group = DefineGroup('Board', src, depend = [''], CPPPATH = CPPPATH)
8+
9+
Return('group')

bsp/spacemit/k1/board/board.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-10-15 IronsideZhang first version
9+
*/
10+
11+
#include <rthw.h>
12+
#include <rtthread.h>
13+
#include "board.h"
14+
#include "drv_uart.h"
15+
16+
/* Defined in link.lds */
17+
extern unsigned int __bss_end;
18+
19+
#define HEAP_BEGIN ((void *)&__bss_end)
20+
#define HEAP_END ((void *)((rt_size_t)HEAP_BEGIN + KERNEL_HEAP_SIZE))
21+
22+
static void __rt_assert_handler(const char *ex_string, const char *func, rt_size_t line)
23+
{
24+
rt_kprintf("\n(%s) assertion failed at function:%s, line number:%d \n", ex_string, func, line);
25+
while (1);
26+
}
27+
28+
/* C entry point for the primary CPU, called from startup_gcc.S */
29+
void primary_cpu_entry(void)
30+
{
31+
rt_hw_interrupt_disable();
32+
rt_assert_set_hook(__rt_assert_handler);
33+
entry(); // Call RT-Thread kernel entry
34+
}
35+
36+
/* This function is called by the kernel before the scheduler starts */
37+
void rt_hw_board_init(void)
38+
{
39+
#ifdef RT_USING_HEAP
40+
/* Initialize the system heap */
41+
rt_system_heap_init(HEAP_BEGIN, HEAP_END);
42+
#endif
43+
44+
/*
45+
* Initialize hardware interrupts:
46+
*/
47+
rt_hw_interrupt_init();
48+
49+
/*
50+
* Initialize the UART driver for console output.
51+
* This function will handle pinctrl and sysctl initialization internally.
52+
*/
53+
rt_hw_uart_init();
54+
55+
#ifdef RT_USING_CONSOLE
56+
/* Set the console device */
57+
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
58+
#endif
59+
60+
#ifdef RT_USING_COMPONENTS_INIT
61+
/* Initialize auto-initialized components */
62+
rt_components_board_init();
63+
#endif
64+
65+
}

0 commit comments

Comments
 (0)