<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>dabbler zhu</title>
    <description>blog &amp; blog theme🤘</description>
    <link>https://hongbingzhu.github.io/</link>
    <atom:link href="https://hongbingzhu.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Tue, 27 Apr 2021 02:42:23 +0000</pubDate>
    <lastBuildDate>Tue, 27 Apr 2021 02:42:23 +0000</lastBuildDate>
    <generator>Jekyll v3.9.0</generator>
    
      <item>
        <title>在线调试Arduino</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#arduino本身-没有调试功能&quot; id=&quot;markdown-toc-arduino本身-没有调试功能&quot;&gt;Arduino本身 （没有调试功能）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#eclipse--sloeber-stm32平台编译失败&quot; id=&quot;markdown-toc-eclipse--sloeber-stm32平台编译失败&quot;&gt;eclipse + sloeber （STM32平台编译失败）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#cmake和makefile-没有代码跳转功能&quot; id=&quot;markdown-toc-cmake和makefile-没有代码跳转功能&quot;&gt;CMake和Makefile （没有代码跳转功能）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#vscode--arduino插件-环境强大未能成功调试&quot; id=&quot;markdown-toc-vscode--arduino插件-环境强大未能成功调试&quot;&gt;VSCode + Arduino插件 （环境强大，未能成功调试）&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

Arduino是一个比较好的平台，里面丰富的库，但是可惜没有在线调试功能。如果仅仅做教学和教育使用，Arduino的IDE环境是可以满足要求的。但是如果应用到项目中，没有在线调试功能显然是不可接受的。尝试在一个使用STM32F103的项目使用arduino平台，将如何进行调试进行了一下总结。目前看，还没有找到各方面都达到要求的环境，只能综合各个方案，根据问题选用。

&lt;h3 id=&quot;arduino本身-没有调试功能&quot;&gt;Arduino本身 （没有调试功能）&lt;/h3&gt;
即使Arduino没有没有在线调试功能，但是Arduino作为官方的环境，显然编译下载的兼容性是最好的。所以我们需要该环境做一下信息对比，以查找出在其他环境下的问题点。Arduino环境下，编译的时候会输出编译过程详细的命令行调用，这为我们脱离Arduino环境编译提供基础。
我使用的STM32芯片，我推荐使用&lt;a href=&quot;https://github.com/stm32duino/BoardManagerFiles&quot;&gt;stm32duino&lt;/a&gt;项目，将json文件地址添加到Preferences对话框的“Additional Boards Manager URLs”里面，Arduino会完成该STM32系列芯片的支持。该项目支持的板子和芯片及其丰富，基本上能ST官方的板子，都支持了。

&lt;h3 id=&quot;eclipse--sloeber-stm32平台编译失败&quot;&gt;eclipse + sloeber （STM32平台编译失败）&lt;/h3&gt;
在以前关于arduino的文章中(2019-02-27-stm32-arduino-f103)，曾经使用过“Eclipse C++ IDE for Arduino”，但是这个项目已经不维护了，推荐使用“The Arduino Eclipse plugin named Sloeber V4”来替代，这个插件不依赖Arduino的IDE本身，其会下载自己的Arduino基本支持工具和库，安装比较费时间，安装完毕之后，还需要在“Arduino=&amp;gt;Preferences”对话框下，“Private hardware path”中添加额外的硬件支持库路径，一般是“C:\Users&amp;lt;User&amp;gt;\AppData\Local\Arduino15”，如果在Arduino下已经下载完毕，这里不需要重复下载。
依据插件的说明，在项目右键的“Properties”菜单下，在项目属性对话框中，在“Arduino”下，有硬件平台，板卡以及其他选项的设置，信息和Arduino环境很类似，正确选择即可，可惜这个方式编译STM32平台有问题，其调用的编译器是“/bin/arm-none-eabi-g++”，显然是不对的。其对于本身自带的基础板子，例如Arduino-DUE，是可以正确编译的，但可惜不是我们要的。由于我也没有AVR的在线调试器，也就没有测试AVR平台的在线调试。
虽然不能编译，但是代码跳转功能是没问题的，还不错。

&lt;h3 id=&quot;cmake和makefile-没有代码跳转功能&quot;&gt;CMake和Makefile （没有代码跳转功能）&lt;/h3&gt;
既然插件编译有问题，那我们可以先脱离Arduino环境生成目标文件，再在eclipse中使用makefile项目来进行调试（期望可以提供调试和代码跳转），经过一番努力，终于搞定了的&lt;a href=&quot;https://hongbingzhu.github.io/downloads/cmake-arduino-stm32f103.rar&quot;&gt;CMake&lt;/a&gt;文件，和&lt;a href=&quot;https://hongbingzhu.github.io/downloads/Makefile-arduino-stm32f103.rar&quot;&gt;Makefile&lt;/a&gt;文件，CMake文件有比较大的坑，如果将两大块，分别生成wrapper和cores库，会出现链接问题。CMake的缺省link调用也有问题，需要自己去手动指定link调用。这么一来，其实远远没有Makefile本身来得更方便。
然后用带有“GNU ARM eclipse”插件的eclipse环境，新建“GDB Hardware Debugging”目标来调试，就可以顺利调试了。gdbserver可以用“STM32CubeIDE”带的“ST-Link_gdbserver”。复制其一个tools下的小目录，就够了，总共也就2M多一点，找个项目附近的地方放就可以了。
似乎这还挺好，唯一遗憾是，没有代码跳转功能。

&lt;h3 id=&quot;vscode--arduino插件-环境强大未能成功调试&quot;&gt;VSCode + Arduino插件 （环境强大，未能成功调试）&lt;/h3&gt;
之后，无意中发现，VSCode+Arduino插件（均为微软出品），其实是更好的一个方案，该插件依赖Arduino环境本省，安装省事。代码跳转功能也好用强大，编译也顺利。可惜调试缺省用的是OpenOCD，而不是J-Link或者ST-Link，而我对OpenOCD不太熟悉，也不知道怎么设定去更换（README里面的相关设置项，似乎不管用）
</description>
        <pubDate>Sat, 24 Apr 2021 20:52:00 +0000</pubDate>
        <link>https://hongbingzhu.github.io/2021/04/24/arduino-debug/</link>
        <guid isPermaLink="true">https://hongbingzhu.github.io/2021/04/24/arduino-debug/</guid>
        
        <category>arduino</category>
        
        <category>debug</category>
        
        <category>jtag</category>
        
        <category>eclipse</category>
        
        <category>vscode</category>
        
        
        <category>arduino</category>
        
        <category>embedded</category>
        
        <category>debug</category>
        
      </item>
    
      <item>
        <title>CANopen和Canfestival</title>
        <description>这个是个不完全转载，仅仅转一下目录，值得广大嵌入式攻城狮去观摩一圈。

