CREEUS means create for us. It's a startup company, which is focus on smart device(IoT devices).
CREEUS是一家初创公司,主要关注智能硬件产品(IoT设备)。它的创立初衷是:
为我们,而创造。
--------------------------------广告结束-----------------------------------
hi,这是一个个人博客,主要记录个人对业界的看法,对技术的总结和对有趣事情的备忘~~
也许十年之后回头看,这样做本身就是一件很有趣的事情 :)
Creeus
Create for us.
2025年8月29日星期五
2015年9月21日星期一
2015年9月20日星期日
nRF51822 bootloader 研究(五)
如何在你的程序中嵌入DFU功能
首先由几点要求:
首先由几点要求:
- The application must use the Device Manager. If the application does not use the Device Manager yet, you must update the application. See BLE Device Manager for more information.
- You must add DFU related files to the BLE application project. See Including DFU files in application.
- You must implement a function that executes application-specific operations to ensure a graceful shutdown of the application. SeeImplementing graceful shutdown.
- The application must correctly set up the BLE services. See Setting up the BLE services.
- The application must propagate SoftDevice BLE events to the BLE DFU Service. See Propagating BLE stack events.
之后,你就可以通过向DFU Service Control Point写入"DFU Start"来启动DFU功能。
nRF51822 bootloader 研究(四)
之前提到了触发DFU有三种方式:1.没有应用程序时候reset。2.按一个按键。3.通过蓝牙远程开启。今天就讲一下如何通过蓝牙服务启动DFU。
examples\ble_peripheral\ble_app_hrs目录下有使用DFU的例子,打开对应的ble_app_hrs_sXXX_with_dfu_pca10028 项目。
这里官方提到了一个share bonding的知识点,以后再详细讨论吧。
examples\ble_peripheral\ble_app_hrs目录下有使用DFU的例子,打开对应的ble_app_hrs_sXXX_with_dfu_pca10028 项目。
这里官方提到了一个share bonding的知识点,以后再详细讨论吧。
nRF51822 bootloader 研究(三)
演示例程和如何制作一个升级包我们都已经讲过了,今天来看看Bootloader内部的细节。
升级镜像(文件)的安全检测
为了保证只有兼容的固件才会被安装到芯片上,NORDIC的Bootloader提供了一种安全检测方法——在真正升级之前,Bootloader需要检测DFU init packet,它的内容如下图:
升级镜像(文件)的安全检测
为了保证只有兼容的固件才会被安装到芯片上,NORDIC的Bootloader提供了一种安全检测方法——在真正升级之前,Bootloader需要检测DFU init packet,它的内容如下图:
DFU init packet
- Device type: A 2-byte value specified by the developer that identifies the device type, for example Heart Rate Belt.
- Device revision: A 2-byte value that can be used to restrict the update to be accepted only on devices with a defined revision number.
- Application version: A 4-byte value identifying the version of the application that is being transferred. This value can be used to allow only software upgrades and prevent downgrades. No example code is provided for this feature.
- Supported SoftDevices: A list of 2-byte values identifying the SoftDevices that are compatible with the application, for example, S110 v7.1 or S110 v8.0.
- Checksum: A 2-byte CRC-16-CCITT for the image to transfer.
其中指定了多个关键字,也就是说你的升级镜像内的关键字也必须和这个Bootloader一一对应,否则这个升级包就会被认为不被兼容而放弃这次升级。
这也就是为什么上一篇提到需要用.zip包来升级,而不是简单的用.hex文件的原因。
Device type and revision
储存在UICR (0x10001080)地址上。如果不想检查这些信息,保证它的值是 0xFFFF就行了。
Application version
例程中的dfu_init_template.c并没有检查这个信息。用户需要自己来添加。
Supported SoftDevices
根据依赖的Softdevice版本,该字段应如下表所示:
| SoftDevice S110 | FWID |
|---|---|
| S110 v7.0.0 | 0x004F |
| S110 v7.1.0 | 0x005A |
| S110 v8.0.0 | 0x0064 |
| S120 v2.0.0 | 0x0060 |
| S130 v1.0.0 | 0x0067 |
| S310 v2.0.0 | 0x005D |
| Development/any | 0xFFFE |
最后,提一个可能会遇到的问题:升级后的应用程序不能运行。
可能的原因是:应用程序的启动地址错误,导致无法运行。
解决办法是:修改代码中的应用程序启动地址,比如 S110 SoftDevice v7.0.0 是 0x00016000. S310 SoftDevice v0.9.0是0x00020000.
nRF51822 bootloader 研究(二)
上一篇大概讲解了如何使用NORDIC提供的Bootloader的DFU功能来升级系统固件,接下来我们来看看其他细节。
如何创建一个固件的镜像(文件)
基本上NORDIC的Bootloader需要一个hex后缀的文件,而不是.bin文件。
另外一个很重要的问题是:到目前位置NORDIC的nRF51系列芯片已经更新了三个版本,每个版本都有对应的Softdevice和SDK,所以如果混用这些的话是会出问题的。
NORDIC的解决方案就是用.zip文件代替.hex文件。
制作.zip的升级包非常简单,只需要使用
运行如下指令显示帮助信息:
如何创建一个固件的镜像(文件)
基本上NORDIC的Bootloader需要一个hex后缀的文件,而不是.bin文件。
另外一个很重要的问题是:到目前位置NORDIC的nRF51系列芯片已经更新了三个版本,每个版本都有对应的Softdevice和SDK,所以如果混用这些的话是会出问题的。
NORDIC的解决方案就是用.zip文件代替.hex文件。
制作.zip的升级包非常简单,只需要使用
C:\Program Files (x86)\Nordic Semiconductor\Master Control Panel\<version>\nrf\nrf.exe即可。运行如下指令显示帮助信息:
nrf.exe dfu genpkg --help
另外你可以指定升级包所适用的Bootloader(类似相互校验):--application-versionversion: the version of the application image, for example,0xff--dev-revisionversion: the revision of the device that should accept the image, for example,1--dev-typetype: the type of the device that should accept the image, for example,1--sd-reqsd_list: a comma-separated list of FWID values of SoftDevices that are valid to be used with the new image, for example,0x4f,0x5a
最后帮助文档中还提到了从.hex文件中提取.bin文件的工具:
<Keil-folder>\ARM\ARMCC\bin\fromelf.exe --bin --output <outfile.bin> <infile.axf>
nRF51822 bootloader 研究(一)
Bootloader通常是MCU中的一小段代码,而且一般是上电以后第一个执行程序。由它拍判断程序的走向,直接跳去主程序运行或者留在Bootloader中升级主程序。
nRF51中把Bootloader中升级固件的部分称作Device Firmware Update(DFU),今天就来研究一下Bootloader重点是其中的DFU。
nRF51的DFU可以升级application,SoftDevice,或者bootloader本身,又或者SoftDevice+bootloader的组合。
官方的例程会在以下几种情况下,进入DFU:
- No application is installed on the device.
- Button 4 is pressed when starting the device.
- The application on the DFU target supports entering DFU mode. In this case, the DFU controller can trigger the application to reset the device and enter DFU mode, which is referred to as buttonless update.
大家比较关心的可能是第三种模式:手机或者其他控制端可以触发设备端(nRF51)进入DFU模式,而不需要手动按键等操作。
按照NORDIC的SDK中的帮助文档,想要完成Bootloader的演示一共需要以下几个步骤:
按照NORDIC的SDK中的帮助文档,想要完成Bootloader的演示一共需要以下几个步骤:
- 准备一块nRF51的开发板和nRF51的USB Dongle。如果觉得官方的太贵的话,可以到ohtcom.taobao.com或者http://www.aliexpress.com/store/1922092去购买第三方开发板。他们是完全兼容的。
- 通过nRFgo Studio(从官网下载)将Softdevice烧写到开发板。S110或者S130都可以,但是要注意芯片的版本和Softdevice的版本是对应的。总之最新的Softdevice必须配合最新的芯片来用。
- 打开SDK(从http://developer.nordicsemi.com/下载)中的例子“dfu_dual_bank_ble_sXXX_pca10028”。同样,最新的SDK必须配合最新的芯片来用。
- 烧写代码进芯片,这里要注意因为不是烧写普通的应用程序,Bootloader需要在芯片的特定位置设置一个标志位。这个操作标准的Keil下载方式做不到的,必须使用NORDIC官方的nrfjprog.exe才行。不过这些都已经在例程里面设置好了,我们不用手动去调节。
- 在SDK的“test_images_update”目录中,找到对应的zip文件发到手机上,然后手机选择用nRF Toolbox打开。“Select File”选择刚才发的那个文件,“Select File type”选择对应的类型,“Select Device”找到设备(通常叫DFU_xxx)。
- 最后点击“Upload”就OK了!
订阅:
评论 (Atom)
