Skip to content

Commit baa3145

Browse files
authored
Merge pull request #3504 from bigmagic123/add_ls2k_bsp
Add ls2k bsp
2 parents e382ae0 + c27f13c commit baa3145

31 files changed

+1787
-62
lines changed

bsp/ls2kdev/.config

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

bsp/ls2kdev/Kconfig

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
mainmenu "RT-Thread Configuration"
2+
3+
config BSP_DIR
4+
string
5+
option env="BSP_ROOT"
6+
default "."
7+
8+
config RTT_DIR
9+
string
10+
option env="RTT_ROOT"
11+
default "../.."
12+
13+
# you can change the RTT_ROOT default "../.." to your rtthread_root,
14+
# example : default "F:/git_repositories/rt-thread"
15+
16+
config PKGS_DIR
17+
string
18+
option env="PKGS_ROOT"
19+
default "packages"
20+
21+
source "$RTT_DIR/Kconfig"
22+
source "$RTT_DIR/libcpu/mips/common/Kconfig"
23+
source "$PKGS_DIR/Kconfig"
24+
25+
config SOC_LS2K1000
26+
bool
27+
select ARCH_MIPS64
28+
select RT_USING_COMPONENTS_INIT
29+
select RT_USING_USER_MAIN
30+
select RT_USING_DEVICE
31+
default y
32+

bsp/ls2kdev/README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# loongson_pi2 板级支持包说明
2+
3+
## 1. 简介
4+
5+
2K龙芯派采是首款采用2K1000低功耗处理的嵌入式方案验证板,具有资源丰富、接口齐全、低功耗、高可靠的特点。
6+
7+
| 硬件 | 描述 |
8+
| -- | -- |
9+
|芯片型号| 2K1000 |
10+
|CPU| GS264 |
11+
|主频| 1GHz |
12+
|DDR3| 2GB |
13+
|片外Flash| 8Mb SPI FLASH |
14+
15+
[龙芯派][1]搭载 2K1000 处理器(主频 1GHz),板载 DDR3 颗粒,实现 DDR3 的运行存储功能。实现了 GPIO 的输入输出,中断功能。板上集成 1 个网 口,集成 3 个 USB 接口,HDMI 接口,LCD 接口,音频输入/输出,集成 SD 卡接口,集成 2 个 CAN 接口,集成 RTC 计时功能。可以外扩 WIFI 模块。2K 龙芯派可以广泛应用于信息安 全、电力、轨道交通、工业控制、信号处理、数据通信、信息教育等领域。
16+
17+
18+
## 2. 编译说明
19+
20+
环境搭建在Ubuntu上进行,首先下载[mips-sde-elf-gcc][2]。该文件存放在网盘中,提取码为ucb2。
21+
22+
解压到指定的目录,然后修改当前bsp目录下的`rtconfig.py`文件。
23+
24+
```python
25+
if CROSS_TOOL == 'gcc':
26+
PLATFORM = 'gcc'
27+
EXEC_PATH = "/opt/mips-2015.05-19-mips-sde-elf-i686-pc-linux-gnu/mips-2015.05/bin/"
28+
```
29+
30+
然后在控制台输入`scons`即可,可以生成`rtthread.elf``rtthread.bin`文件,其中`rtthread.elf`是下载到开发板上的程序。
31+
32+
## 3.程序运行
33+
34+
rt-thread固件目前在龙芯派上推荐使用[pmon][3]通过tftp的方式下载到设备内存中运行。
35+
36+
其中龙芯派硬件分布如下图所示:
37+
38+
![loongsonpi](figures/loongsonpi.png)
39+
40+
首先板子接上12V的电源,然后连接串口,该串口为RS232,所以需要RS232转USB线来进行连接。接着连接`LAN0`网口。
41+
42+
初次上电时,需要按下开发板的`START`按键,听到``启动声后可以在控制台看到串口打印信息。通过启动时在控制台不停的按下字符`c`直到进入到pmon控制台。
43+
44+
45+
46+
需要让开发板和主机处于同一网段,利用pmon的tftp进行固件传输。首先查看主机的ip地址,如果`ifconfig`查看ip是`192.168.12.35`。输入以下指令开始运行。
47+
48+
```
49+
ifaddr syn0 192.168.12.100
50+
load tftp://192.168.12.35/rtthread.elf;
51+
g
52+
```
53+
54+
其中`ifaddr`是设置pmon设置网络的命令,`syn0`表示第一个网卡。然后从tftp的主机上加载`rtthread.elf`文件,此时主机必须有tftp服务器。`g`表示程序跳转运行。
55+
56+
而后可以看到rtthread程序正常的运行。
57+
58+
```
59+
zero at v0 v1 a0 a1 a2 a3
60+
00000000 00000000 00000000 00000000 00000003 aafffea8 8f800000 8f1371d0
61+
t0 t1 t2 t3 t4 t5 t6 t7
62+
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
63+
s0 s1 s2 s3 s4 s5 s6 s7
64+
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
65+
t8 t9 k0 k1 gp sp s8 ra
66+
00000000 00000000 00000000 00000000 00000000 aafffe88 00000000 8f0b1418
67+
Current SR: 0x10008080
68+
69+
\ | /
70+
- RT - Thread Operating System
71+
/ | \ 4.0.3 build Apr 7 2020
72+
2006 - 2020 Copyright by rt-thread team
73+
Hi, this is RT-Thread!!
74+
msh >
75+
```
76+
77+
## 4. 支持情况
78+
79+
| 驱动 | 支持情况 | 备注 |
80+
| ------ | ---- | :------: |
81+
| UART | 支持 | UART0|
82+
83+
## 5. 联系人信息
84+
85+
维护人:[bernard][4]
86+
87+
[1]: http://ftp.loongnix.org/loongsonpi/pi_2/doc
88+
[2]: https://pan.baidu.com/s/17dbdOE4NAJ-qEW7drVRq2w
89+
[3]: http://ftp.loongnix.org/embedd/ls2k/
90+
[4]: https://github.com/BernardXiong

