【FR801xH】富芮坤FR801xH之GPIO

00. 目录

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. GPIO相关类型

位于 components\driver\include\driver_gpio.h。

3.1 system_port_t

enum system_port_t
{
    GPIO_PORT_A,
    GPIO_PORT_B,
    GPIO_PORT_C,
    GPIO_PORT_D,
};

3.2 system_port_bit_t

enum system_port_bit_t
{
    GPIO_BIT_0,
    GPIO_BIT_1,
    GPIO_BIT_2,
    GPIO_BIT_3,
    GPIO_BIT_4,
    GPIO_BIT_5,
    GPIO_BIT_6,
    GPIO_BIT_7,
};

3.3 DIR

#define GPIO_DIR_IN             1
#define GPIO_DIR_OUT            0

04. GPIO相关函数

4.1 gpio_portX_write

/*********************************************************************
 * @fn      gpio_porta_write
 *
 * @brief   set gpio PORTA output value.
 *
 * @param   value   - output value.
 *
 * @return  None.
 */
__INLINE void gpio_porta_write(uint8_t value)
{
    REG_PL_WR(GPIO_PORTA_DATA, value);
}

/*********************************************************************
 * @fn      gpio_portb_write
 *
 * @brief   set gpio PORTB output value.
 *
 * @param   value   - output value.
 *
 * @return  None.
 */
__INLINE void gpio_portb_write(uint8_t value)
{
    REG_PL_WR(GPIO_PORTB_DATA, value);
}

/*********************************************************************
 * @fn      gpio_portc_write
 *
 * @brief   set gpio PORTC output value.
 *
 * @param   value   - output value.
 *
 * @return  None.
 */
__INLINE void gpio_portc_write(uint8_t value)
{
    REG_PL_WR(GPIO_PORTC_DATA, value);
}

/*********************************************************************
 * @fn      gpio_portd_write
 *
 * @brief   set gpio PORTD output value.
 *
 * @param   value   - output value.
 *
 * @return  None.
 */
__INLINE void gpio_portd_write(uint8_t value)
{
    REG_PL_WR(GPIO_PORTD_DATA, value);
}

void gpio_portX_write(uint8_t value)
功能:
	设置一组 IO 由大数字控制时的输出值,x 为 a、b、c、d
参数:
	value  IO 的输出值
返回值:

4.2 gpio_portX_read

/*********************************************************************
 * @fn      gpio_porta_read
 *
 * @brief   get current value of gpio PORTA.
 *
 * @param   None.
 *
 * @return  current value of gpio PORTA.
 */
__INLINE uint8_t gpio_porta_read(void)
{
    return REG_PL_RD(GPIO_PORTA_DATA);
}

/*********************************************************************
 * @fn      gpio_portb_read
 *
 * @brief   get current value of gpio PORTB.
 *
 * @param   None.
 *
 * @return  current value of gpio PORTB.
 */
__INLINE uint8_t gpio_portb_read(void)
{
    return REG_PL_RD(GPIO_PORTB_DATA);
}

/*********************************************************************
 * @fn      gpio_portc_read
 *
 * @brief   get current value of gpio PORTC.
 *
 * @param   None.
 *
 * @return  current value of gpio PORTC.
 */__INLINE uint8_t gpio_portc_read(void)
{
    return REG_PL_RD(GPIO_PORTC_DATA);
}

 /*********************************************************************
  * @fn      gpio_portd_read
  *
  * @brief   get current value of gpio PORTD.
  *
  * @param   None.
  *
  * @return  current value of gpio PORTD.
  */
__INLINE uint8_t gpio_portd_read(void)
{
    return REG_PL_RD(GPIO_PORTD_DATA);
}

uint8_t gpio_portX_read(void)
功能:
	获取一组 IO 由大数字控制时的当前值,x 为 a、b、c、d
参数:
	无
返回值:
	IO 的当前值
    
    

4.3 gpio_portX_set_dir

/*********************************************************************
 * @fn      gpio_porta_set_dir
 *
 * @brief   set gpio works in output or input mode.
 *
 * @param   dir - the in-out direction of gpio, each bit represent one channel,
 *                0: output, 1:input.
 *
 * @return  None.
 */
