【AB32VG1开发】基于RT-Thread 中科蓝讯AB32VG1 bluetrum_sdk BLE开发例程讲解
中科蓝讯最近出的SDK(bluetrum_sdk) V1.1.0,支持了BLE开发,目前官方还没有正式文档,我来摸索一下吧
操作步骤详细请参阅: 基于RT-Thread的AB32VG1开发环境搭建
SDK选择中科蓝讯AB32VG1开发板最新SDK(bluetrum_sdk) 1.1.0安装
操作步骤详细请参阅: 基于RT-Thread的AB32VG1开发环境搭建
注意选择最新SDK 1.1.0
操作步骤详细请参阅: 基于RT-Thread的AB32VG1开发环境搭建
配置详情如下:
开启:
宏: [SOC_AB32VG1]
宏: [PKG_USING_BLUETRUM_NIMBLE]
宏: [BSP_USING_TIM](这后面加的,因为出现这个了定时报告数据时运行错误:(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.这里不管它,编译时看看具体是哪里同, 我们再修改。
首先熟悉一下BLE_SDK代码目录:
工程目录下:
packages\bluetrum_sdk-latest\bluetrum_nimble\porting\npl\rtthread\src\ble_platform.c
我修改如下:
void bt_get_local_bd_addr(uint8_t *addr)
{
uint8_t addr_table[6] = {0x41, 0x42, 0x18, 0x58, 0x68, 0x88}; //mac_addr是6bytes, SDK代码里只写了5个数据
memcpy(addr, addr_table, 6);
}
注意:mac_addr是6bytes, SDK代码里只写了5个数据,这是疏漏还是有意为之
工程目录下:
\packages\bluetrum_sdk-latest\bluetrum_nimble\apps\blehr\src\blehr.c
我修改如下:
static const char *device_name = "Silicon_blehr_sensor";
注意:不能是中文,中文会找不到设备
工程目录下:
packages\bluetrum_sdk-latest\bluetrum_nimble\appsblehrsrc
我修改如下:
static const char *manuf_name = "谷动谷力"; //Sunshine Silicon";可以中文,但长度限制了,没有找到哪里限制了
static const char *model_num = "SunSilicon HR Sensor";
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 */
},
};
这里服务,我们没做修改,保存默认。
编译工程:Ctrl+B,会出错, 如下:
In file included from :
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 :
E:\RT-ThreadWorkspace\AB32_BLE_Demo\rtconfig_preinc.h:8:9: error: no macro name given in #define directive
8 | #define
| ^
make: *** [rt-thread/src/subdir.mk:57: rt-thread/src/device.o] Error 1
make: *** Waiting for unfinished jobs....
In file included from :
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 :
E:\RT-ThreadWorkspace\AB32_BLE_Demo\rtconfig_preinc.h:8:9: error: no macro name given in #define directive
8 | #define
| ^
make: *** [rt-thread/src/subdir.mk:57: rt-thread/src/clock.o] Error 1
make: *** [rt-thread/src/subdir.mk:57: rt-thread/src/components.o] Error 1
make: *** [rt-thread/src/subdir.mk:57: rt-thread/src/idle.o] 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)
双击出错提示,定位到出错的地方,#define后面是空的,删除这个#define即可
保存修改内容: ctrl+s, 编译:ctrl+b
编译成功
将编译好的,目标文件:rtthread.elf,烧录到中科蓝讯AB32VG1 BLE开发板,操作步骤详细请参阅: 基于RT-Thread的AB32VG1开发环境搭建
扫描到与我们代码设置一样BLE设备名字,说明代码修改正确.连接与我们代码设置一样BLE设备名字.
点"读取"即可,这与我们代码设置一样,说明代码修改正确
点"读取"即可,这与我们代码设置一样,说明代码修改正确
心律数据是模拟的,开发板硬件上没有
这个数据点代码有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
更多精彩,欢迎关注微信公众号:
谷动谷力
全部0条评论
快来发表一下你的评论吧 !