diff --git a/IMX6ULL/doc_pic/11_SPI/01_SPI视频概述.md b/IMX6ULL/doc_pic/11_SPI/01_SPI视频概述.md new file mode 100644 index 0000000..c458d1a --- /dev/null +++ b/IMX6ULL/doc_pic/11_SPI/01_SPI视频概述.md @@ -0,0 +1,40 @@ +# SPI视频概述 # + + + +# 1. SPI硬件框架 + +![image-20220216103153006](pic/01_hardware_block.jpg) + + + +## 2. SPI视频涉及的内容 + +* SPI协议 +* SPI驱动程序框架 + * SPI总线设备驱动模型 + * SPI设备树处理过程 +* 简单的SPI设备驱动 + * SPI ADC + * SPI OLED + * 内核自带的spi dev驱动 + +* 复杂的SPI设备驱动 + * SPI+FrameBuffer +* SPI控制器驱动程序 + * 使用GPIO实现 + * 具体芯片的SPI控制器驱动程序分析 + +* SPI调试工具 + * spi-tools +* 高性能:QSPI +* 主控芯片用作SPI从设备 + + + +录制视频时留意这些知识点: + +* SPI3线和SPI4线 +* bits_per_word设置8和16会影响到啥 +* 硬件片选和软件片选在驱动咋用 + diff --git a/IMX6ULL/doc_pic/11_SPI/02_SPI协议介绍.md b/IMX6ULL/doc_pic/11_SPI/02_SPI协议介绍.md new file mode 100644 index 0000000..6bd57f5 --- /dev/null +++ b/IMX6ULL/doc_pic/11_SPI/02_SPI协议介绍.md @@ -0,0 +1,59 @@ +# SPI协议介绍 # + +参考资料: + +* 《SPI Block Guide V04.01.pdf》 +* 《S3C2440A_UserManual_Rev13.pdf》 + +## 1. SPI硬件知识 + +### 1.1 硬件连线 + +![](pic/01_hardware_block.jpg) +引脚含义如下: + +| 引脚 | 含义 | +| -------- | ------------------------------------------------------------ | +| DO(MOSI) | Master Output, Slave Input,
SPI主控用来发出数据,SPI从设备用来接收数据 | +| DI(MISO) | Master Input, Slave Output,
SPI主控用来发出数据,SPI从设备用来接收数据 | +| SCK | Serial Clock,时钟 | +| CS | Chip Select,芯片选择引脚 | + + + +### 1.2 SPI控制器内部结构 + +这个图等我们看完后面的SPI协议,再回过头来讲解: + +![image-20220216121534549](pic/04_spi_block.png) + + + +## 2. SPI协议 + +### 2.1 传输示例 + +假设现在主控芯片要传输一个0x56数据给SPI Flash,时序如下: + +首先CS0先拉低选中SPI Flash,0x56的二进制就是0b0101 0110,因此在每个SCK时钟周期,DO输出对应的电平。 +SPI Flash会在每个时钟周期的上升沿读取D0上的电平。 + + + +### 2.2 SPI模式 + +在SPI协议中,有两个值来确定SPI的模式。 +CPOL:表示SPICLK的初始电平,0为电平,1为高电平 +CPHA:表示相位,即第一个还是第二个时钟沿采样数据,0为第一个时钟沿,1为第二个时钟沿 + +| CPOL | CPHA | 模式 | 含义 | +| :--: | :--: | :--: | :--------------------------------------------: | +| 0 | 0 | 0 | SPICLK初始电平为低电平,在第一个时钟沿采样数据 | +| 0 | 1 | 1 | SPICLK初始电平为低电平,在第二个时钟沿采样数据 | +| 1 | 0 | 2 | SPICLK初始电平为高电平,在第一个时钟沿采样数据 | +| 1 | 1 | 3 | SPICLK初始电平为高电平,在第二个时钟沿采样数据 | +我们常用的是模式0和模式3,因为它们都是在上升沿采样数据,不用去在乎时钟的初始电平是什么,只要在上升沿采集数据就行。 + +极性选什么?格式选什么?通常去参考外接的模块的芯片手册。比如对于OLED,查看它的芯片手册时序部分: + +SCLK的初始电平我们并不需要关心,只要保证在上升沿采样数据就行。 \ No newline at end of file diff --git a/IMX6ULL/doc_pic/11_SPI/02_SPI协议介绍.tif b/IMX6ULL/doc_pic/11_SPI/02_SPI协议介绍.tif new file mode 100644 index 0000000..e40fd44 Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/02_SPI协议介绍.tif differ diff --git a/IMX6ULL/doc_pic/11_SPI/S3C2440A_UserManual_Rev13.pdf b/IMX6ULL/doc_pic/11_SPI/S3C2440A_UserManual_Rev13.pdf new file mode 100644 index 0000000..0c1318a Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/S3C2440A_UserManual_Rev13.pdf differ diff --git a/IMX6ULL/doc_pic/11_SPI/SPI Block Guide V04.01.pdf b/IMX6ULL/doc_pic/11_SPI/SPI Block Guide V04.01.pdf new file mode 100644 index 0000000..20819f3 Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/SPI Block Guide V04.01.pdf differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/01_hardware_block.jpg b/IMX6ULL/doc_pic/11_SPI/pic/01_hardware_block.jpg new file mode 100644 index 0000000..b1c15c8 Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/01_hardware_block.jpg differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/02_spi_send_byte.png b/IMX6ULL/doc_pic/11_SPI/pic/02_spi_send_byte.png new file mode 100644 index 0000000..2fefde7 Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/02_spi_send_byte.png differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/03_spi_protocol.png b/IMX6ULL/doc_pic/11_SPI/pic/03_spi_protocol.png new file mode 100644 index 0000000..0484f50 Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/03_spi_protocol.png differ diff --git a/IMX6ULL/doc_pic/11_SPI/pic/04_spi_block.png b/IMX6ULL/doc_pic/11_SPI/pic/04_spi_block.png new file mode 100644 index 0000000..0036b8b Binary files /dev/null and b/IMX6ULL/doc_pic/11_SPI/pic/04_spi_block.png differ diff --git a/README.md b/README.md index e20d9ec..45913aa 100644 --- a/README.md +++ b/README.md @@ -372,11 +372,13 @@ git clone https://e.coding.net/weidongshan/linux/doc_and_source_for_drivers.git ```shell 15_编写虚拟UART驱动程序_实现数据传输 ``` + * 2021.08.06 发布"UART子系统" ```shell 16_编写虚拟UART驱动程序_调试 ``` + * 2021.08.12 发布"UART子系统" ```shell @@ -390,31 +392,37 @@ git clone https://e.coding.net/weidongshan/linux/doc_and_source_for_drivers.git 19_编写console驱动 20_early_printk和earlycon ``` + * 2021.08.17 完结"UART子系统" ```shell 21_RS485简单讲解 ``` + * 2021.10.11 发布"PCI和PCIe子系统" ```shell 01_从软件开发角度看待PCI和PCIe ``` + * 2021.10.29 发布"PCI和PCIe子系统" ```shell 02_PCI设备的访问方法_非桥设备(type0) ``` + * 2021.11.01 发布"PCI和PCIe子系统" ```shell 03_PCI设备的访问方法_桥设备(type1) ``` + * 2021.11.11 发布"PCI和PCIe子系统" ```shell 04_从软件角度看PCIe设备的硬件结构 ``` + * 2021.11.18 发布"PCI和PCIe子系统" ```shell @@ -426,41 +434,49 @@ git clone https://e.coding.net/weidongshan/linux/doc_and_source_for_drivers.git ```shell 06_PCIe路由方式 ``` + * 2021.12.29 发布"PCI和PCIe子系统" ```shell 07_PCI驱动程序框架 ``` + * 2021.12.31 发布"PCI和PCIe子系统" ```shell 08_RK3399_PCIe芯片手册解读 ``` + * 2022.01.02 发布"PCI和PCIe子系统" ```shell 09_RK3399_PCIe_Host驱动分析_地址映射 ``` + * 2022.01.06 发布"PCI和PCIe子系统" ```shell 10_RK3399_PCIe_Host驱动分析_设备枚举 ``` + * 2022.01.17 发布"PCI和PCIe子系统" ```shell 11_INTx_MSI_MSIX三种中断机制分析 ``` + * 2022.01.20 发布"PCI和PCIe子系统" ```shell 12_INTx中断机制源码分析 ``` + * 2022.01.25 发布"PCI和PCIe子系统" ```shell 13_GICv3_LPI机制 ``` + * 2022.01.26 完结"PCI和PCIe子系统" ```shell @@ -469,6 +485,13 @@ git clone https://e.coding.net/weidongshan/linux/doc_and_source_for_drivers.git 16_怎么编写PCIe设备驱动程序 ``` +* 2021.02.16 发布"SPI子系统": + + ```shell + 01_SPI视频概述 + 02_SPI协议介绍 + ``` + ## 6. 联系方式 diff --git a/STM32MP157/doc_pic/11_SPI/01_SPI视频概述.md b/STM32MP157/doc_pic/11_SPI/01_SPI视频概述.md new file mode 100644 index 0000000..c458d1a --- /dev/null +++ b/STM32MP157/doc_pic/11_SPI/01_SPI视频概述.md @@ -0,0 +1,40 @@ +# SPI视频概述 # + + + +# 1. SPI硬件框架 + +![image-20220216103153006](pic/01_hardware_block.jpg) + + + +## 2. SPI视频涉及的内容 + +* SPI协议 +* SPI驱动程序框架 + * SPI总线设备驱动模型 + * SPI设备树处理过程 +* 简单的SPI设备驱动 + * SPI ADC + * SPI OLED + * 内核自带的spi dev驱动 + +* 复杂的SPI设备驱动 + * SPI+FrameBuffer +* SPI控制器驱动程序 + * 使用GPIO实现 + * 具体芯片的SPI控制器驱动程序分析 + +* SPI调试工具 + * spi-tools +* 高性能:QSPI +* 主控芯片用作SPI从设备 + + + +录制视频时留意这些知识点: + +* SPI3线和SPI4线 +* bits_per_word设置8和16会影响到啥 +* 硬件片选和软件片选在驱动咋用 + diff --git a/STM32MP157/doc_pic/11_SPI/02_SPI协议介绍.md b/STM32MP157/doc_pic/11_SPI/02_SPI协议介绍.md new file mode 100644 index 0000000..6bd57f5 --- /dev/null +++ b/STM32MP157/doc_pic/11_SPI/02_SPI协议介绍.md @@ -0,0 +1,59 @@ +# SPI协议介绍 # + +参考资料: + +* 《SPI Block Guide V04.01.pdf》 +* 《S3C2440A_UserManual_Rev13.pdf》 + +## 1. SPI硬件知识 + +### 1.1 硬件连线 + +![](pic/01_hardware_block.jpg) +引脚含义如下: + +| 引脚 | 含义 | +| -------- | ------------------------------------------------------------ | +| DO(MOSI) | Master Output, Slave Input,
SPI主控用来发出数据,SPI从设备用来接收数据 | +| DI(MISO) | Master Input, Slave Output,
SPI主控用来发出数据,SPI从设备用来接收数据 | +| SCK | Serial Clock,时钟 | +| CS | Chip Select,芯片选择引脚 | + + + +### 1.2 SPI控制器内部结构 + +这个图等我们看完后面的SPI协议,再回过头来讲解: + +![image-20220216121534549](pic/04_spi_block.png) + + + +## 2. SPI协议 + +### 2.1 传输示例 + +假设现在主控芯片要传输一个0x56数据给SPI Flash,时序如下: + +首先CS0先拉低选中SPI Flash,0x56的二进制就是0b0101 0110,因此在每个SCK时钟周期,DO输出对应的电平。 +SPI Flash会在每个时钟周期的上升沿读取D0上的电平。 + + + +### 2.2 SPI模式 + +在SPI协议中,有两个值来确定SPI的模式。 +CPOL:表示SPICLK的初始电平,0为电平,1为高电平 +CPHA:表示相位,即第一个还是第二个时钟沿采样数据,0为第一个时钟沿,1为第二个时钟沿 + +| CPOL | CPHA | 模式 | 含义 | +| :--: | :--: | :--: | :--------------------------------------------: | +| 0 | 0 | 0 | SPICLK初始电平为低电平,在第一个时钟沿采样数据 | +| 0 | 1 | 1 | SPICLK初始电平为低电平,在第二个时钟沿采样数据 | +| 1 | 0 | 2 | SPICLK初始电平为高电平,在第一个时钟沿采样数据 | +| 1 | 1 | 3 | SPICLK初始电平为高电平,在第二个时钟沿采样数据 | +我们常用的是模式0和模式3,因为它们都是在上升沿采样数据,不用去在乎时钟的初始电平是什么,只要在上升沿采集数据就行。 + +极性选什么?格式选什么?通常去参考外接的模块的芯片手册。比如对于OLED,查看它的芯片手册时序部分: + +SCLK的初始电平我们并不需要关心,只要保证在上升沿采样数据就行。 \ No newline at end of file diff --git a/STM32MP157/doc_pic/11_SPI/02_SPI协议介绍.tif b/STM32MP157/doc_pic/11_SPI/02_SPI协议介绍.tif new file mode 100644 index 0000000..e40fd44 Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/02_SPI协议介绍.tif differ diff --git a/STM32MP157/doc_pic/11_SPI/S3C2440A_UserManual_Rev13.pdf b/STM32MP157/doc_pic/11_SPI/S3C2440A_UserManual_Rev13.pdf new file mode 100644 index 0000000..0c1318a Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/S3C2440A_UserManual_Rev13.pdf differ diff --git a/STM32MP157/doc_pic/11_SPI/SPI Block Guide V04.01.pdf b/STM32MP157/doc_pic/11_SPI/SPI Block Guide V04.01.pdf new file mode 100644 index 0000000..20819f3 Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/SPI Block Guide V04.01.pdf differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/01_hardware_block.jpg b/STM32MP157/doc_pic/11_SPI/pic/01_hardware_block.jpg new file mode 100644 index 0000000..b1c15c8 Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/01_hardware_block.jpg differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/02_spi_send_byte.png b/STM32MP157/doc_pic/11_SPI/pic/02_spi_send_byte.png new file mode 100644 index 0000000..2fefde7 Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/02_spi_send_byte.png differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/03_spi_protocol.png b/STM32MP157/doc_pic/11_SPI/pic/03_spi_protocol.png new file mode 100644 index 0000000..0484f50 Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/03_spi_protocol.png differ diff --git a/STM32MP157/doc_pic/11_SPI/pic/04_spi_block.png b/STM32MP157/doc_pic/11_SPI/pic/04_spi_block.png new file mode 100644 index 0000000..0036b8b Binary files /dev/null and b/STM32MP157/doc_pic/11_SPI/pic/04_spi_block.png differ