__INLINE void gpio_porta_set_dir(uint8_t dir)
{
    REG_PL_WR(GPIO_PORTA_DIR, dir);
}

/*********************************************************************
 * @fn      gpio_portb_set_dir
 *
 * @brief   set gpio works in output or input mode.
 *
 * @param   dir - the in-out direction of gpio, each bit represent one channel,
 *                0: output, 1:input.
 *
 * @return  None.
 */
__INLINE void gpio_portb_set_dir(uint8_t dir)
{
    REG_PL_WR(GPIO_PORTB_DIR, dir);
}

/*********************************************************************
 * @fn      gpio_portc_set_dir
 *
 * @brief   set gpio works in output or input mode.
 *
 * @param   dir - the in-out direction of gpio, each bit represent one channel,
 *                0: output, 1:input.
 *
 * @return  None.
 */
__INLINE void gpio_portc_set_dir(uint8_t dir)
{
    REG_PL_WR(GPIO_PORTC_DIR, dir);
}

/*********************************************************************
 * @fn      gpio_portd_set_dir
 *
 * @brief   set gpio works in output or input mode.
 *
 * @param   dir - the in-out direction of gpio, each bit represent one channel,
 *                0: output, 1:input.
 *
 * @return  None.
 */
__INLINE void gpio_portd_set_dir(uint8_t dir)
{
    REG_PL_WR(GPIO_PORTD_DIR, dir);
}

void gpio_portX_set_dir(uint8_t dir)
功能:
	设置一组 IO 由大数字控制时的输入输出,x 为 a、b、c、d
参数:
	dir  输入输出,每一位对应一个 IO,0:输出;1:输入
返回值:

4.4 gpio_portX_get_dir

/*********************************************************************
 * @fn      gpio_porta_set_dir
 *
 * @brief   get current gpio PORTA in-out setting.
 *
 * @param   None.
 *
 * @return  current setting.
 */
__INLINE uint8_t gpio_porta_get_dir(void)
{
    return REG_PL_RD(GPIO_PORTA_DIR);
}

/*********************************************************************
 * @fn      gpio_portb_set_dir
 *
 * @brief   get current gpio PORTB in-out setting.
 *
 * @param   None.
 *
 * @return  current setting.
 */
__INLINE uint8_t gpio_portb_get_dir(void)
{
    return REG_PL_RD(GPIO_PORTB_DIR);
}

/*********************************************************************
 * @fn      gpio_portc_set_dir
 *
 * @brief   get current gpio PORTC in-out setting.
 *
 * @param   None.
 *
 * @return  current setting.
 */
__INLINE uint8_t gpio_portc_get_dir(void)
{
    return REG_PL_RD(GPIO_PORTC_DIR);
}

/*********************************************************************
 * @fn      gpio_portd_set_dir
 *
 * @brief   get current gpio PORTD in-out setting.
 *
 * @param   None.
 *
 * @return  current setting.
 */
__INLINE uint8_t gpio_portd_get_dir(void)
{
    return REG_PL_RD(GPIO_PORTD_DIR);
}

uint8_t gpio_portX_get_dir(void)
功能:
	获取一组 IO 由大数字控制时的输入输出设置,x 为 a、b、c、d
参数:
	无
返回值:
	当前的输入输出配置
    

4.5 gpio_set_dir

/*********************************************************************
 * @fn      gpio_set_dir
 *
 * @brief   set specific gpio channel working mode: output or input.
 *
 * @param   port    - which port this channel belongs to. @ref system_port_t
 *          bit     - channel number. @ref system_port_bit_t
 *          dir     - in-out selection, should be GPIO_DIR_IN or GPIO_DIR_OUT.
 *
 * @return  None.
 */
void gpio_set_dir(enum system_port_t port, enum system_port_bit_t bit, uint8_t dir);
功能:
	设置 IO 由大数字控制时的输入输出,一次设置一个 IO
