1.前言
nRF52810支持Bluetooth 5.1 BLE Central和Peripheral协议栈,在Nordic官方提供的SDK中提供如何使用BLE Central和Peripheral协议栈的Sample Code。SDK如何下载可以参考这篇文章:《【Nordic】官网下载nRF52810相关资料》
下面我们我主要介绍如何在官方提供的SDK nRF5_SDK_17.0.2_d674dde.zip
,在nRF52810硬件平台上移植BLE Central协议栈。因此我们这里选择SoftDevice S132,为什么是选择S132
可以参考这篇文章:《问题4:nRF52810如何选择SoftDevice版本》
2.如何将BLE Central移植到nRF52810
- 参考Nordic官网提供的SDK,但是默认是nRF52823平台,我们需要移植到nRF52810平台,路径如下:
PATH:nRF5_SDK_17.0.2_d674dde\examples\ble_central\ble_app_uart_c\pca10040\s132\arm5_no_packs
-
打开魔法棒
options
配置工程
-
修改
Device
为nRF52810_xxAA
-
修改
Target
,主要是针对System Clock、Rom和Ram分区的配置如下:- Xtal(MHz):64.0 // 根据nRF52810_xxAA datasheet
- IROM1:0x26000 ~ (0x26000 + 0xA000) //
0 ~ 0x26000
是SoftDevice Bin占用的ROM大小,Size为0xA000
是因为nRF52810_xxAA Flash Size为192KB
。 - IRAM1:0x20002A28 ~ (0x20002A28 + 0x35D8) //
0x20000000
为Ram的基地址,0x2A28
为SoftDevice是需要使用的RAM大小,0x35D8
是因为nRF52810_xxAA RAM Size为24KB
。
备注:如果ROM和RAM设置错误,设备无法正常启动,可能打印如下错误Log:
Insufficient RAM allocated for the SoftDevice.
Change the RAM start location from 0x200022c8 to 0x20002a28.
Maximum RAM size for application is 0x35d8.
-
修改
Output
为nrf52810_xxaa
-
修改
C/C++
相关宏定义:
默认宏定义为:
APP_TIMER_V2 APP_TIMER_V2_RTC1_ENABLED BOARD_PCA10040 CONFIG_GPIO_AS_PINRESET FLOAT_ABI_HARD NRF52 NRF52832_XXAA NRF52_PAN_74 NRF_SD_BLE_API_VERSION=7 S132 SOFTDEVICE_PRESENT __HEAP_SIZE=8192 __STACK_SIZE=8192
修改为:
APP_TIMER_V2 APP_TIMER_V2_RTC1_ENABLED BOARD_PCA10040 CONFIG_GPIO_AS_PINRESET FLOAT_ABI_HARD NRF52810_XXAA NRF52_PAN_74 NRF_SD_BLE_API_VERSION=7 S132 SOFTDEVICE_PRESENT __HEAP_SIZE=4096 __STACK_SIZE=4096
-
修改
Debug
工具为JLink
-
修改
Project Target
为nrf52810_xxaa
-
编译工程
3.烧录验证
4.移植过程出现的相关错误
- 错误1:
.\_build\nrf52810_xxaa.axf: Error: L6200E: Symbol UARTE0_UART0_IRQHandler multiply defined (by nrfx_uarte.o and nrfx_uart.o).
解决办法:#ifndef NRFX_PRS_BOX_2_ENABLED #define NRFX_PRS_BOX_2_ENABLED 1 #endif
- 错误2:
.\_build\nrf52810_xxaa.axf: Error: L6406E: No space in execution regions with .ANY selector matching nrf_log_backend_rtt.o(.data).
.\_build\nrf52810_xxaa.axf: Error: L6406E: No space in execution regions with .ANY selector matching nrf_sdh_ble.o(.data).
.\_build\nrf52810_xxaa.axf: Error: L6407E: Sections of aggregate size 0x84 bytes could not fit into .ANY selector(s).
Not enough information to list image symbols.
Not enough information to list the image map.
解决办法:
因为RAM内存不够,SoftDevice S132
占用比较大,所以需要Application减少对RAM的使用,我这里临时的做法是屏蔽了log的打印log_init();
,如下:int main(void) { // Initialize. //log_init(); // 由于RAM内存不够,暂时屏蔽 timer_init(); uart_init(); buttons_leds_init(); db_discovery_init(); power_management_init(); ble_stack_init(); gatt_init(); nus_c_init(); scan_init(); ... }