最有价值的，是里面有正确可以工作版本的文件提供下载，避免入手的时候，各种失败问题。

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程01_初识CAN与CANOpen及相关内容.html&quot;&gt;CANOpen系列教程01_初识CAN与CANOpen及相关内容&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程02_理解CAN总线协议.html&quot;&gt;CANOpen系列教程02_理解CAN总线协议&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程03_CAN收发器功能、原理及作用.html&quot;&gt;CANOpen系列教程03_CAN收发器功能、原理及作用&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程04_CAN总线波特率、位时序、帧类型及格式说明.html&quot;&gt;CANOpen系列教程04_CAN总线波特率、位时序、帧类型及格式说明&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程05_CAN总线同步与位填充、优先级的决定.html&quot;&gt;CANOpen系列教程05_CAN总线同步与位填充、优先级的决定&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程06_结合代码理解CAN底层收发数据（含STM32例程）.html&quot;&gt;CANOpen系列教程06_结合代码理解CAN底层收发数据（含STM32例程）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程07_CANOpen协议概述.html&quot;&gt;CANOpen系列教程07_CANOpen协议概述&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程08_CANOpen通信接口引导学习.html&quot;&gt;CANOpen系列教程08_CANOpen通信接口引导学习&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程09_CANOpen对象字典.html&quot;&gt;CANOpen系列教程09_CANOpen对象字典&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程10_关于Canfestival及对象字典生成工具环境搭建.html&quot;&gt;CANOpen系列教程10_关于Canfestival及对象字典生成工具环境搭建&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程11_深度分析CanFestival_3架构.html&quot;&gt;CANOpen系列教程11_深度分析CanFestival_3架构&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程12_对象字典编辑器操作说明.html&quot;&gt;CANOpen系列教程12_对象字典编辑器操作说明&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程13_协议源码移植（一）.html&quot;&gt;CANOpen系列教程13_协议源码移植（一）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程14_协议源码移植（二）.html&quot;&gt;CANOpen系列教程14_协议源码移植（二）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/CANOpen/CANOpen系列教程15_NMT网络管理和相关源码说明.html&quot;&gt;CANOpen系列教程15_NMT网络管理和相关源码说明&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Mon, 29 Mar 2021 16:13:00 +0000</pubDate>
        <link>https://hongbingzhu.github.io/2021/03/29/CANopen-Canfestivaly/</link>
        <guid isPermaLink="true">https://hongbingzhu.github.io/2021/03/29/CANopen-Canfestivaly/</guid>
        
        <category>CAN</category>
        
        <category>CANopen</category>
        
        <category>Canfestival</category>
        
        <category>reprinting</category>
        
        
        <category>CANopen</category>
        
        <category>Canfestival</category>
        
      </item>
    
      <item>
        <title>嵌入式系统中的printf</title>
        <description>这个是个不完全转载，仅仅转一下目录，值得广大嵌入式攻城狮去观摩一圈。

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/printf/printf系列教程00_概述printf各种打印输出方法和相关内容.html&quot;&gt;printf系列教程00_概述printf各种打印输出方法和相关内容&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/printf/printf系列教程01_UART打印输出配置，基于STM32（Keil、IAR）.html&quot;&gt;printf系列教程01_UART打印输出配置，基于STM32（Keil、IAR）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/printf/printf系列教程02_仿真打印输出配置，基于STM32（Keil、IAR）.html&quot;&gt;printf系列教程02_仿真打印输出配置，基于STM32（Keil、IAR）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/printf/printf系列教程03_SWO打印输出配置，基于Keil『Debug（printf）Viewer』.html&quot;&gt;printf系列教程03_SWO打印输出配置，基于Keil『Debug(printf)Viewer』&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/printf/printf系列教程04_SWO打印输出配置，基于IAR『Terminal IO』.html&quot;&gt;printf系列教程04_SWO打印输出配置，基于IAR『Terminal IO』&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/printf/printf系列教程05_SWO打印输出配置，基于ST-LINK Utility『Serial Wire Viewer』.html&quot;&gt;printf系列教程05_SWO打印输出配置，基于ST-LINK Utility『Serial Wire Viewer』&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/printf/printf系列教程06_SWO打印输出配置，基于J-Link『SWO Viewer』.html&quot;&gt;printf系列教程06_SWO打印输出配置，基于J-Link『SWO Viewer』&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.strongerhuang.com/printf/printf系列教程07_JLink-RTT打印输出配置，基于J-Link『RTT Viewer』.html&quot;&gt;printf系列教程07_JLink-RTT打印输出配置，基于J-Link『RTT Viewer』&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Mon, 29 Mar 2021 16:05:00 +0000</pubDate>
        <link>https://hongbingzhu.github.io/2021/03/29/printf-in-embedded/</link>
        <guid isPermaLink="true">https://hongbingzhu.github.io/2021/03/29/printf-in-embedded/</guid>
        
        <category>printf</category>
        
        <category>debug</category>
        
        <category>reprinting</category>
        
        
        <category>debug</category>
        
        <category>embedded</category>
        
      </item>
    
      <item>
        <title>VHDL/Verilog里的软件工程</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1-vhdl&quot; id=&quot;markdown-toc-1-vhdl&quot;&gt;1. VHDL&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#11-record和type定义&quot; id=&quot;markdown-toc-11-record和type定义&quot;&gt;1.1 record和type定义&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#12-generate语句&quot; id=&quot;markdown-toc-12-generate语句&quot;&gt;1.2 generate语句&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2-verilog&quot; id=&quot;markdown-toc-2-verilog&quot;&gt;2. Verilog&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#21-struct和enum&quot; id=&quot;markdown-toc-21-struct和enum&quot;&gt;2.1 struct和enum&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#22-generate语句&quot; id=&quot;markdown-toc-22-generate语句&quot;&gt;2.2 generate语句&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3-总结&quot; id=&quot;markdown-toc-3-总结&quot;&gt;3. 总结&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

今年开始接触更改产品的FPGA代码，感觉公司虽然搞了很多年了，但是FPGA这块缺乏一些“软件工程”上的概念导入。

如果对于Altera/Xilinx公司，如果做IP库，可能需要考虑各种编译器的兼容性，不能引入太多的“高级”语法，但是，对于一个公司而言，我认为代码的可维护性是放在第一位的，是在编译器兼容性之类之上的要求。

&lt;h3 id=&quot;1-vhdl&quot;&gt;1. VHDL&lt;/h3&gt;

总体而言，VHDL提供了如下一些语法特性，用于简化代码：

&lt;h4 id=&quot;11-record和type定义&quot;&gt;1.1 record和type定义&lt;/h4&gt;
例如对于KM1024i喷头控制，我们可以定义如下：
&lt;pre&gt;&lt;code class=&quot;language-VHDL&quot;&gt;	-- 喷头控制信号
	type KM_HEAD_CTRL_TYPE is record
		load	: std_logic;
		lat		: std_logic;
		gsclk	: std_logic;
		stb		: std_logic;
		plstm2	: std_logic;
		plstm1	: std_logic;
	end record;
	type KM_HEADs_CTRL_TYPE is array (natural range &amp;lt;&amp;gt;) of KM_HEAD_CTRL_TYPE;
	-- 喷头数据信号
	type KM_HEAD_DATA_TYPE is record
		sa		: std_logic_vector(2 downto 0);	-- sa(n)=sa_n, 
		dclk	: std_logic;
	end record;
	type KM_HEADs_DATA_TYPE is array (natural range &amp;lt;&amp;gt;) of KM_HEAD_DATA_TYPE;
&lt;/code&gt;&lt;/pre&gt;
有了上面的定义之后，接口可以为如下的方式：
&lt;pre&gt;&lt;code class=&quot;language-VHDL&quot;&gt;entity KM1024i_8head_v1 is
	port (
		......

		hd_data			: out KM_HEADs_DATA_TYPE(0 to MAX_HEAD_NUM*CHNL_PER_HEAD-1);
		hd_ctrl			: out KM_HEADs_CTRL_TYPE(0 to MAX_HEAD_NUM*CHNL_PER_HEAD-1);

		......
	);
end KM1024i_8head_v1;
&lt;/code&gt;&lt;/pre&gt;
接口简化了很多，原先的接口，非常长的一堆信号列表。

&lt;h4 id=&quot;12-generate语句&quot;&gt;1.2 generate语句&lt;/h4&gt;
我们的FPGA主要在喷头控制上，典型特点就是一块板子上，驱动很多的喷头，典型的是4H和8H，但是甚至有16H的，原先的代码人肉重复，但是在引入generate语句之后，可以大幅度减少代码，甚至可以不同喷头数的板子，代码仅仅需要改几行即可。
&lt;pre&gt;&lt;code class=&quot;language-VHDL&quot;&gt;PRINT_HEAD_GEN : for i in 0 to 7 generate
	HEAD_OPR : opr_setting
	port map (
		sys_clk		=&amp;gt; sys_clk,
		sys_rst		=&amp;gt; sys_rst,
		reg			=&amp;gt; opr_hd(i),
		ctrl		=&amp;gt; opr_op(i),
		cmd_trig	=&amp;gt; opr_trig(i),
		pon_trig	=&amp;gt; pon_trig
	);

	HEAD_CTRL : head_controller
	port map (
		sys_clk		=&amp;gt; sys_clk,
		sys_rst		=&amp;gt; sys_rst,

		head		=&amp;gt; i_hd_ctrl(i),
		f_fire		=&amp;gt; f_fire,
		gs_level	=&amp;gt; gs_level_hd(i),
		fire_dis	=&amp;gt; fire_dis_any,
		fire_skip	=&amp;gt; data_crc_err and fire_dis_on_err,

		grp_select	=&amp;gt; grp_select_hd(i),
		grp_seg_num	=&amp;gt; grp_seg_num_hd(i),
		grp_seg_desc=&amp;gt; grp_seg_desc_hd(i)
	);