bsp/ls2kdev/SConscript

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from building import *
2+
3+
cwd = GetCurrentDir()
4+
objs = []
5+
list = os.listdir(cwd)
6+
7+
for d in list:
8+
path = os.path.join(cwd, d)
9+
if os.path.isfile(os.path.join(path, 'SConscript')):
10+
objs = objs + SConscript(os.path.join(d, 'SConscript'))
11+
12+
Return('objs')

bsp/ls2kdev/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+
rtconfig.AFLAGS += ' -I' + str(Dir('#'))
13+
14+
DefaultEnvironment(tools=[])
15+
env = Environment(tools = ['mingw'],
16+
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
17+
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
18+
AR = rtconfig.AR, ARFLAGS = '-rc',
19+
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
20+
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
21+
22+
Export('RTT_ROOT')
23+
Export('rtconfig')
24+
25+
26+
# prepare building environment
27+
objs = PrepareBuilding(env, RTT_ROOT)
28+
29+
rtconfig.LFLAGS += " -Ttext 0xffffffff80200000"
30+
env.Replace(LINKFLAGS = rtconfig.LFLAGS)
31+
32+
if GetDepend('RT_USING_FPU'):
33+
env['CCFLAGS'] = env['CCFLAGS'].replace('-msoft-float', '-mhard-float')
34+
env['ASFLAGS'] = env['ASFLAGS'].replace('-msoft-float', '-mhard-float')
35+
env['CXXFLAGS'] = env['CXXFLAGS'].replace('-msoft-float', '-mhard-float')
36+
env['LINKFLAGS'] = env['LINKFLAGS'].replace('-msoft-float', '-mhard-float')
37+
38+
# make a building
39+
DoBuilding(TARGET, objs)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from building import *
2+
3+
cwd = GetCurrentDir()
4+
src = Glob('*.c')
5+
6+
group = DefineGroup('Applications', src, depend = [''])
7+
8+
Return('group')

bsp/ls2kdev/applications/main.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
* 2020-04-05 bigmagic first version
9+
*/
10+
11+
#include <rtthread.h>
12+
13+
int main(int argc, char** argv)
14+
{
15+
rt_kprintf("Hi, this is RT-Thread!!\n");
16+
return 0;
17+
}

bsp/ls2kdev/drivers/SConscript

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

bsp/ls2kdev/drivers/board.c

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
* 2020-04-05 bigmagic Initial version
9+
*/
10+
11+
#include <rtthread.h>
12+
#include <rthw.h>
13+
14+
#include "mips_regs.h"
15+
#include "exception.h"
16+
#include "drv_uart.h"
17+
#include "board.h"
18+
/**
19+
* this function will reset CPU
20+
*
21+
*/
22+
void rt_hw_cpu_reset(void)
23+
{
24+
rt_kprintf("reboot system...\n");
25+
while (1);
26+
}
27+
28+
/**
29+
* this function will shutdown CPU
30+
*
31+
*/
32+
void rt_hw_cpu_shutdown(void)
33+
{
34+
rt_kprintf("shutdown...\n");
35+
36+
while (1);
37+
}
38+
39+
40+
/**
41+
* This is the timer interrupt service routine.
42+
*/
43+
void rt_hw_timer_handler(void)
44+
{
45+
unsigned int count;
46+
47+
count = read_c0_compare();
48+
write_c0_compare(count);
49+
write_c0_count(0);
50+
/* increase a OS tick */
51+
rt_tick_increase();
52+
}
53+
54+
/**
55+
* This function will initial OS timer
56+
*/
57+
void rt_hw_timer_init(void)
58+
{
59+
write_c0_compare(CPU_HZ/2/RT_TICK_PER_SECOND);
60+
write_c0_count(0);
61+
mips_unmask_cpu_irq(7);
62+
}
63+
64+
/**
65+
* Board level initialization
66+
*/
67+
void rt_hw_board_init(void)
68+
{
69+
rt_hw_exception_init();
70+
/* init hardware interrupt */
71+
rt_hw_interrupt_init();
72+
73+
#ifdef RT_USING_FPU
74+
/* init hardware fpu */
75+
rt_hw_fpu_init();
76+
#endif
77+
78+
#ifdef RT_USING_SERIAL
79+
/* init hardware UART device */
80+
rt_hw_uart_init();
81+
/* set console device */
82+
rt_console_set_device("uart");
83+
#endif
84+
85+
#ifdef RT_USING_HEAP
86+
rt_system_heap_init((void*)RT_HW_HEAP_BEGIN, (void*)RT_HW_HEAP_END);
87+
#endif
88+
89+
/* init operating system timer */
90+
rt_hw_timer_init();
91+
92+
#ifdef RT_USING_COMPONENTS_INIT
93+
rt_components_board_init();
94+
#endif
95+
96+
rt_kprintf("Current SR: 0x%08x\n", read_c0_status());
97+
98+
}

bsp/ls2kdev/drivers/board.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
* 2020-04-05 bigmagic the first version
9+
*/
10+
11+
#ifndef BOARD_H__
12+
#define BOARD_H__
13+
14+
#include <stdint.h>
15+
16+
extern unsigned char __bss_end;
17+
18+
#define CPU_HZ (100 * 1000 * 1000)
19+
#define RT_HW_HEAP_BEGIN KSEG1BASE//(void*)&__bss_end
20+
#define RT_HW_HEAP_END (void*)(RT_HW_HEAP_BEGIN + 64 * 1024 * 1024)
21+
22+
void rt_hw_board_init(void);
23+
24+
#endif

0 commit comments

Comments
 (0)