【AB32VG1开发】基于RT-Thread 中科蓝讯AB32VG1 BLE开发例程讲解
【AB32VG1开发】基于RT-Thread 中科蓝讯AB32VG1 BLE开发例程讲解中科蓝讯最近出的SDK(bluetrum_sdk) V1.1.0,支持了BLE开发,目前官方还没有正式文档,我来摸索一下吧
安装最近SDK
操作步骤详细请参阅: 基于RT-Thread的AB32VG1开发环境搭建
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233izbys0kesyxiybxi.jpg
选择中科蓝讯AB32VG1开发板最新SDK(bluetrum_sdk) 1.1.0安装
建RT-Thread工程
操作步骤详细请参阅: 基于RT-Thread的AB32VG1开发环境搭建
注意选择最新SDK 1.1.0
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233mbx0wtobbw5200bz.jpg
配置工程操
作步骤详细请参阅: 基于RT-Thread的AB32VG1开发环境搭建
配置详情如下:
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233fzs03ie4hr2hi00z.jpg
开启:
宏:
宏:
宏: (这后面加的,因为出现这个了定时报告数据时运行错误:(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer) assertion failed at function:rt_timer_stop, line number:502 )我以为加上TIMER模块,就加了,但是还是没解决。
配置后,保存会出现错误:local variable 'get_git_root' referenced before assignment Operation failed.这里不管它,编译时看看具体是哪里同, 我们再修改。
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233ochp0gcici87w85x.jpg
修改代码
首先熟悉一下BLE_SDK代码目录:
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233i6qy6yq6khhucbny.jpg
修改mac_addr
工程目录下:
packages\bluetrum_sdk-latest\bluetrum_nimble\porting\npl\rtthread\src\ble_platform.c
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233thfnl4nl4zdzhizy.jpg
我修改如下:
[*]void bt_get_local_bd_addr(uint8_t *addr){ uint8_t addr_table = {0x41, 0x42, 0x18, 0x58, 0x68, 0x88};//mac_addr是6bytes, SDK代码里只写了
复制代码
5个数据 memcpy(addr, addr_table, 6);}
注意:mac_addr是6bytes, SDK代码里只写了5个数据,这是疏漏还是有意为之
修改BLE_name(名字)
工程目录下:
\packages\bluetrum_sdk-latest\bluetrum_nimble\apps\blehr\src\blehr.c
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233xuv4je42hjpevylh.jpg
我修改如下:
static const char *device_name = "Silicon_blehr_sensor";
注意:不能是中文,中文会找不到设备
修改服务及设备信息
工程目录下:
packagesbluetrum_sdk-latestbluetrum_nimbleappsblehrsrc
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233w3w5syzwddyzy3rk.jpg
我修改如下:
[*]static const char *manuf_name = "谷动谷力";//Sunshine Silicon";//可以中文得长度长了,上报不了数据
[*]static const char *model_num = "SunSilicon HR Sensor";
[*]uint16_t hrs_hrm_handle;
[*]
[*]static int gatt_svr_chr_access_heart_rate(uint16_t conn_handle, uint16_t attr_handle,
[*] struct ble_gatt_access_ctxt *ctxt, void *arg);
[*]
[*]static int gatt_svr_chr_access_device_info(uint16_t conn_handle, uint16_t attr_handle,
[*] struct ble_gatt_access_ctxt *ctxt, void *arg);
[*]
[*]static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
[*] {
[*] /* Service: Heart-rate */
[*] .type = BLE_GATT_SVC_TYPE_PRIMARY,
[*] .uuid = BLE_UUID16_DECLARE(GATT_HRS_UUID),
[*] .characteristics = (struct ble_gatt_chr_def[]) { {
[*] /* Characteristic: Heart-rate measurement */
[*] .uuid = BLE_UUID16_DECLARE(GATT_HRS_MEASUREMENT_UUID),
[*] .access_cb = gatt_svr_chr_access_heart_rate,
[*] .val_handle = &hrs_hrm_handle,
[*] .flags = BLE_GATT_CHR_F_NOTIFY,
[*] }, {
[*] /* Characteristic: Body sensor location */
[*] .uuid = BLE_UUID16_DECLARE(GATT_HRS_BODY_SENSOR_LOC_UUID),
[*] .access_cb = gatt_svr_chr_access_heart_rate,
[*] .flags = BLE_GATT_CHR_F_READ,
[*] }, {
[*] 0, /* No more characteristics in this service */
[*] }, }
[*] },
[*]
[*] {
[*] /* Service: Device Information */
[*] .type = BLE_GATT_SVC_TYPE_PRIMARY,
[*] .uuid = BLE_UUID16_DECLARE(GATT_DEVICE_INFO_UUID),
[*] .characteristics = (struct ble_gatt_chr_def[]) { {
[*] /* Characteristic: * Manufacturer name */
[*] .uuid = BLE_UUID16_DECLARE(GATT_MANUFACTURER_NAME_UUID),
[*] .access_cb = gatt_svr_chr_access_device_info,
[*] .flags = BLE_GATT_CHR_F_READ,
[*] }, {
[*] /* Characteristic: Model number string */
[*] .uuid = BLE_UUID16_DECLARE(GATT_MODEL_NUMBER_UUID),
[*] .access_cb = gatt_svr_chr_access_device_info,
[*] .flags = BLE_GATT_CHR_F_READ,
[*] }, {
[*] 0, /* No more characteristics in this service */
[*] }, }
[*] },
[*]
[*] {
[*] 0, /* No more services */
[*] },
[*]};
复制代码
修改服务属性
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233fppaxahat2bz2h52.png
这里服务,我们没做修改,保存默认。
编译
编译工程:Ctrl+B,会出错, 如下:
In file included from <command-line>:E:\RT-ThreadWorkspace\AB32_BLE_Demo\rtconfig_preinc.h:8:9: error: no macro name given in #define directive | #define
| ^In file included from <command-line>:E:\RT-ThreadWorkspace\AB32_BLE_Demo\rtconfig_preinc.h:8:9: error: no macro name given in #define directive
| #define
| ^make: *** Error 1make: *** Waiting for unfinished jobs....In file included from <command-line>:E:\RT-ThreadWorkspace\AB32_BLE_Demo\rtconfig_preinc.h:8:9: error: no macro name given in #define directive 8 | #define | ^In file included from <command-line>:E:\RT-ThreadWorkspace\AB32_BLE_Demo\rtconfig_preinc.h:8:9: error: no macro name given in #define directive
| #define
| ^make: *** Error 1make: *** Error 1make: *** Error 1"make -j4 all2" terminated with exit code 2. Build might be incomplete.14:29:13 Build Failed. 9 errors, 0 warnings. (took 1s.464ms)
http://bbs.sunsili.com/data/attachment/forum/202112/06/220718ziw3rwnuwu5nbzkk.jpg
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233pu1unuwrqqr1zugw.jpg
双击出错提示,定位到出错的地方,#define后面是空的,删除这个#define即可
标题重新编译
保存修改内容: ctrl+s, 编译:ctrl+b
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233t69u61sf3e2ehhlu.jpg
编译成功
调试
将编译好的,目标文件:rtthread.elf,烧录到中科蓝讯AB32VG1 BLE开发板,操作步骤详细请参阅: 基于RT-Thread的AB32VG1开发环境搭建
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233bx3mxyk35zqxblke.jpg
手机打开蓝牙
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233z5l5z18naamauum5.jpg
手机打开蓝牙BLE调试助手
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233fpzb4b9oawja55ca.jpg
连接BLE设备
扫描到与我们代码设置一样BLE设备名字,说明代码修改正确.连接与我们代码设置一样BLE设备名字.
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233wib4b46b4iyysviy.jpg
设备相关数据服务列表 http://bbs.sunsili.com/data/attachment/forum/202112/04/173233x9ssaa3hsq89aheq.jpg
获取BLE设备数据--制造商信息 http://bbs.sunsili.com/data/attachment/forum/202112/04/173233ggq3gih5ttm02x28.jpg
点"读取"即可,这与我们代码设置一样,说明代码修改正确
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233t27k244yy7w54wuw.jpg
获取BLE设备数据--设备型号信息点"读取"即可,这与我们代码设置一样,说明代码修改正确
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233e1wq0zijq00od0oj.jpg
读取心率相关数据 http://bbs.sunsili.com/data/attachment/forum/202112/04/173233v154ch15iijr6q3m.jpg
心率数据自动数据通知上报
心律数据是模拟的,开发板硬件上没有
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233maajjj3fzqr53z3i.jpg
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233h0roj9kun9ipp48k.jpg
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233akp29rdjhhjc7zcl.png
http://bbs.sunsili.com/data/attachment/forum/202112/04/173233ujfjeirveifziizm.png
这个数据点代码有BUG,不定什么时候,报错,每次错误还不一样, 这个还得官方分析一下.
遗留问题
1) 定时上报数据点代码有BUG,不定什么时候,报错,每次错误还不一样, 这个还得官方分析一下.
2)现在只有Read(BLE上报数据)功能,没有write(APP->BLE下达数据)功能,这个后面移植一下
3)连接现有通用**功能, 如微信\涂鸦\天猫精灵.....等等
4)mac_addr是6bytes, 代码里只写了5个数据,这是疏漏还是有意为之
5)制造名长度限制了,没有找到哪里限制了,是不是上报告数据长度限制了,在代码哪里呢上面遗留问题,还请专家帮忙解决一下,我能力有限.
总结
用RT-Thread基本中科蓝讯AB32VG1 BLE开发快捷方便.做一个只要官方有的驱动及软件,相关方便快捷,没有话自己移植的话,还是比较复杂.
我首先发表在公众号的
转载注明出处:https://mp.weixin.qq.com/s/72jVJvEGVFwApsv_hdhxfA更多精彩,欢迎关注微信公众号:
http://bbs.sunsili.com/data/attachment/forum/202112/06/222220dcqqffc54fyzkqwt.png
页:
[1]