end generate;
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;2-verilog&quot;&gt;2. Verilog&lt;/h3&gt;

Verilog语言没有类似于于VHDL的record的定义，也没有C语言的struct。但是，SystemVerilog是支持这些的，所以我们把标准切到SystemVerilog，以支持这些语法特性。以下以Max5183芯片驱动为例：

&lt;h4 id=&quot;21-struct和enum&quot;&gt;2.1 struct和enum&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-Verilog&quot;&gt;// DAC MAX5183 的控制信号
typedef struct {
	logic				clk;
	logic				cs_n;
	logic	[9:0]		data;
	logic 				pwr_down;
	logic				ref_en_n;
	logic				da_en;
} max5183_t;

typedef enum logic[1:0] { ST_OUT_D1, ST_LAT_D1, ST_OUT_D2, ST_LAT_D2 } da_state_t;
&lt;/code&gt;&lt;/pre&gt;
这是控制信号接口和状态机状态定义。

&lt;h4 id=&quot;22-generate语句&quot;&gt;2.2 generate语句&lt;/h4&gt;
这个是Verilog支持的，和VHDL的generate类似，例如，某个板子里面用到了6个fifo，可以这样定义：
&lt;pre&gt;&lt;code class=&quot;language-Verilog&quot;&gt;genvar gi;
generate for (gi = 0; gi &amp;lt; 6; gi = gi+1) begin: fifo_inst_lp
data_fifo data_fifo_inst (
		.clock		(sys_clk				),
		.data		(fifo_inst_data[gi]		),
		.rdreq		(fifo_inst_rd[gi]		),
		.aclr		(fifo_aclr[gi[0]]		),
		.wrreq		(fifo_inst_wr[gi]		),
		.empty		(fifo_inst_empty[gi]	),
		.full		(fifo_inst_full[gi]		),
		.q			(fifo_inst_q[gi]		));
end endgenerate
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;3-总结&quot;&gt;3. 总结&lt;/h3&gt;

虽然说，FPGA代码和一般的软件代码，有截然不同的内涵，但是，毕竟“硬件”已经“软件”化了。引入软件工程的一些概念，对于增加FPGA代码的可维护性和开发效率，是非常有必要，非常有意义的。
</description>
        <pubDate>Sun, 13 Sep 2020 09:17:00 +0000</pubDate>
        <link>https://hongbingzhu.github.io/2020/09/13/VHDL-Verilog-Software-Engineering/</link>
        <guid isPermaLink="true">https://hongbingzhu.github.io/2020/09/13/VHDL-Verilog-Software-Engineering/</guid>
        
        <category>verilog</category>
        
        <category>vhdl</category>
        
        <category>management</category>
        
        
        <category>fpga</category>
        
        <category>verilog</category>
        
        <category>vhdl</category>
        
      </item>
    
      <item>
        <title>安装研发服务器</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1-组织架构&quot; id=&quot;markdown-toc-1-组织架构&quot;&gt;1. 组织架构&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2-创建用户和用户组&quot; id=&quot;markdown-toc-2-创建用户和用户组&quot;&gt;2. 创建用户和用户组&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3-安装和配置svn&quot; id=&quot;markdown-toc-3-安装和配置svn&quot;&gt;3. 安装和配置SVN&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#31-建立svn库&quot; id=&quot;markdown-toc-31-建立svn库&quot;&gt;3.1 建立SVN库&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#32-创建一级目录并配置&quot; id=&quot;markdown-toc-32-创建一级目录并配置&quot;&gt;3.2 创建一级目录并配置&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4-发送通知邮件&quot; id=&quot;markdown-toc-4-发送通知邮件&quot;&gt;4. 发送通知邮件&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

重装服务器真是一个耗精力的过程，尤其是用ghost做数据全盘备份，数据ghost恢复蜗牛一般的速度，再加上ghost居然人生第一次碰到了软件会异常问题，真的是让人痛苦不堪啊。从现在想来，可能不如用imagex来备份数据，imagex至少可以直接mount，省了我不断的恢复过程啊。回想起来，选ghost唯一的理由，应该是：全盘备份，可以必要时候全盘恢复。不过，这个不是这里的重点。这里主要讲服务安装时候，自动化脚本构建。当然，使用构建脚本的方法，可能真的不如直接手动操作，但是，万一需要第二台或第二次再来一遍呢。当然，程序员对于人肉方法，也是倾向于不屑一顾的。

&lt;h3 id=&quot;1-组织架构&quot;&gt;1. 组织架构&lt;/h3&gt;
公司转向了事业部制，大概的公司结构如下：
&lt;img src=&quot;https://hongbingzhu.github.io/downloads/company-arch.png&quot; alt=&quot;公司结构&quot; /&gt;
基本SVN设计是，每个事业部有一个SVN库，下面设一级目录，HW/FPGA/FW/SW，分别授权不同的工程师访问。

