当前位置: 首页 > news >正文

【FR801xH】富芮坤FR801xH之UART

00. 目录

文章目录

    • 00. 目录
    • 01. FR801xH概述
    • 02. FR801xH功能框图
    • 03. UART相关类型
      • 3.1 波特率
      • 3.2 串口设备
    • 04. UART相关函数
      • 4.1 uart_init
      • 4.2 uart_finish_transfers
      • 4.3 uart_read
      • 4.4 uart_write
      • 4.5 uart_putc_noint
      • 4.6 uart_putc_noint_no_wait
      • 4.7 uart_put_data_noint
      • 4.8 uart_get_data_noint
      • 4.9 uart_get_data_nodelay_noint
      • 4.10 uart0_read
      • 4.11 uart0_write
      • 4.12 uart1_read
      • 4.13 uart1_write
    • 05. 程序示例
    • 06. 附录

01. FR801xH概述

在这里插入图片描述

FR801xH 系列芯片是面向SOC(片上系统),易于快速开发的低功耗蓝牙芯片。基于 Freqchip 的蓝牙智能固件和协议栈的支持,完全兼容蓝牙 V5.3(LE 模式)协议。同时用户可以基于芯片内置的 ARM CorteM3 嵌入式 32 位高性能单片机开发各种应用程序。

蓝牙智能固件包括 L2CAP 服务层协议、安全管理器 (SM)、属性协议(ATT)、通用属性配置文件 (GATT)和通用访问配置文件(GAP)。此外,还 支持应用程序配置文件,例如接近度、健康温度计、 心率、血压、血糖、人机界面设备(HID)和 SDK (包括驱动程序、OS-API 等)。SDK 还集成了用于网络应用程序的 SIG Mesh 协议。

采用 Freqchip 的创新技术,将 PMU(锂电池充电 器+LDO)、带 XIP 模式的 QSPI FLASH ROM、 I2C、UART、GPIO、ADC、PWM 集成在一块芯片中,为客户提供:

  • 竞争力的功耗
  • 稳定的蓝牙连接
  • 极低的 BOM 成本

02. FR801xH功能框图

在这里插入图片描述

03. UART相关类型

位于 components\driver\include\driver_uart.h

3.1 波特率

/* BAUD_RATE configuration */
#define BAUD_RATE_921600                 11
#define BAUD_RATE_460800                 10
#define BAUD_RATE_230400                 9
#define BAUD_RATE_115200                 8
#define BAUD_RATE_57600                  7
#define BAUD_RATE_38400                  6
#define BAUD_RATE_19200                  5
#define BAUD_RATE_14400                  4
#define BAUD_RATE_9600                   3
#define BAUD_RATE_4800                   2
#define BAUD_RATE_2400                   1
#define BAUD_RATE_1200                   0

3.2 串口设备

#define UART0                            UART0_BASE
#define UART1                            UART1_BASE

04. UART相关函数

4.1 uart_init

/********************************************************************** @fn      uart_init** @brief   initialize the uart module. Before calling this function, corresponding*          IO mux should be configured correctly.** @param   uart_addr   - which uart will be initialized, UART0 or UART1.*          bandrate    - such as BAUD_RATE_115200.** @return  None.*/
void uart_init(uint32_t uart_addr, uint8_t bandrate);
功能:初始化 UART 模块,函数内会清空 fifo,使能接收非空中断
参数:uart_addr 初始化的端口,可选 UART0、UART1bandrate 配置的波特率,例如 BAUD_RATE_115200
返回值:

4.2 uart_finish_transfers

/********************************************************************** @fn      uart_finish_transfers** @brief   wait for tx fifo empty.** @param   uart_addr   - which uart will be checked, UART0 or UART1.** @return  None.*/
void uart_finish_transfers(uint32_t uart_addr);
功能:等待发送 fifo 为空
参数:uart_addr  -  等待的端口,可选 UART0、UART1
返回值:

4.3 uart_read

/********************************************************************** @fn      uart_write** @brief   get several byte from UART bus with block mode.** @param   uart_addr   - which uart will be used, UART0 or UART1.*          bufptr      - store position of data to be received*          size        - length of data to be received** @return  None.*/
void uart_read(uint32_t uart_addr, uint8_t *buf, uint32_t size);
功能:采用阻塞方式从串口接收
参数:uart_addr 等待的端口,可选 UART0、UART1buf 存放接收数据的指针size 需要接收的数据长度
返回值:

4.4 uart_write

/********************************************************************** @fn      uart_write** @brief   send several byte to UART bus with block mode.** @param   uart_addr   - which uart will be used, UART0 or UART1.*          bufptr      - store position of data to be send*          size        - length of data to be send** @return  None.*/
void uart_write(uint32_t uart_addr, const uint8_t *bufptr, uint32_t size);
功能:采用阻塞方式发送数据到串口
参数:uart_addr 等待的端口,可选 UART0、UART1buf 待发送数据的指针size 待发送的数据长度
返回值:

4.5 uart_putc_noint

