From 1ecdf8dbaa06d41708f533d8c8e0dce7556b2179 Mon Sep 17 00:00:00 2001 From: AceVest Date: Sun, 19 Jan 2020 20:08:33 +0800 Subject: [PATCH] ... --- documents/RISC-V.md | 11 +- learn/circuit/basic/basic-cache.lib | 88 ------------ learn/circuit/basic/basic.bak | 109 -------------- learn/circuit/basic/basic.kicad_pcb | 1 - learn/circuit/basic/basic.pro | 33 ----- learn/circuit/basic/basic.sch | 119 --------------- learn/doc/mac_bash_profile | 4 +- learn/risc-v/00/l.ld | 14 ++ .../TransplanteTencentOStinyToRISCV_1.md | 136 ++++++++++++++++++ tools/mcu/rdserial.go | 6 + 10 files changed, 167 insertions(+), 354 deletions(-) delete mode 100644 learn/circuit/basic/basic-cache.lib delete mode 100644 learn/circuit/basic/basic.bak delete mode 100644 learn/circuit/basic/basic.kicad_pcb delete mode 100644 learn/circuit/basic/basic.pro delete mode 100644 learn/circuit/basic/basic.sch create mode 100644 learn/risc-v/00/l.ld create mode 100644 learn/risc-v/TransplanteTencentOStinyToRISCV_1.md diff --git a/documents/RISC-V.md b/documents/RISC-V.md index e689d52..9d9f138 100644 --- a/documents/RISC-V.md +++ b/documents/RISC-V.md @@ -11,7 +11,7 @@ Bumblebe内核遵循的标准 RISC-V 特权架构文档版本为:“特权架构 ### 2. CSR `mtvec`的MODE部分 -在riscv-privileged-v1.10.pdf文档中,`mtvect`MODE的合法值为: +在riscv-privileged-v1.10.pdf文档中,`mtvec`MODE的合法值为: |Value|Name|Description| |:-:|:-:|:--| @@ -42,6 +42,13 @@ Bumblebe内核遵循的标准 RISC-V 特权架构文档版本为:“特权架构 1. `mtvt2`的最低位`mtvt2.MTVT2EN == 0`,则所有非向量中断共享的入口地址由CSR寄存器`mtvec`的值(忽略最低2位的值)指定 2. `mtvt2`的最低位`mtvt2.MTVT2EN == 1`,则所有非向量中断共享的入口地址由CSR寄存器`mtvt2`的值(忽略最低2位的值)指定 -ECLIC的每个中断源均可以设置成向量或者非向量处理(通过寄存器`clicintattr[i].shv`),如果中断被配置为向量处理模式,则该中断被处理器内核响应后,处理器直接跳入该中断的向量入口(Vector Table Entry)存储的目标地址(ECLIC中断向量表的基地址保存在`mtvt`中,通过这个寄存器查得)。 +**注:** + +**向量中断模式** *指各个中断直接跳到各个中断的入口地址,由`mtvt`指定* + +**非向量中断模式** *指各个中断共享同一个入口地址,由`mtvt2`指定* + +每个中断源均可以设置成向量或者非向量处理(通过寄存器`clicintattr[i].shv`)。 + *疑问:如果`mtvt2.MTVT2EN==0` 且在clicintattr[i]中配置成向量中断,就与riscv-privileged-v1.10.pdf中的"vectored interrupt"基本等价?只是一个是从`mtvt`中取出基址,一个是从`mtvec`中取出基址?* \ No newline at end of file diff --git a/learn/circuit/basic/basic-cache.lib b/learn/circuit/basic/basic-cache.lib deleted file mode 100644 index 7ab54b3..0000000 --- a/learn/circuit/basic/basic-cache.lib +++ /dev/null @@ -1,88 +0,0 @@ -EESchema-LIBRARY Version 2.4 -#encoding utf-8 -# -# Device_C -# -DEF Device_C C 0 10 N Y 1 F N -F0 "C" 25 100 50 H V L CNN -F1 "Device_C" 25 -100 50 H V L CNN -F2 "" 38 -150 50 H I C CNN -F3 "" 0 0 50 H I C CNN -$FPLIST - C_* -$ENDFPLIST -DRAW -P 2 0 1 20 -80 -30 80 -30 N -P 2 0 1 20 -80 30 80 30 N -X ~ 1 0 150 110 D 50 50 1 1 P -X ~ 2 0 -150 110 U 50 50 1 1 P -ENDDRAW -ENDDEF -# -# Device_R -# -DEF Device_R R 0 0 N Y 1 F N -F0 "R" 80 0 50 V V C CNN -F1 "Device_R" 0 0 50 V V C CNN -F2 "" -70 0 50 V I C CNN -F3 "" 0 0 50 H I C CNN -$FPLIST - R_* -$ENDFPLIST -DRAW -S -40 -100 40 100 0 1 10 N -X ~ 1 0 150 50 D 50 50 1 1 P -X ~ 2 0 -150 50 U 50 50 1 1 P -ENDDRAW -ENDDEF -# -# Switch_SW_Push -# -DEF Switch_SW_Push SW 0 40 N N 1 F N -F0 "SW" 50 100 50 H V L CNN -F1 "Switch_SW_Push" 0 -60 50 H V C CNN -F2 "" 0 200 50 H I C CNN -F3 "" 0 200 50 H I C CNN -DRAW -C -80 0 20 0 1 0 N -C 80 0 20 0 1 0 N -P 2 0 1 0 0 50 0 120 N -P 2 0 1 0 100 50 -100 50 N -X 1 1 -200 0 100 R 50 50 0 1 P -X 2 2 200 0 100 L 50 50 0 1 P -ENDDRAW -ENDDEF -# -# power_+3V3 -# -DEF power_+3V3 #PWR 0 0 Y Y 1 F P -F0 "#PWR" 0 -150 50 H I C CNN -F1 "power_+3V3" 0 140 50 H V C CNN -F2 "" 0 0 50 H I C CNN -F3 "" 0 0 50 H I C CNN -ALIAS +3.3V -DRAW -P 2 0 1 0 -30 50 0 100 N -P 2 0 1 0 0 0 0 100 N -P 2 0 1 0 0 100 30 50 N -X +3V3 1 0 0 0 U 50 50 1 1 W N -ENDDRAW -ENDDEF -# -# power_Earth -# -DEF power_Earth #PWR 0 0 Y Y 1 F P -F0 "#PWR" 0 -250 50 H I C CNN -F1 "power_Earth" 0 -150 50 H I C CNN -F2 "" 0 0 50 H I C CNN -F3 "" 0 0 50 H I C CNN -DRAW -P 2 0 1 0 -25 -75 25 -75 N -P 2 0 1 0 -5 -100 5 -100 N -P 2 0 1 0 0 -50 0 0 N -P 2 0 1 0 50 -50 -50 -50 N -X Earth 1 0 0 0 D 50 50 1 1 W N -ENDDRAW -ENDDEF -# -#End Library diff --git a/learn/circuit/basic/basic.bak b/learn/circuit/basic/basic.bak deleted file mode 100644 index e959bd9..0000000 --- a/learn/circuit/basic/basic.bak +++ /dev/null @@ -1,109 +0,0 @@ -EESchema Schematic File Version 4 -EELAYER 29 0 -EELAYER END -$Descr A4 11693 8268 -encoding utf-8 -Sheet 1 1 -Title "" -Date "" -Rev "" -Comp "" -Comment1 "" -Comment2 "" -Comment3 "" -Comment4 "" -$EndDescr -$Comp -L Device:R R? -U 1 1 5CF46E84 -P 2300 2050 -F 0 "R?" V 2093 2050 50 0000 C CNN -F 1 "4.7K" V 2184 2050 50 0000 C CNN -F 2 "" V 2230 2050 50 0001 C CNN -F 3 "~" H 2300 2050 50 0001 C CNN - 1 2300 2050 - 0 1 1 0 -$EndComp -$Comp -L Device:R R? -U 1 1 5CF47D6C -P 2300 2700 -F 0 "R?" V 2093 2700 50 0000 C CNN -F 1 "1K" V 2184 2700 50 0000 C CNN -F 2 "" V 2230 2700 50 0001 C CNN -F 3 "~" H 2300 2700 50 0001 C CNN - 1 2300 2700 - 0 1 1 0 -$EndComp -$Comp -L Device:C C? -U 1 1 5CF4820F -P 3450 2050 -F 0 "C?" V 3198 2050 50 0000 C CNN -F 1 "104pF" V 3289 2050 50 0000 C CNN -F 2 "" H 3488 1900 50 0001 C CNN -F 3 "~" H 3450 2050 50 0001 C CNN - 1 3450 2050 - 0 1 1 0 -$EndComp -$Comp -L power:+3V3 #PWR? -U 1 1 5CF48B55 -P 4400 2700 -F 0 "#PWR?" H 4400 2550 50 0001 C CNN -F 1 "+3V3" V 4415 2828 50 0000 L CNN -F 2 "" H 4400 2700 50 0001 C CNN -F 3 "" H 4400 2700 50 0001 C CNN - 1 4400 2700 - 0 1 1 0 -$EndComp -$Comp -L power:Earth #PWR? -U 1 1 5CF49CDA -P 1100 2050 -F 0 "#PWR?" H 1100 1800 50 0001 C CNN -F 1 "Earth" H 1100 1900 50 0001 C CNN -F 2 "" H 1100 2050 50 0001 C CNN -F 3 "~" H 1100 2050 50 0001 C CNN - 1 1100 2050 - 0 1 1 0 -$EndComp -$Comp -L Switch:SW_Push SW? -U 1 1 5CF4C6BB -P 3450 2700 -F 0 "SW?" H 3450 2985 50 0000 C CNN -F 1 "SW_Push" H 3450 2894 50 0000 C CNN -F 2 "" H 3450 2900 50 0001 C CNN -F 3 "~" H 3450 2900 50 0001 C CNN - 1 3450 2700 - 1 0 0 -1 -$EndComp -Wire Wire Line - 2450 2700 2800 2700 -Wire Wire Line - 3650 2700 4050 2700 -Wire Wire Line - 2450 2050 2800 2050 -Wire Wire Line - 3600 2050 4050 2050 -Wire Wire Line - 4050 2050 4050 2700 -Connection ~ 4050 2700 -Wire Wire Line - 4050 2700 4400 2700 -Wire Wire Line - 2800 2050 2800 2700 -Connection ~ 2800 2050 -Wire Wire Line - 2800 2050 3300 2050 -Connection ~ 2800 2700 -Wire Wire Line - 2800 2700 3250 2700 -Wire Wire Line - 1100 2050 2150 2050 -Text Label 1000 2700 0 50 ~ 0 -INPUT -Wire Wire Line - 1000 2700 2150 2700 -$EndSCHEMATC diff --git a/learn/circuit/basic/basic.kicad_pcb b/learn/circuit/basic/basic.kicad_pcb deleted file mode 100644 index 02c8ecb..0000000 --- a/learn/circuit/basic/basic.kicad_pcb +++ /dev/null @@ -1 +0,0 @@ -(kicad_pcb (version 4) (host kicad "dummy file") ) diff --git a/learn/circuit/basic/basic.pro b/learn/circuit/basic/basic.pro deleted file mode 100644 index 152769c..0000000 --- a/learn/circuit/basic/basic.pro +++ /dev/null @@ -1,33 +0,0 @@ -update=22/05/2015 07:44:53 -version=1 -last_client=kicad -[general] -version=1 -RootSch= -BoardNm= -[pcbnew] -version=1 -LastNetListRead= -UseCmpFile=1 -PadDrill=0.600000000000 -PadDrillOvalY=0.600000000000 -PadSizeH=1.500000000000 -PadSizeV=1.500000000000 -PcbTextSizeV=1.500000000000 -PcbTextSizeH=1.500000000000 -PcbTextThickness=0.300000000000 -ModuleTextSizeV=1.000000000000 -ModuleTextSizeH=1.000000000000 -ModuleTextSizeThickness=0.150000000000 -SolderMaskClearance=0.000000000000 -SolderMaskMinWidth=0.000000000000 -DrawSegmentWidth=0.200000000000 -BoardOutlineThickness=0.100000000000 -ModuleOutlineThickness=0.150000000000 -[cvpcb] -version=1 -NetIExt=net -[eeschema] -version=1 -LibDir= -[eeschema/libraries] diff --git a/learn/circuit/basic/basic.sch b/learn/circuit/basic/basic.sch deleted file mode 100644 index aedcf93..0000000 --- a/learn/circuit/basic/basic.sch +++ /dev/null @@ -1,119 +0,0 @@ -EESchema Schematic File Version 4 -EELAYER 29 0 -EELAYER END -$Descr A4 11693 8268 -encoding utf-8 -Sheet 1 1 -Title "" -Date "" -Rev "" -Comp "" -Comment1 "" -Comment2 "" -Comment3 "" -Comment4 "" -$EndDescr -$Comp -L Device:R R? -U 1 1 5CF46E84 -P 2350 1650 -F 0 "R?" V 2143 1650 50 0000 C CNN -F 1 "4.7K" V 2234 1650 50 0000 C CNN -F 2 "" V 2280 1650 50 0001 C CNN -F 3 "~" H 2350 1650 50 0001 C CNN - 1 2350 1650 - 0 1 1 0 -$EndComp -$Comp -L Device:R R? -U 1 1 5CF47D6C -P 2350 2300 -F 0 "R?" V 2143 2300 50 0000 C CNN -F 1 "1K" V 2234 2300 50 0000 C CNN -F 2 "" V 2280 2300 50 0001 C CNN -F 3 "~" H 2350 2300 50 0001 C CNN - 1 2350 2300 - 0 1 1 0 -$EndComp -$Comp -L Device:C C? -U 1 1 5CF4820F -P 3500 1650 -F 0 "C?" V 3248 1650 50 0000 C CNN -F 1 "104pF" V 3339 1650 50 0000 C CNN -F 2 "" H 3538 1500 50 0001 C CNN -F 3 "~" H 3500 1650 50 0001 C CNN - 1 3500 1650 - 0 1 1 0 -$EndComp -$Comp -L power:+3V3 #PWR? -U 1 1 5CF48B55 -P 4450 2300 -F 0 "#PWR?" H 4450 2150 50 0001 C CNN -F 1 "+3V3" V 4465 2428 50 0000 L CNN -F 2 "" H 4450 2300 50 0001 C CNN -F 3 "" H 4450 2300 50 0001 C CNN - 1 4450 2300 - 0 1 1 0 -$EndComp -$Comp -L power:Earth #PWR? -U 1 1 5CF49CDA -P 1150 1650 -F 0 "#PWR?" H 1150 1400 50 0001 C CNN -F 1 "Earth" H 1150 1500 50 0001 C CNN -F 2 "" H 1150 1650 50 0001 C CNN -F 3 "~" H 1150 1650 50 0001 C CNN - 1 1150 1650 - 0 1 1 0 -$EndComp -$Comp -L Switch:SW_Push SW? -U 1 1 5CF4C6BB -P 3500 2300 -F 0 "SW?" H 3500 2585 50 0000 C CNN -F 1 "SW_Push" H 3500 2494 50 0000 C CNN -F 2 "" H 3500 2500 50 0001 C CNN -F 3 "~" H 3500 2500 50 0001 C CNN - 1 3500 2300 - 1 0 0 -1 -$EndComp -Wire Wire Line - 2500 2300 2850 2300 -Wire Wire Line - 3700 2300 4100 2300 -Wire Wire Line - 2500 1650 2850 1650 -Wire Wire Line - 3650 1650 4100 1650 -Wire Wire Line - 4100 1650 4100 2300 -Connection ~ 4100 2300 -Wire Wire Line - 4100 2300 4450 2300 -Wire Wire Line - 2850 1650 2850 2300 -Connection ~ 2850 1650 -Wire Wire Line - 2850 1650 3350 1650 -Connection ~ 2850 2300 -Wire Wire Line - 2850 2300 3300 2300 -Wire Wire Line - 1150 1650 2200 1650 -Text Label 1050 2300 0 50 ~ 0 -INPUT -Wire Wire Line - 1050 2300 2200 2300 -Wire Notes Line - 700 1100 4950 1100 -Wire Notes Line - 4950 1100 4950 2500 -Wire Notes Line - 4950 2500 700 2500 -Wire Notes Line - 700 2500 700 1100 -Text Notes 1050 1250 0 50 ~ 0 -Hardware debounce circuit -$EndSCHEMATC diff --git a/learn/doc/mac_bash_profile b/learn/doc/mac_bash_profile index 8c28a5e..7c097a5 100644 --- a/learn/doc/mac_bash_profile +++ b/learn/doc/mac_bash_profile @@ -6,8 +6,8 @@ export PATH=/usr/local/sbin:$PATH export PATH=$HOME/.local/bin:$PATH export PATH=$PATH:$HOME/workspace/esp/xtensa-esp32-elf/bin export PATH=$PATH:$HOME/workspace/esp/xtensa-lx106-elf/bin -#export IDF_PATH=$HOME/workspace/esp/esp-idf -export IDF_PATH=$HOME/workspace/esp/ESP8266_RTOS_SDK +export IDF_PATH=$HOME/workspace/esp/esp-idf +#export IDF_PATH=$HOME/workspace/esp/ESP8266_RTOS_SDK export PATH=$PATH:/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/ export PATH=$PATH:$HOME/Library/Arduino15/packages/arduino/tools/avrdude/6.0.1-arduino5/bin export PATH=$PATH:/usr/local/opt/go/libexec/bin diff --git a/learn/risc-v/00/l.ld b/learn/risc-v/00/l.ld new file mode 100644 index 0000000..5ee6716 --- /dev/null +++ b/learn/risc-v/00/l.ld @@ -0,0 +1,14 @@ +OUTPUT_ARCH( "riscv" ) +ENTRY(_start) + +SECTIONS +{ + . = 0x80000000; + .text ALIGN(0x1000) : { + *(.text.entry) + *(.text) + } + .data ALIGN(0x1000) : { *(.data) } + .bss : { *(.bss) } + _end = .; +} diff --git a/learn/risc-v/TransplanteTencentOStinyToRISCV_1.md b/learn/risc-v/TransplanteTencentOStinyToRISCV_1.md new file mode 100644 index 0000000..acfe9f0 --- /dev/null +++ b/learn/risc-v/TransplanteTencentOStinyToRISCV_1.md @@ -0,0 +1,136 @@ +# 如何将TencentOS tiny移植到RISC-V + +## 背景 + +在2019年8月份,腾讯面向物联网领域开发的实时操作系统TencentOS tiny开始向公司内部员工开放限量内测,最初看到这个公告便火速提交了申请,当时并不是对这个内核有什么好奇,而是作为开发板爱好者,单纯地想薅一块免费的开发板来玩玩。当然内测也是有条件的,需要做一个简单的项目,写写报告,最好给开发同学提提建议和修修BUG,于是就有了我之前写的一篇文章《在中移动标准板上利用TencentOS tiny实现GPS追踪功能》。 + +在完成这个程序的同时也偶尔给内核提提BUG,加点驱动。后来内核开发组的同事说要不你玩的时候顺便支持一下RISC-V吧,于是内核代码就有了RISC-V相关的部分。 + +初次尝试移植必然要走很多弯路,写这文章的主要目的并不是要记录我是怎么掉坑和爬坑的经历,而是经过自己的整理,以一条自认为最简单和清晰的移植路径来阐述移植过程,希望能对移植其它芯片或对这部分有兴趣的同学有点帮助。 + +现在TencentOS tiny内核代码已经正式开源,地址:`https://github.com/Tencent/TencentOS-tiny`。 + +阅读这这篇文章需要你有比较扎实的C和汇编的功底和RISC-V相关的知识。 + +RISC-V相关的大家可以到`https://github.com/riscv/riscv-isa-manual/releases`下载《riscv-spec.pdf》和《riscv-privileged.pdf》两个PDF文件了解相关信息。另再从《RISC-V架构与嵌入式开发快速入门》这本书中拣选些信息就足够了。 + + +## 开发环境准备 + +其实需要准备的工具很简单 + +1. 下载最新的qemu的最新版本4.1.0的代码 + +``` +wget https://download.qemu.org/qemu-4.1.0.tar.xz +tar xvJf qemu-4.1.0.tar.xz +cd qemu-4.1.0 +./configure --target-list=riscv32-softmmu +make +make install +``` + +2. 安装`riscv-none-gcc` + + 下载地址`https://github.com/gnu-mcu-eclipse/riscv-none-gcc/releases` + + 加入环境变量,以v8.2.0-2.2 20190521版本为例 + + 假设解压到`$HOME`目录下,则`export PATH=$PATH:$HOME/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin` + + +## 开发环境验证 + +在开始前我们先写个小程序验证一下环境,把开发环境各个环节打通。 + +首先我们编写个简单到极致的程序 + +``` +// start.S +.global _start +.section .text +.align 2 +_start: + nop + nop + nop +``` + +然后我们写个链接脚本 + +``` +/*link.lds*/ +OUTPUT_ARCH( "riscv" ) +ENTRY( _start ) + +SECTIONS +{ + . = 0x800000000; + .text : { + *(.text); + } +} +``` +编写一个简单的调试器脚本 + +``` +# gdbscript +file kernel.elf +target remote :1234 +b _start +c +``` + +编译链接程序 + +``` +riscv-none-embed-gcc start.S -T link.lds -nostdlib -o kernel.elf +``` + +用虚拟机启动这个最简单的内核 + +``` +qemu-system-riscv32 -machine spike -kernel kernel.elf -S -s +``` + +然后用gdb连接到qemu + +``` +riscv-none-embed-gdb -x gdbscript +``` + +如果你在gdb中看到如下输出,并在执行n后有nop,那就说明整个环境没有问题了。 + +``` +Breakpoint 1 at 0x80000000: file start.S, line 5. + +Breakpoint 1, _start () at start.S:5 +5 nop +(gdb) n +6 nop +(gdb) +7 nop +``` + + +## 移植准备 + +TencentOS tiny 的代码目录树如下 + +``` +TencentOS_tiny +├── arch +├── board +├── components +├── devices +├── doc +├── examples +├── kernel +├── net +├── osal +├── platform +├── test +└── tools +``` + +目前的移植过程中只需要保留`kernel`目录下的代码,还有`arch`, `board`两个目录,其它的都可以暂时删掉。 \ No newline at end of file diff --git a/tools/mcu/rdserial.go b/tools/mcu/rdserial.go index 481af22..0446320 100644 --- a/tools/mcu/rdserial.go +++ b/tools/mcu/rdserial.go @@ -15,6 +15,7 @@ import ( "github.com/tarm/serial" "log" "os" + "time" ) func main() { @@ -41,6 +42,11 @@ func main() { } defer f.Close() + time.Sleep(1*time.Second) + s.Write([]byte("ATE0\r\n")) + time.Sleep(1*time.Second) + s.Write([]byte("AT\r\n")) + time.Sleep(1*time.Second) for { buf := make([]byte, 4096) n, err := s.Read(buf) -- 2.44.0