&lt;h3 id=&quot;2-创建用户和用户组&quot;&gt;2. 创建用户和用户组&lt;/h3&gt;
用户归属于事业部，需要创建事业部组，事业部下根据研发性质，在细分成HW/FPGA/FW/SW用户组，创建用户用命令“net user”，从Excel生成命令脚本使用Excel的VBA生成，代码如下：
&lt;pre&gt;&lt;code class=&quot;language-basic&quot;&gt;Sub CreateScript()
    Dim row As Integer, i As Integer
    Dim tsUsr As TextStream, tsSmtp As TextStream
    Dim usr As String, grp As String, cmt As String
    Dim outFolder As String
    
    Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
    outFolder = &quot;D:\BYHX\Server\&quot;
    Set tsUsr = fso.OpenTextFile(outFolder &amp;amp; &quot;0.servadmin.cmd&quot;, ForWriting, True)
    Set tsSmtp = fso.OpenTextFile(outFolder &amp;amp; &quot;0.sendmail.ps1&quot;, ForWriting, True)
    
    ' PowerShell，需要先执行以下的语句，才能执行ps1脚本
    tsSmtp.WriteLine &quot;# Execute below command first, then ps1 script will allowed.&quot;
    tsSmtp.WriteLine &quot;# Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser&quot;
    
    ' 创建事业部和大的用户性质用户组
    For row = 2 To 18
        grp = Range(&quot;L&quot; &amp;amp; row)
        If Left(grp, 2) &amp;lt;&amp;gt; &quot;RD&quot; Then grp = &quot;BU-&quot; &amp;amp; grp
        tsUsr.WriteLine &quot;net localgroup &quot; &amp;amp; grp &amp;amp; &quot; /add /comment:&quot;&quot;&quot; &amp;amp; Range(&quot;M&quot; &amp;amp; row) &amp;amp; &quot;&quot;&quot;&quot;
    Next row
    
    ' 创建事业部下研发分类用户组，以及列出同类研发事业部组列表
    For row = 2 To 13
        grp = Range(&quot;L&quot; &amp;amp; row)
        cmt = Range(&quot;M&quot; &amp;amp; row)
        If Left(grp, 2) &amp;lt;&amp;gt; &quot;RD&quot; Then grp = &quot;BU-&quot; &amp;amp; grp
        tsUsr.WriteLine &quot;net localgroup &quot; &amp;amp; grp &amp;amp; &quot;-HW   /add /comment:&quot;&quot;&quot; &amp;amp; cmt &amp;amp; &quot; 硬件&quot;&quot;&quot;
        tsUsr.WriteLine &quot;net localgroup &quot; &amp;amp; grp &amp;amp; &quot;-FPGA /add /comment:&quot;&quot;&quot; &amp;amp; cmt &amp;amp; &quot; FPGA&quot;&quot;&quot;
        tsUsr.WriteLine &quot;net localgroup &quot; &amp;amp; grp &amp;amp; &quot;-FW   /add /comment:&quot;&quot;&quot; &amp;amp; cmt &amp;amp; &quot; 嵌入&quot;&quot;&quot;
        tsUsr.WriteLine &quot;net localgroup &quot; &amp;amp; grp &amp;amp; &quot;-SW   /add /comment:&quot;&quot;&quot; &amp;amp; cmt &amp;amp; &quot; 软件&quot;&quot;&quot;
    Next row
    
    For row = 2 To 1000
        usr = Trim(Range(&quot;A&quot; &amp;amp; row).Text)
        grp = Trim(Range(&quot;D&quot; &amp;amp; row).Text)
        ' 行的A列为空，表示处理结束
        If usr = &quot;&quot; Then Exit For
        ' 非RD的，添加BU前缀
        If Left(grp, 2) &amp;lt;&amp;gt; &quot;RD&quot; Then grp = &quot;BU-&quot; &amp;amp; grp
        ' 添加用户
        tsUsr.WriteLine &quot;net user &quot; &amp;amp; usr &amp;amp; &quot; &quot;&quot;&quot; &amp;amp; Range(&quot;B&quot; &amp;amp; row) &amp;amp; &quot;&quot;&quot; /add /active:yes /expires:never /fullname:&quot; &amp;amp; Range(&quot;C&quot; &amp;amp; row)
        ' 用户密码永不过期
        tsUsr.WriteLine &quot;wmic useraccount where name='&quot; &amp;amp; usr &amp;amp; &quot;' set passwordexpires=false&quot;
        ' 把用户添加到事业部
        tsUsr.WriteLine &quot;net localgroup &quot; &amp;amp; grp &amp;amp; &quot; &quot; &amp;amp; usr &amp;amp; &quot; /add&quot;
        
        ' 根据研发内容，添加用户到事业部研发组
        If Range(&quot;E&quot; &amp;amp; row).Text = &quot;Y&quot; Then tsUsr.WriteLine &quot;net localgroup &quot; &amp;amp; grp &amp;amp; &quot;-HW   &quot; &amp;amp; usr &amp;amp; &quot; /add&quot; &amp;amp; vbCrLf &amp;amp; &quot;net localgroup RD-AllHW   &quot; &amp;amp; usr &amp;amp; &quot; /add&quot;
        If Range(&quot;F&quot; &amp;amp; row).Text = &quot;Y&quot; Then tsUsr.WriteLine &quot;net localgroup &quot; &amp;amp; grp &amp;amp; &quot;-FPGA &quot; &amp;amp; usr &amp;amp; &quot; /add&quot; &amp;amp; vbCrLf &amp;amp; &quot;net localgroup RD-AllFPGA &quot; &amp;amp; usr &amp;amp; &quot; /add&quot;
        If Range(&quot;G&quot; &amp;amp; row).Text = &quot;Y&quot; Then tsUsr.WriteLine &quot;net localgroup &quot; &amp;amp; grp &amp;amp; &quot;-FW   &quot; &amp;amp; usr &amp;amp; &quot; /add&quot; &amp;amp; vbCrLf &amp;amp; &quot;net localgroup RD-AllFW   &quot; &amp;amp; usr &amp;amp; &quot; /add&quot;
        If Range(&quot;H&quot; &amp;amp; row).Text = &quot;Y&quot; Then tsUsr.WriteLine &quot;net localgroup &quot; &amp;amp; grp &amp;amp; &quot;-SW   &quot; &amp;amp; usr &amp;amp; &quot; /add&quot; &amp;amp; vbCrLf &amp;amp; &quot;net localgroup RD-AllSW   &quot; &amp;amp; usr &amp;amp; &quot; /add&quot;
        If Range(&quot;I&quot; &amp;amp; row).Text = &quot;Y&quot; Then tsUsr.WriteLine &quot;net localgroup BU-Leader &quot; &amp;amp; usr &amp;amp; &quot; /add&quot;
    Next row
        
    tsUsr.Close
    tsSmtp.Close
    MsgBox &quot;OK&quot;
End Sub
&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&quot;3-安装和配置svn&quot;&gt;3. 安装和配置SVN&lt;/h3&gt;
&lt;h4 id=&quot;31-建立svn库&quot;&gt;3.1 建立SVN库&lt;/h4&gt;
安装完毕之后，建立一个Demo库，手动添加管理账号的读写访问权限，拷贝出账号认证配置文件，再准备好需要的svn的hook文件。
准备好事业部列表文件“1.svn-repo.txt”，每行只有事业部的名称（从Excel拷贝出来即可），用批处理命令，生成SVN库，以及离线SVN配置。
&lt;pre&gt;&lt;code class=&quot;language-cmd&quot;&gt;for /f %%i in (1.svn-repo.txt) do (
svnadmin create E:\Repositories\%%i
mkdir %%i\conf\
mkdir %%i\hooks\
copy /y VisualSVN-WinAuthz.ini %%i\conf\
copy /y pre-commit.cmd %%i\hooks\
)
&lt;/code&gt;&lt;/pre&gt;

&lt;h4 id=&quot;32-创建一级目录并配置&quot;&gt;3.2 创建一级目录并配置&lt;/h4&gt;
用svn命令，管理账号，创建各个库的一级目录：
&lt;pre&gt;&lt;code class=&quot;language-cmd&quot;&gt;for /f %%i in (1.svn-repo.txt) do (
svn mkdir https://BYHX-MasterServ:8443/svn/%%i/hw -m &quot;Create hardware folder&quot;
svn mkdir https://BYHX-MasterServ:8443/svn/%%i/fpga -m &quot;Create FPGA folder&quot;
svn mkdir https://BYHX-MasterServ:8443/svn/%%i/fw -m &quot;Create firmware folder&quot;
svn mkdir https://BYHX-MasterServ:8443/svn/%%i/sw -m &quot;Create software folder&quot;
)
&lt;/code&gt;&lt;/pre&gt;
用类似的循环，用“PsGetsid”工具，获取用户的SID信息文件，单个SID信息类似于
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SID for my-co-server\whom:
S-1-5-21-316025195-1075053894-3005689260-1012

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
利用shell脚本，处理SID信息（注意先转换“sidresult.txt”为unix格式）
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;cat &lt;/span&gt;sidresult.txt | egrep &lt;span class=&quot;s2&quot;&gt;&quot;SID&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;for|S&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\-&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;1&quot;&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;sed&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'N;s/\n//g'&lt;/span&gt; | &lt;span class=&quot;nb&quot;&gt;sed&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'s/^.*\\//g'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; sidlist.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
处理完信息类似于：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;whom:S-1-5-21-316025195-1075053894-3005689260-1012
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
有了SID信息表之后，用Excel的VBA，处理权限信息：
&lt;pre&gt;&lt;code class=&quot;language-basic&quot;&gt;Function GetSID(sName As String)
    Dim sidFile As TextStream
    Dim outFolder As String
    Dim str As String, s1 As String
    Dim pos As Integer
    
    outFolder = &quot;D:\BYHX\Server\&quot;
    
    Set sidFile = fso.OpenTextFile(outFolder &amp;amp; &quot;sidlist.txt&quot;, ForReading)
    Do While Not sidFile.AtEndOfStream
        str = sidFile.ReadLine
        pos = InStr(str, &quot;:&quot;)
        s1 = Left(str, pos - 1)
        If s1 = sName Then
            GetSID = mid(str, pos + 1)
            Exit Do
        End If
    Loop
End Function

