FR8018HA开发资料
目录
1. 概况 ............................................................................................................................................................................. 10
1.1 FR801xH SDK 结构 ............................................................................................................................................ 10
1.2 空间分配 .......................................................................................................................................................... 10
1.2.1 地址空间 ................................................................................................................................................ 10
1.2.2 空间分配 ................................................................................................................................................ 11
1.3 代码流程 .......................................................................................................................................................... 12
1.3.1 user_custom_parameters 函数 ............................................................................................................. 12
1.3.2 user_entry_before_ble_init 函数 .......................................................................................................... 13
1.3.3 user_entry_after_ble_init 函数 ............................................................................................................. 13
1.3.4 睡眠唤醒用户接口 ................................................................................................................................ 14
1.4 __jump_table .................................................................................................................................................... 14
1.5 SDK 项目工程 .................................................................................................................................................. 15
1.6 芯片烧录 .......................................................................................................................................................... 15
1.6.1 基于 Keil J-Link 的烧录方式 ............................................................................................................... 16
1.6.2 采用 PC 烧录工具 串口进行烧录 ........................................................................................................ 17
1.6.3 量产烧录 ................................................................................................................................................ 18
2. 低功耗管理 ................................................................................................................................................................. 19
2.1 工作模式 .......................................................................................................................................................... 19
2.2 程序运行流程 .................................................................................................................................................. 19
2.3 唤醒条件 .......................................................................................................................................................... 20
3. BLE 协议栈 ................................................................................................................................................................. 21
3.1 GAP API ............................................................................................................................................................. 21
3.1.1 GAP 事件 ................................................................................................................................................ 21
3.1.1.1 GAP Event Type Defines ............................................................................................................ 21
3.1.1.2 GAP Link Established Event ....................................................................................................... 21
3.1.1.3 GAP Link Disconnect Event ........................................................................................................ 22
3.1.1.4 GAP Link Parameter Update Reject Event ................................................................................. 22
3.1.1.5 GAP Link Parameter Update Success Event............................................................................... 22
3.1.1.6 GAP Advertising Report Event ................................................................................................... 22
3.1.1.7 GAP Peer Feature Event ............................................................................................................ 23
3.1.1.8 GAP GATT MTU Event ................................................................................................................ 23
3.1.1.9 GAP Security Master Authentication Request Event ................................................................. 23
3.1.1.10 GAP Message Event ................................................................................................................... 23
3.1.1.11 GAP Advertising Mode Defines ................................................................................................. 24
3.1.1.12 GAP Advertising Type Defines ................................................................................................... 24
3.1.1.13 GAP Advertising Channel Defines ............................................................................................. 24
3.1.1.14 GAP Advertising Filter Mode Defines ........................................................................................ 25
3.1.1.15 GAP Advertising Paramters ....................................................................................................... 25
3.1.1.16 GAP Scan Mode Defines ............................................................................................................ 25
3.1.1.17 GAP Scan Result Type Defines ................................................................................................... 25
3.1.1.18 GAP Scan Paramters .................................................................................................................. 25
3.1.1.19 GAP Pairing Mode Defines ........................................................................................................ 26
3.1.1.20 GAP IO Capabilities Defines ...................................................................................................... 26
FR801xH SDK User Guide | 2020-05 v1.0.8
3 / 108
3.1.1.21 GAP Security Parameters .......................................................................................................... 26
3.1.1.22 Gap bond information ............................................................................................................... 26
3.1.2 GAP 函数 ................................................................................................................................................ 27
3.1.2.1 GAP Set Event Callback Function .............................................................................................. 27
3.1.2.2 GAP Set Advertising Paramters ................................................................................................. 27
3.1.2.3 GAP Set Advertising data .......................................................................................................... 29
3.1.2.4 GAP Set Advertising Response data .......................................................................................... 29
3.1.2.5 GAP Start Advertising ................................................................................................................ 29
3.1.2.6 GAP Stop Advertising ................................................................................................................ 30
3.1.2.7 GAP Start Scanning .................................................................................................................... 30
3.1.2.8 GAP Stop Scanning .................................................................................................................... 30
3.1.2.9 GAP Connect Request ............................................................................................................... 31
3.1.2.10 GAP Cancel Connection Procedure ........................................................................................... 31
3.1.2.11 GAP Disconnect Request ........................................................................................................... 31
3.1.2.12 GAP Get Local Address .............................................................................................................. 32
3.1.2.13 GAP Set Local Address ............................................................................................................... 32
3.1.2.14 GAP Set White List .................................................................................................................... 32
3.1.2.15 GAP Set Resolved Address List .................................................................................................. 33
3.1.2.16 GAP Get Connection Status ....................................................................................................... 33
3.1.2.17 GAP Get Encryption Status ........................................................................................................ 33
3.1.2.18 GAP Set Device Name ............................................................................................................... 34
3.1.2.19 GAP Get Device Name ............................................................................................................... 34
3.1.2.20 GAP Set Device Appearance ...................................................................................................... 34
3.1.2.21 GAP Get Device Appearance ..................................................................................................... 34
3.1.2.22 GAP Get Connection Number ................................................................................................... 35
3.1.2.23 GAP Get Link RSSI ...................................................................................................................... 35
3.1.2.24 GAP Enable RSSI report in real time .......................................................................................... 35
3.1.2.25 GAP Connection Parameters Update Request .......................................................................... 35
3.2 GATT API ............................................................................................................................................................ 36
3.2.1 GATT 事件 ............................................................................................................................................. 36
3.2.1.1 GATT Property Bitmap Defines.................................................................................................. 36
3.2.1.2 GATT Operation Defines ............................................................................................................ 36
3.2.1.3 GATT Event Type ........................................................................................................................ 36
3.2.1.4 GATT Operation Complete Event .............................................................................................. 37
3.2.1.5 GATT Message Data .................................................................................................................. 37
3.2.1.6 GATT Message Event ................................................................................................................. 37
3.2.1.7 GATT Attribute Structure ........................................................................................................... 38
3.2.1.8 GATT Service Structure.............................................................................................................. 38
3.2.1.9 GATT Client Structure ................................................................................................................ 38
3.2.1.10 GATT Client Read ....................................................................................................................... 39
3.2.1.11 GATT Client Enable Notification ................................................................................................ 39
3.2.1.12 GATT Notification Structure ...................................................................................................... 39
3.2.1.13 GATT Indication Structure ......................................................................................................... 39
3.2.2 GATT 函数 ............................................................................................................................................. 40
FR801xH SDK User Guide | 2020-05 v1.0.8
4 / 108
3.2.2.1 GATT Add Service ...................................................................................................................... 40
3.2.2.2 GATT Add Client ........................................................................................................................ 40
3.2.2.3 GATT Change Service UUID ....................................................................................................... 40
3.2.2.4 GATT Change Client UUID ......................................................................................................... 40
3.2.2.5 GATT Discover Peer Device All Services .................................................................................... 41
3.2.2.6 GATT Discover Peer Device Service By UUID ............................................................................. 41
3.2.2.7 GATT Write Request .................................................................................................................. 42
3.2.2.8 GATT Write Command............................................................................................................... 42
3.2.2.9 GATT Enable Notification .......................................................................................................... 43
3.2.2.10 GATT Read Request ................................................................................................................... 43
3.2.2.11 GATT Notification ...................................................................................................................... 44
3.2.2.12 GATT Indication ......................................................................................................................... 44
3.2.2.13 GATT MTU Exchange Request ................................................................................................... 45
3.2.2.14 GATT Get negotiated MTU size ................................................................................................. 45
3.2.2.15 GATT deal message from HOST (condition: RTOS enable) ........................................................ 45
3.3 Mesh API ........................................................................................................................................................... 45
3.3.1 Mesh 事件 .............................................................................................................................................. 46
3.3.1.1 Mesh Event Type Defines .......................................................................................................... 46
3.3.1.2 Mesh network information updates ......................................................................................... 46
3.3.1.3 Mesh Supported Features ......................................................................................................... 46
3.3.1.4 Mesh Provision Output OOB Mode .......................................................................................... 47
3.3.1.5 Mesh Provision Input OOB Mode ............................................................................................. 47
3.3.1.6 Mesh Provision Information ...................................................................................................... 47
3.3.1.7 Mesh Provision States ............................................................................................................... 48
3.3.1.8 Mesh Publish Message Type ..................................................................................................... 48
3.3.1.9 Mesh Response Message type .................................................................................................. 48
3.3.1.10 Mesh Receive Message Type .................................................................................................... 48
3.3.1.11 Mesh Model Structure .............................................................................................................. 49
3.3.1.12 Mesh Provision State Change Event .......................................................................................... 49
3.3.1.13 Mesh Model Message Indication .............................................................................................. 49
3.3.1.14 Network Key is NOT updated .................................................................................................... 50
3.3.1.15 Network Key is updated ............................................................................................................ 50
3.3.1.16 Application Key is NOT updated ................................................................................................ 50
3.3.1.17 Application Key is updated ........................................................................................................ 50
3.3.1.18 Model publication parameter for NOT virtual publication address .......................................... 51
3.3.1.19 Model publication parameter for virtual publication address .................................................. 51
3.3.1.20 Model subscription entry .......................................................................................................... 52
3.3.1.21 Key binding entry ...................................................................................................................... 52
3.3.1.22 Configuration updated indication ............................................................................................. 52
3.3.1.23 Mesh Event Structure ................................................................................................................ 52
3.3.2 Mesh 函数 .............................................................................................................................................. 53
3.3.2.1 Mesh Set Application Callback Function ................................................................................... 53
3.3.2.2 Mesh Initialization ..................................................................................................................... 53
3.3.2.3 Mesh Set Runtime ..................................................................................................................... 53
FR801xH SDK User Guide | 2020-05 v1.0.8
5 / 108
3.3.2.4 Mesh Start ................................................................................................................................. 54
3.3.2.5 Mesh Stop ................................................................................................................................. 54
3.3.2.6 Mesh Model Bind AppKey ......................................................................................................... 54
3.3.2.7 Mesh Model Subscribe Group Message ................................................................................... 54
3.3.2.8 Mesh Add Models ..................................................................................................................... 55
3.3.2.9 Mesh Publish Message .............................................................................................................. 55
3.3.2.10 Mesh Send Response message ................................................................................................. 55
3.3.2.11 Mesh Provision Parameters response ....................................................................................... 55
3.3.2.12 Mesh Provision Authentication Data Response ........................................................................ 56
3.3.2.13 Mesh Composition Data Response ........................................................................................... 56
3.3.2.14 Mesh Store Information Into Flash ........................................................................................... 56
3.3.2.15 Mesh Clear Information In Flash ............................................................................................... 56
3.4 Security API ....................................................................................................................................................... 57
3.4.1 Security 函数 ......................................................................................................................................... 57
3.4.1.1 GAP Bond Manager Initializtion ................................................................................................ 57
3.4.1.2 GAP Get Bond Device Information ............................................................................................ 57
3.4.1.3 GAP Bond Manager Delete All Bondings ................................................................................... 58
3.4.1.4 GAP Bond Manager Delete Single Bondging ............................................................................. 58
3.4.1.5 GAP Set Security Parameters .................................................................................................... 58
3.4.1.6 GAP Sending Pairing Password .................................................................................................. 59
3.4.1.7 GAP Pairing Request .................................................................................................................. 59
3.4.1.8 GAP Encrypt Request ................................................................................................................ 59
3.4.1.9 GAP Get Bond Status ................................................................................................................. 59
3.4.1.10 GAP Security Request ................................................................................................................ 60
3.5 BLE Profiles ........................................................................................................................................................ 60
3.5.1 HID .......................................................................................................................................................... 61
3.5.1.1 HID service 事件 ...................................................................................................................... 61
3.5.1.2 HID service 函数 ...................................................................................................................... 61
3.5.2 DIS .......................................................................................................................................................... 62
3.5.2.1 DIS 事件 ................................................................................................................................... 62
3.5.2.2 DIS 函数 ................................................................................................................................... 63
3.5.3 Battery service ....................................................................................................................................... 63
3.5.3.1 BATT 事件 ................................................................................................................................ 63
3.5.3.2 BATT 函数 ................................................................................................................................ 64
3.5.4 OTA ......................................................................................................................................................... 64
3.5.4.1 OTA 函数 .................................................................................................................................. 64
4. OSAL API ...................................................................................................................................................................... 65
4.1 Task API ............................................................................................................................................................. 65
4.1.1 Task 函数 .............................................................................................................................................. 65
4.1.1.1 OS Task Create ........................................................................................................................... 65
4.1.1.2 OS Task Delete ........................................................................................................................... 66
4.1.1.3 OS Message Post ....................................................................................................................... 66
4.1.1.4 OS User Loop Event Set ............................................................................................................. 66
4.1.1.5 OS User Loop Event Clear .......................................................................................................... 67
FR801xH SDK User Guide | 2020-05 v1.0.8
6 / 108
4.2 Clock API ........................................................................................................................................................... 67
4.2.1 Clock 函数 ............................................................................................................................................. 67
4.2.1.1 OS Timer Initialization ............................................................................................................... 67
4.2.1.2 OS Timer Start ........................................................................................................................... 68
4.2.1.3 OS Timer Stop ........................................................................................................................... 68
4.3 Memory API ...................................................................................................................................................... 68
4.3.1 Memory 函数 ........................................................................................................................................ 68
4.3.1.1 OS Malloc .................................................................................................................................. 68
4.3.1.2 OS Get Free Heap Size ............................................................................................................... 68
4.3.1.3 OS Show Message List ............................................................................................................... 69
4.3.1.4 OS Show Kernel Malloc Informationi ........................................................................................ 69
4.3.1.5 OS Show Memory List ............................................................................................................... 69
5. MCU 外设驱动 ............................................................................................................................................................ 70
5.1 IO MUX .............................................................................................................................................................. 70
5.1.1 普通 IO 接口 .......................................................................................................................................... 70
5.1.1.1 IO 功能设置 ............................................................................................................................. 70
5.1.1.2 IO 上拉设置 ............................................................................................................................. 71
5.1.2 支持低功耗模式的 IO 接口 .................................................................................................................. 71
5.1.2.1 IO 使能低功耗模式 ................................................................................................................. 71
5.1.2.2 IO 关闭低功耗模式 ................................................................................................................. 71
5.1.2.3 IO 低功耗模式功能设置 ......................................................................................................... 72
5.1.2.4 IO 低功耗模式输入输出设置 ................................................................................................. 72
5.1.2.5 IO 低功耗模式上拉设置 ......................................................................................................... 72
5.1.2.6 IO 使能低功耗唤醒 ................................................................................................................. 73
5.1.2.7 IO 低功耗模式中断入口 ......................................................................................................... 73
5.2 GPIO .................................................................................................................................................................. 74
5.2.1 普通 GPIO 接口 ..................................................................................................................................... 74
5.2.1.1 GPIO 输出 ................................................................................................................................ 74
5.2.1.2 GPIO 获取当前值 ..................................................................................................................... 74
5.2.1.3 GPIO 设置整个 port 输入输出 ................................................................................................. 74
5.2.1.4 GPIO 获取整个 port 输入输出配置 ........................................................................................ 74
5.2.1.5 GPIO 设置单个 IO 输入输出 ................................................................................................... 75
5.2.2 低功耗模式 GPIO 接口 .......................................................................................................................... 75
5.2.2.1 GPIO 低功耗模式输出值 ........................................................................................................ 75
5.2.2.2 GPIO 低功耗模式输入值 ........................................................................................................ 76
5.3 UART ................................................................................................................................................................. 76
5.3.1 UART 初始化 ......................................................................................................................................... 76
5.3.2 UART 等待发送 FIFO 为空.................................................................................................................... 76
5.3.3 从串口读取数据 .................................................................................................................................... 77
5.3.4 从串口发送数据 .................................................................................................................................... 77
5.3.5 UART 发送一个字节且等待完成 ......................................................................................................... 77
5.3.6 UART 发送一个字节且立即返回 ......................................................................................................... 78
5.3.7 UART 发送多个字节且等待完成 ......................................................................................................... 78
5.3.8 UART 读取特定个数字节 ..................................................................................................................... 78
FR801xH SDK User Guide | 2020-05 v1.0.8
7 / 108
5.3.9 UART 读取特定个数字节,诺 FIFO 为空则先返回 ............................................................................ 78
5.3.10 UART0 读数据 ....................................................................................................................................... 79
5.3.11 UART0 发数据 ....................................................................................................................................... 79
5.3.12 UART1 读数据 ....................................................................................................................................... 79
5.3.13 UART1 写数据 ....................................................................................................................................... 79
5.4 SPI ..................................................................................................................................................................... 80
5.4.1 SPI 初始化 ............................................................................................................................................. 80
5.4.2 SPI 发送并接收 ..................................................................................................................................... 80
5.4.3 SPI 发送 ................................................................................................................................................. 81
5.4.4 SPI 接收 ................................................................................................................................................. 81
5.5 I2C ..................................................................................................................................................................... 81
5.5.1 I2C 初始化............................................................................................................................................. 81
5.5.2 I2C 发送一个字节 ................................................................................................................................. 82
5.5.3 I2C 发送多个字节 ................................................................................................................................. 82
5.5.4 I2C 读取一个字节 ................................................................................................................................. 82
5.5.5 I2C 读取多个字节 ................................................................................................................................. 83
5.6 Timer ................................................................................................................................................................. 83
5.6.1 Timer 初始化 ........................................................................................................................................ 83
5.6.2 Timer 启动 ............................................................................................................................................ 83
5.6.3 Timer 停止 ............................................................................................................................................ 83
5.6.4 Timer 获取 load 值 ............................................................................................................................... 84
5.6.5 Timer 获取当前计数值 ........................................................................................................................ 84
5.6.6 Timer 清中断 ........................................................................................................................................ 84
5.7 PWM ................................................................................................................................................................. 84
5.7.1 普通 PWM 接口 ................................................................................................................................... 85
5.7.1.1 PWM 初始化 ........................................................................................................................... 85
5.7.1.2 PWM 启动 ............................................................................................................................... 85
5.7.1.3 PWM 停止 ............................................................................................................................... 85
5.7.1.4 PWM 更新参数........................................................................................................................ 85
5.7.2 低功耗模式 PWM 接口 ....................................................................................................................... 86
5.7.2.1 低功耗 PWM 初始化 ............................................................................................................... 86
5.7.2.2 低功耗 PWM 设置参数 ........................................................................................................... 86
5.7.2.3 低功耗 PWM 启动................................................................................................................... 86
5.7.2.4 低功耗 PWM 停止................................................................................................................... 87
5.8 ADC ................................................................................................................................................................... 87
5.8.1 ADC 初始化 ........................................................................................................................................... 87
5.8.2 ADC 开始采样 ....................................................................................................................................... 88
5.8.3 ADC 停止采样 ....................................................................................................................................... 88
5.8.4 ADC 读取结果 ....................................................................................................................................... 88
5.9 WDT .................................................................................................................................................................. 88
5.9.1 WDT 初始化 .......................................................................................................................................... 89
5.9.2 WDT 喂狗 .............................................................................................................................................. 89
5.9.3 WDT 启动 .............................................................................................................................................. 89
5.9.4 WDT 停止 .............................................................................................................................................. 89
FR801xH SDK User Guide | 2020-05 v1.0.8
8 / 108
5.9.5 WDT 中断处理接口 .............................................................................................................................. 89
5.10 RTC .................................................................................................................................................................... 90
5.10.1 RTC 初始化 ........................................................................................................................................... 90
5.10.2 RTC 启动 ............................................................................................................................................... 91
5.10.3 RTC 停止 ............................................................................................................................................... 91
5.10.4 RTC 中断处理接口................................................................................................................................ 91
5.11 QDEC ................................................................................................................................................................. 92
5.11.1 QDEC 初始化 ........................................................................................................................................ 92
5.11.2 QDEC 设置引脚 .................................................................................................................................... 92
5.11.3 QDEC 设置清零条件 ............................................................................................................................. 93
5.11.4 QDEC 设置中断阀值 ............................................................................................................................. 93
5.11.5 QDEC 设置中断类型 ............................................................................................................................. 93
5.11.6 QDEC 去抖 ............................................................................................................................................ 93
5.11.7 QDEC 读取旋转计数 ............................................................................................................................. 93
5.11.8 QDEC 中断处理接口 ............................................................................................................................. 94
5.12 Key Scan ............................................................................................................................................................ 95
5.12.1 Key Scan 结构体定义 ........................................................................................................................... 95
5.12.1.1 Key Scan 参数 .......................................................................................................................... 95
5.12.2 Key Scan 函数 ....................................................................................................................................... 95
5.12.2.1 Key Scan 初始化 ...................................................................................................................... 95
5.12.2.2 Key Scan 中断处理接口 .......................................................................................................... 95
5.13 PMU .................................................................................................................................................................. 96
5.13.1 PMU 配置系统电源 .............................................................................................................................. 96
5.13.2 PMU 判断系统是否第一次上电 .......................................................................................................... 96
5.13.3 PMU 使能中断 ...................................................................................................................................... 97
5.13.4 PMU 关闭中断 ...................................................................................................................................... 97
5.13.5 PMU 使能 Codec 供电 .......................................................................................................................... 97
5.13.6 PMU 关闭 Codec 供电 .......................................................................................................................... 98
5.13.7 PMU 设置 LDO_OUT 和 IO 电压值 ...................................................................................................... 98
5.13.8 PMU 设置 32K 时钟源 .......................................................................................................................... 98
5.13.9 PMU 设置内部 RC 频率 ....................................................................................................................... 98
5.13.10 PMU Charger 中断接口 ............................................................................................................ 99
5.13.11 PMU 低电压监测中断接口 ..................................................................................................... 99
5.13.12 PMU 高温监测中断接口 ....................................................................................................... 100
6. 其他 ........................................................................................................................................................................... 101
6.1 获取 SDK 编译时间 ........................................................................................................................................ 101
6.2 系统函数 ........................................................................................................................................................ 101
6.2.1 关机函数 .............................................................................................................................................. 101
6.2.2 使能睡眠 .............................................................................................................................................. 101
6.2.3 关闭睡眠 .............................................................................................................................................. 102
6.2.4 获取系统运行时间 .............................................................................................................................. 102
7. OTA............................................................................................................................................................................. 103
7.1 OTA profile ...................................................................................................................................................... 103
7.2 OTA 交互包格式 ............................................................................................................................................. 103
FR801xH SDK User Guide | 2020-05 v1.0.8
概况 9 / 108
7.2.1 OTA 主机端的请求包格式(通过 write attribute): ..................................................................... 103
7.2.1.1 获取新固件的可用存储基地址 ............................................................................................. 104
7.2.1.2 获取当前固件版本号 ............................................................................................................. 104
7.2.1.3 擦除扇区(4KB) .................................................................................................................. 104
7.2.1.4 写入数据 ................................................................................................................................ 104
7.2.1.5 重启 104
7.2.2 FR801xH 的回复包格式(通过 Notify attribute):......................................................................... 104
7.2.2.1 获取新固件的可用存储基地址 ............................................................................................. 104
7.2.2.2 获取当前固件版本号 ............................................................................................................. 105
7.2.2.3 擦除扇区(4KB) .................................................................................................................. 105
7.2.2.4 写入数据 ................................................................................................................................ 105
7.2.2.5 重启 105
7.3 OTA 流程 ......................................................................................................................................................... 105
联系方式 .......................................................................................................................................................................... 107
勘误记录 .......................................................................................................................................................................... 108
评论