/********************************************************************** @fn      uart_putc_noint** @brief   send a byte to UART bus, return until tx fifo is empty.** @param   uart_addr   - which uart will be used, UART0 or UART1.*          c           - data to be send** @return  None.*/
void uart_putc_noint(uint32_t uart_addr, uint8_t c);
功能:发送一个字符,且等待发送 fifo 为空
参数:uart_addr 使用的端口,可选 UART0、UART1c 待发送的字符
返回值:

4.6 uart_putc_noint_no_wait

/********************************************************************** @fn      uart_putc_noint** @brief   send a byte to UART bus without the byte is sent.** @param   uart_addr   - which uart will be used, UART0 or UART1.*          c           - data to be send** @return  None.*/
void uart_putc_noint_no_wait(uint32_t uart_addr, uint8_t c);
功能:将待发送的字符写入到发送 fifo
参数:uart_addr 使用的端口,可选 UART0、UART1c 待发送的字符
返回值:

4.7 uart_put_data_noint

/********************************************************************** @fn      uart_put_data_noint** @brief   send several bytes to UART bus, return until tx fifo is empty.** @param   uart_addr   - which uart will be used, UART0 or UART1.*          d           - data buffer pointer*          size        - how many bytes to be send.** @return  None.*/
void uart_put_data_noint(uint32_t uart_addr, const uint8_t *d, int size);
功能:发送特定长度的字符,且等待发送 fifo 为空
参数:uart_addr 使用的端口,可选 UART0、UART1d 待发送数据的保存地址指针size 待发送数据的长度
返回值:

4.8 uart_get_data_noint

/********************************************************************** @fn      uart_get_data_noint** @brief   get data with specified length, return until all data are acquired.** @param   uart_addr   - which uart will be used, UART0 or UART1.*          d           - data buffer pointer*          size        - how many bytes to be read.** @return  None.*/
void uart_get_data_noint(uint32_t uart_addr, uint8_t *buf, int size);
功能:获取特定长度的字符
参数:uart_addr  -  使用的端口,可选 UART0、UART1buf  -  待接收数据的保存地址指针size  -  待接收数据的长度
返回值:

4.9 uart_get_data_nodelay_noint

/********************************************************************** @fn      uart_get_data_nodelay_noint** @brief   get data with specified length, return until rx fifo is empty *          or all data are acquired.** @param   uart_addr   - which uart will be used, UART0 or UART1.*          d           - data buffer pointer*          size        - how many bytes to be read.** @return  how many bytes have been read, may be less than parameter size.*/
int uart_get_data_nodelay_noint(uint32_t uart_addr, uint8_t *buf, int size);
功能:获取特定长度的字符,当接收 fifo 为空时就会返回
参数:uart_addr  -  使用的端口,可选 UART0、UART1buf  -  待接收数据的保存地址指针size  -  待接收数据的长度
返回值:实际接收到的数据长度

4.10 uart0_read

/********************************************************************** @fn      uart0_read** @brief   get data with specified length. Interrup will be enable inside this function,*          callback will be called once all data are acquired.** @param   bufptr  - ram pointer used to store read data.*          size    - how many bytes to be read.*          callback- callback function when all data are acquired.** @return  None.*/
void uart0_read_for_hci(uint8_t *bufptr, uint32_t size, uart_int_callback callback, void *dummy);
#define uart0_read(bufptr, size, callback)      uart0_read_for_hci(bufptr, size, callback, NULL)
功能:采用中断加回调函数的方式从 UART0 中读取特定长度的数据,需配合内置的 uart0_isr 使用(也就是无需重新实现 UART0 的中断处理函数)。
参数:bufptr  -  待接收数据的保存地址指针size  -  待接收数据的长度callback  -  接收完数据的回调函数
返回值:

4.11 uart0_write

/********************************************************************** @fn      uart0_write** @brief   send data with specified length. callback will be called once all *          data are sent.** @param   bufptr  - ram pointer used to store send data.*          size    - how many bytes to be sent.*          callback- callback function when all data are sent.** @return  None.*/
void uart0_write_for_hci(uint8_t *bufptr, uint32_t size, uart_int_callback callback, void *dummy);
#define uart0_write(bufptr, size, callback)      uart0_write_for_hci(bufptr, size, callback, NULL)
功能:采用中断加回调函数的方式用 UART0 中发送特定长度的数据,需配合内置的 uart0_isr 使用(也就是无需重新实现 UART0 的中断处理函数)。
参数:bufptr  -  待发送数据的保存地址指针size  -  待发送数据的长度callback  -  发送完数据的回调函数
返回值:

4.12 uart1_read

/********************************************************************** @fn      uart1_read** @brief   get data with specified length. Interrup will be enable inside this function,*          callback will be called once all data are acquired.** @param   bufptr  - ram pointer used to store read data.*          size    - how many bytes to be read.*          callback- callback function when all data are acquired.** @return  None.*/
void uart1_read_for_hci(uint8_t *bufptr, uint32_t size, uart_int_callback callback, void *dummy);
#define uart1_read(bufptr, size, callback)      uart1_read_for_hci(bufptr, size, callback, NULL)
功能:采用中断加回调函数的方式从 UART1 中读取特定长度的数据,需配合内置的 uart1_isr 使用(也就是无需重新实现 UART1 的中断处理函数)。
参数:bufptr  -  待接收数据的保存地址指针size  -  待接收数据的长度callback  -  接收完数据的回调函数
返回值:

4.13 uart1_write

/********************************************************************** @fn      uart1_write** @brief   send data with specified length. callback will be called once all *          data are sent.** @param   bufptr  - ram pointer used to store send data.*          size    - how many bytes to be sent.*          callback- callback function when all data are sent.** @return  None.*/
void uart1_write_for_hci(uint8_t *bufptr, uint32_t size, uart_int_callback callback, void *dummy);
#define uart1_write(bufptr, size, callback)      uart1_write_for_hci(bufptr, size, callback, NULL)
功能:采用中断加回调函数的方式用 UART1 中发送特定长度的数据,需配合内置的 uart1_isr 使用(也就是无需重新实现 UART0 的
中断处理函数)。
参数:bufptr  -  待发送数据的保存地址指针size  -  待发送数据的长度callback  -  发送完数据的回调函数
返回值:

05. 程序示例

程序示例

__attribute__((section("ram_code"))) void uart0_isr_ram(void)
{uint8_t int_id;uint8_t c;volatile struct uart_reg_t *uart_reg = (volatile struct uart_reg_t *)UART0_BASE;int_id = uart_reg->u3.iir.int_id;if (int_id == 0x04 || int_id == 0x0c) /* Receiver data available or Character time-out indication */{while (uart_reg->lsr & 0x01){c = uart_reg->u1.data;uart_putc_noint_no_wait(UART0, c);}}else if (int_id == 0x06){// uart_reg->u3.iir.int_id = int_id;// uart_reg->u2.ier.erlsi = 0;volatile uint32_t line_status = uart_reg->lsr;}
}void peripheral_demo(void)
{
#if 0system_set_port_pull(GPIO_PD6, true);system_set_port_mux(GPIO_PORT_D, GPIO_BIT_6, PORTD6_FUNC_UART0_RXD);system_set_port_mux(GPIO_PORT_D, GPIO_BIT_7, PORTD7_FUNC_UART0_TXD);uart_init(UART0, BAUD_RATE_115200);co_printf("uart0 demo\r\n");
#endifsystem_set_port_pull(GPIO_PD4, true);system_set_port_mux(GPIO_PORT_D, GPIO_BIT_4, PORTD4_FUNC_UART0_RXD);system_set_port_mux(GPIO_PORT_D, GPIO_BIT_5, PORTD5_FUNC_UART0_TXD);// uart_init(UART1, BAUD_RATE_115200);uart_param_t param ={.baud_rate = 115200,.data_bit_num = 8,.pari = 0,.stop_bit = 1,};uart_init1(UART0, param);NVIC_EnableIRQ(UART0_IRQn);co_printf("uart0 demo\r\n");
}

运行结果

******Connected************Start Auto Burn******
****************************************************
******CRC Success************Burn Success******
?uart0 demo

串口调试助手


[11:59:33.982]发→◇aa
[11:59:34.006]收←◆aa
[11:59:38.770]发→◇bb
[11:59:38.780]收←◆bb
[11:59:50.265]发→◇cc
[11:59:50.278]收←◆cc

06. 附录

http://www.dtcms.com/a/263661.html

相关文章:

  • npm list的使用方法详细介绍
  • 基于 Three.js 与 WebGL 的商场全景 VR 导航系统源码级解析
  • python 操作 hive
  • vue | 插件 | 移动文件的插件 —— move-file-cli 插件 的安装与使用
  • RabbitMQ - SpringAMQP及Work模型
  • C++仿函数与谓词深度解析:函数对象的艺术
  • android apk签名
  • 文件系统之配置网络参数
  • SiFli 52 UART的RX唤醒MCU怎么做
  • 飞算 JavaAI:我的编程强力助推引擎
  • Vue Vue-route (3)
  • Web性能测试常用指标(转自百度AI)
  • PHP爬虫实战指南:获取淘宝商品详情
  • 飞算 JavaAI 开发助手:深度学习驱动下的 Java 全链路智能开发新范式
  • 图神经网络(篇一)-GraphSage
  • CyclicBarrier(同步屏障)是什么?它的原理和用法是什么?
  • 新手向:从零开始Node.js超详细安装、配置与使用指南
  • Embeddings模型
  • 微服务介绍
  • Unity进阶课程【六】Android、ios、Pad 终端设备打包局域网IP调试、USB调试、性能检测、控制台打印日志等、C#
  • 【RTSP从零实践】4、使用RTP协议封装并传输AAC
  • 学习threejs,使用自定义GLSL 着色器,生成艺术作品
  • 电机参数测量
  • 自由学习记录(66)
  • JT808教程:消息的结构
  • react中在Antd3.x版本中 Select框在单选时 选中框的高度调整
  • Qt 实现Opencv功能模块切换界面功能
  • 【算法】动态规划:python实现 1
  • TensorFlow内核剖析:分布式TensorFlow架构解析与实战指南
  • mini-electron使用方法