Sub ModiPrivilege()
    Dim row As Integer, i As Integer
    Dim outFolder As String
    Dim authFile As TextStream
    Dim str As String, s1 As String
    Dim usr As String, grp As String
    
    Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
    outFolder = &quot;D:\BYHX\Server\&quot;

    ' 给负责人添加库的完全权限
    For row = 2 To 1000
        usr = Trim(Range(&quot;A&quot; &amp;amp; row).Text)
        grp = Trim(Range(&quot;D&quot; &amp;amp; row).Text)
        ' 行的A列为空，表示处理结束
        If usr = &quot;&quot; Then Exit For
        ' 非RD的，添加BU前缀
        If Left(grp, 2) &amp;lt;&amp;gt; &quot;RD&quot; Then grp = &quot;BU-&quot; &amp;amp; grp
        
        If Range(&quot;I&quot; &amp;amp; row).Text = &quot;Y&quot; Then
            str = outFolder &amp;amp; grp &amp;amp; &quot;\conf\VisualSVN-WinAuthz.ini&quot;
            Set authFile = fso.OpenTextFile(str, ForAppending)
            authFile.WriteLine GetSID(usr) &amp;amp; &quot;=rw&quot;
            authFile.Close
        End If
    Next row

    ' 事业部下研发分类用户组，设置权限
    For row = 2 To 13
        grp = Range(&quot;L&quot; &amp;amp; row)
        If Left(grp, 2) &amp;lt;&amp;gt; &quot;RD&quot; Then grp = &quot;BU-&quot; &amp;amp; grp
        
        Set authFile = fso.OpenTextFile(outFolder &amp;amp; grp &amp;amp; &quot;\conf\VisualSVN-WinAuthz.ini&quot;, ForAppending)
        authFile.WriteLine vbCrLf &amp;amp; &quot;[/hw]&quot;
        authFile.WriteLine GetSID(grp &amp;amp; &quot;-HW&quot;) &amp;amp; &quot;=rw&quot;
        authFile.WriteLine vbCrLf &amp;amp; &quot;[/fpga]&quot;
        authFile.WriteLine GetSID(grp &amp;amp; &quot;-FPGA&quot;) &amp;amp; &quot;=rw&quot;
        authFile.WriteLine vbCrLf &amp;amp; &quot;[/fw]&quot;
        authFile.WriteLine GetSID(grp &amp;amp; &quot;-FW&quot;) &amp;amp; &quot;=rw&quot;
        authFile.WriteLine vbCrLf &amp;amp; &quot;[/sw]&quot;
        authFile.WriteLine GetSID(grp &amp;amp; &quot;-SW&quot;) &amp;amp; &quot;=rw&quot;
        authFile.Close
    Next row
    
    MsgBox &quot;OK&quot;
End Sub
&lt;/code&gt;&lt;/pre&gt;
将离线的SVN配置文件，复制到SVN库目录，重启SVN服务，SVN配置完成。

&lt;h3 id=&quot;4-发送通知邮件&quot;&gt;4. 发送通知邮件&lt;/h3&gt;
需要把各个账户的密码，通知到各位同仁。将Excel的用户名和密码这两列，复制到文本文件。转为unix格式。发送邮件脚本如下：
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/bash&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;mailaccount.txt&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;while &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;IFS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;read&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; line
&lt;span class=&quot;k&quot;&gt;do
	&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_usr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$line&lt;/span&gt; | gawk &lt;span class=&quot;s1&quot;&gt;'{printf &quot;%s&quot;,$1}'&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;
	&lt;span class=&quot;nv&quot;&gt;_pwd&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$line&lt;/span&gt; | gawk &lt;span class=&quot;s1&quot;&gt;'{printf &quot;%s&quot;,$2}'&lt;/span&gt; | ./htmlenc.exe&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;
	&lt;span class=&quot;nb&quot;&gt;cat &lt;/span&gt;SwithMailSettings.xml | &lt;span class=&quot;nb&quot;&gt;sed&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;s/__to_person__/&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$_usr&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/g&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;s/__password__/&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$_pwd&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;/g&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; account.xml
	./SwithMail.exe /s /x account.xml
&lt;span class=&quot;k&quot;&gt;done&lt;/span&gt; &amp;lt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$input&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
命令行邮件工具选择了“SwithMail”，依据的是&lt;a href=&quot;https://www.raymond.cc/blog/sending-email-using-command-line-useful-for-downtime-alert-notification/&quot;&gt;7 Command Line Utilities to Easily Send Email Using SMTP&lt;/a&gt;的推荐。当然，用PowerShell也可以，就是比较麻烦一点点。
</description>
        <pubDate>Fri, 07 Feb 2020 15:37:00 +0000</pubDate>
        <link>https://hongbingzhu.github.io/2020/02/07/rd-server/</link>
        <guid isPermaLink="true">https://hongbingzhu.github.io/2020/02/07/rd-server/</guid>
        
        <category>server</category>
        
        <category>management</category>
        
        
        <category>server</category>
        
      </item>
    
      <item>
        <title>OpenCV笔记（I）</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#ubuntu-1604下安装&quot; id=&quot;markdown-toc-ubuntu-1604下安装&quot;&gt;Ubuntu 16.04下安装&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#cmake找不到新编译安装的opencv&quot; id=&quot;markdown-toc-cmake找不到新编译安装的opencv&quot;&gt;cmake找不到新编译安装的opencv&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

这里记一下开始入手OpenCV碰到的一些问题以及解决办法。学习参考书是《OpenCV 4 计算机视觉项目实战（原书第2版）》，ISBN：978-7-111-63164-4。

&lt;h3 id=&quot;ubuntu-1604下安装&quot;&gt;Ubuntu 16.04下安装&lt;/h3&gt;

构建安装原书最主要的两个命令和测试命令是：
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;cmake &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;CMAKE_BUILD_TYPE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;RELEASE &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;CMAKE_INSTALL_PREFIX&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/full/path/to/opencv-4.0.0/build &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;INSTALL_C_EXAMPLES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;ON &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;BUILD_EXAMPLES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;ON &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;OPEN_EXTRA_MODULES_PATH&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/full/path/to/opencv_contrib-4.0.0/modules ..
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cp&lt;/span&gt; /full/path/to/opencv-4.0.0/build/lib/pkgconfig/opencv.pc /usr/local/lib/pkgconfig/opencv4.pc
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /full/path/to/opencv-4.0.0/samples/cpp
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;g++ &lt;span class=&quot;nt&quot;&gt;-ggdb&lt;/span&gt; &lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;pkg-config &lt;span class=&quot;nt&quot;&gt;--cflags&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--libs&lt;/span&gt; opencv4&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt; opencv_version.cpp &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; /tmp/opencv_version &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; /tmp/opencv_version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
这里面会碰到几个问题：

&lt;ol&gt;
  &lt;li&gt;下载&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ippicv_2019_lnx_intel64_general_20180723.tgz&lt;/code&gt;会被卡住&lt;/li&gt;
&lt;/ol&gt;

这个不算是国内问题，是cmake缺省不支持https的问题。&lt;img src=&quot;http://morecoder.com/article/1262570.html&quot; alt=&quot;这里&quot; /&gt;有关于这个问题的说明。我只做了
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;libcurl4-openssl-dev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
cmake就应该可以成功了

&lt;ol&gt;
  &lt;li&gt;复制opencv.pc的时候，会找不到opencv.pc&lt;/li&gt;
&lt;/ol&gt;

似乎opencv认为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pkg-config&lt;/code&gt;包管理器已经落伍，所以缺省是不会生成该文件的。要生成该命令，需要修改cmake命令，打开产生opencv.pc的选项：
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;cmake ... &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;OPENCV_GENERATE_PKGCONFIG&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;ON ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;编译测试程序出错&lt;/li&gt;
&lt;/ol&gt;

这里面有几个错误，1) 需要c++11； 2) 连接找不到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cv::CommandLineParser&lt;/code&gt;类的一些函数，解决方法是：
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;LD_LIBRARY_PATH&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/full/path/to/opencv-4.0.0/build/lib
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;g++ &lt;span class=&quot;nt&quot;&gt;-std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;c++11 &lt;span class=&quot;nt&quot;&gt;-ggdb&lt;/span&gt; opencv_version.cpp  &lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;pkg-config &lt;span class=&quot;nt&quot;&gt;--cflags&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--libs&lt;/span&gt; opencv4&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; /tmp/opencv_version &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; /tmp/opencv_version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;cmake找不到新编译安装的opencv&quot;&gt;cmake找不到新编译安装的opencv&lt;/h3&gt;

在编译第二章的示例程序的时候，会发现cmake会失败，需要把CMakeLists.txt的寻找opencv包命令这句修改为：
&lt;div class=&quot;language-cmake highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nf&quot;&gt;FIND_PACKAGE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; OpenCV 4.1.2 REQUIRED PATHS /home/opencv/4.1.2 &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Sat, 26 Oct 2019 21:23:00 +0000</pubDate>
        <link>https://hongbingzhu.github.io/2019/10/26/opencv-start/</link>
        <guid isPermaLink="true">https://hongbingzhu.github.io/2019/10/26/opencv-start/</guid>
        
        <category>opencv</category>
        
        
        <category>opencv</category>
        
      </item>
    
      <item>
        <title>ARM调试器只能偶尔连接成功问题</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#背景&quot; id=&quot;markdown-toc-背景&quot;&gt;背景&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#接线查看&quot; id=&quot;markdown-toc-接线查看&quot;&gt;接线查看&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#jtag信号分析&quot; id=&quot;markdown-toc-jtag信号分析&quot;&gt;JTAG信号分析&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#分析&quot; id=&quot;markdown-toc-分析&quot;&gt;分析&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