参数:
	port IO 所属的端口组
	bit  IO 的 channel 编号
	dir  输入或者输出
返回值:

示例

gpio_set_dir(GPIO_PORT_A, GPIO_BIT_0, GPIO_DIR_OUT);

05. 低功耗模式GPIO接口

5.1 pmu_set_gpio_value

/*********************************************************************
 * @fn      pmu_set_gpio_value
 *
 * @brief   set value of IOs which are controlled by PMU.
 *          example usage:
 *          pmu_set_gpio_value(GPIO_PORT_A, (1<<GPIO_BIT0)|((1<<GPIO_BIT1), 1)
 *
 * @param   port    - which group the io belongs to, @ref system_port_t
 *          bits    - the numbers of io
 *          value   - 1: set the IO to high, 0: set the IO to low.
 *
 * @return  None.
 */
void pmu_set_gpio_value(enum system_port_t port, uint8_t bits, uint8_t value);
功能:
	当某个 pin 脚被配置为 pmu gpio 控制,并且是输出模式时,设置该 pin 脚的值
参数:
	port 选择 pin 脚对应的 port 口,一共有 4 个 port 口,PA,PB,PC,PD。参见 enum system_port_t 定义。
	bits 选择 pin 脚对应的 pin 号码,bit7~bit0 分别代表每个 port 口的 pin7~pin0。每个 bit 位表示该 pin 被选中。
	Value 设置 pin 脚输出值。只能填以下二值:1,该 pin 输出为高。0,该 pin 输出为低。
返回值:

示例

void pmu_gpio_test(void)
{
    pmu_set_port_mux(GPIO_PORT_A,GPIO_BIT_0,PMU_PORT_MUX_GPIO);
    pmu_set_port_mux(GPIO_PORT_A,GPIO_BIT_1,PMU_PORT_MUX_GPIO);
    pmu_set_pin_to_PMU(GPIO_PORT_A,BIT(0)|BIT(1) );
    pmu_set_pin_dir(GPIO_PORT_A,BIT(0)|BIT(1), GPIO_DIR_OUT);
    pmu_set_pin_pull(GPIO_PORT_A, BIT(0)|BIT(1), true);
    pmu_set_gpio_value(GPIO_PORT_A, BIT(0)|BIT(1), 1);
    co_delay_100us(10);
    
	pmu_set_gpio_value(GPIO_PORT_A, BIT(0)|BIT(1), 0);
}    

5.2 pmu_get_gpio_value

/*********************************************************************
 * @fn      pmu_get_gpio_value
 *
 * @brief   get value of IO which are controlled by PMU and in GPIO mode.
 *          example usage:
 *          pmu_get_gpio_value(GPIO_PORT_A, GPIO_BIT_0)
 *
 * @param   port    - which group the io belongs to, @ref system_port_t
 *          bit     - the number of io
 *
 * @return  1: the IO is high, 0: the IO is low..
 */
uint8_t pmu_get_gpio_value(enum system_port_t port, uint8_t bit);
功能:
	当某个 pin 脚被配置为 pmu gpio 控制,并且是输入模式时,获取该 pin 脚的值。
参数:
	port 选择 pin 脚对应的 port 口,一共有 4 个 port 口,PA,PB,PC,PD。参见 enum system_port_t 定义。
	bit 选择 pin 脚对应的 pin 号码,参见 enum system_port_bit_t 定义
返回值:
	IO口的值

示例

void pmu_gpio_test(void)
{
    pmu_set_port_mux(GPIO_PORT_A,GPIO_BIT_2,PMU_PORT_MUX_GPIO);
    pmu_set_port_mux(GPIO_PORT_A,GPIO_BIT_3,PMU_PORT_MUX_GPIO);
    pmu_set_pin_to_PMU(GPIO_PORT_A,BIT(2)|BIT(3) );
    pmu_set_pin_dir(GPIO_PORT_A,BIT(2)|BIT(3), false);
    co_printf("PA2:%d,PA3:%d\r\n",pmu_get_gpio_value(GPIO_PORT_A,GPIO_BIT_2)
    	,pmu_get_gpio_value(GPIO_PORT_A,GPIO_BIT_3) );
}

