[docs] update api rst and demo rst
BIN
docs/development_guide/build/html/_images/bl706_avb_ck_link.png
Normal file
After Width: | Height: | Size: 302 KiB |
After Width: | Height: | Size: 259 KiB |
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 49 KiB |
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 86 KiB |
BIN
docs/development_guide/build/html/_images/pwm_step_motor.gif
Normal file
After Width: | Height: | Size: 48 MiB |
BIN
docs/development_guide/build/html/_images/pwm_step_motor.png
Normal file
After Width: | Height: | Size: 165 KiB |
BIN
docs/development_guide/build/html/_images/pwm_step_motor1.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
docs/development_guide/build/html/_images/pwm_step_motor2.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
docs/development_guide/build/html/_images/pwm_step_motor3.png
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
docs/development_guide/build/html/_images/shell_demo.gif
Normal file
After Width: | Height: | Size: 5.6 MiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 149 KiB |
BIN
docs/development_guide/build/html/_images/step_motor.png
Normal file
After Width: | Height: | Size: 384 KiB |
BIN
docs/development_guide/build/html/_images/step_motor_info.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
docs/development_guide/build/html/_images/uln2003.png
Normal file
After Width: | Height: | Size: 92 KiB |
|
@ -3,13 +3,238 @@ ADC 设备
|
|||
|
||||
简介
|
||||
------------------------
|
||||
ADC (Analog-to-digital Converter) 是用于将模拟形式的连续信号转换为数字形式的离散信号的一类设备,他可以将外围电路传感器产生的模拟信号转化为机器可识别的数字信号。
|
||||
博流系列MCU中的ADC设备具有以下特性
|
||||
|
||||
- 可以选择 12/14/16 bits转换结果输出
|
||||
- ADC最大工作时钟为2MHZ
|
||||
- 支持2.0V,3.2V可选内部参考电压
|
||||
- 支持DMA将转换结果搬运到内存
|
||||
- 支持单次单通道转换、连续单通道转换、单次多通道转换和连续多通道转换模式四种模式
|
||||
- 支持单端与差分两种输入模式
|
||||
- 12路外部模拟通道
|
||||
- 2路DAC内部通道
|
||||
- 1路VBAT/2通道
|
||||
|
||||
|
||||
ADC 设备结构体定义
|
||||
------------------------
|
||||
.. code-block:: C
|
||||
|
||||
typedef struct adc_device {
|
||||
struct device parent;
|
||||
adc_clk_div_t clk_div;
|
||||
adc_vref_t vref;
|
||||
bool continuous_conv_mode;
|
||||
bool differential_mode;
|
||||
adc_data_width_t data_width;
|
||||
adc_fifo_threshold_t fifo_threshold;
|
||||
adc_pga_gain_t gain;
|
||||
} adc_device_t;
|
||||
|
||||
- parent 继承父类属性
|
||||
- clk_div ADC模块时钟内部分频
|
||||
- vref 参考电压选择 2.0/3.2V可选
|
||||
- continuous_conv_mode 是否选择为连续模式,若为连续模式,则一次adc_start操作,ADC连续工作,直到adc_stop。否则,每adc_start一次,adc仅转换一次结果。
|
||||
- differential_mode 选择是否为差分模式,若为差分模式,则可以测量负电压。
|
||||
- data_width 测量宽度选择,ADC实际精度为12bits,但是通过OSR多次取平均可以达到14bits/16bits的精度,注意,当选择更高的数据宽度后,频率会因为取平均而下降。详情可参考枚举信息。
|
||||
- fifo_threshold 此参数影响DMA搬运阈值以及ADC FIFO中断阈值
|
||||
- gain ADC对输入信号的增益选择
|
||||
- 其他待补充
|
||||
|
||||
ADC 设备参数配置表
|
||||
------------------------
|
||||
|
||||
每一个 ADC 设备都有一个参数配置宏,宏定义位于 ``bsp/board/xxx`` 目录下 ``peripheral_config.h`` 文件,变量定义位于 ``hal_adc.c`` 中,因此无需用户自己定义变量。当用户打开对应设备的宏,该设备的配置才生效。例如打开宏 ``BSP_USING_ADC0`` 即生效,同时 ``ADC`` 设备就可以进行注册和使用了。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
/*参数配置宏*/
|
||||
#if defined(BSP_USING_ADC0)
|
||||
#ifndef ADC0_CONFIG
|
||||
#define ADC0_CONFIG \
|
||||
{ \
|
||||
.clk_div = ADC_CLOCK_DIV_32, \
|
||||
.vref = ADC_VREF_3P2V, \
|
||||
.continuous_conv_mode = DISABLE, \
|
||||
.differential_mode = DISABLE, \
|
||||
.data_width = ADC_DATA_WIDTH_16B_WITH_256_AVERAGE, \
|
||||
.fifo_threshold = ADC_FIFO_THRESHOLD_1BYTE, \
|
||||
.gain = ADC_GAIN_1 \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*变量定义*/
|
||||
static adc_device_t adcx_device[ADC_MAX_INDEX] = {
|
||||
#ifdef BSP_USING_ADC0
|
||||
ADC0_CONFIG,
|
||||
#endif
|
||||
};
|
||||
|
||||
.. note:: 上述配置可以通过 ``ADC_DEV(dev)->xxx`` 进行修改,只能在调用 ``device_open`` 之前使用。
|
||||
|
||||
ADC 设备接口
|
||||
------------------------
|
||||
ADC 设备接口全部遵循标准设备驱动管理层提供的接口。
|
||||
|
||||
|
||||
**ADC_register**
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
``adc_register`` 用来注册一个 ADC 设备,在注册之前需要打开对应 ADC 设备的宏定义。例如定义宏 ``BSP_USING_ADC0`` 方可使用 ``ADC0`` 设备,注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 ``ADC0`` 设备。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
int ADC_register(enum ADC_index_type index, const char *name, uint16_t flag);
|
||||
|
||||
- index 要注册的设备索引
|
||||
- name 为注册的设备命名
|
||||
- flag 默认可读可写属性
|
||||
|
||||
``index`` 用来选择 ADC 设备配置,一个 index 对应一个 ADC 设备配置,比如 ``ADC0_INDEX`` 对应 ``ADC0_CONFIG`` 配置,``index`` 有如下可选类型
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
enum ADC_index_type
|
||||
{
|
||||
#ifdef BSP_USING_ADC0
|
||||
ADC0_INDEX,
|
||||
#endif
|
||||
ADC_MAX_INDEX
|
||||
};
|
||||
|
||||
**device_open**
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
``device_open`` 用于 ADC 设备的打开,``oflag`` 表示以何种方式打开。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
|
||||
- dev 设备句柄
|
||||
- oflag 设备的打开方式
|
||||
- return 错误码,0 表示打开成功,其他表示错误
|
||||
|
||||
``oflag`` 可以写入以下参数:
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
#define DEVICE_OFLAG_STREAM_TX 0x001 /* 设备以轮训发送模式打开 */
|
||||
#define DEVICE_OFLAG_STREAM_RX 0x002 /* 设备以轮训接收模式打开 */
|
||||
#define DEVICE_OFLAG_INT_TX 0x004 /* 设备以中断发送模式打开 */
|
||||
#define DEVICE_OFLAG_INT_RX 0x008 /* 设备以中断接收模式打开 */
|
||||
#define DEVICE_OFLAG_DMA_TX 0x010 /* 设备以 DMA 发送模式打开 */
|
||||
#define DEVICE_OFLAG_DMA_RX 0x020 /* 设备以 DMA 接收模式打开 */
|
||||
|
||||
**device_close**
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
``device_close`` 用于设备的关闭。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
int device_close(struct device *dev);
|
||||
|
||||
- dev 设备句柄
|
||||
- return 错误码,0 表示关闭成功,其他表示错误
|
||||
|
||||
**device_control**
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
``device_control`` 用于根据命令对 ADC 设备进行控制和参数的修改。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
int device_control(struct device *dev, int cmd, void *args);
|
||||
|
||||
- dev 设备句柄
|
||||
- cmd 设备控制命令
|
||||
- args 控制参数
|
||||
- return 不同的控制命令返回的意义不同。
|
||||
|
||||
串口设备除了标准的控制命令,还具有自己特殊的控制命令。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
#define DEVICE_CTRL_ADC_CHANNEL_START 0x10
|
||||
#define DEVICE_CTRL_ADC_CHANNEL_STOP 0x11
|
||||
#define DEVICE_CTRL_ADC_CHANNEL_CONFIG 0x12
|
||||
#define DEVICE_CTRL_ADC_VBAT_ON 0x13
|
||||
#define DEVICE_CTRL_ADC_VBAT_OFF 0x14
|
||||
#define DEVICE_CTRL_ADC_TSEN_ON 0x15
|
||||
#define DEVICE_CTRL_ADC_TSEN_OFF 0x16
|
||||
|
||||
``args`` 根据不同的 ``cmd`` 传入不同,具体如下:
|
||||
|
||||
|
||||
+-----------------------------------+-----------------------+-------------------------------------+
|
||||
|cmd |args |description |
|
||||
+===================================+=======================+=====================================+
|
||||
|DEVICE_CTRL_SET_INT |ADC_it_type |开启ADC设备中断 |
|
||||
+-----------------------------------+-----------------------+-------------------------------------+
|
||||
|DEVICE_CTRL_CLR_INT |ADC_it_type |关闭ADC设备中断 |
|
||||
+-----------------------------------+-----------------------+-------------------------------------+
|
||||
|DEVICE_CTRL_CONFIG |ADC_param_cfg_t* |修改ADC配置 |
|
||||
+-----------------------------------+-----------------------+-------------------------------------+
|
||||
|DEVICE_CTRL_ADC_CHANNEL_CONFIG |adc_channel_cfg_t* |配置ADC通道信息 |
|
||||
+-----------------------------------+-----------------------+-------------------------------------+
|
||||
|DEVICE_CTRL_ATTACH_RX_DMA |struct device* |链接接收dma设备 |
|
||||
+-----------------------------------+-----------------------+-------------------------------------+
|
||||
|DEVICE_CTRL_ADC_CHANNEL_START |struct device* |开始/继续 ADC转换 |
|
||||
+-----------------------------------+-----------------------+-------------------------------------+
|
||||
|DEVICE_CTRL_ADC_CHANNEL_STOP |NULL |停止ADC转换 |
|
||||
+-----------------------------------+-----------------------+-------------------------------------+
|
||||
|DEVICE_CTRL_ADC_VBAT_ON |NULL |打开内部VDD测量电路 |
|
||||
+-----------------------------------+-----------------------+-------------------------------------+
|
||||
|DEVICE_CTRL_ADC_VBAT_OFF |NULL |关闭内部VDD测量电路 |
|
||||
+-----------------------------------+-----------------------+-------------------------------------+
|
||||
|DEVICE_CTRL_ADC_TSEN_ON |NULL |打开内部温度测量电路(需硬件支持) |
|
||||
+-----------------------------------+-----------------------+-------------------------------------+
|
||||
|DEVICE_CTRL_ADC_TSEN_OFF |uint32_t* |关闭内部温度测量电路(需硬件支持) |
|
||||
+-----------------------------------+-----------------------+-------------------------------------+
|
||||
|
||||
|
||||
**device_read**
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
``device_read`` 用于 ADC 设备数据的接收,接收方式根据打开方式可以是轮询、中断、dma。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
int device_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size);
|
||||
|
||||
- dev 设备句柄
|
||||
- pos 无作用
|
||||
- buffer 要读入的 buffer 缓冲区
|
||||
- size 要读入的长度
|
||||
- return 错误码,0 表示读入成功,其他表示错误
|
||||
|
||||
**device_set_callback**
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
``device_set_callback`` 用于注册一个ADC阈值中断回调函数。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
int device_set_callback(struct device *dev, void (*callback)(struct device *dev, void *args, uint32_t size, uint32_t event));
|
||||
|
||||
- dev 设备句柄
|
||||
- callback 要注册的中断回调函数
|
||||
|
||||
- dev 设备句柄
|
||||
- args 接收发送缓冲区,数据类型为 uint8_t*
|
||||
- size 传输长度
|
||||
- event 中断事件类型
|
||||
|
||||
串口设备 ``event`` 类型如下
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
enum ADC_event_type
|
||||
{
|
||||
ADC_EVENT_FIFO_READY,
|
||||
ADC_EVENT_OVERRUN,
|
||||
ADC_EVENT_UNDERRUN,
|
||||
};
|
|
@ -17,7 +17,7 @@ BLE
|
|||
- BLE协议栈的架构:
|
||||
.. figure:: img/image1.png
|
||||
|
||||
+ 总共有3个主要层,共同构成了一个完整的蓝牙低能耗协议栈
|
||||
+ 总共有3个主要层,共同构成了一个完整的蓝牙低能耗协议栈
|
||||
- Host:这一层位于应用程序之下,由多个(非实时)网络和传输协议组成,使应用程序能够以标准和互操作的方式与对等设备通信。
|
||||
- Controller:控制器实现了链路层(LE LL),这是一种低层次的实时协议,它与无线电硬件一起提供了空中通信的标准互操作。LL处理包的接收和传输,保证数据的传递,并处理所有LL控制程序。
|
||||
- Radio Hardware:实现所需的模拟和数字基带功能块,允许链路层固件在频谱的2.4GHz波段发送和接收。
|
||||
|
@ -25,7 +25,7 @@ BLE
|
|||
- 主控Host:
|
||||
.. figure:: img/image2.png
|
||||
|
||||
* 蓝牙Host层实现了所有高级协议和配置文件,最重要的是它为应用程序提供了高级API
|
||||
* 蓝牙Host层实现了所有高级协议和配置文件,最重要的是它为应用程序提供了高级API
|
||||
- HCI:Host与controller接口
|
||||
- L2CAP:逻辑链路控制和适应协议
|
||||
- GATT:通用属性配置层(Generic Attribute Profile)
|
||||
|
@ -34,14 +34,14 @@ BLE
|
|||
|
||||
- 应用Application
|
||||
* 应用层是用户开发实际蓝牙应用的地方,包含必要的协议栈参数设置,以及各种功能函数的调用。我们分别从蓝牙从机和蓝牙主机两种设备来分析。
|
||||
* 蓝牙从机
|
||||
* 蓝牙从机
|
||||
- 相关硬件和基础服务初始化
|
||||
- 设置广播参数:广播数据,广播间隔,扫描回应等参数或者数据
|
||||
- 设置Profile:添加从机服务、特征值,还有设置回调函数用于接收主机数据等
|
||||
- 设置配对参数(可选)
|
||||
- 启动广播,开始运行
|
||||
- 等待相关事件,及事件处理,例如收到主机发来的数据,被链接等等
|
||||
* 蓝牙主机
|
||||
* 蓝牙主机
|
||||
- 相关硬件和基础服务初始化
|
||||
- 设置扫描参数
|
||||
- 设置连接参数
|
||||
|
@ -95,8 +95,8 @@ API参考
|
|||
* @param[in] param: 指向广播配置参数指针
|
||||
* @param[in] ad: 指向广播包中数据指针
|
||||
* @param[in] ad_len: 广播包中数据的长度
|
||||
* @param[in] sd: 指向扫描响应包数据指针
|
||||
* @param[in] sd_len: 扫描响应包数据的长度
|
||||
* @param[in] sd: 指向扫描响应包数据指针
|
||||
* @param[in] sd_len: 扫描响应包数据的长度
|
||||
* @return 0:成功,!=0:失败
|
||||
*/
|
||||
|
||||
|
@ -110,8 +110,8 @@ API参考
|
|||
* function 更新BLE广播数据
|
||||
* @param[in] ad: 指向广播包中数据指针
|
||||
* @param[in] ad_len: 广播包中数据的长度
|
||||
* @param[in] sd: 指向扫描响应包数据指针
|
||||
* @param[in] sd_len: 扫描响应包数据的长度
|
||||
* @param[in] sd: 指向扫描响应包数据指针
|
||||
* @param[in] sd_len: 扫描响应包数据的长度
|
||||
* @return 0:成功,!=0:失败
|
||||
*/
|
||||
|
||||
|
@ -121,7 +121,7 @@ API参考
|
|||
::
|
||||
|
||||
/**
|
||||
* function 停止BLE广播
|
||||
* function 停止BLE广播
|
||||
* @param[in] 空
|
||||
* @return 0:成功,!=0:失败
|
||||
*/
|
||||
|
|
|
@ -46,9 +46,9 @@
|
|||
- type 获取的外设时钟频率类型
|
||||
|
||||
``type`` 提供以下几种类型
|
||||
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
enum peripheral_clock_type
|
||||
{
|
||||
PERIPHERAL_CLOCK_UART = 0,
|
||||
|
|
|
@ -29,7 +29,7 @@ DMA 设备结构体定义
|
|||
uint8_t dst_burst_size;
|
||||
uint8_t src_width;
|
||||
uint8_t dst_width;
|
||||
dma_lli_ctrl_t *lli_cfg;
|
||||
dma_lli_ctrl_t *lli_cfg;
|
||||
} dma_device_t;
|
||||
|
||||
- parent 继承父类属性
|
||||
|
@ -60,7 +60,7 @@ DMA 设备结构体定义
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
#define DMA_LLI_ONCE_MODE 0
|
||||
#define DMA_LLI_ONCE_MODE 0
|
||||
#define DMA_LLI_CYCLE_MODE 1
|
||||
|
||||
``src_req`` 提供以下类型
|
||||
|
@ -76,8 +76,8 @@ DMA 设备结构体定义
|
|||
#define DMA_REQUEST_I2C0_TX 0x00000007 /*!< DMA request peripheral:I2C TX */
|
||||
#define DMA_REQUEST_SPI0_RX 0x0000000A /*!< DMA request peripheral:SPI RX */
|
||||
#define DMA_REQUEST_SPI0_TX 0x0000000B /*!< DMA request peripheral:SPI TX */
|
||||
#define DMA_REQUEST_I2S_RX 0x00000014 /*!< DMA request peripheral:I2S RX */
|
||||
#define DMA_REQUEST_I2S_TX 0x00000015 /*!< DMA request peripheral:I2S TX */
|
||||
#define DMA_REQUEST_I2S_RX 0x00000014 /*!< DMA request peripheral:I2S RX */
|
||||
#define DMA_REQUEST_I2S_TX 0x00000015 /*!< DMA request peripheral:I2S TX */
|
||||
#define DMA_REQUEST_ADC0 0x00000016 /*!< DMA request peripheral:ADC0 */
|
||||
#define DMA_REQUEST_DAC0 0x00000017 /*!< DMA request peripheral:DAC0 */
|
||||
#define DMA_REQUEST_USB_EP0 0x00000018 /*!< DMA request peripheral:USB EP0*/
|
||||
|
@ -102,8 +102,8 @@ DMA 设备结构体定义
|
|||
#define DMA_REQUEST_I2C0_TX 0x00000007 /*!< DMA request peripheral:I2C TX */
|
||||
#define DMA_REQUEST_SPI0_RX 0x0000000A /*!< DMA request peripheral:SPI RX */
|
||||
#define DMA_REQUEST_SPI0_TX 0x0000000B /*!< DMA request peripheral:SPI TX */
|
||||
#define DMA_REQUEST_I2S_RX 0x00000014 /*!< DMA request peripheral:I2S RX */
|
||||
#define DMA_REQUEST_I2S_TX 0x00000015 /*!< DMA request peripheral:I2S TX */
|
||||
#define DMA_REQUEST_I2S_RX 0x00000014 /*!< DMA request peripheral:I2S RX */
|
||||
#define DMA_REQUEST_I2S_TX 0x00000015 /*!< DMA request peripheral:I2S TX */
|
||||
#define DMA_REQUEST_ADC0 0x00000016 /*!< DMA request peripheral:ADC0 */
|
||||
#define DMA_REQUEST_DAC0 0x00000017 /*!< DMA request peripheral:DAC0 */
|
||||
#define DMA_REQUEST_USB_EP0 0x00000018 /*!< DMA request peripheral:USB EP0*/
|
||||
|
@ -172,7 +172,7 @@ DMA 设备参数配置表
|
|||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*变量定义*/
|
||||
static dma_device_t dmax_device[DMA_MAX_INDEX] =
|
||||
|
@ -212,11 +212,11 @@ DMA 设备接口全部遵循标准设备驱动管理层提供的接口。并且
|
|||
|
||||
**dma_register**
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
``dma_register`` 用来注册一个 DMA 设备的一个通道,在注册之前需要打开对应 DMA 设备的通道宏定义。例如定义宏 ``BSP_USING_DMA_CH0`` 方可使用 ``DMA`` 设备的 0 通道,注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 ``DMA`` 设备的 0 通道。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
int dma_register(enum dma_index_type index, const char *name, uint16_t flag);
|
||||
|
||||
- index 要注册的设备索引
|
||||
|
@ -226,7 +226,7 @@ DMA 设备接口全部遵循标准设备驱动管理层提供的接口。并且
|
|||
``index`` 用来选择 DMA 设备某个通道的配置,一个 index 对应一个 DMA 设备的一个通道配置,比如 ``DMA_CH0_INDEX`` 对应 DMA 通道0 配置,``index`` 有如下可选类型
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
enum dma_index_type
|
||||
{
|
||||
#ifdef BSP_USING_DMA0_CH0
|
||||
|
@ -263,7 +263,7 @@ DMA 设备接口全部遵循标准设备驱动管理层提供的接口。并且
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
|
||||
- dev 设备句柄
|
||||
- oflag 设备的打开方式
|
||||
|
@ -287,11 +287,11 @@ DMA 设备接口全部遵循标准设备驱动管理层提供的接口。并且
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_close(struct device *dev);
|
||||
int device_close(struct device *dev);
|
||||
|
||||
- dev 设备句柄
|
||||
- return 错误码,0 表示关闭成功,其他表示错误
|
||||
|
||||
|
||||
**device_control**
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -299,7 +299,7 @@ DMA 设备接口全部遵循标准设备驱动管理层提供的接口。并且
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_control(struct device *dev, int cmd, void *args);
|
||||
int device_control(struct device *dev, int cmd, void *args);
|
||||
|
||||
- dev 设备句柄
|
||||
- cmd 设备控制命令
|
||||
|
@ -348,7 +348,7 @@ DMA 设备除了标准的控制命令,还具有自己特殊的控制命令。
|
|||
- dev 设备句柄
|
||||
- args 无用
|
||||
- size 无用
|
||||
- event 中断事件类型
|
||||
- event 中断事件类型
|
||||
|
||||
DMA 设备 ``event`` 类型如下
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ GPIO 设备接口
|
|||
``gpio_set_mode`` 用来配置 gpio 的模式。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
void gpio_set_mode(uint32_t pin, uint32_t mode);
|
||||
|
||||
- pin 要配置的引脚
|
||||
|
@ -36,7 +36,7 @@ GPIO 设备接口
|
|||
``mode`` 提供以下几种类型
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
#define GPIO_OUTPUT_MODE 0
|
||||
#define GPIO_OUTPUT_PP_MODE 1
|
||||
#define GPIO_OUTPUT_PD_MODE 2
|
||||
|
@ -58,31 +58,31 @@ GPIO 设备接口
|
|||
``gpio_write`` 设置引脚电平
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
void gpio_write(uint32_t pin, uint32_t value);
|
||||
|
||||
|
||||
- pin 要设置的引脚
|
||||
- value 要设置的电平
|
||||
|
||||
|
||||
**gpio_toggle**
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
``gpio_toggle`` 翻转引脚电平
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
void gpio_toggle(uint32_t pin);
|
||||
|
||||
- pin 要翻转的引脚
|
||||
|
||||
**gpio_read**
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
``gpio_read`` 读取引脚电平
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
int gpio_read(uint32_t pin);
|
||||
|
||||
|
||||
|
@ -91,11 +91,11 @@ GPIO 设备接口
|
|||
|
||||
**gpio_attach_irq**
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
``gpio_attach_irq`` 为中断引脚附加中断回调函数
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
void gpio_attach_irq(uint32_t pin, void (*cbfun)(uint32_t pin));
|
||||
|
||||
- pin 要附加中断回调的引脚
|
||||
|
@ -103,11 +103,11 @@ GPIO 设备接口
|
|||
|
||||
**gpio_irq_enable**
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
``gpio_irq_enable`` 开启gpio某个引脚的中断
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
void gpio_irq_enable(uint32_t pin,uint8_t enabled);
|
||||
|
||||
- pin 要开启或者关闭中断的引脚
|
||||
|
|
|
@ -30,7 +30,7 @@ I2C 设备结构体定义
|
|||
- parent 继承父类属性
|
||||
- ch i2c id,0 表示 i2c0,1 表示 i2c1
|
||||
- mode i2c 传输模式,0 为使用硬件 i2c,1 为使用软件 i2c,当前软件 i2c 暂时无效
|
||||
- phase
|
||||
- phase
|
||||
- 其他待补充
|
||||
|
||||
I2C 设备参数配置表
|
||||
|
@ -70,11 +70,11 @@ I2C 设备标准接口当前仅使用 ``device_open`` , 并提供标准的数据
|
|||
|
||||
**i2c_register**
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
``i2c_register`` 用来注册一个 I2C 设备,在注册之前需要打开对应 I2C 设备的宏定义。例如定义宏 ``BSP_USING_I2C0`` 方可使用 ``I2C0`` 设备,注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 ``I2C0`` 设备。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
int i2c_register(enum i2c_index_type index, const char *name, uint16_t flag);
|
||||
|
||||
- index 要注册的设备索引
|
||||
|
@ -84,7 +84,7 @@ I2C 设备标准接口当前仅使用 ``device_open`` , 并提供标准的数据
|
|||
``index`` 用来选择 I2C 设备,一个 index 对应一个 I2C 设备配置,比如 ``I2C0_INDEX`` 对应 ``I2C0_CONFIG`` 配置,``index`` 有如下可选类型
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
enum i2c_index_type
|
||||
{
|
||||
#ifdef BSP_USING_I2C0
|
||||
|
@ -100,7 +100,7 @@ I2C 设备标准接口当前仅使用 ``device_open`` , 并提供标准的数据
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
|
||||
- dev 设备句柄
|
||||
- oflag 设备的打开方式
|
||||
|
@ -124,7 +124,7 @@ I2C 设备标准接口当前仅使用 ``device_open`` , 并提供标准的数据
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int i2c_transfer(struct device *dev, i2c_msg_t msgs[], uint32_t num);
|
||||
int i2c_transfer(struct device *dev, i2c_msg_t msgs[], uint32_t num);
|
||||
|
||||
- dev 设备句柄
|
||||
- msgs 需要传输的消息
|
||||
|
|
|
@ -6,7 +6,7 @@ PWM 设备
|
|||
|
||||
脉冲宽度调制(Pulse width modulation,简称 PWM)是一种用数字方式实现模拟电压控制的技术。它是通过对一系列脉冲的宽度进行调制,等效出所需要的波形(包含形状以及幅值),对模拟信号电平进行数字编码,也就是说通过调节占空比的变化来调节信号、能量等的变化,占空比就是指在一个周期内,信号处于高电平的时间占据整个信号周期的百分比,例如方波的占空比就是50%。博流系列 MCU 中 DMA 设备具有以下特性:
|
||||
|
||||
- 支持5通道PWM信号生成
|
||||
- 支持5通道 PWM 信号生成
|
||||
- 三种时钟源可选择(总线时钟 <bclk>、晶振时钟 <xtal_ck>、慢速时钟 <32k>),搭配 16-bit 时钟分频器
|
||||
- 双门限值域设定,增加脉冲弹性
|
||||
|
||||
|
@ -15,21 +15,29 @@ PWM 设备结构体定义
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
typedef struct pwm_device
|
||||
{
|
||||
typedef struct pwm_device {
|
||||
struct device parent;
|
||||
uint8_t ch;
|
||||
uint32_t frequency;
|
||||
uint8_t dutycycle;
|
||||
uint8_t polarity_invert_mode;
|
||||
uint16_t period;
|
||||
uint16_t threshold_low;
|
||||
uint16_t threshold_high;
|
||||
uint16_t it_pulse_count;
|
||||
|
||||
} pwm_device_t;
|
||||
|
||||
- parent 继承父类属性
|
||||
- ch 通道号,使能PWM通道0则ch为0,使能PWM通道0则ch为1,以此类推
|
||||
- frequency 默认频率
|
||||
- dutycycle 默认占空比(0-100)
|
||||
- polarity_invert_mode 极性翻转使能
|
||||
- period PWM 周期值
|
||||
- threshold_low PWM 低门限阈值
|
||||
- threshold_high PWM 高门限阈值
|
||||
- it_pulse_count 触发中断条件的周期计数值
|
||||
|
||||
.. note:: PWM 实际频率 = PWM 时钟源/分频/period ,period 非 PWM 实际周期,
|
||||
|
||||
.. note:: PWM 占空比 = threshold_low/threshold_high * 100%
|
||||
|
||||
PWM 设备参数配置表
|
||||
------------------------
|
||||
|
||||
|
@ -40,15 +48,19 @@ PWM 设备参数配置表
|
|||
/*参数配置宏*/
|
||||
#if defined(BSP_USING_PWM_CH2)
|
||||
#ifndef PWM_CH2_CONFIG
|
||||
#define PWM_CH2_CONFIG \
|
||||
{ \
|
||||
.ch = 2, \
|
||||
.frequency = 1000000, \
|
||||
.dutycycle = 0, \
|
||||
}
|
||||
#define PWM_CH2_CONFIG \
|
||||
{ \
|
||||
.ch = 2, \
|
||||
.polarity_invert_mode = DISABLE, \
|
||||
.period = 0, \
|
||||
.threshold_low = 0, \
|
||||
.threshold_high = 0, \
|
||||
.it_pulse_count = 0, \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*变量定义*/
|
||||
static pwm_device_t pwmx_device[PWM_MAX_INDEX] = {
|
||||
#ifdef BSP_USING_PWM_CH0
|
||||
|
@ -77,11 +89,11 @@ PWM 设备接口全部遵循标准设备驱动管理层提供的接口。并且
|
|||
|
||||
**pwm_register**
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
``pwm_register`` 用来注册一个 PWM 设备的一个通道,在注册之前需要打开对应 PWM 设备某个通道的宏定义,例如定义 ``BSP_USING_PWM_CH0`` 方可使用 ``PWM`` 通道0 设备。注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 PWM 设备。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
int pwm_register(enum pwm_index_type index, const char *name, uint16_t flag);
|
||||
|
||||
- index 要注册的设备索引
|
||||
|
@ -91,7 +103,7 @@ PWM 设备接口全部遵循标准设备驱动管理层提供的接口。并且
|
|||
``index`` 用来选择 PWM 设备某个通道的配置,一个 index 对应一个 PWM 设备的一个通道配置,比如 ``PWM_CH0_INDEX`` 对应 PWM 通道0 配置,``index`` 有如下可选类型
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
enum pwm_index_type
|
||||
{
|
||||
#ifdef BSP_USING_PWM_CH0
|
||||
|
@ -119,7 +131,7 @@ PWM 设备接口全部遵循标准设备驱动管理层提供的接口。并且
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
|
||||
- dev 设备句柄
|
||||
- oflag 设备的打开方式
|
||||
|
@ -143,11 +155,11 @@ PWM 设备接口全部遵循标准设备驱动管理层提供的接口。并且
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_close(struct device *dev);
|
||||
int device_close(struct device *dev);
|
||||
|
||||
- dev 设备句柄
|
||||
- return 错误码,0 表示关闭成功,其他表示错误
|
||||
|
||||
|
||||
**device_control**
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -155,7 +167,7 @@ PWM 设备接口全部遵循标准设备驱动管理层提供的接口。并且
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_control(struct device *dev, int cmd, void *args);
|
||||
int device_control(struct device *dev, int cmd, void *args);
|
||||
|
||||
- dev 设备句柄
|
||||
- cmd 设备控制命令
|
||||
|
@ -170,21 +182,23 @@ PWM 设备除了标准的控制命令,还具有自己特殊的控制命令。
|
|||
|
||||
``args`` 根据不同的 ``cmd`` 传入不同,具体如下:
|
||||
|
||||
+------------------------------------------+-----------------+----------------------------+
|
||||
|cmd |args |description |
|
||||
+==========================================+=================+============================+
|
||||
|DEVICE_CTRL_SET_INT |NULL |开启pwm传输完成中断 |
|
||||
+------------------------------------------+-----------------+----------------------------+
|
||||
|DEVICE_CTRL_CLR_INT |NULL |关闭pwm传输完成中断 |
|
||||
+------------------------------------------+-----------------+----------------------------+
|
||||
|DEVICE_CTRL_RESUME |NULL |恢复pwm通道 |
|
||||
+------------------------------------------+-----------------+----------------------------+
|
||||
|DEVICE_CTRL_SUSPEND |NULL |挂起pwm通道 |
|
||||
+------------------------------------------+-----------------+----------------------------+
|
||||
|DEVICE_CTRL_CONFIG |pwm_config_t |配置pwm通道频率和占空比 |
|
||||
+------------------------------------------+-----------------+----------------------------+
|
||||
|DEIVCE_CTRL_PWM_IT_PULSE_COUNT_CONFIG |uint32_t* |配置中断计数阈值 |
|
||||
+------------------------------------------+-----------------+----------------------------+
|
||||
+------------------------------------------+---------------------------+--------------------------+
|
||||
|cmd |args |description |
|
||||
+==========================================+===========================+==========================+
|
||||
|DEVICE_CTRL_SET_INT |NULL |弃用 |
|
||||
+------------------------------------------+---------------------------+--------------------------+
|
||||
|DEVICE_CTRL_CLR_INT |NULL |弃用 |
|
||||
+------------------------------------------+---------------------------+--------------------------+
|
||||
|DEVICE_CTRL_RESUME |NULL |开启当前PWM通道 |
|
||||
+------------------------------------------+---------------------------+--------------------------+
|
||||
|DEVICE_CTRL_SUSPEND |NULL |关闭当前PWM通道 |
|
||||
+------------------------------------------+---------------------------+--------------------------+
|
||||
|DEIVCE_CTRL_PWM_FREQUENCE_CONFIG |uint32_t |配置当前PWM通道周期值 |
|
||||
+------------------------------------------+---------------------------+--------------------------+
|
||||
|DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG |pwm_dutycycle_config_t |配置当前PWM通道占空比 |
|
||||
+------------------------------------------+---------------------------+--------------------------+
|
||||
|DEIVCE_CTRL_PWM_IT_PULSE_COUNT_CONFIG |uint32_t |配置触发PWM中断周期值 |
|
||||
+------------------------------------------+---------------------------+--------------------------+
|
||||
|
||||
**device_set_callback**
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -201,7 +215,7 @@ PWM 设备除了标准的控制命令,还具有自己特殊的控制命令。
|
|||
- dev 设备句柄
|
||||
- args 无用
|
||||
- size 无用
|
||||
- event 中断事件类型
|
||||
- event 中断事件类型
|
||||
|
||||
PWM设备 ``event`` 类型如下
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ SPI 设备结构体定义
|
|||
------------------------
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
typedef struct spi_device
|
||||
{
|
||||
struct device parent;
|
||||
|
@ -84,7 +84,7 @@ SPI 设备结构体定义
|
|||
``datasize`` 提供以下类型
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
#define SPI_DATASIZE_8BIT 0
|
||||
#define SPI_DATASIZE_16BIT 1
|
||||
#define SPI_DATASIZE_24BIT 2
|
||||
|
@ -132,11 +132,11 @@ SPI 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
|
||||
**spi_register**
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
``spi_register`` 用来注册一个 SPI 设备,在注册之前需要打开对应 SPI 设备的宏定义,例如定义宏 ``BSP_USING_SPI0`` 方可使用 SPI0 设备。注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 SPI 设备。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
int spi_register(enum spi_index_type index, const char *name, uint16_t flag);
|
||||
|
||||
- index 要注册的设备索引
|
||||
|
@ -146,7 +146,7 @@ SPI 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
``index`` 用来选择 SPI 设备配置,一个 index 对应一个 SPI 设备配置,比如 ``SPI0_INDEX`` 对应 ``SPI0_CONFIG`` 配置,``index`` 有如下可选类型
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
enum spi_index_type
|
||||
{
|
||||
#ifdef BSP_USING_SPI0
|
||||
|
@ -162,7 +162,7 @@ SPI 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
|
||||
- dev 设备句柄
|
||||
- oflag 设备的打开方式
|
||||
|
@ -186,11 +186,11 @@ SPI 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_close(struct device *dev);
|
||||
int device_close(struct device *dev);
|
||||
|
||||
- dev 设备句柄
|
||||
- return 错误码,0 表示关闭成功,其他表示错误
|
||||
|
||||
|
||||
**device_control**
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -198,7 +198,7 @@ SPI 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_control(struct device *dev, int cmd, void *args);
|
||||
int device_control(struct device *dev, int cmd, void *args);
|
||||
|
||||
- dev 设备句柄
|
||||
- cmd 设备控制命令
|
||||
|
@ -246,7 +246,7 @@ SPI 设备除了标准的控制命令,还具有自己特殊的控制命令。
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size);
|
||||
int device_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size);
|
||||
|
||||
- dev 设备句柄
|
||||
- pos 无作用
|
||||
|
@ -261,7 +261,7 @@ SPI 设备除了标准的控制命令,还具有自己特殊的控制命令。
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size);
|
||||
int device_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size);
|
||||
|
||||
- dev 设备句柄
|
||||
- pos 无作用
|
||||
|
@ -284,7 +284,7 @@ SPI 设备除了标准的控制命令,还具有自己特殊的控制命令。
|
|||
- dev 设备句柄
|
||||
- args 接收发送缓冲区,数据类型为 uint8_t*
|
||||
- size 传输长度
|
||||
- event 中断事件类型
|
||||
- event 中断事件类型
|
||||
|
||||
SPI 设备 ``event`` 类型如下
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ API 分层模型
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_register(struct device *dev, const char *name, uint16_t flag);
|
||||
int device_register(struct device *dev, const char *name, uint16_t flag);
|
||||
|
||||
- dev 设备句柄。
|
||||
- name 设备名称。
|
||||
|
@ -133,7 +133,7 @@ API 分层模型
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_unregister(const char *name);
|
||||
int device_unregister(const char *name);
|
||||
|
||||
- dev 设备句柄
|
||||
- name 要删除的设备名称
|
||||
|
@ -160,7 +160,7 @@ API 分层模型
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
|
||||
- dev 设备句柄
|
||||
- oflag 设备的打开方式
|
||||
|
@ -184,11 +184,11 @@ API 分层模型
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_close(struct device *dev);
|
||||
int device_close(struct device *dev);
|
||||
|
||||
- dev 设备句柄
|
||||
- return 错误码,0 表示关闭成功,其他表示错误
|
||||
|
||||
|
||||
**device_control**
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -196,7 +196,7 @@ API 分层模型
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_control(struct device *dev, int cmd, void *args);
|
||||
int device_control(struct device *dev, int cmd, void *args);
|
||||
|
||||
- dev 设备句柄
|
||||
- cmd 设备控制命令
|
||||
|
@ -230,7 +230,7 @@ API 分层模型
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size);
|
||||
int device_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size);
|
||||
|
||||
- dev 设备句柄
|
||||
- pos 不同的设备 pos 的意义不同
|
||||
|
@ -245,7 +245,7 @@ API 分层模型
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size);
|
||||
int device_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size);
|
||||
|
||||
- dev 设备句柄
|
||||
- pos 不同的设备 pos 的意义不同
|
||||
|
|
|
@ -20,7 +20,7 @@ UART 设备结构体定义
|
|||
------------------------
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
typedef struct uart_device
|
||||
{
|
||||
struct device parent;
|
||||
|
@ -48,7 +48,7 @@ UART 设备结构体定义
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
typedef enum
|
||||
typedef enum
|
||||
{
|
||||
UART_DATA_LEN_5 = 0, /*!< Data length is 5 bits */
|
||||
UART_DATA_LEN_6 = 1, /*!< Data length is 6 bits */
|
||||
|
@ -59,8 +59,8 @@ UART 设备结构体定义
|
|||
``stopbits`` 提供以下类型
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
typedef enum
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UART_STOP_ONE = 0, /*!< One stop bit */
|
||||
UART_STOP_ONE_D_FIVE = 1, /*!< 1.5 stop bit */
|
||||
|
@ -70,8 +70,8 @@ UART 设备结构体定义
|
|||
``parity`` 提供以下类型
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
typedef enum
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UART_PAR_NONE = 0, /*!< No parity */
|
||||
UART_PAR_ODD = 1, /*!< Parity bit is odd */
|
||||
|
@ -120,11 +120,11 @@ UART 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
|
||||
**uart_register**
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
``uart_register`` 用来注册一个 UART 设备,在注册之前需要打开对应 UART 设备的宏定义。例如定义宏 ``BSP_USING_UART0`` 方可使用 ``UART0`` 设备,注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 ``UART0`` 设备。
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
int uart_register(enum uart_index_type index, const char *name, uint16_t flag);
|
||||
|
||||
- index 要注册的设备索引
|
||||
|
@ -134,7 +134,7 @@ UART 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
``index`` 用来选择 UART 设备配置,一个 index 对应一个 UART 设备配置,比如 ``UART0_INDEX`` 对应 ``UART0_CONFIG`` 配置,``index`` 有如下可选类型
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
|
||||
enum uart_index_type
|
||||
{
|
||||
#ifdef BSP_USING_UART0
|
||||
|
@ -153,7 +153,7 @@ UART 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
int device_open(struct device *dev, uint16_t oflag);
|
||||
|
||||
- dev 设备句柄
|
||||
- oflag 设备的打开方式
|
||||
|
@ -177,11 +177,11 @@ UART 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_close(struct device *dev);
|
||||
int device_close(struct device *dev);
|
||||
|
||||
- dev 设备句柄
|
||||
- return 错误码,0 表示关闭成功,其他表示错误
|
||||
|
||||
|
||||
**device_control**
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -189,7 +189,7 @@ UART 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_control(struct device *dev, int cmd, void *args);
|
||||
int device_control(struct device *dev, int cmd, void *args);
|
||||
|
||||
- dev 设备句柄
|
||||
- cmd 设备控制命令
|
||||
|
@ -209,9 +209,9 @@ UART 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
+---------------------------------+---------------------+------------------------------+
|
||||
|cmd |args |description |
|
||||
+=================================+=====================+==============================+
|
||||
|DEVICE_CTRL_SET_INT |uart_it_type |开启spi设备中断 |
|
||||
|DEVICE_CTRL_SET_INT |uart_it_type |开启uart设备中断 |
|
||||
+---------------------------------+---------------------+------------------------------+
|
||||
|DEVICE_CTRL_CLR_INT |uart_it_type |关闭spi设备中断 |
|
||||
|DEVICE_CTRL_CLR_INT |uart_it_type |关闭uart设备中断 |
|
||||
+---------------------------------+---------------------+------------------------------+
|
||||
|DEVICE_CTRL_CONFIG |uart_param_cfg_t* |修改串口配置 |
|
||||
+---------------------------------+---------------------+------------------------------+
|
||||
|
@ -241,7 +241,7 @@ UART 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size);
|
||||
int device_write(struct device *dev, uint32_t pos, const void *buffer, uint32_t size);
|
||||
|
||||
- dev 设备句柄
|
||||
- pos 无作用
|
||||
|
@ -256,7 +256,7 @@ UART 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
|
||||
.. code-block:: C
|
||||
|
||||
int device_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size);
|
||||
int device_read(struct device *dev, uint32_t pos, void *buffer, uint32_t size);
|
||||
|
||||
- dev 设备句柄
|
||||
- pos 无作用
|
||||
|
@ -279,7 +279,7 @@ UART 设备接口全部遵循标准设备驱动管理层提供的接口。
|
|||
- dev 设备句柄
|
||||
- args 接收发送缓冲区,数据类型为 uint8_t*
|
||||
- size 传输长度
|
||||
- event 中断事件类型
|
||||
- event 中断事件类型
|
||||
|
||||
串口设备 ``event`` 类型如下
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ Linux OR WSL 环境开发指南
|
|||
$ wget -c https://dev.bouffalolab.com/media/upload/download/riscv64-elf-x86_64-20210120.tar.gz
|
||||
$ mkdir -p riscv64-elf-20210120
|
||||
$ tar -zxvf riscv64-elf-x86_64-20210120.tar.gz -C riscv64-elf-20210120
|
||||
$ sudo cp ~/riscv64-elf-20210120 /usr/bin
|
||||
$ sudo cp -rf ~/riscv64-elf-20210120 /usr/bin
|
||||
$ echo "export PATH=\"$PATH:/usr/bin/riscv64-elf-20210120/bin\"" >> ~/.bashrc
|
||||
$ source ~/.bashrc
|
||||
|
||||
|
@ -39,9 +39,9 @@ Linux OR WSL 环境开发指南
|
|||
$ sudo apt update
|
||||
$ sudo apt install make
|
||||
$ cd ~
|
||||
$ wget -c https://cmake.org/files/v3.19/cmake-3.19.3-Linux-x86_64.tar.gz
|
||||
$ wget -c https://cmake.org/files/v3.19/cmake-3.19.3-Linux-x86_64.tar.gz
|
||||
$ tar -zxvf cmake-3.19.3-Linux-x86_64.tar.gz
|
||||
$ sudo cp ~/cmake-3.19.3-Linux-x86_64 /usr/bin
|
||||
$ sudo cp -rf ~/cmake-3.19.3-Linux-x86_64 /usr/bin
|
||||
$ echo "export PATH=\"$PATH:/usr/bin/cmake-3.19.3-Linux-x86_64/bin\"" >> ~/.bashrc
|
||||
$ source ~/.bashrc
|
||||
|
||||
|
@ -119,7 +119,7 @@ Linux OR WSL 环境开发指南
|
|||
:linenos:
|
||||
|
||||
$ sudo apt install picocom # 若已经安装请忽略
|
||||
$ picocom -b 2000000 /dev/ttyUSB0
|
||||
$ picocom -b 2000000 /dev/ttyUSB0 # 注意你的可用串口号 (如使用 Sipeed RV-debugger)
|
||||
|
||||
- 按一下开发板上的 ``rst`` 按键,即可在串口终端中看到 ``hello world!``
|
||||
|
||||
|
|
|
@ -6,15 +6,15 @@ Windows 下使用 CDK (类 MDK Keil)开发指南
|
|||
本文档介绍了如何在 Windows 下使用 `平头哥半导体 <https://www.t-heah.cn/about>`_ 开发的 CDK 集成开发环境,
|
||||
来完成博流 BL702 系列 MCU 的相关软件开发工作。
|
||||
|
||||
关于剑池 CDK ,这是一款由平头哥半导体开发打造的集成开发环境。它拥有和传统 MCU 开发环境十分近似的操作和设置,旨在不改变用户开发习惯的基础上,全面接入云端开发资源,结合图形化的 OSTracer、Profiling 等调试分析工具,加速用户产品开发。
|
||||
关于剑池 CDK ,这是一款由平头哥半导体开发打造的集成开发环境。它拥有和传统 MCU 开发环境十分近似的操作和设置,旨在不改变用户开发习惯的基础上,全面接入云端开发资源,结合图形化的 OSTracer、Profiling 等调试分析工具,加速用户产品开发
|
||||
|
||||
|
||||
需要的软硬件环境
|
||||
-----------------------------
|
||||
|
||||
- 剑池 CDK 软件
|
||||
- 一根 USB Type-A 数据线
|
||||
- 一个 CK-Link 仿真器
|
||||
- 一根 USB Type-A 数据线、一根 Type-C 数据线
|
||||
- 一个 CK-Link 仿真器 or 一个 Sipeed RV-Debugger Plus 调试器
|
||||
- 一个 USB-TTL 串口模块
|
||||
- 杜邦线若干
|
||||
|
||||
|
@ -22,9 +22,9 @@ Windows 下使用 CDK (类 MDK Keil)开发指南
|
|||
下载剑池 CDK 软件安装包
|
||||
-----------------------------
|
||||
|
||||
- `剑池CDK <https://occ.t-head.cn/development/series/download?id=3864775351511420928&type=kind&softPlatformType=4#sticky>`_ 软件安装可以从平头哥半导体 OCC 官网获取到。
|
||||
- `剑池CDK <https://occ.t-head.cn/development/series/download?id=3864775351511420928&type=kind&softPlatformType=4#sticky>`_ 软件安装可以从平头哥半导体 OCC 官网获取到
|
||||
|
||||
- 下载完成后,解压缩,双击 ``setup.exe``,按照其提示,完成软件安装即可。
|
||||
- 下载完成后,解压缩,双击 ``setup.exe``,按照其提示,完成软件安装即可
|
||||
|
||||
|
||||
下载 bl_mcu_sdk 软件开发包
|
||||
|
@ -33,7 +33,7 @@ Windows 下使用 CDK (类 MDK Keil)开发指南
|
|||
- 从开源社区下载 bl_mcu_sdk 软件开发包。
|
||||
|
||||
- 可以使用 ``git clone`` 或者直接 ``download`` 的方式下 SDK
|
||||
- 使用 ``git clone`` 前请确保已正确安装 ``git``,打开支持 ``git`` 的终端输入以下命令即可获取最新的 SDK。
|
||||
- 使用 ``git clone`` 前请确保已正确安装 ``git``,打开支持 ``git`` 的终端输入以下命令即可获取最新的 SDK
|
||||
|
||||
.. code-block:: bash
|
||||
:linenos:
|
||||
|
@ -47,16 +47,17 @@ Windows 下使用 CDK (类 MDK Keil)开发指南
|
|||
|
||||
- 具体开发板的连接, 请参考 :ref:`connect_hardware` 部分
|
||||
- 请确保开发板被正确设置后再进行下面的步骤
|
||||
|
||||
|
||||
|
||||
测试 Hello World 工程
|
||||
------------------------------
|
||||
|
||||
**使用 Sipeed RV-Debugger Plus 调试工程时请按照下面的步骤进行:**
|
||||
|
||||
打开 Hello World
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- 获取到 SDK 后,进入 sdk 中的 ``examples/hellowd/helloworld/cdk`` 目录下,双击 ``helloworld.cdkproj``,即可打开 ``Helloworld`` 工程。
|
||||
|
||||
- 获取到 SDK 后,进入 sdk 中的 ``examples/hellowd/helloworld/cdk`` 目录下,双击 ``helloworld.cdkproj``,即可打开 ``Helloworld`` 工程
|
||||
|
||||
编译 Hello World
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -66,6 +67,78 @@ Windows 下使用 CDK (类 MDK Keil)开发指南
|
|||
|
||||
helloworld.cdkproj
|
||||
|
||||
- 在活动工程下拉菜单选择 ``OpenOCD_Debug`` 工程,由于 Sipeed RV-Debugger Plus 是使用 OpenOCD 调试的,所以本教程基于 ``OpenOCD_Debug`` 工程;
|
||||
- 如 Sipeed RV-Debugger Plus 没有正确安装驱动,请参考 :ref:`sipeed_rv_debugger_plus` 部分,设置好驱动程序,在进行下面的步骤
|
||||
|
||||
- 在 CDK 工具栏中,点击编译图标即可编译工程
|
||||
|
||||
- 点击 ``1`` 处 图标 ``Build Project`` 即可编译当前选中的工程
|
||||
- 点击 ``2`` 处 图标 ``Clean Project`` 即可清除上次编译的结果
|
||||
- 点击 ``3`` 处 图标 ``Flash Download`` 即可将编译好的代码下载到芯片中 (**使用 OpenOCD Debug 不能使用 Flash 下载功能**)
|
||||
- 点击 ``4`` 处 图标 ``Start/Stop Debug`` 即可进行 debug 的相关操作
|
||||
- 也可以在 ``Project`` 中,右击工程名称,通过右击菜单中的选项对项目进行编译等操作
|
||||
|
||||
|
||||
烧写 Hello World
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- 在 CDK 中使用 OpenOCD 模式的调试方式时,暂不支持直接使用 CDK 相关 flash 工具下载代码,所以请使用 BL Dev Cube 工具进行程序烧写,烧写代码请参考 :ref:`bl_dev_cube` 部分进行
|
||||
- 代码烧写完成后使用 CDK 进行 Debug
|
||||
|
||||
运行 Hello World
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- 从 CDK 的菜单栏 ``View->Serial Pane``,打开串口面板,在打开的 ``Serial Pane`` 中右击,进行串口设置,选择你对应的串口号和波特率
|
||||
|
||||
.. figure:: img/cdk4.png
|
||||
.. figure:: img/cdk3.png
|
||||
:alt:
|
||||
|
||||
CDK Serial Pane setting
|
||||
|
||||
- 按下板子上的 ``RST`` 按键,即可在串口中看到代码的运行结果
|
||||
|
||||
.. figure:: img/cdk6.png
|
||||
:alt:
|
||||
|
||||
HelloWorld!
|
||||
|
||||
|
||||
调试 Hello World
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- 点击工具栏上方的 ``Start/Stop Debugger`` 按钮,进入 debug 界面,如下图所示
|
||||
|
||||
.. figure:: img/cdk10.png
|
||||
:alt:
|
||||
|
||||
Debug HelloWorld!
|
||||
|
||||
- 在 debug 界面下,左侧的 ``Register`` 窗口中,可以查看 ``CPU`` 内部寄存器数据;右侧的 ``Peripherals`` 外设面板中,
|
||||
可以查看相应外设寄存器数据,外设的选择可以在顶部菜单栏的 ``Peripherals->System Viewer`` 选择;
|
||||
点击上方工具栏中的相关调试按钮可以进行断点设置、单步调试、指令单步和全速运行等操作。
|
||||
当然这些操作都有相应的快捷键和快捷设置方法,详情请参考 ``CDK Help``,这里就不作过多介绍了。
|
||||
|
||||
- 我们点击单步运行按钮,运行代码,即可看到指示光标移动到下一句代码,同时可以看到串口面板中显示了我们输出的 ``Hello World!``
|
||||
|
||||
|
||||
**使用 CK-Link 调试工程时请按照下面的步骤进行:**
|
||||
|
||||
打开 Hello World
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- 获取到 SDK 后,进入 sdk 中的 ``examples/hellowd/helloworld/cdk`` 目录下,双击 ``helloworld.cdkproj``,即可打开 ``Helloworld`` 工程
|
||||
|
||||
编译 Hello World
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. figure:: img/cdk1.png
|
||||
:alt:
|
||||
|
||||
helloworld.cdkproj
|
||||
|
||||
- 在活动工程下拉菜单可以选择 ``CK_Link_Debug`` 或者 ``OpenOCD_Debug`` 工程,本教程基于 ``CK_Link_Debug`` 工程
|
||||
|
||||
- 在 CDK 工具栏中,点击编译图标即可编译工程
|
||||
|
||||
- 点击 ``1`` 处 图标 ``Build Project`` 即可编译当前选中的工程
|
||||
|
@ -94,7 +167,7 @@ Windows 下使用 CDK (类 MDK Keil)开发指南
|
|||
:alt:
|
||||
|
||||
CDK Project Setting
|
||||
|
||||
|
||||
- 点击 ``Project View`` 中的项目设置按钮,打开 ``Project Setting`` 窗口,或者通过右击 ``Project`` 名称中右击菜单栏中打开
|
||||
|
||||
- 在打开的 ``Project Setting`` 窗口中,选择 ``Flash`` 标签,配置需要的 Flash 算法
|
||||
|
@ -107,7 +180,7 @@ Windows 下使用 CDK (类 MDK Keil)开发指南
|
|||
- 在 ``Flash`` 标签中,点击 ``Add`` 按纽,在打开的列表中选择 ``bl70x_flash`` 算法,点击 ``Add`` 添加到工程中,``Flash`` 标签下的其他设置,如图所示:
|
||||
|
||||
- 点击 OK 后,如配置正确,点击 ``Flash Download`` 即可将编译好的代码下载到芯片中
|
||||
|
||||
|
||||
|
||||
.. figure:: img/cdk5.png
|
||||
:alt:
|
||||
|
@ -155,7 +228,7 @@ Windows 下使用 CDK (类 MDK Keil)开发指南
|
|||
点击上方工具栏中的相关调试按钮可以进行断点设置、单步调试、指令单步和全速运行等操作。
|
||||
当然这些操作都有相应的快捷键和快捷设置方法,详情请参考 ``CDK Help``,这里就不作过多介绍了。
|
||||
|
||||
- 我们点击单步运行按钮,运行代码,即可看到指示光标移动到下一句代码,同时可以看到串口面板中显示了我们输出的 ``Hello World!``
|
||||
- 我们点击单步运行按钮,运行代码,即可看到指示光标移动到下一句代码,同时可以看到串口面板中显示了我们输出的 ``Hello World!``
|
||||
|
||||
.. figure:: img/cdk11.png
|
||||
:alt:
|
||||
|
|
|
@ -144,7 +144,7 @@ Windows 下使用 Eclipse 开发指南
|
|||
|
||||
- 点击 eclipse 工具栏中的 ``Debug`` 按钮,进入 debug 配置窗口
|
||||
- 选择 ``GDB SEGGER J-Link Debugging->Jlink_bl_mcu_sdk`` Debug 配置,在 ``C/C++ Application:`` 选项中选择需要调试的 ``.elf`` 文件
|
||||
- 先点击 ``Apply`` 后,在点击 ``Debug`` 即可进行 ``Debug``
|
||||
- 先点击 ``Apply`` 后,在点击 ``Debug`` 即可进行 ``Debug``
|
||||
|
||||
.. figure:: img/pic14.png
|
||||
:alt:
|
||||
|
@ -153,7 +153,7 @@ Windows 下使用 Eclipse 开发指南
|
|||
|
||||
.. figure:: img/pic15.png
|
||||
:alt:
|
||||
|
||||
|
||||
Eclipse Debugging
|
||||
|
||||
|
||||
|
|
|
@ -59,17 +59,17 @@ BLDevCube 烧录工具指南
|
|||
- 硬件连接需要更改为支持 Openocd 的调试器连接(本教程以 Sipeed RV Debugger 为例):
|
||||
|
||||
- 1. 首先将 RV 调试器连接到电脑的 USB 接口,打开设备管理器,会发现调试器被识别为两个串口(注:不是开发板上的串口)
|
||||
|
||||
|
||||
.. figure:: img/sipeed_rv_debugger_1.png
|
||||
|
||||
- 2. 从 sipeed 下载 ``zadig-2.4`` 替换驱动程序。下载地址:`http://dl.sipeed.com/MAIX/tools/sipeed-rv-debugger/zadig-2.4.exe <http://dl.sipeed.com/MAIX/tools/sipeed-rv-debugger/zadig-2.4.exe>`_
|
||||
- 3. 下载好双击打开 ``zadig-2.4.exe``,选择 Options 勾选 List All Devices.
|
||||
|
||||
|
||||
.. figure:: img/sipeed_rv_debugger_3.png
|
||||
|
||||
|
||||
- 4. 找到 JTAG Debugger(Interface 0),然后选择替换的驱动为 WinUSB 点击 Replace Driver 替换
|
||||
- 5. 再次打开设备管理器, 看到其中一个串口被替换成通用串行总线设备就说明安装成功
|
||||
|
||||
|
||||
.. figure:: img/sipeed_rv_debugger_2.png
|
||||
|
||||
- 6.将调试器的 JTAG 引脚与开发板的 JTAG 引脚连接起来
|
||||
|
|
|
@ -20,8 +20,8 @@ BL706_IOT 开发板
|
|||
bl706-iot board CK-Link
|
||||
-------------------------------
|
||||
JTAG_TDI <--> TDI
|
||||
JTAG_TDO <--> TDO
|
||||
JTAG_TCK <--> TCK
|
||||
JTAG_TDO <--> TDO
|
||||
JTAG_TCK <--> TCK
|
||||
JTAG_TMS <--> TMS
|
||||
VDD33 <--> VREF
|
||||
GND <--> GND
|
||||
|
@ -45,8 +45,8 @@ BL706_IOT 开发板
|
|||
bl706-iot board j-link
|
||||
-------------------------------
|
||||
JTAG_TDI <--> TDI
|
||||
JTAG_TDO <--> TDO
|
||||
JTAG_TCK <--> TCK
|
||||
JTAG_TDO <--> TDO
|
||||
JTAG_TCK <--> TCK
|
||||
JTAG_TMS <--> TMS
|
||||
VDD33 <--> VTref
|
||||
GND <--> GND
|
||||
|
@ -82,16 +82,73 @@ BL706_IOT 开发板
|
|||
|
||||
- 烧写方法同上
|
||||
|
||||
BL702_AVB 开发板
|
||||
BL706_AVB 开发板
|
||||
--------------------------
|
||||
|
||||
.. important:: BL706_AVB 开发板有多个引脚存在复用情况,请仔细检查所需功能引脚是否被复用了;FUNC1:「Default: PIX; Connect: I2S/JTAG」,FUNC2:「Default: I2S; Connect: SPI」; **如果需要调试,请务必记得将 FUNC1 跳帽连接**
|
||||
|
||||
使用 Sipeed RV-Debugger Plus 烧写、调试连接方法
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- 将 BL706_AVB 开发板先供电
|
||||
- 将 RV-Debugger Plus 调试器连接到电脑 USB 口,如没有正确安装驱动,请参考 :ref:`sipeed_rv_debugger_plus` 部分,设置好驱动程序,在进行下面的步骤
|
||||
- 将调试器和 BL706_AVB 开发板使用排线连接起来(如下图所示)
|
||||
|
||||
.. important:: 使用调试功能是一定要将 FUNC1 跳帽连接,否则引脚被复用其他功能,不能使用 JTAG 功能;串口功能可以正常使用
|
||||
|
||||
.. figure:: img/bl706_avb_rv_debugger_plus.png
|
||||
:alt:
|
||||
|
||||
RV-Debugger connect bl706_avb board
|
||||
|
||||
使用 CK-Link 烧写、调试连接方法
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- ``TO DO``
|
||||
- 将 CK-Link USB 接口使用合适的 USB 数据线正确连接到 PC 主机
|
||||
- 将 bl706_avb 开发板的 FUNC1 跳帽短接
|
||||
- 将 ``HD8`` 组的引脚使用排线引到转接板
|
||||
- 将转接板的标准 ``JTAG`` 引脚使用杜邦线与 ``CK-Link`` 对应的 ``JTAG`` 引脚连接起来
|
||||
- 若没有使用 CK-Link 给开发板供电,需要给开发板单独供电
|
||||
|
||||
::
|
||||
|
||||
bl706-avb board CK-Link
|
||||
-------------------------------
|
||||
JTAG_TDI <--> TDI
|
||||
JTAG_TDO <--> TDO
|
||||
JTAG_TCK <--> TCK
|
||||
JTAG_TMS <--> TMS
|
||||
VDD33 <--> VREF
|
||||
GND <--> GND
|
||||
|
||||
|
||||
.. figure:: img/bl706_avb_ck_link.png
|
||||
:alt:
|
||||
|
||||
ck_link connect bl706_avb board
|
||||
|
||||
使用串口烧写程序连接方法
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- ``TO DO``
|
||||
- 使用串口烧写前,请确保正确安装了 ``Bouffalo Lab Dev Cube`` 或命令行烧写工具
|
||||
|
||||
- 使用 ``Type-C USB`` 数据线 or ``Mini USB`` 数据线连接到开发板上对应的 ``Type-C`` 接口 or ``Mini`` 接口上。
|
||||
- 按下开发板上的 ``Boot`` 键,不要释放
|
||||
- 按下开发板上的 ``RST`` 键,此时已经进入 ``Boot ROM``,可以释放两个按键
|
||||
- 这时就可以从 ``Bouffalo Lab Dev Cube`` 中看到相应的串口 ``COM`` 号,如没有出现,请点击 ``Refresh`` 按钮刷新一下
|
||||
|
||||
|
||||
- 如没有合适的数据线,也可以使用一些常见的 ``USB-TTL`` 模块,连接到开发板的 ``UART0`` 端口进行烧写。 ``UART0`` 在 ``HD12`` 组上,连接方法如下:
|
||||
|
||||
- 如果使用 Sipeed RV-Debugger Plus 通过排线连接了 BL706_AVB 开发板,则也可以使用 Sipeed RV Debugger Plus 的串口
|
||||
|
||||
::
|
||||
|
||||
USB-TTL BL706_AVB
|
||||
----------------------
|
||||
TXD <--> RX0
|
||||
RXD <--> TX0
|
||||
GND <--> GND
|
||||
|
||||
-
|
||||
|
||||
|
|
|
@ -4,30 +4,30 @@
|
|||
硬件环境准备
|
||||
-----------------------------
|
||||
|
||||
- 一块 BL702 系列 MCU 的开发板:
|
||||
- 至少有一块 BL702 系列 MCU 的开发板:
|
||||
|
||||
- BL706_IOT 开发板, or
|
||||
- BL706_IOT 开发板
|
||||
- BL706_AVB 开发板
|
||||
|
||||
BL706_Iot 开发板如下图所示
|
||||
|
||||
.. figure:: img/bl702_iot.png
|
||||
:alt:
|
||||
|
||||
|
||||
BL706_IoT
|
||||
|
||||
BL706_AVB 开发板如下图所示
|
||||
|
||||
.. figure:: img/bl706_avb.png
|
||||
:alt:
|
||||
|
||||
|
||||
BL706_AVB
|
||||
|
||||
- 一个支持标准 JTAG 功能的调试器,下面几款调试器中选择一款与开发环境适合即可:
|
||||
|
||||
- CK-Link 仿真器
|
||||
- Jlink V11 仿真器
|
||||
- Sipeed USB-JTAG/TTL 调试器
|
||||
- Sipeed RV-Debugger Plus 调试器
|
||||
- Bouffalo Lab Debugger 调试器
|
||||
|
||||
- 一台 PC 主机(运行 Windows 或者 Linux 系统)
|
||||
|
@ -35,9 +35,66 @@ BL706_AVB 开发板如下图所示
|
|||
软件环境准备
|
||||
--------------------------------
|
||||
|
||||
为了更好的进行 BL702 系列 MCU 的开发,建议您应当具备以下开发环境:
|
||||
为了更好的进行 BL702 系列 MCU 的开发,建议您应当至少具备以下一种开发环境:
|
||||
|
||||
- Windows 使用 `CDK <Windows_quick_start_cdk.html>`_ 环境开发 (建议 Windows 7 以上版本。) ,or
|
||||
- `Windows <Windows_quick_start_eclipse.html>`_ 使用 Eclipse 环境开发 (建议 Windows 7 以上版本。) ,or
|
||||
- Windows 使用 `CDK <Windows_quick_start_cdk.html>`_ 环境开发 (建议 Windows 7 以上版本)
|
||||
- `Windows <Windows_quick_start_eclipse.html>`_ 使用 Eclipse 环境开发 (建议 Windows 7 以上版本)
|
||||
- `Linux <Linux_quick_start_ubuntu.html>`_ (建议使用 Ubuntu 18 以上的 LTS 版本)
|
||||
|
||||
|
||||
.. _sipeed_rv_debugger_plus:
|
||||
|
||||
调试器驱动安装设置
|
||||
-----------------------------
|
||||
|
||||
- 本节主要介绍 **Sipeed RV-Debugger Plus** 调试器的驱动安装设置,若使用 **CK-Link** 或者 **J-Link** 无需阅读本节内容
|
||||
|
||||
.. figure:: img/sipeed_rv_debugger_plus.png
|
||||
:alt:
|
||||
|
||||
Sipeed RV-Debugger plus
|
||||
|
||||
**Windows**
|
||||
|
||||
- Sipeed RV-Debugger Plus 调试器在 Windows 系统中所以时我们需要将驱动更换为 ``Win USB`` 驱动
|
||||
|
||||
- 1. 首先,将调试器 Type-C USB 接口使用 USB 数据线连接到 PC 主机,打开 PC 的设备管理器,在端口一栏可以看到调试器被识别为两个串口(*注:不是开发板上的串口*),或者在 ``通用串行总线控制器`` 看到 ``USB Serial Converter A`` 和 ``USB Serial Converter B``
|
||||
|
||||
.. figure:: img/sipeed_rv_debugger_1.png
|
||||
|
||||
.. figure:: img/sipeed_rv_debugger_4.png
|
||||
|
||||
- 2. 从 sipeed 网站下载 ``zadig-2.4`` 替换驱动程序。下载地址:`http://dl.sipeed.com/MAIX/tools/sipeed-rv-debugger/zadig-2.4.exe <http://dl.sipeed.com/MAIX/tools/sipeed-rv-debugger/zadig-2.4.exe>`_
|
||||
- 3. 下载好双击打开 ``zadig-2.4.exe``,选择 Options 勾选 List All Devices.
|
||||
|
||||
.. figure:: img/sipeed_rv_debugger_3.png
|
||||
|
||||
- 4. 找到 JTAG Debugger(Interface 0),然后选择替换的驱动为 ``WinUSB`` 点击 Replace Driver 替换
|
||||
- 5. 再次打开设备管理器, 看到其中一个串口被替换成通用串行总线设备就说明安装成功
|
||||
|
||||
.. figure:: img/sipeed_rv_debugger_2.png
|
||||
|
||||
- 6. 到这里 Sipeed RV-Debugger Plus 的设备驱动就更换好了,接下来就可以愉快的玩耍啦~
|
||||
|
||||
|
||||
**可能出现的问题:**
|
||||
|
||||
.. caution:: 1. 调试器接上时没有出现两个串口,调试器上有一个 LED 常亮,那么应该是进入了 Boot 模式。请将调试器断电重新上电,注意先不要将调试器连接到目标板;调试器上电后,正常情况下两个 LED 灯会闪烁一下熄灭;此时再看一下任务管理器中的设备是否正确。
|
||||
|
||||
.. caution:: 2. 在设备管理器中没有看到任何串口,但是在``通用串行总线控制器``中看到 ``USB Serial Converter A`` 和 ``USB Serial Converter B``;遇到这种情况,请到 `FTDI 官网 <https://ftdichip.com/drivers/vcp-drivers/>`_ 下载与系统匹配的驱动,将 ``USB Serial Converter B`` 重新安装为串口;``USB Serial Converter A`` 也即 Interface 0,使用 ``zadig-2.4.exe`` 替换为 WinUSB 驱动。
|
||||
|
||||
**Linux**
|
||||
|
||||
- 安装 Openocd 及其需要的依赖项
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ apt install openocd libusb-dev libftdi-dev libhidapi-dev
|
||||
|
||||
- 重新插拔调试器使修改生效
|
||||
- 打开 Terminal,在终端中输入 lsusb 命令,即可看到如下信息的设备
|
||||
|
||||
.. code-block::bash
|
||||
|
||||
$ Bus 001 Device 003: ID 0403:6010 Future Technology Devices International, Ltd FT2232C Dual USB-UART/FIFO IC
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ BL MCU SDK 将为您提供博流 BL70X 系列 MCU 开发的全方位支持。
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: API 手册
|
||||
|
@ -42,28 +42,31 @@ BL MCU SDK 将为您提供博流 BL70X 系列 MCU 开发的全方位支持。
|
|||
api_reference/api_spi
|
||||
api_reference/api_adc
|
||||
api_reference/api_dac
|
||||
.. api_reference/api_ble
|
||||
|
||||
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: 基础外设例程
|
||||
:numbered:
|
||||
|
||||
samples/basic samples/blink_demo
|
||||
samples/basic samples/button_demo
|
||||
samples/basic samples/breath_pwm_demo
|
||||
samples/basic samples/uart_loopback_demo
|
||||
samples/basic samples/mtimer_demo
|
||||
samples/basic samples/dma_m2m_demo
|
||||
samples/basic samples/i2c_eeprom_demo
|
||||
samples/basic samples/spi_lcd_demo
|
||||
samples/basic samples/adc_key_demo
|
||||
samples/basic samples/gpio/index
|
||||
samples/basic samples/uart/index
|
||||
samples/basic samples/pwm/index
|
||||
samples/basic samples/mtimer/index
|
||||
samples/basic samples/dma/index
|
||||
samples/basic samples/spi/index
|
||||
samples/basic samples/i2c/index
|
||||
samples/basic samples/adc/index
|
||||
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:caption: 进阶例程
|
||||
:numbered:
|
||||
|
||||
|
||||
samples/advance samples/shell_demo
|
||||
samples/advance samples/fatfs_demo
|
||||
samples/advance samples/lowpower_demo
|
||||
|
|
|
@ -48,7 +48,7 @@ BLE client 软件实现
|
|||
uint8_t buf[20] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
|
||||
while(1)
|
||||
{
|
||||
k_sem_take(&write_data_poll_sem, K_FOREVER);
|
||||
k_sem_take(&write_data_poll_sem, K_FOREVER);
|
||||
BT_WARN("ble_write_data\r\n");
|
||||
// Send data to server
|
||||
error = bt_gatt_write_without_response(ble_tp_conn,char_hdl.tp_wr_hdl,buf,20,0);
|
||||
|
@ -75,7 +75,7 @@ BLE server 软件实现
|
|||
:linenos:
|
||||
|
||||
int ble_start_adv(void)
|
||||
{
|
||||
{
|
||||
struct bt_le_adv_param adv_param = {
|
||||
//options:3, connectable undirected, adv one time
|
||||
.options = 3, \
|
||||
|
@ -83,7 +83,7 @@ BLE server 软件实现
|
|||
.interval_max = BT_GAP_ADV_FAST_INT_MAX_3, \
|
||||
};
|
||||
|
||||
|
||||
|
||||
char *adv_name = "BL_TEST_01"; // This name must be the same as adv_name in ble_central
|
||||
uint8_t data[1] = {(BT_LE_AD_LIMITED | BT_LE_AD_NO_BREDR)};
|
||||
uint8_t data_uuid[2] = {0x12, 0x18};//0x1812
|
||||
|
@ -119,8 +119,8 @@ BLE server 软件实现
|
|||
char data[244] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};
|
||||
k_sem_give(¬ify_poll_sem);
|
||||
while(1)
|
||||
{
|
||||
k_sem_take(¬ify_poll_sem, K_FOREVER);
|
||||
{
|
||||
k_sem_take(¬ify_poll_sem, K_FOREVER);
|
||||
//send data to client
|
||||
err = bt_gatt_notify(ble_tp_conn, get_attr(BT_CHAR_BLE_TP_NOT_ATTR_VAL_INDEX), data, (tx_mtu_size - 3));
|
||||
BT_WARN("ble tp send notify : %d\n", err);
|
||||
|
@ -168,7 +168,7 @@ BLE server 软件实现
|
|||
.. figure:: img/ble_server.png
|
||||
:alt:
|
||||
|
||||
|
||||
|
||||
- **手机连接 bl702**
|
||||
|
||||
.. figure:: img/phone_connect.jpg
|
||||
|
|
|
@ -25,4 +25,4 @@ bl_mcu_sdk 开源了 boot2_iap 的软件源码,用户可以到 examples/boot2_
|
|||
实验现象
|
||||
-----------------------------
|
||||
|
||||
使用 Dev Cube 完成 IAP 功能的具体步骤,请参阅 `DevCube用户手册 <https://dev.bouffalolab.com/media/upload/doc/DevCube%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8Cv1.2.pdf>`_ <IAP 程序下载>章节。
|
||||
使用 Dev Cube 完成 IAP 功能的具体步骤,请参阅 `DevCube用户手册 <https://dev.bouffalolab.com/media/upload/doc/DevCube%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8Cv1.3.pdf>`_ <IAP 程序下载>章节。
|
|
@ -5,13 +5,13 @@ LowPower 低功耗评估
|
|||
------------------------
|
||||
|
||||
博流系列芯片拥有丰富的低功耗特性,以适配不同的低功耗应用场合。为了方便用户快速的评测使用 bl 系列 MCU 低功耗性能 bl_mcu_sdk 提供了一套抽象的低功耗接口,将低功耗等级分为四个等级,分别为
|
||||
|
||||
|
||||
1. Running : Running 为 CPU 正常运行时的功耗,由客户应用代码执行的功能决定功耗。
|
||||
|
||||
|
||||
2. WFI :WFI 模式,CPU 的 clock 处于被 Gating 状态,CPU 停止运行,当用户退出WFI模式的时候程序将会继续运行。
|
||||
|
||||
|
||||
3. PDS : PDS 模式,关闭了芯片上大多数电源域,同时关闭了 CPU,和 CPU 处于同一个电源域的 ITCM,DTCM 等 RAM 不可使用,只有 64K 的 OCTAM 可以保存数据,可以通过内部 RTC 进行唤醒,或者使用 GPIO 引脚(在 GPIO 电源域没有关闭的情况下)唤醒。
|
||||
|
||||
|
||||
4. HBN : HBN 模式,关闭了芯片上绝大多数电源域,关闭了 CPU 以及 64K OCRAM,只有位于 AON 域的 4K RAM 可以保存数据,可以通过内部 RTC 进行唤醒,或者使用特定的唤醒引脚(位于 AON 域的引脚)唤醒。
|
||||
|
||||
|
||||
|
@ -59,7 +59,7 @@ bl_mcu_sdk 提供了一个简单的低功耗参考示例(bl_mcu_sdk examples/pow
|
|||
- 电流表
|
||||
- 一台 PC 主机(运行 Windows 或者 Linux 系统)
|
||||
- TTL 转 USB
|
||||
|
||||
|
||||
如下图所示,将电流表串联进入 bl706 模组的供电线路,通过 PC 端的串口调试助手软件,下发不同的低功耗指令,使得 bl706 进入对应的低功耗模式
|
||||
观察电流表示值,完成评估。
|
||||
|
||||
|
|
|
@ -1,32 +1,198 @@
|
|||
SHELL 命令行调试
|
||||
====================
|
||||
|
||||
为方便用户使用 pc 或者其他控制器对开发板进行功能的调试(非仿真器调试),这里提供了 shell 命令行组件,类似于在 linux 下进行命令行操作。用户在 PC 端或者其他控制端进行命令的发送,通过串口、usb、以太网、蓝牙、wifi等方式,将数据发送给开发板的 shell 中,shell 会读取接收的命令进行解析并对已经注册的内部函数扫描,扫描到与之匹配的函数以后,执行匹配的函数,并实时返回传入的键值和函数执行的结果给 pc or 控制端。其中需要注意,控制器端需要发送标准键盘的键值。
|
||||
为方便用户使用 pc 或者其他控制器对开发板进行功能的调试(非仿真器调试),我们为用户提供了 shell 命令行组件,类似于在 linux 下进行命令行操作。用户在 PC 端或者其他控制端进行命令的发送,通过串口、usb、以太网、蓝牙、wifi等方式,将数据发送给开发板的 shell 中,shell 会读取接收的命令进行解析并对已经注册的内部函数扫描,扫描到与之匹配的函数以后,执行匹配的函数,并实时返回传入的键值和函数执行的结果给 pc or 控制端。其中需要注意,控制器端需要发送标准键盘的键值。
|
||||
本 demo 将演示如何使用 **shell** 通过串口进行命令行调试。
|
||||
|
||||
本 shell 组件有以下功能:
|
||||
|
||||
- 支持标准键盘字符控制
|
||||
- 支持命令自动补全
|
||||
- 支持上下键查看历史命令
|
||||
- 支持左右键修改命令
|
||||
- 支持文件系统、网络系统调试
|
||||
|
||||
准备工具
|
||||
-----------------------
|
||||
|
||||
- pc控制端使用串口终端软件:xshell或者mobaxterm
|
||||
- pc控制端使用串口终端软件:xshell 或者 mobaxterm
|
||||
- 连接介质:usb转串口 or 网络 or usb
|
||||
|
||||
硬件连接
|
||||
-----------------------------
|
||||
|
||||
本 demo 基于 BL706_IOT 开发板,连接方式如下
|
||||
|
||||
::
|
||||
|
||||
GPIO function GPIO pin
|
||||
----------------------------------
|
||||
UART0_TX <--> GPIO14
|
||||
UART0_RX <--> GPIO15
|
||||
|
||||
|
||||
软件实现
|
||||
-------------------------
|
||||
|
||||
串口中使用 SHELL
|
||||
shell 移植到串口
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
BLE 中使用 SHELL
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
- 软件代码见 ``examples/shell``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
#define BSP_UART_CLOCK_SOURCE ROOT_CLOCK_SOURCE_PLL_96M
|
||||
#define BSP_UART_CLOCK_DIV 0
|
||||
|
||||
- 配置 ``UART`` 设备时钟源,见 ``bsp/board/bl706_iot/clock_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
#define CONFIG_GPIO14_FUNC GPIO_FUN_UART0_TX
|
||||
#define CONFIG_GPIO15_FUNC GPIO_FUN_UART0_RX
|
||||
|
||||
- 配置 ``UART`` 设备复用引脚,见 ``bsp/board/bl706_iot/pinmux_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
#define BSP_USING_UART0
|
||||
|
||||
#if defined(BSP_USING_UART0)
|
||||
#ifndef UART0_CONFIG
|
||||
#define UART0_CONFIG \
|
||||
{ \
|
||||
.id = 0, \
|
||||
.baudrate = 2000000,\
|
||||
.databits = UART_DATA_LEN_8, \
|
||||
.stopbits = UART_STOP_ONE, \
|
||||
.parity = UART_PAR_NONE, \
|
||||
.fifo_threshold = 1, \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
- 使能 ``BSP_USING_UART0`` 并配置 ``UART`` 设备配置,见 ``bsp/board/bl706_iot/peripheral_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
bflb_platform_init();
|
||||
|
||||
- 在 ``bflb_platform_init`` 函数中,我们已经注册并且打开了一个调试用的串口设备,给用户实现一个 ``MSG`` 的基本功能用作打印输出报文。具体实现如下
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
uart_register(board_get_debug_uart_index(), "debug_log", DEVICE_OFLAG_RDWR);
|
||||
struct device *uart = device_find("debug_log");
|
||||
|
||||
if (uart)
|
||||
{
|
||||
device_open(uart, DEVICE_OFLAG_STREAM_TX | DEVICE_OFLAG_INT_RX);
|
||||
device_set_callback(uart, NULL);
|
||||
device_control(uart, DEVICE_CTRL_CLR_INT, (void *)(UART_RX_FIFO_IT));
|
||||
}
|
||||
|
||||
- 首先调用 ``uart_register`` 函数注册 ``UART`` 设备,当前注册 ``UART0``
|
||||
- 然后通过 ``find`` 函数找到设备对应的句柄,保存于 ``uart`` 句柄中
|
||||
- 最后使用 ``device_open`` 以轮询发送和中断接收来打开 ``uart`` 设备,默认关闭中断并且不注册接收中断回调函数
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
struct device *uart = device_find("debug_log");
|
||||
if (uart) {
|
||||
device_set_callback(uart, shell_irq_callback);
|
||||
device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT));
|
||||
}
|
||||
|
||||
- 通过 ``device_set_callback`` 函数,为 ``UART0`` 注册接收中断服务函数。通过 ``device_control`` 函数打开 ``UART_RX_FIFO_IT`` 中断
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
void shell_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t state)
|
||||
{
|
||||
uint8_t data;
|
||||
if (state == UART_EVENT_RX_FIFO) {
|
||||
data = *(uint8_t *)args;
|
||||
shell_handler(data);
|
||||
}
|
||||
}
|
||||
|
||||
- 中断回调函数中,判断 ``state`` 是否是 ``UART_EVENT_RX_FIFO``,是的话就将接收的字节传入 ``shell_handler`` 函数。
|
||||
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
shell_init();
|
||||
|
||||
- 调用 ``shell_init`` 初始化 shell 组件。
|
||||
|
||||
以太网中使用 SHELL
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
SHELL 命令注册
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
shell 命令注册使用以下两个宏
|
||||
|
||||
- **SHELL_CMD_EXPORT**
|
||||
|
||||
``SHELL_CMD_EXPORT`` 有两个参数,``command`` 代表需要注册的函数名,pc 或者控制器将发送 ``command`` 对设备进行命令控制,desc`` 是对该注册函数的描述,
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
void hellowd()
|
||||
{
|
||||
MSG("hello World\r\n");
|
||||
}
|
||||
SHELL_CMD_EXPORT(hellowd, hellowd test)
|
||||
|
||||
- **SHELL_CMD_EXPORT_ALIAS**
|
||||
|
||||
``SHELL_CMD_EXPORT_ALIAS`` 有三个参数,``command`` 代表需要注册的函数名,``alias`` 是对该注册函数名重命名,pc 或者控制器将发送 ``alias`` 对设备进行命令控制,``desc`` 是对该注册函数的描述,
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
void hellowd()
|
||||
{
|
||||
MSG("hello World\r\n");
|
||||
}
|
||||
SHELL_CMD_EXPORT_ALIAS(hellowd, hellwd,hellowd test)
|
||||
|
||||
|
||||
编译和烧录
|
||||
-----------------------------
|
||||
|
||||
- **CDK 编译**
|
||||
|
||||
打开项目中提供的工程文件:shell.cdkproj
|
||||
|
||||
参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可
|
||||
|
||||
- **命令行编译**
|
||||
|
||||
.. code-block:: bash
|
||||
:linenos:
|
||||
|
||||
$ cd <sdk_path>/bl_mcu_sdk
|
||||
$ make BOARD=bl706_iot APP=shell SUPPORT_SHELL=y
|
||||
|
||||
- **烧录**
|
||||
|
||||
详见 :ref:`bl_dev_cube`
|
||||
|
||||
|
||||
实验现象
|
||||
-----------------------------
|
||||
|
||||
.. figure:: img/shell_demo.gif
|
||||
:alt:
|
||||
|
||||
shell test
|
||||
|
||||
|
|
|
@ -31,14 +31,14 @@ ADC - 按键检测电压
|
|||
#define BSP_ADC_CLOCK_SOURCE ROOT_CLOCK_SOURCE_XCLK
|
||||
#define BSP_ADC_CLOCK_DIV 0
|
||||
|
||||
- 配置 ``ADC`` 设备时钟源,见 ``bsp/board/bl706_avb/clock_config.h``
|
||||
- 配置 ``ADC`` 设备时钟源,见 ``bsp/board/bl706_avb/clock_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
#define CONFIG_GPIO18_FUNC GPIO_FUN_ADC
|
||||
|
||||
- 配置 ``ADC`` 设备复用引脚,见 ``bsp/board/bl706_iot/pinmux_config.h``
|
||||
- 配置 ``ADC`` 设备复用引脚,见 ``bsp/board/bl706_iot/pinmux_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
@ -78,7 +78,7 @@ ADC - 按键检测电压
|
|||
ADC_DEV(adc_key)->continuous_conv_mode = ENABLE;
|
||||
device_open(adc_key, DEVICE_OFLAG_STREAM_RX);
|
||||
device_control(adc_key,DEVICE_CTRL_ADC_CHANNEL_CONFIG,&adc_channel_cfg);
|
||||
|
||||
|
||||
}else{
|
||||
MSG("device open failed\r\n");
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ ADC - 按键检测电压
|
|||
- **CDK工具编译**
|
||||
|
||||
打开项目中提供的工程文件:adc_key.cdkproj
|
||||
|
||||
|
||||
参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可
|
||||
|
||||
- **命令行编译**
|
|
@ -0,0 +1,9 @@
|
|||
=======================
|
||||
ADC 示例
|
||||
=======================
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
ADC - 按键检测电压 <adc_key_demo>
|
|
@ -56,7 +56,7 @@ DMA - RAM间数据搬运
|
|||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
dma_reload(dma,(uint32_t)dma_src_buffer,(uint32_t)dma_dst_buffer,8000);
|
||||
dma_reload(dma,(uint32_t)dma_src_buffer,(uint32_t)dma_dst_buffer,8000);
|
||||
dma_channel_start(dma);
|
||||
|
||||
- 调用 ``dma_reload`` 函数对dma 通道0的配置进行补充,``DMA0_CH0_CONFIG`` 中已经补充了一部分配置,这边主要补充源数据地址和目标数据地址以及传输总长度
|
||||
|
@ -92,7 +92,7 @@ DMA - RAM间数据搬运
|
|||
- **CDK 编译**
|
||||
|
||||
打开项目中提供的工程文件:dma_m2m.cdkproj
|
||||
|
||||
|
||||
参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可
|
||||
|
||||
- **命令行编译**
|
|
@ -0,0 +1,9 @@
|
|||
=======================
|
||||
DMA 示例
|
||||
=======================
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
DMA - RAM间数据搬运 <dma_m2m_demo>
|
|
@ -42,7 +42,7 @@ GPIO 中断 - 按键检测
|
|||
- **CDK 编译**
|
||||
|
||||
打开项目中提供的工程文件:gpio_int.cdkproj
|
||||
|
||||
|
||||
参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可
|
||||
|
||||
- **命令行编译**
|
|
@ -0,0 +1,10 @@
|
|||
=======================
|
||||
GPIO 示例
|
||||
=======================
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
GPIO 输出 - 流水灯 <blink_demo>
|
||||
GPIO 中断 - 流水灯 <button_demo>
|
|
@ -25,7 +25,7 @@ I2C - AT24CXX 读写
|
|||
#define BSP_I2C_CLOCK_SOURCE ROOT_CLOCK_SOURCE_BCLK
|
||||
#define BSP_I2C_CLOCK_DIV 0
|
||||
|
||||
- 配置 ``I2C`` 设备时钟源,见 ``bsp/board/bl706_iot/clock_config.h``
|
||||
- 配置 ``I2C`` 设备时钟源,见 ``bsp/board/bl706_iot/clock_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
@ -33,7 +33,7 @@ I2C - AT24CXX 读写
|
|||
#define CONFIG_GPIO11_FUNC GPIO_FUN_I2C
|
||||
#define CONFIG_GPIO16_FUNC GPIO_FUN_I2C
|
||||
|
||||
- 配置 ``I2C`` 设备复用引脚,见 ``bsp/board/bl706_iot/peripheral_config.h``
|
||||
- 配置 ``I2C`` 设备复用引脚,见 ``bsp/board/bl706_iot/peripheral_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
@ -97,7 +97,7 @@ I2C - AT24CXX 读写
|
|||
- **CDK 编译**
|
||||
|
||||
打开项目中提供的工程文件:i2c_at24cxx.cdkproj
|
||||
|
||||
|
||||
参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可
|
||||
|
||||
- **命令行编译**
|
|
@ -0,0 +1,9 @@
|
|||
=======================
|
||||
I2C 示例
|
||||
=======================
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
I2C - AT24CXX 读写 <i2c_eeprom_demo>
|
|
@ -0,0 +1,9 @@
|
|||
=======================
|
||||
MTIMER 示例
|
||||
=======================
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
MTIMER - 系统定时器 <mtimer_demo>
|
|
@ -1,4 +1,4 @@
|
|||
MTIMER - 内核定时器
|
||||
MTIMER - 系统定时器
|
||||
====================
|
||||
|
||||
本 demo 基于 risc-v 内核自带的一个 64 位定时器(MTIMER)编写。本 demo 可以为后面 os tick 提供参考。
|
||||
|
@ -11,7 +11,7 @@ MTIMER - 内核定时器
|
|||
-----------------------------
|
||||
|
||||
- 软件代码见 ``examples/systick``
|
||||
|
||||
|
||||
.. note:: ``mtimer`` 时钟默认经过分频以后为 1M,方便后面使用,减少计算时间。
|
||||
|
||||
.. code-block:: C
|
||||
|
@ -34,7 +34,7 @@ MTIMER - 内核定时器
|
|||
- **CDK 编译**
|
||||
|
||||
打开项目中提供的工程文件:systick.cdkproj
|
||||
|
||||
|
||||
参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可
|
||||
|
||||
- **命令行编译**
|
||||
|
@ -44,7 +44,7 @@ MTIMER - 内核定时器
|
|||
|
||||
$ cd <sdk_path>/bl_mcu_sdk
|
||||
$ make BOARD=bl706_iot APP=systick
|
||||
|
||||
|
||||
- **烧录**
|
||||
|
||||
详见 :ref:`bl_dev_cube`
|
||||
|
@ -52,4 +52,4 @@ MTIMER - 内核定时器
|
|||
实验现象
|
||||
-----------------------------
|
||||
|
||||
``tick`` 值每秒自增 1 并通过串口打印。
|
||||
``tick`` 值每秒自增 1 并通过串口打印。
|
|
@ -0,0 +1,10 @@
|
|||
=======================
|
||||
PWM 示例
|
||||
=======================
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
PWM - 呼吸灯 <pwm_breath_demo>
|
||||
PWM - 驱动步进电机 <pwm_step_motor>
|
|
@ -1,7 +1,7 @@
|
|||
PWM - 呼吸灯
|
||||
====================
|
||||
|
||||
本demo基于PWM外设轮询模式编写。
|
||||
本 demo 基于 PWM 外设轮询模式编写。
|
||||
|
||||
硬件连接
|
||||
-----------------------------
|
||||
|
@ -22,12 +22,20 @@ PWM - 呼吸灯
|
|||
|
||||
- 软件代码见 ``examples/pwm/pwm_breath_led``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
#define BSP_PWM_CLOCK_SOURCE ROOT_CLOCK_SOURCE_XCLK
|
||||
#define BSP_PWM_CLOCK_DIV 1
|
||||
|
||||
- 配置 ``PWM`` 设备时钟源,见 ``bsp/board/bl706_iot/clock_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
#define CONFIG_GPIO22_FUNC GPIO_FUN_PWM
|
||||
|
||||
- 配置 ``PWM`` 设备复用引脚,见 ``bsp/board/bl706_iot/pinmux_config.h``
|
||||
- 配置 ``PWM`` 设备复用引脚,见 ``bsp/board/bl706_iot/pinmux_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
@ -51,12 +59,14 @@ PWM - 呼吸灯
|
|||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
pwm_register(PWM_CH2_INDEX, "led_breath", DEVICE_OFLAG_RDWR);
|
||||
pwm_register(PWM_CH2_INDEX, "led_breath", DEVICE_OFLAG_RDWR);
|
||||
|
||||
struct device *led_breath = device_find("led_breath");
|
||||
|
||||
if (led_breath)
|
||||
{
|
||||
if (led_breath) {
|
||||
PWM_DEV(led_breath)->period = 32; //frequence = 32M/1/32 = 1Mhz
|
||||
PWM_DEV(led_breath)->threshold_low = 16;
|
||||
PWM_DEV(led_breath)->threshold_high = 32;
|
||||
device_open(led_breath, DEVICE_OFLAG_STREAM_TX);
|
||||
pwm_channel_start(led_breath);
|
||||
}
|
||||
|
@ -64,19 +74,23 @@ PWM - 呼吸灯
|
|||
|
||||
- 首先调用 ``pwm_register`` 函数注册 ``PWM`` 设备的一个通道,当前注册 ``PWM_CH2``
|
||||
- 然后通过 ``find`` 函数找到设备对应的句柄,保存于 ``led_breath`` 句柄中
|
||||
- 设置 ``PWM_CH2`` 的频率为 1Mhz,占空比为50%
|
||||
- 使用 ``device_open`` 以轮询模式来打开 ``led_breath`` 设备
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
pwm_config_t pwm_cfg = {
|
||||
1000000,
|
||||
0,
|
||||
};
|
||||
|
||||
device_control(led_breath, DEVICE_CTRL_CONFIG, &pwm_cfg);
|
||||
for (pwm_cfg.threshold_high = 0; pwm_cfg.threshold_high <= 32; pwm_cfg.threshold_high++) {
|
||||
device_control(led_breath, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg);
|
||||
bflb_platform_delay_ms(50);
|
||||
}
|
||||
|
||||
- 使用 ``device_contorl`` 函数,配合 ``DEVICE_CTRL_CONFIG`` 指令,可以修改当前 PWM 通道的频率和占空比。
|
||||
for (pwm_cfg.threshold_high = 32; 0 <= pwm_cfg.threshold_high && pwm_cfg.threshold_high <= 32; pwm_cfg.threshold_high--) {
|
||||
device_control(led_breath, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg);
|
||||
bflb_platform_delay_ms(50);
|
||||
}
|
||||
|
||||
- 使用 ``device_contorl`` 函数,配合 ``DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG`` 指令,可以修改当前 PWM 通道的占空比。
|
||||
|
||||
编译和烧录
|
||||
-----------------------------
|
||||
|
@ -84,7 +98,7 @@ PWM - 呼吸灯
|
|||
- **CDK 编译**
|
||||
|
||||
打开项目中提供的工程文件:pwm_breath_led.cdkproj
|
||||
|
||||
|
||||
参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可
|
||||
|
||||
- **命令行编译**
|
||||
|
@ -104,7 +118,7 @@ PWM - 呼吸灯
|
|||
-----------------------------
|
||||
|
||||
|
||||
.. figure:: img/pwm_demo.gif
|
||||
.. figure:: img/pwm_demo.gif
|
||||
:alt:
|
||||
|
||||
pwm breath led!
|
|
@ -0,0 +1,281 @@
|
|||
PWM - 驱动步进电机
|
||||
====================
|
||||
|
||||
步进电机是一种将电脉冲转化为角位移的执行机构。当步进驱动器接收到一个脉冲信号,它就驱动步进电机按设定的方向转动一个固定的角度(及步进角)。可以通过控制脉冲个来控制角位移量,从而达到准确定位的目的;同时可以通过控制脉冲频率来控制电机转动的速度和加速度,从而达到调速的目的。
|
||||
|
||||
本 demo 采用步进电机 28BYJ48 型四相八拍电机,使用 ULN2003 芯片驱动,电压为 DC5V—DC12V。当对步进电机施加一系列连续不断的控制脉冲时,它可以连续不断地转动。每一个脉冲信号对应步进电机的某一相或两相绕组的通电状态改变一次,也就对应转子转过一定的角度(一个步距角)。当通电状态的改变完成一个循环时,转子转过一个齿距。
|
||||
|
||||
.. figure:: img/step_motor.png
|
||||
:alt:
|
||||
|
||||
28BYJ48
|
||||
|
||||
.. figure:: img/uln2003.png
|
||||
:alt:
|
||||
|
||||
ULN2003
|
||||
|
||||
这个步进电机内部有个真正的步进马达转子,每一个脉冲能使这个真正的转子转动5.625°,看下图的数据表格中的减速比是1:64,意思是这个真正的步进马达转子转动64周才能让输出轴转动1周,因此下图的表格中步距角度才写的是5.625°/64,表明的意思是一个脉冲可以让输出轴转动5.625°/64的角度。所以要让马达转一周(360°), 则需要360/5.625*64=4096个脉冲。
|
||||
脉冲(或拍)的数量决定转动的角度,单位时间内脉冲(或拍)的数量决定转动的速度
|
||||
|
||||
.. figure:: img/step_motor_info.png
|
||||
:alt:
|
||||
|
||||
四相步进电机可以在不同的通电方式下运行,常见的通电方式有如下三种:
|
||||
|
||||
- 一相励磁:单(单相绕组通电)四拍(A+,B+,A-,B-......)
|
||||
|
||||
.. figure:: img/pwm_step_motor1.png
|
||||
:alt:
|
||||
|
||||
- 二相励磁:双(双相绕组通电)四拍(A+B+,B+A-,A-B-,B-A+......)
|
||||
|
||||
.. figure:: img/pwm_step_motor2.png
|
||||
:alt:
|
||||
|
||||
- 一二相励磁:八拍(A+B+,B+,B+A-,A-,A-B-,B-,B-A+,A+......)
|
||||
|
||||
.. figure:: img/pwm_step_motor3.png
|
||||
:alt:
|
||||
|
||||
|
||||
硬件连接
|
||||
-----------------------------
|
||||
|
||||
本 demo 基于BL706_IOT开发板,连接方式如下
|
||||
|
||||
::
|
||||
|
||||
GPIO function GPIO pin
|
||||
----------------------------------
|
||||
PWM_CH0 <--> GPIO10
|
||||
PWM_CH1 <--> GPIO11
|
||||
PWM_CH2 <--> GPIO12
|
||||
PWM_CH3 <--> GPIO3
|
||||
|
||||
.. figure:: img/pwm_step_motor.png
|
||||
:alt:
|
||||
|
||||
参考电路
|
||||
|
||||
软件实现
|
||||
-----------------------------
|
||||
|
||||
- 软件代码见 ``examples/pwm/pwm_step_motor``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
#define BSP_PWM_CLOCK_SOURCE ROOT_CLOCK_SOURCE_RC_32K
|
||||
#define BSP_PWM_CLOCK_DIV 32
|
||||
|
||||
- 配置 ``PWM`` 设备时钟源,见 ``bsp/board/bl706_iot/clock_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
#define CONFIG_GPIO3_FUNC GPIO_FUN_PWM
|
||||
#define CONFIG_GPIO10_FUNC GPIO_FUN_PWM
|
||||
#define CONFIG_GPIO11_FUNC GPIO_FUN_PWM
|
||||
#define CONFIG_GPIO12_FUNC GPIO_FUN_PWM
|
||||
|
||||
- 配置 ``PWM`` 设备复用引脚,见 ``bsp/board/bl706_iot/pinmux_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
#define BSP_USING_PWM_CH0
|
||||
#define BSP_USING_PWM_CH1
|
||||
#define BSP_USING_PWM_CH2
|
||||
#define BSP_USING_PWM_CH3
|
||||
|
||||
#if defined(BSP_USING_PWM_CH0)
|
||||
#ifndef PWM_CH0_CONFIG
|
||||
#define PWM_CH0_CONFIG \
|
||||
{ \
|
||||
.ch = 0, \
|
||||
.polarity_invert_mode = DISABLE, \
|
||||
.period = 0, \
|
||||
.threshold_low = 0, \
|
||||
.threshold_high = 0, \
|
||||
.it_pulse_count = 0, \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(BSP_USING_PWM_CH1)
|
||||
#ifndef PWM_CH1_CONFIG
|
||||
#define PWM_CH1_CONFIG \
|
||||
{ \
|
||||
.ch = 1, \
|
||||
.polarity_invert_mode = DISABLE, \
|
||||
.period = 0, \
|
||||
.threshold_low = 0, \
|
||||
.threshold_high = 0, \
|
||||
.it_pulse_count = 0, \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(BSP_USING_PWM_CH2)
|
||||
#ifndef PWM_CH2_CONFIG
|
||||
#define PWM_CH2_CONFIG \
|
||||
{ \
|
||||
.ch = 2, \
|
||||
.polarity_invert_mode = DISABLE, \
|
||||
.period = 0, \
|
||||
.threshold_low = 0, \
|
||||
.threshold_high = 0, \
|
||||
.it_pulse_count = 0, \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(BSP_USING_PWM_CH3)
|
||||
#ifndef PWM_CH3_CONFIG
|
||||
#define PWM_CH3_CONFIG \
|
||||
{ \
|
||||
.ch = 3, \
|
||||
.polarity_invert_mode = DISABLE, \
|
||||
.period = 0, \
|
||||
.threshold_low = 0, \
|
||||
.threshold_high = 0, \
|
||||
.it_pulse_count = 0, \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
- 使能 ``BSP_USING_PWM_CH0``, ``BSP_USING_PWM_CH1`` , ``BSP_USING_PWM_CH2``, ``BSP_USING_PWM_CH3`` 并配置 ``PWM`` 设备配置,见 ``bsp/board/bl706_iot/peripheral_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
pwm_register(PWM_CH0_INDEX, "motor_ch0", DEVICE_OFLAG_RDWR);
|
||||
pwm_register(PWM_CH1_INDEX, "motor_ch1", DEVICE_OFLAG_RDWR);
|
||||
pwm_register(PWM_CH2_INDEX, "motor_ch2", DEVICE_OFLAG_RDWR);
|
||||
pwm_register(PWM_CH3_INDEX, "motor_ch3", DEVICE_OFLAG_RDWR);
|
||||
|
||||
motor_ch0 = device_find("motor_ch0");
|
||||
motor_ch1 = device_find("motor_ch1");
|
||||
motor_ch2 = device_find("motor_ch2");
|
||||
motor_ch3 = device_find("motor_ch3");
|
||||
|
||||
if (motor_ch0) {
|
||||
PWM_DEV(motor_ch0)->period = 8; //frequence = 32K/160/8 = 25hz
|
||||
PWM_DEV(motor_ch0)->threshold_low = 2;
|
||||
PWM_DEV(motor_ch0)->threshold_high = 7;
|
||||
PWM_DEV(motor_ch0)->polarity_invert_mode = ENABLE;
|
||||
device_open(motor_ch0, DEVICE_OFLAG_STREAM_TX);
|
||||
}
|
||||
if (motor_ch1) {
|
||||
PWM_DEV(motor_ch1)->period = 8; //frequence = 32K/160/8 = 25hz
|
||||
PWM_DEV(motor_ch1)->threshold_low = 1;
|
||||
PWM_DEV(motor_ch1)->threshold_high = 4;
|
||||
device_open(motor_ch1, DEVICE_OFLAG_STREAM_TX);
|
||||
}
|
||||
if (motor_ch2) {
|
||||
PWM_DEV(motor_ch2)->period = 8; //frequence = 32K/160/8 = 25hz
|
||||
PWM_DEV(motor_ch2)->threshold_low = 3;
|
||||
PWM_DEV(motor_ch2)->threshold_high = 6;
|
||||
device_open(motor_ch2, DEVICE_OFLAG_STREAM_TX);
|
||||
}
|
||||
if (motor_ch3) {
|
||||
PWM_DEV(motor_ch3)->period = 8; //frequence = 32K/160/8 = 25hz
|
||||
PWM_DEV(motor_ch3)->threshold_low = 5;
|
||||
PWM_DEV(motor_ch3)->threshold_high = 8;
|
||||
device_open(motor_ch3, DEVICE_OFLAG_STREAM_TX);
|
||||
}
|
||||
pwm_channel_start(motor_ch0);
|
||||
pwm_channel_start(motor_ch1);
|
||||
pwm_channel_start(motor_ch2);
|
||||
pwm_channel_start(motor_ch3);
|
||||
|
||||
|
||||
- 首先调用 ``pwm_register`` 函数注册 ``PWM`` 设备的一个通道,当前注册 PWM 通道0/1/2/3
|
||||
- 然后通过 ``find`` 函数找到设备对应的句柄,保存于4个句柄中
|
||||
- 设置 4个通道 的频率为 125hz,占空比为37.5%
|
||||
- 使用 ``device_open`` 以轮询模式来打开 4个通道
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
||||
enum motor_dir_type {
|
||||
CW,
|
||||
CCW,
|
||||
STOP
|
||||
};
|
||||
|
||||
void motor_set_dir(enum motor_dir_type dir)
|
||||
{
|
||||
pwm_dutycycle_config_t pwm_cfg[4];
|
||||
|
||||
if (dir == CW) {
|
||||
pwm_cfg[0].threshold_low = 2;
|
||||
pwm_cfg[0].threshold_high = 7;
|
||||
pwm_cfg[1].threshold_low = 1;
|
||||
pwm_cfg[1].threshold_high = 4;
|
||||
pwm_cfg[2].threshold_low = 3;
|
||||
pwm_cfg[2].threshold_high = 6;
|
||||
pwm_cfg[3].threshold_low = 5;
|
||||
pwm_cfg[3].threshold_high = 8;
|
||||
}
|
||||
|
||||
else if (dir == CCW) {
|
||||
pwm_cfg[0].threshold_low = 2;
|
||||
pwm_cfg[0].threshold_high = 7;
|
||||
pwm_cfg[1].threshold_low = 5;
|
||||
pwm_cfg[1].threshold_high = 8;
|
||||
pwm_cfg[2].threshold_low = 3;
|
||||
pwm_cfg[2].threshold_high = 6;
|
||||
pwm_cfg[3].threshold_low = 1;
|
||||
pwm_cfg[3].threshold_high = 4;
|
||||
} else if (dir == STOP) {
|
||||
pwm_cfg[0].threshold_low = 0;
|
||||
pwm_cfg[0].threshold_high = 0;
|
||||
pwm_cfg[1].threshold_low = 0;
|
||||
pwm_cfg[1].threshold_high = 0;
|
||||
pwm_cfg[2].threshold_low = 0;
|
||||
pwm_cfg[2].threshold_high = 0;
|
||||
pwm_cfg[3].threshold_low = 0;
|
||||
pwm_cfg[3].threshold_high = 0;
|
||||
}
|
||||
device_control(motor_ch0, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[0]);
|
||||
device_control(motor_ch1, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[1]);
|
||||
device_control(motor_ch2, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[2]);
|
||||
device_control(motor_ch3, DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG, &pwm_cfg[3]);
|
||||
}
|
||||
|
||||
- 使用 ``device_contorl`` 函数,配合 ``DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG`` 指令,修改4个 PWM 通道的的高低阈值。
|
||||
|
||||
.. note:: 该函数的功能主要用于切换步进电机的方向
|
||||
|
||||
编译和烧录
|
||||
-----------------------------
|
||||
|
||||
- **CDK 编译**
|
||||
|
||||
打开项目中提供的工程文件:pwm_step_motor.cdkproj
|
||||
|
||||
参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可
|
||||
|
||||
- **命令行编译**
|
||||
|
||||
.. code-block:: bash
|
||||
:linenos:
|
||||
|
||||
$ cd <sdk_path>/bl_mcu_sdk
|
||||
$ make BOARD=bl706_iot APP=pwm_step_motor
|
||||
|
||||
- **烧录**
|
||||
|
||||
详见 :ref:`bl_dev_cube`
|
||||
|
||||
|
||||
实验现象
|
||||
-----------------------------
|
||||
|
||||
.. figure:: img/pwm_step_motor.gif
|
||||
:alt:
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
=======================
|
||||
SPI 示例
|
||||
=======================
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
SPI - TFT LCD 显示 <spi_lcd_demo>
|
|
@ -28,7 +28,7 @@ SPI - TFT LCD 显示
|
|||
#define BSP_SPI_CLOCK_SOURCE ROOT_CLOCK_SOURCE_BCLK
|
||||
#define BSP_SPI_CLOCK_DIV 0
|
||||
|
||||
- 配置 ``SPI`` 设备时钟源,见 ``bsp/board/bl706_avb/clock_config.h``
|
||||
- 配置 ``SPI`` 设备时钟源,见 ``bsp/board/bl706_avb/clock_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
@ -37,7 +37,7 @@ SPI - TFT LCD 显示
|
|||
#define CONFIG_GPIO20_FUNC GPIO_FUN_SPI
|
||||
#define CONFIG_GPIO21_FUNC GPIO_FUN_SPI
|
||||
|
||||
- 配置 ``SPI`` 设备复用引脚,见 ``bsp/board/bl706_avb/pinmux_config.h``
|
||||
- 配置 ``SPI`` 设备复用引脚,见 ``bsp/board/bl706_avb/pinmux_config.h``
|
||||
|
||||
.. note:: ``bsp/board/bl706_avb/pinmux_config.h`` 当前给所有的示例demo使用,所以,需要先选定 ``PINMUX_SELECT`` 为 ``PINMUX_LVGL``,开启其中一个 demo
|
||||
|
||||
|
@ -89,7 +89,7 @@ SPI - TFT LCD 显示
|
|||
}
|
||||
|
||||
- 配置 ``LCD_CS`` 和 ``LCD_DC`` 引脚为输出模式并拉高
|
||||
- 调用 ``spi_register`` 函数注册 ``SPI`` 设备,当前注册 ``SPI0``
|
||||
- 调用 ``spi_register`` 函数注册 ``SPI`` 设备,当前注册 ``SPI0``
|
||||
- 然后通过 ``find`` 函数找到设备对应的句柄,保存于 ``spi0`` 句柄中
|
||||
- 最后使用 ``device_open`` 以轮询发送模式来打开 ``spi0`` 设备
|
||||
|
||||
|
@ -128,7 +128,7 @@ SPI - TFT LCD 显示
|
|||
- **CDK 编译**
|
||||
|
||||
打开项目中提供的工程文件:spi_lcd.cdkproj
|
||||
|
||||
|
||||
参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可
|
||||
|
||||
- **命令行编译**
|
||||
|
@ -146,7 +146,7 @@ SPI - TFT LCD 显示
|
|||
实验现象
|
||||
-----------------------------
|
||||
|
||||
.. figure:: img/spi_lcd.png
|
||||
.. figure:: img/spi_lcd.png
|
||||
:alt:
|
||||
|
||||
spi display!
|
|
@ -0,0 +1,9 @@
|
|||
=======================
|
||||
UART 示例
|
||||
=======================
|
||||
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
UART - 数据自收发 <uart_loopback_demo>
|
|
@ -26,7 +26,7 @@ UART - 数据自收发
|
|||
#define BSP_UART_CLOCK_SOURCE ROOT_CLOCK_SOURCE_PLL_96M
|
||||
#define BSP_UART_CLOCK_DIV 0
|
||||
|
||||
- 配置 ``UART`` 设备时钟源,见 ``bsp/board/bl706_iot/clock_config.h``
|
||||
- 配置 ``UART`` 设备时钟源,见 ``bsp/board/bl706_iot/clock_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
@ -34,7 +34,7 @@ UART - 数据自收发
|
|||
#define CONFIG_GPIO14_FUNC GPIO_FUN_UART0_TX
|
||||
#define CONFIG_GPIO15_FUNC GPIO_FUN_UART0_RX
|
||||
|
||||
- 配置 ``UART`` 设备复用引脚,见 ``bsp/board/bl706_iot/pinmux_config.h``
|
||||
- 配置 ``UART`` 设备复用引脚,见 ``bsp/board/bl706_iot/pinmux_config.h``
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
@ -73,13 +73,13 @@ UART - 数据自收发
|
|||
if (uart)
|
||||
{
|
||||
device_open(uart, DEVICE_OFLAG_STREAM_TX | DEVICE_OFLAG_INT_RX);
|
||||
device_set_callback(uart, uart_iqr_callback);
|
||||
device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT));
|
||||
device_set_callback(uart, NULL);
|
||||
device_control(uart, DEVICE_CTRL_CLR_INT, (void *)(UART_RX_FIFO_IT));
|
||||
}
|
||||
|
||||
- 首先调用 ``uart_register`` 函数注册 ``UART`` 设备,当前注册 ``UART0``
|
||||
- 然后通过 ``find`` 函数找到设备对应的句柄,保存于 ``uart`` 句柄中
|
||||
- 最后使用 ``device_open`` 以轮询发送和中断接收来打开 ``uart`` 设备,调用 ``device_set_callback`` 注册一个 ``UART0`` 中断回调函数,调用 ``device_control`` 开启 ``UART RX FIFO`` 中断
|
||||
- 最后使用 ``device_open`` 以轮询发送和中断接收来打开 ``uart`` 设备,默认关闭中断并且不注册接收中断回调函数
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
@ -90,7 +90,7 @@ UART - 数据自收发
|
|||
device_control(uart, DEVICE_CTRL_SET_INT, (void *)(UART_RX_FIFO_IT|UART_RTO_IT));
|
||||
}
|
||||
|
||||
- 通过 ``device_set_callback`` 函数,注册用户指定的中断服务函数。通过 ``device_control`` 函数打开 ``RX FIFO`` 和 ``RTO`` 中断
|
||||
- 通过 ``device_set_callback`` 函数,注册用户指定的``UART0`` 接收中断服务函数。通过 ``device_control`` 函数打开 ``RX_FIFO`` 和 ``RTO`` 中断
|
||||
|
||||
.. code-block:: C
|
||||
:linenos:
|
||||
|
@ -107,9 +107,9 @@ UART - 数据自收发
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
- 此函数是示例的中断服务函数,作用是将接受到的数据原封不动的发送出去。
|
||||
|
||||
|
||||
- ``state`` 会返回 ``UART`` 设备的中断类型
|
||||
- ``args`` 包含了返回数据指针
|
||||
- ``size`` 包含返回数据的长度
|
||||
|
@ -124,7 +124,7 @@ UART - 数据自收发
|
|||
- **CDK 编译**
|
||||
|
||||
打开项目中提供的工程文件:uart_echo.cdkproj
|
||||
|
||||
|
||||
参照 :ref:`windows_cdk_quick_start` 的步骤编译下载即可
|
||||
|
||||
- **命令行编译**
|
|
@ -111,22 +111,29 @@
|
|||
<li class="toctree-l2"><a class="reference internal" href="#id1">9.1. 简介</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#id2">9.2. ADC 设备结构体定义</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#id3">9.3. ADC 设备参数配置表</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#id4">9.4. ADC 设备接口</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#id4">9.4. ADC 设备接口</a><ul>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#adc-register">9.4.1. <strong>ADC_register</strong></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#device-open">9.4.2. <strong>device_open</strong></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#device-close">9.4.3. <strong>device_close</strong></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#device-control">9.4.4. <strong>device_control</strong></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#device-read">9.4.5. <strong>device_read</strong></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#device-set-callback">9.4.6. <strong>device_set_callback</strong></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="api_dac.html">10. DAC 设备</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
@ -206,15 +213,261 @@
|
|||
<h1><span class="section-number">9. </span>ADC 设备<a class="headerlink" href="#adc" title="永久链接至标题">¶</a></h1>
|
||||
<div class="section" id="id1">
|
||||
<h2><span class="section-number">9.1. </span>简介<a class="headerlink" href="#id1" title="永久链接至标题">¶</a></h2>
|
||||
<p>ADC (Analog-to-digital Converter) 是用于将模拟形式的连续信号转换为数字形式的离散信号的一类设备,他可以将外围电路传感器产生的模拟信号转化为机器可识别的数字信号。
|
||||
博流系列MCU中的ADC设备具有以下特性</p>
|
||||
<ul class="simple">
|
||||
<li><p>可以选择 12/14/16 bits转换结果输出</p></li>
|
||||
<li><p>ADC最大工作时钟为2MHZ</p></li>
|
||||
<li><p>支持2.0V,3.2V可选内部参考电压</p></li>
|
||||
<li><p>支持DMA将转换结果搬运到内存</p></li>
|
||||
<li><p>支持单次单通道转换、连续单通道转换、单次多通道转换和连续多通道转换模式四种模式</p></li>
|
||||
<li><p>支持单端与差分两种输入模式</p></li>
|
||||
<li><p>12路外部模拟通道</p></li>
|
||||
<li><p>2路DAC内部通道</p></li>
|
||||
<li><p>1路VBAT/2通道</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="id2">
|
||||
<h2><span class="section-number">9.2. </span>ADC 设备结构体定义<a class="headerlink" href="#id2" title="永久链接至标题">¶</a></h2>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">typedef</span> <span class="k">struct</span> <span class="nc">adc_device</span> <span class="p">{</span>
|
||||
<span class="k">struct</span> <span class="nc">device</span> <span class="n">parent</span><span class="p">;</span>
|
||||
<span class="n">adc_clk_div_t</span> <span class="n">clk_div</span><span class="p">;</span>
|
||||
<span class="n">adc_vref_t</span> <span class="n">vref</span><span class="p">;</span>
|
||||
<span class="kt">bool</span> <span class="n">continuous_conv_mode</span><span class="p">;</span>
|
||||
<span class="kt">bool</span> <span class="n">differential_mode</span><span class="p">;</span>
|
||||
<span class="n">adc_data_width_t</span> <span class="n">data_width</span><span class="p">;</span>
|
||||
<span class="n">adc_fifo_threshold_t</span> <span class="n">fifo_threshold</span><span class="p">;</span>
|
||||
<span class="n">adc_pga_gain_t</span> <span class="n">gain</span><span class="p">;</span>
|
||||
<span class="p">}</span> <span class="n">adc_device_t</span><span class="p">;</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>parent 继承父类属性</p></li>
|
||||
<li><p>clk_div ADC模块时钟内部分频</p></li>
|
||||
<li><p>vref 参考电压选择 2.0/3.2V可选</p></li>
|
||||
<li><p>continuous_conv_mode 是否选择为连续模式,若为连续模式,则一次adc_start操作,ADC连续工作,直到adc_stop。否则,每adc_start一次,adc仅转换一次结果。</p></li>
|
||||
<li><p>differential_mode 选择是否为差分模式,若为差分模式,则可以测量负电压。</p></li>
|
||||
<li><p>data_width 测量宽度选择,ADC实际精度为12bits,但是通过OSR多次取平均可以达到14bits/16bits的精度,注意,当选择更高的数据宽度后,频率会因为取平均而下降。详情可参考枚举信息。</p></li>
|
||||
<li><p>fifo_threshold 此参数影响DMA搬运阈值以及ADC FIFO中断阈值</p></li>
|
||||
<li><p>gain ADC对输入信号的增益选择</p></li>
|
||||
<li><p>其他待补充</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="id3">
|
||||
<h2><span class="section-number">9.3. </span>ADC 设备参数配置表<a class="headerlink" href="#id3" title="永久链接至标题">¶</a></h2>
|
||||
<p>每一个 ADC 设备都有一个参数配置宏,宏定义位于 <code class="docutils literal notranslate"><span class="pre">bsp/board/xxx</span></code> 目录下 <code class="docutils literal notranslate"><span class="pre">peripheral_config.h</span></code> 文件,变量定义位于 <code class="docutils literal notranslate"><span class="pre">hal_adc.c</span></code> 中,因此无需用户自己定义变量。当用户打开对应设备的宏,该设备的配置才生效。例如打开宏 <code class="docutils literal notranslate"><span class="pre">BSP_USING_ADC0</span></code> 即生效,同时 <code class="docutils literal notranslate"><span class="pre">ADC</span></code> 设备就可以进行注册和使用了。</p>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="cm">/*参数配置宏*/</span>
|
||||
<span class="cp">#if defined(BSP_USING_ADC0)</span>
|
||||
<span class="cp">#ifndef ADC0_CONFIG</span>
|
||||
<span class="cp">#define ADC0_CONFIG \</span>
|
||||
<span class="cp"> { \</span>
|
||||
<span class="cp"> .clk_div = ADC_CLOCK_DIV_32, \</span>
|
||||
<span class="cp"> .vref = ADC_VREF_3P2V, \</span>
|
||||
<span class="cp"> .continuous_conv_mode = DISABLE, \</span>
|
||||
<span class="cp"> .differential_mode = DISABLE, \</span>
|
||||
<span class="cp"> .data_width = ADC_DATA_WIDTH_16B_WITH_256_AVERAGE, \</span>
|
||||
<span class="cp"> .fifo_threshold = ADC_FIFO_THRESHOLD_1BYTE, \</span>
|
||||
<span class="cp"> .gain = ADC_GAIN_1 \</span>
|
||||
<span class="cp"> }</span>
|
||||
<span class="cp">#endif</span>
|
||||
<span class="cp">#endif</span>
|
||||
|
||||
<span class="cm">/*变量定义*/</span>
|
||||
<span class="k">static</span> <span class="n">adc_device_t</span> <span class="n">adcx_device</span><span class="p">[</span><span class="n">ADC_MAX_INDEX</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
|
||||
<span class="cp">#ifdef BSP_USING_ADC0</span>
|
||||
<span class="n">ADC0_CONFIG</span><span class="p">,</span>
|
||||
<span class="cp">#endif</span>
|
||||
<span class="p">};</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">注解</p>
|
||||
<p>上述配置可以通过 <code class="docutils literal notranslate"><span class="pre">ADC_DEV(dev)->xxx</span></code> 进行修改,只能在调用 <code class="docutils literal notranslate"><span class="pre">device_open</span></code> 之前使用。</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="id4">
|
||||
<h2><span class="section-number">9.4. </span>ADC 设备接口<a class="headerlink" href="#id4" title="永久链接至标题">¶</a></h2>
|
||||
<p>ADC 设备接口全部遵循标准设备驱动管理层提供的接口。</p>
|
||||
<div class="section" id="adc-register">
|
||||
<h3><span class="section-number">9.4.1. </span><strong>ADC_register</strong><a class="headerlink" href="#adc-register" title="永久链接至标题">¶</a></h3>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">adc_register</span></code> 用来注册一个 ADC 设备,在注册之前需要打开对应 ADC 设备的宏定义。例如定义宏 <code class="docutils literal notranslate"><span class="pre">BSP_USING_ADC0</span></code> 方可使用 <code class="docutils literal notranslate"><span class="pre">ADC0</span></code> 设备,注册完成以后才可以使用其他接口,如果没有定义宏,则无法使用 <code class="docutils literal notranslate"><span class="pre">ADC0</span></code> 设备。</p>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span> <span class="nf">ADC_register</span><span class="p">(</span><span class="k">enum</span> <span class="n">ADC_index_type</span> <span class="n">index</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">,</span> <span class="kt">uint16_t</span> <span class="n">flag</span><span class="p">);</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>index 要注册的设备索引</p></li>
|
||||
<li><p>name 为注册的设备命名</p></li>
|
||||
<li><p>flag 默认可读可写属性</p></li>
|
||||
</ul>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">index</span></code> 用来选择 ADC 设备配置,一个 index 对应一个 ADC 设备配置,比如 <code class="docutils literal notranslate"><span class="pre">ADC0_INDEX</span></code> 对应 <code class="docutils literal notranslate"><span class="pre">ADC0_CONFIG</span></code> 配置,<code class="docutils literal notranslate"><span class="pre">index</span></code> 有如下可选类型</p>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">enum</span> <span class="n">ADC_index_type</span>
|
||||
<span class="p">{</span>
|
||||
<span class="cp">#ifdef BSP_USING_ADC0</span>
|
||||
<span class="n">ADC0_INDEX</span><span class="p">,</span>
|
||||
<span class="cp">#endif</span>
|
||||
<span class="n">ADC_MAX_INDEX</span>
|
||||
<span class="p">};</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="device-open">
|
||||
<h3><span class="section-number">9.4.2. </span><strong>device_open</strong><a class="headerlink" href="#device-open" title="永久链接至标题">¶</a></h3>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">device_open</span></code> 用于 ADC 设备的打开,<code class="docutils literal notranslate"><span class="pre">oflag</span></code> 表示以何种方式打开。</p>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span> <span class="nf">device_open</span><span class="p">(</span><span class="k">struct</span> <span class="nc">device</span> <span class="o">*</span><span class="n">dev</span><span class="p">,</span> <span class="kt">uint16_t</span> <span class="n">oflag</span><span class="p">);</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>dev 设备句柄</p></li>
|
||||
<li><p>oflag 设备的打开方式</p></li>
|
||||
<li><p>return 错误码,0 表示打开成功,其他表示错误</p></li>
|
||||
</ul>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">oflag</span></code> 可以写入以下参数:</p>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="cp">#define DEVICE_OFLAG_STREAM_TX 0x001 </span><span class="cm">/* 设备以轮训发送模式打开 */</span><span class="cp"></span>
|
||||
<span class="cp">#define DEVICE_OFLAG_STREAM_RX 0x002 </span><span class="cm">/* 设备以轮训接收模式打开 */</span><span class="cp"></span>
|
||||
<span class="cp">#define DEVICE_OFLAG_INT_TX 0x004 </span><span class="cm">/* 设备以中断发送模式打开 */</span><span class="cp"></span>
|
||||
<span class="cp">#define DEVICE_OFLAG_INT_RX 0x008 </span><span class="cm">/* 设备以中断接收模式打开 */</span><span class="cp"></span>
|
||||
<span class="cp">#define DEVICE_OFLAG_DMA_TX 0x010 </span><span class="cm">/* 设备以 DMA 发送模式打开 */</span><span class="cp"></span>
|
||||
<span class="cp">#define DEVICE_OFLAG_DMA_RX 0x020 </span><span class="cm">/* 设备以 DMA 接收模式打开 */</span><span class="cp"></span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="device-close">
|
||||
<h3><span class="section-number">9.4.3. </span><strong>device_close</strong><a class="headerlink" href="#device-close" title="永久链接至标题">¶</a></h3>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">device_close</span></code> 用于设备的关闭。</p>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span> <span class="nf">device_close</span><span class="p">(</span><span class="k">struct</span> <span class="nc">device</span> <span class="o">*</span><span class="n">dev</span><span class="p">);</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>dev 设备句柄</p></li>
|
||||
<li><p>return 错误码,0 表示关闭成功,其他表示错误</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="device-control">
|
||||
<h3><span class="section-number">9.4.4. </span><strong>device_control</strong><a class="headerlink" href="#device-control" title="永久链接至标题">¶</a></h3>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">device_control</span></code> 用于根据命令对 ADC 设备进行控制和参数的修改。</p>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span> <span class="nf">device_control</span><span class="p">(</span><span class="k">struct</span> <span class="nc">device</span> <span class="o">*</span><span class="n">dev</span><span class="p">,</span> <span class="kt">int</span> <span class="n">cmd</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">args</span><span class="p">);</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>dev 设备句柄</p></li>
|
||||
<li><p>cmd 设备控制命令</p></li>
|
||||
<li><p>args 控制参数</p></li>
|
||||
<li><p>return 不同的控制命令返回的意义不同。</p></li>
|
||||
</ul>
|
||||
<p>串口设备除了标准的控制命令,还具有自己特殊的控制命令。</p>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="cp">#define DEVICE_CTRL_ADC_CHANNEL_START 0x10</span>
|
||||
<span class="cp">#define DEVICE_CTRL_ADC_CHANNEL_STOP 0x11</span>
|
||||
<span class="cp">#define DEVICE_CTRL_ADC_CHANNEL_CONFIG 0x12</span>
|
||||
<span class="cp">#define DEVICE_CTRL_ADC_VBAT_ON 0x13</span>
|
||||
<span class="cp">#define DEVICE_CTRL_ADC_VBAT_OFF 0x14</span>
|
||||
<span class="cp">#define DEVICE_CTRL_ADC_TSEN_ON 0x15</span>
|
||||
<span class="cp">#define DEVICE_CTRL_ADC_TSEN_OFF 0x16</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">args</span></code> 根据不同的 <code class="docutils literal notranslate"><span class="pre">cmd</span></code> 传入不同,具体如下:</p>
|
||||
<table class="docutils align-default">
|
||||
<colgroup>
|
||||
<col style="width: 37%" />
|
||||
<col style="width: 24%" />
|
||||
<col style="width: 39%" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="row-odd"><th class="head"><p>cmd</p></th>
|
||||
<th class="head"><p>args</p></th>
|
||||
<th class="head"><p>description</p></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="row-even"><td><p>DEVICE_CTRL_SET_INT</p></td>
|
||||
<td><p>ADC_it_type</p></td>
|
||||
<td><p>开启ADC设备中断</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>DEVICE_CTRL_CLR_INT</p></td>
|
||||
<td><p>ADC_it_type</p></td>
|
||||
<td><p>关闭ADC设备中断</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p>DEVICE_CTRL_CONFIG</p></td>
|
||||
<td><p>ADC_param_cfg_t*</p></td>
|
||||
<td><p>修改ADC配置</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>DEVICE_CTRL_ADC_CHANNEL_CONFIG</p></td>
|
||||
<td><p>adc_channel_cfg_t*</p></td>
|
||||
<td><p>配置ADC通道信息</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p>DEVICE_CTRL_ATTACH_RX_DMA</p></td>
|
||||
<td><p>struct device*</p></td>
|
||||
<td><p>链接接收dma设备</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>DEVICE_CTRL_ADC_CHANNEL_START</p></td>
|
||||
<td><p>struct device*</p></td>
|
||||
<td><p>开始/继续 ADC转换</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p>DEVICE_CTRL_ADC_CHANNEL_STOP</p></td>
|
||||
<td><p>NULL</p></td>
|
||||
<td><p>停止ADC转换</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>DEVICE_CTRL_ADC_VBAT_ON</p></td>
|
||||
<td><p>NULL</p></td>
|
||||
<td><p>打开内部VDD测量电路</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p>DEVICE_CTRL_ADC_VBAT_OFF</p></td>
|
||||
<td><p>NULL</p></td>
|
||||
<td><p>关闭内部VDD测量电路</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>DEVICE_CTRL_ADC_TSEN_ON</p></td>
|
||||
<td><p>NULL</p></td>
|
||||
<td><p>打开内部温度测量电路(需硬件支持)</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p>DEVICE_CTRL_ADC_TSEN_OFF</p></td>
|
||||
<td><p>uint32_t*</p></td>
|
||||
<td><p>关闭内部温度测量电路(需硬件支持)</p></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="section" id="device-read">
|
||||
<h3><span class="section-number">9.4.5. </span><strong>device_read</strong><a class="headerlink" href="#device-read" title="永久链接至标题">¶</a></h3>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">device_read</span></code> 用于 ADC 设备数据的接收,接收方式根据打开方式可以是轮询、中断、dma。</p>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span> <span class="nf">device_read</span><span class="p">(</span><span class="k">struct</span> <span class="nc">device</span> <span class="o">*</span><span class="n">dev</span><span class="p">,</span> <span class="kt">uint32_t</span> <span class="n">pos</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">buffer</span><span class="p">,</span> <span class="kt">uint32_t</span> <span class="n">size</span><span class="p">);</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>dev 设备句柄</p></li>
|
||||
<li><p>pos 无作用</p></li>
|
||||
<li><p>buffer 要读入的 buffer 缓冲区</p></li>
|
||||
<li><p>size 要读入的长度</p></li>
|
||||
<li><p>return 错误码,0 表示读入成功,其他表示错误</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="device-set-callback">
|
||||
<h3><span class="section-number">9.4.6. </span><strong>device_set_callback</strong><a class="headerlink" href="#device-set-callback" title="永久链接至标题">¶</a></h3>
|
||||
<p><code class="docutils literal notranslate"><span class="pre">device_set_callback</span></code> 用于注册一个ADC阈值中断回调函数。</p>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span> <span class="nf">device_set_callback</span><span class="p">(</span><span class="k">struct</span> <span class="nc">device</span> <span class="o">*</span><span class="n">dev</span><span class="p">,</span> <span class="kt">void</span> <span class="p">(</span><span class="o">*</span><span class="n">callback</span><span class="p">)(</span><span class="k">struct</span> <span class="nc">device</span> <span class="o">*</span><span class="n">dev</span><span class="p">,</span> <span class="kt">void</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="kt">uint32_t</span> <span class="n">size</span><span class="p">,</span> <span class="kt">uint32_t</span> <span class="n">event</span><span class="p">));</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<ul>
|
||||
<li><p>dev 设备句柄</p></li>
|
||||
<li><p>callback 要注册的中断回调函数</p>
|
||||
<blockquote>
|
||||
<div><ul class="simple">
|
||||
<li><p>dev 设备句柄</p></li>
|
||||
<li><p>args 接收发送缓冲区,数据类型为 uint8_t*</p></li>
|
||||
<li><p>size 传输长度</p></li>
|
||||
<li><p>event 中断事件类型</p></li>
|
||||
</ul>
|
||||
</div></blockquote>
|
||||
</li>
|
||||
</ul>
|
||||
<p>串口设备 <code class="docutils literal notranslate"><span class="pre">event</span></code> 类型如下</p>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">enum</span> <span class="n">ADC_event_type</span>
|
||||
<span class="p">{</span>
|
||||
<span class="n">ADC_EVENT_FIFO_READY</span><span class="p">,</span>
|
||||
<span class="n">ADC_EVENT_OVERRUN</span><span class="p">,</span>
|
||||
<span class="n">ADC_EVENT_UNDERRUN</span><span class="p">,</span>
|
||||
<span class="p">};</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -110,15 +110,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
|
|
@ -120,15 +120,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
<link rel="index" title="索引" href="../genindex.html" />
|
||||
<link rel="search" title="搜索" href="../search.html" />
|
||||
<link rel="next" title="1. GPIO 输出 - 流水灯" href="../samples/basic%20samples/blink_demo.html" />
|
||||
<link rel="next" title="1. GPIO 示例" href="../samples/basic%20samples/gpio/index.html" />
|
||||
<link rel="prev" title="9. ADC 设备" href="api_adc.html" />
|
||||
</head>
|
||||
|
||||
|
@ -118,15 +118,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
@ -224,7 +223,7 @@
|
|||
</div>
|
||||
<footer>
|
||||
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
||||
<a href="../samples/basic%20samples/blink_demo.html" class="btn btn-neutral float-right" title="1. GPIO 输出 - 流水灯" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
|
||||
<a href="../samples/basic%20samples/gpio/index.html" class="btn btn-neutral float-right" title="1. GPIO 示例" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
|
||||
<a href="api_adc.html" class="btn btn-neutral float-left" title="9. ADC 设备" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -130,15 +130,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
|
|
@ -124,15 +124,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
|
|
@ -123,15 +123,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
|
|
@ -129,15 +129,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
@ -219,30 +218,42 @@
|
|||
<h2><span class="section-number">5.1. </span>简介<a class="headerlink" href="#id1" title="永久链接至标题">¶</a></h2>
|
||||
<p>脉冲宽度调制(Pulse width modulation,简称 PWM)是一种用数字方式实现模拟电压控制的技术。它是通过对一系列脉冲的宽度进行调制,等效出所需要的波形(包含形状以及幅值),对模拟信号电平进行数字编码,也就是说通过调节占空比的变化来调节信号、能量等的变化,占空比就是指在一个周期内,信号处于高电平的时间占据整个信号周期的百分比,例如方波的占空比就是50%。博流系列 MCU 中 DMA 设备具有以下特性:</p>
|
||||
<ul class="simple">
|
||||
<li><p>支持5通道PWM信号生成</p></li>
|
||||
<li><p>支持5通道 PWM 信号生成</p></li>
|
||||
<li><p>三种时钟源可选择(总线时钟 <bclk>、晶振时钟 <xtal_ck>、慢速时钟 <32k>),搭配 16-bit 时钟分频器</p></li>
|
||||
<li><p>双门限值域设定,增加脉冲弹性</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="id2">
|
||||
<h2><span class="section-number">5.2. </span>PWM 设备结构体定义<a class="headerlink" href="#id2" title="永久链接至标题">¶</a></h2>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">typedef</span> <span class="k">struct</span> <span class="nc">pwm_device</span>
|
||||
<span class="p">{</span>
|
||||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="k">typedef</span> <span class="k">struct</span> <span class="nc">pwm_device</span> <span class="p">{</span>
|
||||
<span class="k">struct</span> <span class="nc">device</span> <span class="n">parent</span><span class="p">;</span>
|
||||
<span class="kt">uint8_t</span> <span class="n">ch</span><span class="p">;</span>
|
||||
<span class="kt">uint32_t</span> <span class="n">frequency</span><span class="p">;</span>
|
||||
<span class="kt">uint8_t</span> <span class="n">dutycycle</span><span class="p">;</span>
|
||||
<span class="kt">uint8_t</span> <span class="n">polarity_invert_mode</span><span class="p">;</span>
|
||||
<span class="kt">uint16_t</span> <span class="n">period</span><span class="p">;</span>
|
||||
<span class="kt">uint16_t</span> <span class="n">threshold_low</span><span class="p">;</span>
|
||||
<span class="kt">uint16_t</span> <span class="n">threshold_high</span><span class="p">;</span>
|
||||
<span class="kt">uint16_t</span> <span class="n">it_pulse_count</span><span class="p">;</span>
|
||||
|
||||
<span class="p">}</span> <span class="n">pwm_device_t</span><span class="p">;</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>parent 继承父类属性</p></li>
|
||||
<li><p>ch 通道号,使能PWM通道0则ch为0,使能PWM通道0则ch为1,以此类推</p></li>
|
||||
<li><p>frequency 默认频率</p></li>
|
||||
<li><p>dutycycle 默认占空比(0-100)</p></li>
|
||||
<li><p>polarity_invert_mode 极性翻转使能</p></li>
|
||||
<li><p>period PWM 周期值</p></li>
|
||||
<li><p>threshold_low PWM 低门限阈值</p></li>
|
||||
<li><p>threshold_high PWM 高门限阈值</p></li>
|
||||
<li><p>it_pulse_count 触发中断条件的周期计数值</p></li>
|
||||
</ul>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">注解</p>
|
||||
<p>PWM 实际频率 = PWM 时钟源/分频/period ,period 非 PWM 实际周期,</p>
|
||||
</div>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">注解</p>
|
||||
<p>PWM 占空比 = threshold_low/threshold_high * 100%</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="id3">
|
||||
<h2><span class="section-number">5.3. </span>PWM 设备参数配置表<a class="headerlink" href="#id3" title="永久链接至标题">¶</a></h2>
|
||||
|
@ -250,15 +261,19 @@
|
|||
<div class="highlight-C notranslate"><div class="highlight"><pre><span></span><span class="cm">/*参数配置宏*/</span>
|
||||
<span class="cp">#if defined(BSP_USING_PWM_CH2)</span>
|
||||
<span class="cp">#ifndef PWM_CH2_CONFIG</span>
|
||||
<span class="cp">#define PWM_CH2_CONFIG \</span>
|
||||
<span class="cp">{ \</span>
|
||||
<span class="cp"> .ch = 2, \</span>
|
||||
<span class="cp"> .frequency = 1000000, \</span>
|
||||
<span class="cp"> .dutycycle = 0, \</span>
|
||||
<span class="cp">}</span>
|
||||
<span class="cp">#define PWM_CH2_CONFIG \</span>
|
||||
<span class="cp"> { \</span>
|
||||
<span class="cp"> .ch = 2, \</span>
|
||||
<span class="cp"> .polarity_invert_mode = DISABLE, \</span>
|
||||
<span class="cp"> .period = 0, \</span>
|
||||
<span class="cp"> .threshold_low = 0, \</span>
|
||||
<span class="cp"> .threshold_high = 0, \</span>
|
||||
<span class="cp"> .it_pulse_count = 0, \</span>
|
||||
<span class="cp"> }</span>
|
||||
<span class="cp">#endif</span>
|
||||
<span class="cp">#endif</span>
|
||||
|
||||
|
||||
<span class="cm">/*变量定义*/</span>
|
||||
<span class="k">static</span> <span class="n">pwm_device_t</span> <span class="n">pwmx_device</span><span class="p">[</span><span class="n">PWM_MAX_INDEX</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
|
||||
<span class="cp">#ifdef BSP_USING_PWM_CH0</span>
|
||||
|
@ -372,9 +387,9 @@
|
|||
<p><code class="docutils literal notranslate"><span class="pre">args</span></code> 根据不同的 <code class="docutils literal notranslate"><span class="pre">cmd</span></code> 传入不同,具体如下:</p>
|
||||
<table class="docutils align-default">
|
||||
<colgroup>
|
||||
<col style="width: 48%" />
|
||||
<col style="width: 20%" />
|
||||
<col style="width: 32%" />
|
||||
<col style="width: 44%" />
|
||||
<col style="width: 28%" />
|
||||
<col style="width: 27%" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr class="row-odd"><th class="head"><p>cmd</p></th>
|
||||
|
@ -385,27 +400,31 @@
|
|||
<tbody>
|
||||
<tr class="row-even"><td><p>DEVICE_CTRL_SET_INT</p></td>
|
||||
<td><p>NULL</p></td>
|
||||
<td><p>开启pwm传输完成中断</p></td>
|
||||
<td><p>弃用</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>DEVICE_CTRL_CLR_INT</p></td>
|
||||
<td><p>NULL</p></td>
|
||||
<td><p>关闭pwm传输完成中断</p></td>
|
||||
<td><p>弃用</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p>DEVICE_CTRL_RESUME</p></td>
|
||||
<td><p>NULL</p></td>
|
||||
<td><p>恢复pwm通道</p></td>
|
||||
<td><p>开启当前PWM通道</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>DEVICE_CTRL_SUSPEND</p></td>
|
||||
<td><p>NULL</p></td>
|
||||
<td><p>挂起pwm通道</p></td>
|
||||
<td><p>关闭当前PWM通道</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p>DEVICE_CTRL_CONFIG</p></td>
|
||||
<td><p>pwm_config_t</p></td>
|
||||
<td><p>配置pwm通道频率和占空比</p></td>
|
||||
<tr class="row-even"><td><p>DEIVCE_CTRL_PWM_FREQUENCE_CONFIG</p></td>
|
||||
<td><p>uint32_t</p></td>
|
||||
<td><p>配置当前PWM通道周期值</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>DEIVCE_CTRL_PWM_IT_PULSE_COUNT_CONFIG</p></td>
|
||||
<td><p>uint32_t*</p></td>
|
||||
<td><p>配置中断计数阈值</p></td>
|
||||
<tr class="row-odd"><td><p>DEIVCE_CTRL_PWM_DUTYCYCLE_CONFIG</p></td>
|
||||
<td><p>pwm_dutycycle_config_t</p></td>
|
||||
<td><p>配置当前PWM通道占空比</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p>DEIVCE_CTRL_PWM_IT_PULSE_COUNT_CONFIG</p></td>
|
||||
<td><p>uint32_t</p></td>
|
||||
<td><p>配置触发PWM中断周期值</p></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -130,15 +130,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
|
|
@ -129,15 +129,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
|
|
@ -127,15 +127,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
@ -412,11 +411,11 @@
|
|||
<tbody>
|
||||
<tr class="row-even"><td><p>DEVICE_CTRL_SET_INT</p></td>
|
||||
<td><p>uart_it_type</p></td>
|
||||
<td><p>开启spi设备中断</p></td>
|
||||
<td><p>开启uart设备中断</p></td>
|
||||
</tr>
|
||||
<tr class="row-odd"><td><p>DEVICE_CTRL_CLR_INT</p></td>
|
||||
<td><p>uart_it_type</p></td>
|
||||
<td><p>关闭spi设备中断</p></td>
|
||||
<td><p>关闭uart设备中断</p></td>
|
||||
</tr>
|
||||
<tr class="row-even"><td><p>DEVICE_CTRL_CONFIG</p></td>
|
||||
<td><p>uart_param_cfg_t*</p></td>
|
||||
|
|
|
@ -110,15 +110,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
|
|
@ -132,15 +132,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
@ -242,7 +241,7 @@
|
|||
$ wget -c https://dev.bouffalolab.com/media/upload/download/riscv64-elf-x86_64-20210120.tar.gz
|
||||
$ mkdir -p riscv64-elf-20210120
|
||||
<span class="hll">$ tar -zxvf riscv64-elf-x86_64-20210120.tar.gz -C riscv64-elf-20210120
|
||||
</span><span class="hll">$ sudo cp ~/riscv64-elf-20210120 /usr/bin
|
||||
</span><span class="hll">$ sudo cp -rf ~/riscv64-elf-20210120 /usr/bin
|
||||
</span><span class="hll">$ <span class="nb">echo</span> <span class="s2">"export PATH=\"</span><span class="nv">$PATH</span><span class="s2">:/usr/bin/riscv64-elf-20210120/bin\""</span> >> ~/.bashrc
|
||||
</span>$ <span class="nb">source</span> ~/.bashrc
|
||||
</pre></div>
|
||||
|
@ -262,7 +261,7 @@ $ sudo apt install make
|
|||
$ <span class="nb">cd</span> ~
|
||||
$ wget -c https://cmake.org/files/v3.19/cmake-3.19.3-Linux-x86_64.tar.gz
|
||||
<span class="hll">$ tar -zxvf cmake-3.19.3-Linux-x86_64.tar.gz
|
||||
</span><span class="hll">$ sudo cp ~/cmake-3.19.3-Linux-x86_64 /usr/bin
|
||||
</span><span class="hll">$ sudo cp -rf ~/cmake-3.19.3-Linux-x86_64 /usr/bin
|
||||
</span><span class="hll">$ <span class="nb">echo</span> <span class="s2">"export PATH=\"</span><span class="nv">$PATH</span><span class="s2">:/usr/bin/cmake-3.19.3-Linux-x86_64/bin\""</span> >> ~/.bashrc
|
||||
</span>$ <span class="nb">source</span> ~/.bashrc
|
||||
</pre></div>
|
||||
|
@ -351,7 +350,7 @@ $ wget -c https://cmake.org/files/v3.19/cmake-3.19.3-Linux-x86_64.tar.gz
|
|||
</ul>
|
||||
<div class="highlight-bash notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
||||
<span class="normal">2</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span> $ sudo apt install picocom <span class="c1"># 若已经安装请忽略</span>
|
||||
$ picocom -b <span class="m">2000000</span> /dev/ttyUSB0
|
||||
$ picocom -b <span class="m">2000000</span> /dev/ttyUSB0 <span class="c1"># 注意你的可用串口号 (如使用 Sipeed RV-debugger)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
<ul class="simple">
|
||||
|
|
|
@ -104,6 +104,11 @@
|
|||
<li class="toctree-l4"><a class="reference internal" href="#id7">2.1.5.3. 烧写 Hello World</a></li>
|
||||
<li class="toctree-l4"><a class="reference internal" href="#id8">2.1.5.4. 运行 Hello World</a></li>
|
||||
<li class="toctree-l4"><a class="reference internal" href="#id9">2.1.5.5. 调试 Hello World</a></li>
|
||||
<li class="toctree-l4"><a class="reference internal" href="#id10">2.1.5.6. 打开 Hello World</a></li>
|
||||
<li class="toctree-l4"><a class="reference internal" href="#id11">2.1.5.7. 编译 Hello World</a></li>
|
||||
<li class="toctree-l4"><a class="reference internal" href="#id12">2.1.5.8. 烧写 Hello World</a></li>
|
||||
<li class="toctree-l4"><a class="reference internal" href="#id13">2.1.5.9. 运行 Hello World</a></li>
|
||||
<li class="toctree-l4"><a class="reference internal" href="#id14">2.1.5.10. 调试 Hello World</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -131,15 +136,14 @@
|
|||
</ul>
|
||||
<p class="caption"><span class="caption-text">基础外设例程</span></p>
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/blink_demo.html">1. GPIO 输出 - 流水灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/button_demo.html">2. GPIO 中断 - 按键检测</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/breath_pwm_demo.html">3. PWM - 呼吸灯</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart_loopback_demo.html">4. UART - 数据自收发</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer_demo.html">5. MTIMER - 内核定时器</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma_m2m_demo.html">6. DMA - RAM间数据搬运</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c_eeprom_demo.html">7. I2C - AT24CXX 读写</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi_lcd_demo.html">8. SPI - TFT LCD 显示</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc_key_demo.html">9. ADC - 按键检测电压</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/gpio/index.html">1. GPIO 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/uart/index.html">2. UART 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/pwm/index.html">3. PWM 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/mtimer/index.html">4. MTIMER 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/dma/index.html">5. DMA 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/spi/index.html">6. SPI 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/i2c/index.html">7. I2C 示例</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="../samples/basic%20samples/adc/index.html">8. ADC 示例</a></li>
|
||||
</ul>
|
||||
<p class="caption"><span class="caption-text">进阶例程</span></p>
|
||||
<ul>
|
||||
|
@ -221,13 +225,13 @@
|
|||
<span id="windows-cdk-quick-start"></span><h1><span class="section-number">2.1. </span>Windows 下使用 CDK (类 MDK Keil)开发指南<a class="headerlink" href="#windows-cdk-mdk-keil" title="永久链接至标题">¶</a></h1>
|
||||
<p>本文档介绍了如何在 Windows 下使用 <a class="reference external" href="https://www.t-heah.cn/about">平头哥半导体</a> 开发的 CDK 集成开发环境,
|
||||
来完成博流 BL702 系列 MCU 的相关软件开发工作。</p>
|
||||
<p>关于剑池 CDK ,这是一款由平头哥半导体开发打造的集成开发环境。它拥有和传统 MCU 开发环境十分近似的操作和设置,旨在不改变用户开发习惯的基础上,全面接入云端开发资源,结合图形化的 OSTracer、Profiling 等调试分析工具,加速用户产品开发。</p>
|
||||
<p>关于剑池 CDK ,这是一款由平头哥半导体开发打造的集成开发环境。它拥有和传统 MCU 开发环境十分近似的操作和设置,旨在不改变用户开发习惯的基础上,全面接入云端开发资源,结合图形化的 OSTracer、Profiling 等调试分析工具,加速用户产品开发</p>
|
||||
<div class="section" id="id2">
|
||||
<h2><span class="section-number">2.1.1. </span>需要的软硬件环境<a class="headerlink" href="#id2" title="永久链接至标题">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p>剑池 CDK 软件</p></li>
|
||||
<li><p>一根 USB Type-A 数据线</p></li>
|
||||
<li><p>一个 CK-Link 仿真器</p></li>
|
||||
<li><p>一根 USB Type-A 数据线、一根 Type-C 数据线</p></li>
|
||||
<li><p>一个 CK-Link 仿真器 or 一个 Sipeed RV-Debugger Plus 调试器</p></li>
|
||||
<li><p>一个 USB-TTL 串口模块</p></li>
|
||||
<li><p>杜邦线若干</p></li>
|
||||
</ul>
|
||||
|
@ -235,8 +239,8 @@
|
|||
<div class="section" id="cdk">
|
||||
<h2><span class="section-number">2.1.2. </span>下载剑池 CDK 软件安装包<a class="headerlink" href="#cdk" title="永久链接至标题">¶</a></h2>
|
||||
<ul class="simple">
|
||||
<li><p><a class="reference external" href="https://occ.t-head.cn/development/series/download?id=3864775351511420928&type=kind&softPlatformType=4#sticky">剑池CDK</a> 软件安装可以从平头哥半导体 OCC 官网获取到。</p></li>
|
||||
<li><p>下载完成后,解压缩,双击 <code class="docutils literal notranslate"><span class="pre">setup.exe</span></code>,按照其提示,完成软件安装即可。</p></li>
|
||||
<li><p><a class="reference external" href="https://occ.t-head.cn/development/series/download?id=3864775351511420928&type=kind&softPlatformType=4#sticky">剑池CDK</a> 软件安装可以从平头哥半导体 OCC 官网获取到</p></li>
|
||||
<li><p>下载完成后,解压缩,双击 <code class="docutils literal notranslate"><span class="pre">setup.exe</span></code>,按照其提示,完成软件安装即可</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="bl-mcu-sdk">
|
||||
|
@ -245,7 +249,7 @@
|
|||
<li><p>从开源社区下载 bl_mcu_sdk 软件开发包。</p>
|
||||
<ul class="simple">
|
||||
<li><p>可以使用 <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">clone</span></code> 或者直接 <code class="docutils literal notranslate"><span class="pre">download</span></code> 的方式下 SDK</p></li>
|
||||
<li><p>使用 <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">clone</span></code> 前请确保已正确安装 <code class="docutils literal notranslate"><span class="pre">git</span></code>,打开支持 <code class="docutils literal notranslate"><span class="pre">git</span></code> 的终端输入以下命令即可获取最新的 SDK。</p></li>
|
||||
<li><p>使用 <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">clone</span></code> 前请确保已正确安装 <code class="docutils literal notranslate"><span class="pre">git</span></code>,打开支持 <code class="docutils literal notranslate"><span class="pre">git</span></code> 的终端输入以下命令即可获取最新的 SDK</p></li>
|
||||
</ul>
|
||||
<div class="highlight-bash notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="hll">$ git clone https://gitee.com/bouffalolab/bl_mcu_sdk.git --recursive
|
||||
</span></pre></div>
|
||||
|
@ -262,19 +266,92 @@
|
|||
</div>
|
||||
<div class="section" id="hello-world">
|
||||
<h2><span class="section-number">2.1.5. </span>测试 Hello World 工程<a class="headerlink" href="#hello-world" title="永久链接至标题">¶</a></h2>
|
||||
<p><strong>使用 Sipeed RV-Debugger Plus 调试工程时请按照下面的步骤进行:</strong></p>
|
||||
<div class="section" id="id5">
|
||||
<h3><span class="section-number">2.1.5.1. </span>打开 Hello World<a class="headerlink" href="#id5" title="永久链接至标题">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>获取到 SDK 后,进入 sdk 中的 <code class="docutils literal notranslate"><span class="pre">examples/hellowd/helloworld/cdk</span></code> 目录下,双击 <code class="docutils literal notranslate"><span class="pre">helloworld.cdkproj</span></code>,即可打开 <code class="docutils literal notranslate"><span class="pre">Helloworld</span></code> 工程。</p></li>
|
||||
<li><p>获取到 SDK 后,进入 sdk 中的 <code class="docutils literal notranslate"><span class="pre">examples/hellowd/helloworld/cdk</span></code> 目录下,双击 <code class="docutils literal notranslate"><span class="pre">helloworld.cdkproj</span></code>,即可打开 <code class="docutils literal notranslate"><span class="pre">Helloworld</span></code> 工程</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="id6">
|
||||
<h3><span class="section-number">2.1.5.2. </span>编译 Hello World<a class="headerlink" href="#id6" title="永久链接至标题">¶</a></h3>
|
||||
<div class="figure align-default" id="id10">
|
||||
<div class="figure align-default" id="id15">
|
||||
<img alt="" src="../_images/cdk1.png" />
|
||||
<p class="caption"><span class="caption-text">helloworld.cdkproj</span><a class="headerlink" href="#id10" title="永久链接至图片">¶</a></p>
|
||||
<p class="caption"><span class="caption-text">helloworld.cdkproj</span><a class="headerlink" href="#id15" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>在活动工程下拉菜单选择 <code class="docutils literal notranslate"><span class="pre">OpenOCD_Debug</span></code> 工程,由于 Sipeed RV-Debugger Plus 是使用 OpenOCD 调试的,所以本教程基于 <code class="docutils literal notranslate"><span class="pre">OpenOCD_Debug</span></code> 工程;</p></li>
|
||||
<li><p>如 Sipeed RV-Debugger Plus 没有正确安装驱动,请参考 <a class="reference internal" href="get_started.html#sipeed-rv-debugger-plus"><span class="std std-ref">调试器驱动安装设置</span></a> 部分,设置好驱动程序,在进行下面的步骤</p></li>
|
||||
<li><p>在 CDK 工具栏中,点击编译图标即可编译工程</p>
|
||||
<ul>
|
||||
<li><p>点击 <code class="docutils literal notranslate"><span class="pre">1</span></code> 处 图标 <code class="docutils literal notranslate"><span class="pre">Build</span> <span class="pre">Project</span></code> 即可编译当前选中的工程</p></li>
|
||||
<li><p>点击 <code class="docutils literal notranslate"><span class="pre">2</span></code> 处 图标 <code class="docutils literal notranslate"><span class="pre">Clean</span> <span class="pre">Project</span></code> 即可清除上次编译的结果</p></li>
|
||||
<li><p>点击 <code class="docutils literal notranslate"><span class="pre">3</span></code> 处 图标 <code class="docutils literal notranslate"><span class="pre">Flash</span> <span class="pre">Download</span></code> 即可将编译好的代码下载到芯片中 (<strong>使用 OpenOCD Debug 不能使用 Flash 下载功能</strong>)</p></li>
|
||||
<li><p>点击 <code class="docutils literal notranslate"><span class="pre">4</span></code> 处 图标 <code class="docutils literal notranslate"><span class="pre">Start/Stop</span> <span class="pre">Debug</span></code> 即可进行 debug 的相关操作</p></li>
|
||||
<li><p>也可以在 <code class="docutils literal notranslate"><span class="pre">Project</span></code> 中,右击工程名称,通过右击菜单中的选项对项目进行编译等操作</p></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="id7">
|
||||
<h3><span class="section-number">2.1.5.3. </span>烧写 Hello World<a class="headerlink" href="#id7" title="永久链接至标题">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>在 CDK 中使用 OpenOCD 模式的调试方式时,暂不支持直接使用 CDK 相关 flash 工具下载代码,所以请使用 BL Dev Cube 工具进行程序烧写,烧写代码请参考 <a class="reference internal" href="bl_dev_cube.html#bl-dev-cube"><span class="std std-ref">BLDevCube 烧录工具指南</span></a> 部分进行</p></li>
|
||||
<li><p>代码烧写完成后使用 CDK 进行 Debug</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="id8">
|
||||
<h3><span class="section-number">2.1.5.4. </span>运行 Hello World<a class="headerlink" href="#id8" title="永久链接至标题">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>从 CDK 的菜单栏 <code class="docutils literal notranslate"><span class="pre">View->Serial</span> <span class="pre">Pane</span></code>,打开串口面板,在打开的 <code class="docutils literal notranslate"><span class="pre">Serial</span> <span class="pre">Pane</span></code> 中右击,进行串口设置,选择你对应的串口号和波特率</p></li>
|
||||
</ul>
|
||||
<div class="figure align-default">
|
||||
<img alt="../_images/cdk4.png" src="../_images/cdk4.png" />
|
||||
</div>
|
||||
<div class="figure align-default" id="id16">
|
||||
<img alt="" src="../_images/cdk3.png" />
|
||||
<p class="caption"><span class="caption-text">CDK Serial Pane setting</span><a class="headerlink" href="#id16" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>按下板子上的 <code class="docutils literal notranslate"><span class="pre">RST</span></code> 按键,即可在串口中看到代码的运行结果</p></li>
|
||||
</ul>
|
||||
<div class="figure align-default" id="id17">
|
||||
<img alt="" src="../_images/cdk6.png" />
|
||||
<p class="caption"><span class="caption-text">HelloWorld!</span><a class="headerlink" href="#id17" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="id9">
|
||||
<h3><span class="section-number">2.1.5.5. </span>调试 Hello World<a class="headerlink" href="#id9" title="永久链接至标题">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>点击工具栏上方的 <code class="docutils literal notranslate"><span class="pre">Start/Stop</span> <span class="pre">Debugger</span></code> 按钮,进入 debug 界面,如下图所示</p></li>
|
||||
</ul>
|
||||
<div class="figure align-default" id="id18">
|
||||
<img alt="" src="../_images/cdk10.png" />
|
||||
<p class="caption"><span class="caption-text">Debug HelloWorld!</span><a class="headerlink" href="#id18" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>在 debug 界面下,左侧的 <code class="docutils literal notranslate"><span class="pre">Register</span></code> 窗口中,可以查看 <code class="docutils literal notranslate"><span class="pre">CPU</span></code> 内部寄存器数据;右侧的 <code class="docutils literal notranslate"><span class="pre">Peripherals</span></code> 外设面板中,
|
||||
可以查看相应外设寄存器数据,外设的选择可以在顶部菜单栏的 <code class="docutils literal notranslate"><span class="pre">Peripherals->System</span> <span class="pre">Viewer</span></code> 选择;
|
||||
点击上方工具栏中的相关调试按钮可以进行断点设置、单步调试、指令单步和全速运行等操作。
|
||||
当然这些操作都有相应的快捷键和快捷设置方法,详情请参考 <code class="docutils literal notranslate"><span class="pre">CDK</span> <span class="pre">Help</span></code>,这里就不作过多介绍了。</p></li>
|
||||
<li><p>我们点击单步运行按钮,运行代码,即可看到指示光标移动到下一句代码,同时可以看到串口面板中显示了我们输出的 <code class="docutils literal notranslate"><span class="pre">Hello</span> <span class="pre">World!</span></code></p></li>
|
||||
</ul>
|
||||
<p><strong>使用 CK-Link 调试工程时请按照下面的步骤进行:</strong></p>
|
||||
</div>
|
||||
<div class="section" id="id10">
|
||||
<h3><span class="section-number">2.1.5.6. </span>打开 Hello World<a class="headerlink" href="#id10" title="永久链接至标题">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>获取到 SDK 后,进入 sdk 中的 <code class="docutils literal notranslate"><span class="pre">examples/hellowd/helloworld/cdk</span></code> 目录下,双击 <code class="docutils literal notranslate"><span class="pre">helloworld.cdkproj</span></code>,即可打开 <code class="docutils literal notranslate"><span class="pre">Helloworld</span></code> 工程</p></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="id11">
|
||||
<h3><span class="section-number">2.1.5.7. </span>编译 Hello World<a class="headerlink" href="#id11" title="永久链接至标题">¶</a></h3>
|
||||
<div class="figure align-default" id="id19">
|
||||
<img alt="" src="../_images/cdk1.png" />
|
||||
<p class="caption"><span class="caption-text">helloworld.cdkproj</span><a class="headerlink" href="#id19" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>在活动工程下拉菜单可以选择 <code class="docutils literal notranslate"><span class="pre">CK_Link_Debug</span></code> 或者 <code class="docutils literal notranslate"><span class="pre">OpenOCD_Debug</span></code> 工程,本教程基于 <code class="docutils literal notranslate"><span class="pre">CK_Link_Debug</span></code> 工程</p></li>
|
||||
<li><p>在 CDK 工具栏中,点击编译图标即可编译工程</p>
|
||||
<ul>
|
||||
<li><p>点击 <code class="docutils literal notranslate"><span class="pre">1</span></code> 处 图标 <code class="docutils literal notranslate"><span class="pre">Build</span> <span class="pre">Project</span></code> 即可编译当前选中的工程</p></li>
|
||||
|
@ -286,39 +363,39 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="id7">
|
||||
<h3><span class="section-number">2.1.5.3. </span>烧写 Hello World<a class="headerlink" href="#id7" title="永久链接至标题">¶</a></h3>
|
||||
<div class="section" id="id12">
|
||||
<h3><span class="section-number">2.1.5.8. </span>烧写 Hello World<a class="headerlink" href="#id12" title="永久链接至标题">¶</a></h3>
|
||||
<ul>
|
||||
<li><p>由于目前 CDK 软件中还没有包含我们的 flash 算法,所以需要我们手动将 flash 算法放到 CDK 安装目录,具体操作如下:</p>
|
||||
<ul class="simple">
|
||||
<li><p>进入 SDK 目录下 <code class="docutils literal notranslate"><span class="pre">tools\cdk_flashloader</span></code> 目录</p></li>
|
||||
<li><p>将目录下的 <code class="docutils literal notranslate"><span class="pre">bl70x_flasher.elf</span></code> 文件,拷贝到 CDK 工具的 <code class="docutils literal notranslate"><span class="pre">C-Sky\CDK\CSKY\Flash</span></code> 目录中</p></li>
|
||||
</ul>
|
||||
<div class="figure align-default" id="id11">
|
||||
<div class="figure align-default" id="id20">
|
||||
<img alt="" src="../_images/cdk7.png" />
|
||||
<p class="caption"><span class="caption-text">CDK Flash Loader</span><a class="headerlink" href="#id11" title="永久链接至图片">¶</a></p>
|
||||
<p class="caption"><span class="caption-text">CDK Flash Loader</span><a class="headerlink" href="#id20" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="figure align-default" id="id12">
|
||||
<div class="figure align-default" id="id21">
|
||||
<img alt="" src="../_images/cdk8.png" />
|
||||
<p class="caption"><span class="caption-text">CDK Project Setting</span><a class="headerlink" href="#id12" title="永久链接至图片">¶</a></p>
|
||||
<p class="caption"><span class="caption-text">CDK Project Setting</span><a class="headerlink" href="#id21" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>点击 <code class="docutils literal notranslate"><span class="pre">Project</span> <span class="pre">View</span></code> 中的项目设置按钮,打开 <code class="docutils literal notranslate"><span class="pre">Project</span> <span class="pre">Setting</span></code> 窗口,或者通过右击 <code class="docutils literal notranslate"><span class="pre">Project</span></code> 名称中右击菜单栏中打开</p></li>
|
||||
<li><p>在打开的 <code class="docutils literal notranslate"><span class="pre">Project</span> <span class="pre">Setting</span></code> 窗口中,选择 <code class="docutils literal notranslate"><span class="pre">Flash</span></code> 标签,配置需要的 Flash 算法</p></li>
|
||||
</ul>
|
||||
<div class="figure align-default" id="id13">
|
||||
<div class="figure align-default" id="id22">
|
||||
<img alt="" src="../_images/cdk9.png" />
|
||||
<p class="caption"><span class="caption-text">CDK Project Flash setting</span><a class="headerlink" href="#id13" title="永久链接至图片">¶</a></p>
|
||||
<p class="caption"><span class="caption-text">CDK Project Flash setting</span><a class="headerlink" href="#id22" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>在 <code class="docutils literal notranslate"><span class="pre">Flash</span></code> 标签中,点击 <code class="docutils literal notranslate"><span class="pre">Add</span></code> 按纽,在打开的列表中选择 <code class="docutils literal notranslate"><span class="pre">bl70x_flash</span></code> 算法,点击 <code class="docutils literal notranslate"><span class="pre">Add</span></code> 添加到工程中,<code class="docutils literal notranslate"><span class="pre">Flash</span></code> 标签下的其他设置,如图所示:</p></li>
|
||||
<li><p>点击 OK 后,如配置正确,点击 <code class="docutils literal notranslate"><span class="pre">Flash</span> <span class="pre">Download</span></code> 即可将编译好的代码下载到芯片中</p></li>
|
||||
</ul>
|
||||
<div class="figure align-default" id="id14">
|
||||
<div class="figure align-default" id="id23">
|
||||
<img alt="" src="../_images/cdk5.png" />
|
||||
<p class="caption"><span class="caption-text">CDK Flashdownload Success</span><a class="headerlink" href="#id14" title="永久链接至图片">¶</a></p>
|
||||
<p class="caption"><span class="caption-text">CDK Flashdownload Success</span><a class="headerlink" href="#id23" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>如下载失败请检查:</p>
|
||||
|
@ -343,34 +420,34 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="id8">
|
||||
<h3><span class="section-number">2.1.5.4. </span>运行 Hello World<a class="headerlink" href="#id8" title="永久链接至标题">¶</a></h3>
|
||||
<div class="section" id="id13">
|
||||
<h3><span class="section-number">2.1.5.9. </span>运行 Hello World<a class="headerlink" href="#id13" title="永久链接至标题">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>从 CDK 的菜单栏 <code class="docutils literal notranslate"><span class="pre">View->Serial</span> <span class="pre">Pane</span></code>,打开串口面板,在打开的 <code class="docutils literal notranslate"><span class="pre">Serial</span> <span class="pre">Pane</span></code> 中右击,进行串口设置,选择你对应的串口号和波特率</p></li>
|
||||
</ul>
|
||||
<div class="figure align-default">
|
||||
<img alt="../_images/cdk4.png" src="../_images/cdk4.png" />
|
||||
</div>
|
||||
<div class="figure align-default" id="id15">
|
||||
<div class="figure align-default" id="id24">
|
||||
<img alt="" src="../_images/cdk3.png" />
|
||||
<p class="caption"><span class="caption-text">CDK Serial Pane setting</span><a class="headerlink" href="#id15" title="永久链接至图片">¶</a></p>
|
||||
<p class="caption"><span class="caption-text">CDK Serial Pane setting</span><a class="headerlink" href="#id24" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>按下板子上的 <code class="docutils literal notranslate"><span class="pre">RST</span></code> 按键,即可在串口中看到代码的运行结果</p></li>
|
||||
</ul>
|
||||
<div class="figure align-default" id="id16">
|
||||
<div class="figure align-default" id="id25">
|
||||
<img alt="" src="../_images/cdk6.png" />
|
||||
<p class="caption"><span class="caption-text">HelloWorld!</span><a class="headerlink" href="#id16" title="永久链接至图片">¶</a></p>
|
||||
<p class="caption"><span class="caption-text">HelloWorld!</span><a class="headerlink" href="#id25" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="id9">
|
||||
<h3><span class="section-number">2.1.5.5. </span>调试 Hello World<a class="headerlink" href="#id9" title="永久链接至标题">¶</a></h3>
|
||||
<div class="section" id="id14">
|
||||
<h3><span class="section-number">2.1.5.10. </span>调试 Hello World<a class="headerlink" href="#id14" title="永久链接至标题">¶</a></h3>
|
||||
<ul class="simple">
|
||||
<li><p>点击工具栏上方的 <code class="docutils literal notranslate"><span class="pre">Start/Stop</span> <span class="pre">Debugger</span></code> 按钮,进入 debug 界面,如下图所示</p></li>
|
||||
</ul>
|
||||
<div class="figure align-default" id="id17">
|
||||
<div class="figure align-default" id="id26">
|
||||
<img alt="" src="../_images/cdk10.png" />
|
||||
<p class="caption"><span class="caption-text">Debug HelloWorld!</span><a class="headerlink" href="#id17" title="永久链接至图片">¶</a></p>
|
||||
<p class="caption"><span class="caption-text">Debug HelloWorld!</span><a class="headerlink" href="#id26" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
<ul class="simple">
|
||||
<li><p>在 debug 界面下,左侧的 <code class="docutils literal notranslate"><span class="pre">Register</span></code> 窗口中,可以查看 <code class="docutils literal notranslate"><span class="pre">CPU</span></code> 内部寄存器数据;右侧的 <code class="docutils literal notranslate"><span class="pre">Peripherals</span></code> 外设面板中,
|
||||
|
@ -379,9 +456,9 @@
|
|||
当然这些操作都有相应的快捷键和快捷设置方法,详情请参考 <code class="docutils literal notranslate"><span class="pre">CDK</span> <span class="pre">Help</span></code>,这里就不作过多介绍了。</p></li>
|
||||
<li><p>我们点击单步运行按钮,运行代码,即可看到指示光标移动到下一句代码,同时可以看到串口面板中显示了我们输出的 <code class="docutils literal notranslate"><span class="pre">Hello</span> <span class="pre">World!</span></code></p></li>
|
||||
</ul>
|
||||
<div class="figure align-default" id="id18">
|
||||
<div class="figure align-default" id="id27">
|
||||
<img alt="" src="../_images/cdk11.png" />
|
||||
<p class="caption"><span class="caption-text">Debug HelloWorld!</span><a class="headerlink" href="#id18" title="永久链接至图片">¶</a></p>
|
||||
<p class="caption"><span class="caption-text">Debug HelloWorld!</span><a class="headerlink" href="#id27" title="永久链接至图片">¶</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|