这里分析一个ARM板子JTAG调试器经常连接失败，只能偶尔连上目标板问题。

&lt;h3 id=&quot;背景&quot;&gt;背景&lt;/h3&gt;

这是原先另一个部门的板子，在部门合并之后，最近要对这个板子的代码体系进行转移，在过问开发进度时，工程师反映这个板子调试很难连接，所以错误不好定位。这个问题前段时间反映过，但是当时比较忙，没有过问。现在看起来这个问题影响问题定位了，所以看起来这个问题需要彻底看一下了。听原先负责这个板子的工程师，这些年也都是这样，这个芯片很难连接，以前如果不行就换板子。这个芯片是LPC2136，我们部门原先并不使用，但是LPC2132和LPC2134则是使用过的，并不存在问题。简单测试了一下这个板子，确实是连接非常困难。

&lt;h3 id=&quot;接线查看&quot;&gt;接线查看&lt;/h3&gt;

首先找了对比板子LPC2132，连接非常顺利。对比两个板子的图，分析JTAG接口连接，从原理图上看，JTAG接口连接并没有什么不妥，和对比板子一致，量硬件连接，也没有问题。连接总是提示“Failed to connect”。看来只能对JTAG进行分析了。

&lt;h3 id=&quot;jtag信号分析&quot;&gt;JTAG信号分析&lt;/h3&gt;

把所有的JTAG信号线飞出来，接上逻辑分析仪，采集JTAG信号。首先采集正常的板卡的信号，如下：
&lt;img src=&quot;https://hongbingzhu.github.io/downloads/jtag-ok.png&quot; alt=&quot;正常JTAG信号&quot; /&gt;
从上到下，顺序为TRST，TDI，TMS，TCK，RTCK，TDO，从图中看，有来有回，一切正常。只是中间有一个异常，我最初设定为用TRST下降沿触发，却没有抓到，从波形看，TRST确实一直为高，这个当时也没有在意，不影响抓信号。

再抓一个不正常板卡的信号，如下：
&lt;img src=&quot;https://hongbingzhu.github.io/downloads/jtag-err.png&quot; alt=&quot;异常JTAG信号&quot; /&gt;
从信号看，没有RTCK，也没有TDO输出。测量RTCK信号，并没有和地短路等异常发生。

这时想起来了最初看到的异常板卡的复位电路，是一个简单的RC复位。当时一打眼的时候，觉得这个电路取值有点问题，其中R=10k，C=100nF，稍有RC复位电路设计经验的，都可以看出这个取值不太合理，但是这个板子上电工作一直是正常的，也就没在意。对比对照板卡，其RC取值为100k，1uF。使用镊子强制复位异常板卡，果然可以JTAG连接成功。更换RC取值，板卡JTAG连接正常。

&lt;h3 id=&quot;分析&quot;&gt;分析&lt;/h3&gt;

这个板子原因是很清楚的了，复位电路复位时间过短，造成芯片没有很好复位。但是还有一个奇怪的问题，这个板子上电运行从来没有出过问题。猜测是CPU内核在复位链里面复位比较早，而JTAG口复位比较晚？还有一个问题，这个芯片手册有写明这个芯片有内部POR，为什么没有起作用？
</description>
        <pubDate>Tue, 24 Sep 2019 21:58:00 +0000</pubDate>
        <link>https://hongbingzhu.github.io/2019/09/24/jtag-only-sometimes-connected/</link>
        <guid isPermaLink="true">https://hongbingzhu.github.io/2019/09/24/jtag-only-sometimes-connected/</guid>
        
        <category>debugger</category>
        
        <category>arm</category>
        
        
        <category>embedded</category>
        
        <category>hardware</category>
        
      </item>
    
      <item>
        <title>RT-Thread中的串口DMA分析</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#背景&quot; id=&quot;markdown-toc-背景&quot;&gt;背景&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#dma接收准备&quot; id=&quot;markdown-toc-dma接收准备&quot;&gt;DMA接收准备&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#dma接收&quot; id=&quot;markdown-toc-dma接收&quot;&gt;DMA接收&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#dma发送&quot; id=&quot;markdown-toc-dma发送&quot;&gt;DMA发送&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

这里分析一下RT-Thread中串口DMA方式的实现，以供做新处理器串口支持时的参考。

&lt;h3 id=&quot;背景&quot;&gt;背景&lt;/h3&gt;

在如今的芯片性能和外设强大功能的情况下，串口不实现DMA/中断方式操作，我认为在实际项目中基本是不可接受的，但遗憾的是，rt-thread现有支持的实现中，基本上没有支持串口的DMA，文档也没有关于串口DMA支持相关的说明，这里以STM32实现为背景，梳理一下串口DMA的实现流程，以供新处理器实现时以作参考。

&lt;h3 id=&quot;dma接收准备&quot;&gt;DMA接收准备&lt;/h3&gt;

启用DMA接收，需要在打开设备的时候做一些处理，入口函数为rt_device_open()。主体实现是：
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;rt_err_t&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rt_device_open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rt_device_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_uint16_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oflag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;device_init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;device_open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oflag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

device_init()就是rt_serial_init()函数，其主要是调用configure()函数，
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_err_t&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rt_serial_init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_device&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ops&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ops&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;configure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
在stm32下，其configure()函数是stm32_configure()，其根据设备打开参数，配置STM32外设的寄存器。包括波特率、校验等串口工作参数。

device_open()函数就是rt_serial_open()函数，其主要实现是：
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_err_t&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rt_serial_open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_device&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_uint16_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oflag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;

&lt;span class=&quot;cp&quot;&gt;#ifdef RT_SERIAL_USING_DMA        
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oflag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_DEVICE_FLAG_DMA_RX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bufsz&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_rx_dma&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rx_dma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;rx_dma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_rx_dma&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_malloc&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_rx_dma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;RT_ASSERT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rx_dma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;rx_dma&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;activated&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial_rx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rx_dma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_rx_fifo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rx_fifo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;rx_fifo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_rx_fifo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_malloc&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_rx_fifo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bufsz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;RT_ASSERT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rx_fifo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;rx_fifo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rt_uint8_t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rx_fifo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;rt_memset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rx_fifo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bufsz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;rx_fifo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;put_index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;rx_fifo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;rx_fifo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;is_full&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial_rx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rx_fifo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;cm&quot;&gt;/* configure fifo address and length to low level device */&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ops&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;control&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_DEVICE_CTRL_CONFIG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_DEVICE_FLAG_DMA_RX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;open_flag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_DEVICE_FLAG_DMA_RX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif &lt;/span&gt;&lt;span class=&quot;cm&quot;&gt;/* RT_SERIAL_USING_DMA */&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;	&lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#ifdef RT_SERIAL_USING_DMA
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oflag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_DEVICE_FLAG_DMA_TX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_tx_dma&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tx_dma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;tx_dma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_tx_dma&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_malloc&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_tx_dma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;RT_ASSERT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tx_dma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;tx_dma&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;activated&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;rt_data_queue_init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tx_dma&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data_queue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial_tx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tx_dma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;open_flag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_DEVICE_FLAG_DMA_TX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;cm&quot;&gt;/* configure low level device */&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ops&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;control&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_DEVICE_CTRL_CONFIG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;RT_DEVICE_FLAG_DMA_TX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif &lt;/span&gt;&lt;span class=&quot;cm&quot;&gt;/* RT_SERIAL_USING_DMA */&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
可见，其主要工作是为DMA接收准备FIFO缓冲区；为DMA发送准备发送数据缓冲队列，但是好像STM32中断并没有用到发送数据缓冲。

DMA配置数据来源是rt_hw_usart_init()函数，缺省的配置参数由宏RT_SERIAL_CONFIG_DEFAULT决定，
这里决定了缺省的接收缓冲区参数是64字节，通讯缺省参数是：115200,8N1。
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#define RT_SERIAL_RB_BUFSZ              64
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;dma接收&quot;&gt;DMA接收&lt;/h3&gt;

