下你所需,载你所想!
汇集开发技术源码资料

nordic的蓝牙芯片的BootLoader例程和相关说明

:43.969KB :1 :2022-10-19 16:30:11

部分简介

nordic的蓝牙芯片的BootLoader例程和相关说明如果开发者对于本文件有需要的可以参考。
n
nRF51822之BootLoader
一)nRF51822程序加载顺序
1)SoftDevice加载;
2)SoftDevice初始化蓝牙协议栈;
3)SoftDevice检查0x10001014处是否保存有有效的BootLoader地址, 如果不是跳转到0x14000处的APP执行,流程结束.
4)SoftDevice跳转到BootLoader
5)BootLoader进行他的业务处理工作;
6)BootLoader跳转到0x14000处的APP执行,流程结束.
二)实现步骤
1)修改SoftDivice.hex
看NRF_UICR_Type结构,有一个BOOTLOADERADDR字段, 这个就是指向的BootLoader地址
typedef struct {/*!< UICR Structure*/
__IO uint32_t CLENR0; /*!< Length of code region 0.*/
__IO uint32_t RBPCONF; /*!< Readback protection configuration.*/
__IO uint32_t XTALFREQ; /*!< Reset value for CLOCK XTALFREQ register.*/
__I uint32_t RESERVED0;
__I uint32_t FWID; /*!< Firmware ID.*/
__IO uint32_t BOOTLOADERADDR;/*!< Bootloader start address.*/
} NRF_UICR_Type;
默认情况下,SoftDivice.hex没有指定BootLoader地址;
我们需要在SoftDivice.hex中插入一行
:0410140000300100A7
参考HEX文件说明
这里修改0x10001014地址的数据为"00300100"就是0x13000, 这个地址根据BootLoader的实际位置修改.
2)编写BootLoader
BootLoader本身是一个普通的程序,只是在跳转到APP执行时需要特殊处理
static void interrupts_disable(void) {
uint32_t interrupt_setting_mask = NVIC->ISER[0];
for (uint8_t irq=0; irq < 32; irq ) {
if (interrupt_setting_mask & (1 << irq)) {
NVIC_DisableIRQ((IRQn_Type) irq);
}
}
}
__asm void StartApplication(uint32_t start_addr){
LDR R2, [R0] ; Get App MSP.
MSR MSP, R2 ; Set the main stack pointer to the applications MSP.
LDR R3, [R0, #0x00000004] ; Get application reset vector address.
BX R3 ; No return - stack code is now activated only through SVC and plain interrupts.
ALIGN
}
/**
* 跳转到APP执行
*/
static void bootloader_app_start(uint32_t app_addr) {
sd_softdevice_disable();
interrupts_disable();
sd_softdevice_forward_to_application();
StartApplication(app_addr);
}
把BootLoader写入我们上面定义的地址 0x13000
3)编写APP
APP跟没有BootLoader时是一样的,依然放在 0x14000 处
.
├── bootloader
│ ├── arm
│ │ ├── JLinkSettings.ini
│ │ ├── bootloader.uvopt
│ │ └── bootloader.uvproj
│ ├── arm_startup_nrf51.s
│ ├── bootloader.c
│ ├── bootloader_util_arm.c
│ ├── dfu_dual_bank.c
│ ├── dfu_single_bank.c
│ ├── dfu_transport_ble.c
│ ├── dfu_transport_serial.c
│ ├── hci_transport_config.h
│ ├── include
│ │ ├── bootloader.h
│ │ ├── bootloader_types.h
│ │ ├── bootloader_util.h
│ │ ├── dfu.h
│ │ ├── dfu_transport.h
│ │ └── dfu_types.h
│ └── main.c
└── nrf51822-bootloader.zip
3 directories, 19 files

热门推荐

相关文章