06. GPIO程序示例

程序示例

// 普通GPIO示例
void peripheral_demo(void)
{
    co_printf("digital gpio demo\r\n");
    // digital gpio output
    system_set_port_mux(GPIO_PORT_D, GPIO_BIT_4, PORTD4_FUNC_D4);
    system_set_port_mux(GPIO_PORT_D, GPIO_BIT_5, PORTD5_FUNC_D5);
    gpio_set_dir(GPIO_PORT_D, GPIO_BIT_4, GPIO_DIR_OUT);
    gpio_set_dir(GPIO_PORT_D, GPIO_BIT_5, GPIO_DIR_OUT);

    gpio_set_pin_value(GPIO_PORT_D, GPIO_BIT_4, 1);
    gpio_set_pin_value(GPIO_PORT_D, GPIO_BIT_5, 1);
    co_delay_100us(10000);
    gpio_set_pin_value(GPIO_PORT_D, GPIO_BIT_4, 0);
    gpio_set_pin_value(GPIO_PORT_D, GPIO_BIT_5, 0);

    // digital gpio input
    system_set_port_mux(GPIO_PORT_D, GPIO_BIT_7, PORTD7_FUNC_D7);
    system_set_port_mux(GPIO_PORT_D, GPIO_BIT_6, PORTD6_FUNC_D6);
    gpio_set_dir(GPIO_PORT_D, GPIO_BIT_7, GPIO_DIR_IN);
    gpio_set_dir(GPIO_PORT_D, GPIO_BIT_6, GPIO_DIR_IN);
    system_set_port_pull((GPIO_PD6 | GPIO_PD7), true);
    co_printf("PD6:%d\r\n", gpio_get_pin_value(GPIO_PORT_D, GPIO_BIT_6));
    co_printf("PD7:%d\r\n", gpio_get_pin_value(GPIO_PORT_D, GPIO_BIT_7));
}

运行结果

******Connected******

******Start Auto Burn******
****************************************************
******CRC Success******

******Burn Success******
?digital gpio demo
PD6:1
PD7:1

07. 附录

官网:https://www.freqchip.com/

### 芮坤 FR801xH 蓝牙模块的技术规格 芮坤 FR801xH 是一款高性能的蓝牙低功耗 (BLE) 模块,适用于各种物联网(IoT)应用场景。该模块基于 ARM Cortex-M3 架构设计,具有强大的处理能力和较低的能耗。 #### 主要技术参数 - **处理器**: 基于ARM Cortex-M3内核,最高工作频率可达96 MHz[^2] - **内存资源** - Flash: 高达512 KB - SRAM: 至少64 KB - **无线性能** - 支持Bluetooth Low Energy v4.2标准 - 发射功率:+5 dBm至-30 dBm可调 - 接收灵敏度:-95 dBm@1Mbps GFSK - **接口与外设** - UART/SPI/IIC等多种串行通信接口 - 多路PWM输出以及ADC输入通道 - GPIO端口数量充足,便于连接外部设备[^3] #### 应用场景 由于其出色的能效表现和丰的外围功能,FR801xH非常适合用于以下领域: - 可穿戴电子产品:如智能手表、健身追踪器等; - 家庭自动化系统:包括智能家居控制器、环境监测装置等; - 工业控制网络:实现机器间的数据交换及远程监控; - 医疗保健器械:便携式医疗仪器、健康监护终端等; #### 特性亮点 - **易于集成**:提供完整的软件开发套件(SDK),简化应用程序编写过程[^1]。 - **安全可靠**:通过配置Service和服务特性来保障数据传输的安全性。 - **灵活调试**:配备专门的BLE调试工具——BLE调试宝串口调试助手,方便开发者进行测试验证。 ```c // 示例代码片段展示如何初始化GPIO引脚作为输出模式 void init_gpio_output(void){ // 设置PA0为推挽输出模式 SET_GPIO_MODE(GPIO_PORT_A, GPIO_BIT_0, OUTPUT_PP); } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沧海一笑-dj

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值