DMA接收我们从DMA中断开始分析，DMA接收中断服务函数为UARTn_DMA_RX_IRQHandler()，其调用HAL库的DMA处理函数HAL_DMA_IRQHandler()，该函数调用回调函数HAL_UART_RxCpltCallback()或HAL_UART_RxHalfCpltCallback()，这两个函数进入真正的中断服务处理函数dma_isr(struct rt_serial_device *)，主体代码如下：
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;dma_isr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_device&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/* 如果是DMA-RX中断 */&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__HAL_DMA_GET_IT_SOURCE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;uart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dma_rx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DMA_IT_TC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RESET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__HAL_DMA_GET_IT_SOURCE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;uart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dma_rx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DMA_IT_HT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RESET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;level&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_hw_interrupt_disable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;cm&quot;&gt;/* 得到本次接收到的数据量 */&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;recv_total_index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bufsz&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__HAL_DMA_GET_COUNTER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;uart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dma_rx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recv_total_index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;cm&quot;&gt;/* 这一句代码，是什么意思？ */&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;recv_len&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bufsz&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;uart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dma_rx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;last_index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;cm&quot;&gt;/* 减去以前接收到的数据量，得到本次接收到的数据数量 */&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;recv_len&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recv_total_index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;uart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dma_rx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;last_index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;cm&quot;&gt;/* 更新接收历史数据量 */&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;uart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dma_rx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;last_index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recv_total_index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;rt_hw_interrupt_enable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recv_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;cm&quot;&gt;/* 如果有新数据，调用serial设备模块的通用处理 */&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;rt_hw_serial_isr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_SERIAL_EVENT_RX_DMADONE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recv_len&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

在serial模块的函数rt_hw_serial_isr()中，主体代码是：
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rt_hw_serial_isr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_device&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_SERIAL_EVENT_RX_DMADONE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;rt_base_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;cm&quot;&gt;/* get DMA rx length */&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0xff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bufsz&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;cm&quot;&gt;/* 这个case的处理逻辑不知道怎么应用，看起来STM32实现并没有处理这个case */&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_rx_dma&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rx_dma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;rx_dma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_rx_dma&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial_rx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;RT_ASSERT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rx_dma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;RT_ASSERT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rx_indicate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rx_indicate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;rx_dma&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;activated&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;cm&quot;&gt;/* disable interrupt */&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;level&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_hw_interrupt_disable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;cm&quot;&gt;/* update fifo put index, 将数据放入接收缓冲区 */&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;rt_dma_recv_update_put_index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;cm&quot;&gt;/* calculate received total length, 更新缓冲区信息 */&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_dma_calc_recved_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;cm&quot;&gt;/* enable interrupt */&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;rt_hw_interrupt_enable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;cm&quot;&gt;/* invoke callback, 通知上层，有新数据到达 */&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rx_indicate&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rx_indicate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

上层接到通知后，读取函数最终调用驱动读函数rt_serial_read()函数，在DMA的条件下，调用_serial_dma_rx()从缓冲区读取数据。其代码为：
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_size_t&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rt_serial_read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_device&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_off_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_size_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;open_flag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_DEVICE_FLAG_DMA_RX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_serial_dma_rx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rt_uint8_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;dma发送&quot;&gt;DMA发送&lt;/h3&gt;

DMA发送从驱动写函数rt_serial_write()开始，在DMA的条件下，调用_serial_dma_tx()，_serial_dma_tx()再调用操作的DMA发送函数发送数据，代码为：
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_size_t&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rt_serial_write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_device&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_off_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_size_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;open_flag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_DEVICE_FLAG_DMA_TX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_serial_dma_tx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_uint8_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;rt_inline&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;_serial_dma_tx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_device&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_uint8_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/* make a DMA transfer */&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ops&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dma_transmit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rt_uint8_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RT_SERIAL_DMA_TX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
STM32的dma_transmit()实现函数是stm32_dma_transmit()，其实现就是简单调用HAL_UART_Transmit_DMA()，代码为：
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_size_t&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;stm32_dma_transmit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_serial_device&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serial&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_uint8_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rt_size_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;direction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HAL_UART_Transmit_DMA&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;uart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HAL_OK&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;......&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
实现非常简单。
</description>
        <pubDate>Wed, 11 Sep 2019 11:09:00 +0000</pubDate>
        <link>https://hongbingzhu.github.io/2019/09/11/rt-thread-usart-dma-mode/</link>
        <guid isPermaLink="true">https://hongbingzhu.github.io/2019/09/11/rt-thread-usart-dma-mode/</guid>
        
        <category>rt-thread</category>
        
        <category>stm32</category>
        
        <category>usart</category>
        
        
        <category>embedded</category>
        
        <category>rtos</category>
        
      </item>
    
      <item>
        <title>设备中LPC2368芯片个例参数问题导致故障的分析</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#过程&quot; id=&quot;markdown-toc-过程&quot;&gt;过程&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#结论和进一步确认&quot; id=&quot;markdown-toc-结论和进一步确认&quot;&gt;结论和进一步确认&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

最近公司的设备客户报告在终端客户那里出现了板卡加热不受控，出现了持续加热导致设备一些贵重部件损坏。由于历史上很多现场问题，板卡什么拆到别的地方搭复现平台，基本都是以失败告终，所以出差去现场分析。

&lt;h3 id=&quot;过程&quot;&gt;过程&lt;/h3&gt;

客户端排查，原始板卡现场运行可复现（大约0.5~3天可复现一次），复现以后，测量MCU外围信号，没有异常。不断电触发外部复位信号，设备不能恢复，重新上电可以正常工作。

对MCU去掉代码解密，复现后，挂JTAG跟踪，发现MCU处于perfetch abort中断的catch中。测试发现内部SRAM，寄存器均可以正常操作；对比Flash上的代码，没有问题。使用调试器复位，发现在出问题以后，MCU只能短暂正常工作极短的时间，系统初始化部分都结束不了，基本上，也是最后MCU处于perfetch abort状态，偶尔处于data abort状态。考虑对终端客户的影响，客户处替换板卡。

搭建虚拟台子，确定这个故障该板卡是可以在虚拟台子上复现的。复现后，挂JTAG，调试器复位运行表现和在客户机器上表现一致，测试SRAM，寄存器，没有问题。检查ARM内核寄存器，VIC状态，SCB外设状态，管脚配置状态，没有发现问题。将MAM模块的Flash fetch cycle从2改为3，发现MCU可以正常运行了。

&lt;h3 id=&quot;结论和进一步确认&quot;&gt;结论和进一步确认&lt;/h3&gt;

结论是这片芯片Flash模块存在问题。参数可能不符合文档的指标。

带板卡回公司，通过调整PLL设定，并取其他板卡做对比，发现这片芯片，Flash在略超过20MHz就会出问题，而其他对比芯片，一般可以工作在25~26MHz，由此可以确定，这片芯片，属于个例问题，参数不达标。
</description>
        <pubDate>Sun, 02 Jun 2019 11:09:00 +0000</pubDate>
        <link>https://hongbingzhu.github.io/2019/06/02/lpc2368-chip-fault/</link>
        <guid isPermaLink="true">https://hongbingzhu.github.io/2019/06/02/lpc2368-chip-fault/</guid>
        
        <category>nxp</category>
        
        <category>lpc2368</category>
        
        
        <category>embedded</category>
        
        <category>hardware</category>
        
      </item>
    
      <item>
        <title>部署代码review和CI</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#docker安装&quot; id=&quot;markdown-toc-docker安装&quot;&gt;Docker安装&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#gitlab转移&quot; id=&quot;markdown-toc-gitlab转移&quot;&gt;gitlab转移&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#phabricator转移&quot; id=&quot;markdown-toc-phabricator转移&quot;&gt;Phabricator转移&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#编译服务器&quot; id=&quot;markdown-toc-编译服务器&quot;&gt;编译服务器&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

公司原先搭了一个代码Review的服务器，由于历史原因，装的是一个32bit的Ubuntu系统，后来由于需要，需要安装gitlab，由于gitlab需要64位系统，所以临时凑合了个vagrant，本质就是一个纯粹的虚拟机，感觉不爽，这两天终于抽出时间来重新整理了一下。基于Ubuntu 18.04 x64版本和Docker来部署，减少后面换机器换系统可能导致的重复安装工作。

&lt;h3 id=&quot;docker安装&quot;&gt;Docker安装&lt;/h3&gt;
Docker安装还是比较简单的。
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;apt-transport-https ca-certificates curl gnupg-agent software-properties-common
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;curl &lt;span class=&quot;nt&quot;&gt;-fsSL&lt;/span&gt; https://download.docker.com/linux/ubuntu/gpg | &lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-key add -
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-key fingerprint 0EBFCD88 &lt;span class=&quot;c&quot;&gt;# should have something output, key 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;add-apt-repository &lt;span class=&quot;s2&quot;&gt;&quot;deb [arch=amd64] https://download.docker.com/linux/ubuntu &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;lsb_release &lt;span class=&quot;nt&quot;&gt;-cs&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; stable&quot;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get update
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;docker-ce docker-ce-cli containerd.io
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;usermod &lt;span class=&quot;nt&quot;&gt;-aG&lt;/span&gt; docker &lt;span class=&quot;nv&quot;&gt;$USER&lt;/span&gt;  &lt;span class=&quot;c&quot;&gt;# 执行完重新登录，后面就可以不用sudo执行docker命令了。&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;gitlab转移&quot;&gt;gitlab转移&lt;/h3&gt;
gitlab转移还是比较方便的，gitlab本身就提供各个版本的docker镜像，gitlab转移必须要在同一个版本之间，下载该版本对应的docker镜像，以daemon方式运行：
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker run &lt;span class=&quot;nt&quot;&gt;--detach&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--publish&lt;/span&gt; 192.168.30.102:443:443 &lt;span class=&quot;nt&quot;&gt;--publish&lt;/span&gt; 192.168.30.102:80:80 &lt;span class=&quot;nt&quot;&gt;--publish&lt;/span&gt; 8222:22 &lt;span class=&quot;nt&quot;&gt;--restart&lt;/span&gt; always &lt;span class=&quot;nt&quot;&gt;--volume&lt;/span&gt; /home/gitlab/config:/etc/gitlab &lt;span class=&quot;nt&quot;&gt;--volume&lt;/span&gt; /home/gitlab/logs:/var/log/gitlab &lt;span class=&quot;nt&quot;&gt;--volume&lt;/span&gt; /home/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:9.5.4-ce.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
按照&lt;a href=&quot;https://gitlab.com/gitlab-org/gitlab-ce/blob/7e3bb679a92156304972e2db1ae49c9b0e4cd188/doc/raketasks/backup_restore.md#restore-prerequisites&quot;&gt;Backing up and restoring GitLab&lt;/a&gt;指导，对于Omnibus Package方式的安装，只要在源机器端执行：
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;gitlab-rake gitlab:backup:create
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
在/var/opt/gitlab/backups/下找到备份文件，复制到目标机器的/home/gitlab/data/backups/下。注意：这个步骤同时复制源机器的“/etc/gitlab/gitlab-secrets.json”到目标机器对应目录“/home/gitlab/config”下

进入docker机器，执行恢复：
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-rake gitlab:backup:restore &lt;span class=&quot;nv&quot;&gt;BACKUP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;ts_yyyy_mm_dd_ver
gitlab-ctl status
gitlab-ctl restart
gitlab-rake gitlab:check &lt;span class=&quot;nv&quot;&gt;SANITIZE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
提示一切成功。如果“gitlab-secrets.json”在执行gitlab:backup:restore前没有复制到目标机，恢复的时候可能会提示出错。
ts_yyyy_mm_dd_ver是指gitlab生成的备份文件，文件名最后的“_gitlab_backup.tar”不需要输入。访问“http://192.168.30.102”，一切如旧，数据转移成功。

&lt;h3 id=&quot;phabricator转移&quot;&gt;Phabricator转移&lt;/h3&gt;
由于这个有一定的特殊要求，比较合适的“fauria/lamp”映像，php是7.0的，不符合phabricator的要求，所以基于“fauria/lamp”的Dockerfile和“ubuntu 18.04”镜像，自己build了一个，Dockerfile如下：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;FROM ubuntu:18.04
MAINTAINER zhuhongbing&amp;lt;hongbingzhu@gmail.com&amp;gt;
LABEL Description=&quot;My own LAMP stack, based on Ubuntu 18.04 LTS. Based on fauria/docker-lamp.&quot; \
        License=&quot;Apache License 2.0&quot; \
        Usage=&quot;docker run -d ...&quot; \
        Version=&quot;1.0&quot;

RUN apt-get update
RUN apt-get upgrade -y

ENV DEBIAN_FRONTEND noninteractive
ENV ALLOW_OVERRIDE All
ENV DATE_TIMEZONE UTC
ENV TERM xterm

RUN apt-get install mysql-server php apache2 libapache2-mod-php -y
RUN apt-get install php-mysql php-gd php-curl php-apcu php-cli php-json php-mbstring -y
RUN apt-get install git vim curl ftp -y
RUN apt-get install python-pygments subversion -y

COPY index.php /var/www/html/
COPY run-lamp.sh /usr/sbin/

RUN a2enmod rewrite
RUN chmod +x /usr/sbin/run-lamp.sh
RUN chown -R www-data:www-data /var/www/html

VOLUME /mnt/host

EXPOSE 80
EXPOSE 443

CMD [&quot;/usr/sbin/run-lamp.sh&quot;]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

这里需要注意的是ENV命令，这个会影响build的过程和最终映像运行的。里面的TERM原先是“dumb”，这个会导致vim界面异常，如果基于Ubuntu，测试设置为xterm是比较好的。也是服务器版ubuntu的缺省设置。

Phabricator要求的组件在定制版docker里面基本都就绪了，所以后面基本上在运行的容器中执行数据恢复就行了。

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;phabricator/ &lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./bin/storage dump | &lt;span class=&quot;nb&quot;&gt;gzip&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; backup.sql.gz &lt;span class=&quot;c&quot;&gt;# 源机器&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;gunzip&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; backup.sql.gz | mysql &lt;span class=&quot;c&quot;&gt;# 目标机器&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
同时注意恢复文件“phabricator/conf/local/local.json”。
注意：phabricator的190418版本，似乎恢复完毕以后，需要先开一下phd，才能正常访问，比较坑。折腾了好久。以前版本的phabricator邮件很好配置，更新版本之后，邮件始终折腾不成功了，比较坑，谁有经验告诉我一下。配置如下：
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &quot;metamta.default-address&quot;: &quot;phabricator@byhx-china.com&quot;,
  &quot;cluster.mailers&quot;: [
    {
      &quot;key&quot;: &quot;smtp-mailer&quot;,
      &quot;type&quot;: &quot;smtp&quot;,
      &quot;options&quot;: {
        &quot;host&quot;: &quot;mail.my-company.com&quot;,
        &quot;port&quot;: 25,
        &quot;user&quot;: &quot;phabricator@my-company.com&quot;,
        &quot;password&quot;: &quot;my-account-pwd&quot;,
        &quot;message-id&quot;: false
      }
    }
  ],
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;编译服务器&quot;&gt;编译服务器&lt;/h3&gt;
编译服务器主要用于从代码服务器抓取代码版本并编译，主要是做交叉编译，比较坑的是“/etc/hosts”文件，这个文件运行的时候会自动重新生成，见
&lt;a href=&quot;https://stackoverflow.com/questions/27521678/etc-hosts-file-of-a-docker-container-gets-overwritten&quot;&gt;/etc/hosts file of a docker container gets overwritten&lt;/a&gt;里面指向的discussion &lt;a href=&quot;https://github.com/moby/moby/issues/2267&quot;&gt;Allow customization of /etc/hosts, /etc/resolv.conf, etc. in containers #2267&lt;/a&gt;。简而言之，就是需要在运行docker的时候增加参数“–add-host=”&amp;lt;name_host&amp;gt;:&amp;lt;ip_host&amp;gt;””来解决。
</description>
        <pubDate>Mon, 22 Apr 2019 20:54:00 +0000</pubDate>
        <link>https://hongbingzhu.github.io/2019/04/22/docker/</link>
        <guid isPermaLink="true">https://hongbingzhu.github.io/2019/04/22/docker/</guid>
        
        <category>docker</category>
        
        <category>review</category>
        
        <category>ci</category>
        
        
        <category>linux</category>
        
      </item>
    
  </channel>
</rss>
