BLE-NRF51822教程17-DFU使用手机升级

时间:2023-03-09 09:37:03
BLE-NRF51822教程17-DFU使用手机升级

演示的工程是

[application]    nRF51_SDK_10.0.0_dc26b5e\examples\ble_peripheral\ble_app_hrs\pca10028\s110_with_dfu

[bootload]      nRF51_SDK_10.0.0_dc26b5e\examples\dfu\bootloader\pca10028\dual_bank_ble_s110

[softdevice]    nRF51_SDK_10.0.0_dc26b5e\components\softdevice\s110\hex\s110_nrf51_8.0.0_softdevice.hex

1、先檫除

BLE-NRF51822教程17-DFU使用手机升级

2、下载softdevice

BLE-NRF51822教程17-DFU使用手机升级

3、打开bootload工程并编译下载

需要注意的地方修改BootLoader

如果使用NRF51822_XXAC(256KB-FLASH,32KB-RAM )

BLE-NRF51822教程17-DFU使用手机升级

如果使用 NRF51822_XXAA(256KB-FLASH,16KB-RAM )

BLE-NRF51822教程17-DFU使用手机升级

来自官方论坛

BLE-NRF51822教程17-DFU使用手机升级

接上述步骤,在options ...窗口中点击"Utilities"选项卡,Arguments一栏 --family nRF51 --program "#H"

BLE-NRF51822教程17-DFU使用手机升级

4、现在回到我们ble_app_hrs\pca10028\s110_with_dfu编译下载

5、在手机app中可以看到

BLE-NRF51822教程17-DFU使用手机升级

6、使用脚本生成升级使用的ZIP

这个使用hex文件为ble_app_hrs工程的hex

BLE-NRF51822教程17-DFU使用手机升级

BLE-NRF51822教程17-DFU使用手机升级

generate_application_bin.Bat脚本如下:

@echo off
set /p file_name=hex文件名,可以拖拽,回车键结束:
echo %file_name%
copy %file_name% application.hex
nrfutil.exe dfu genpkg %file_name%.zip --application application.hex --application-version 0xFFFFFFFF --dev-revision 0xffff --dev-type 0xffff --sd-req 0xfffe
del application.hex
pause 

将这个ZIP文件发送给手机,然后在手机端进行升级

BLE-NRF51822教程17-DFU使用手机升级

BLE-NRF51822教程17-DFU使用手机升级

BLE-NRF51822教程17-DFU使用手机升级

BLE-NRF51822教程17-DFU使用手机升级

在烧录完程序后,产品默认是DFU模式,要令产品进入正常模式,方法之一是执行一次UPDATE。方法之二是修改BOOTLODER工程。

现在我们将讲解方法二:

在bootload的工程中修改

#if defined ( __CC_ARM )
uint8_t  m_boot_settings[CODE_PAGE_SIZE] __attribute__((at(BOOTLOADER_SETTINGS_ADDRESS))) __attribute__((used));              /**< This variable reserves a codepage for bootloader specific settings, to ensure the compiler doesn't locate any code or variables at his location. */
uint32_t m_uicr_bootloader_start_address __attribute__((at(NRF_UICR_BOOT_START_ADDRESS))) = BOOTLOADER_REGION_START;            /**< This variable ensures that the linker script will write the bootloader start address to the UICR register. This value will be written in the HEX file and thus written to UICR when the bootloader is flashed into the chip. */
#elif defined ( __GNUC__ )
__attribute__ ((section(".bootloaderSettings"))) uint8_t m_boot_settings[CODE_PAGE_SIZE];                                       /**< This variable reserves a codepage for bootloader specific settings, to ensure the compiler doesn't locate any code or variables at his location. */
__attribute__ ((section(".uicrBootStartAddress"))) volatile uint32_t m_uicr_bootloader_start_address = BOOTLOADER_REGION_START; /**< This variable ensures that the linker script will write the bootloader start address to the UICR register. This value will be written in the HEX file and thus written to UICR when the bootloader is flashed into the chip. */
#elif defined ( __ICCARM__ )
__no_init uint8_t m_boot_settings[CODE_PAGE_SIZE] @ 0x0003FC00;                                                                 /**< This variable reserves a codepage for bootloader specific settings, to ensure the compiler doesn't locate any code or variables at his location. */
__root    const uint32_t m_uicr_bootloader_start_address @ 0x10001014 = BOOTLOADER_REGION_START;                                /**< This variable ensures that the linker script will write the bootloader start address to the UICR register. This value will be written in the HEX file and thus written to UICR when the bootloader is flashed into the chip. */
#endif

将第2行修改为

uint8_t  m_boot_settings[CODE_PAGE_SIZE] __attribute__((at(BOOTLOADER_SETTINGS_ADDRESS))) __attribute__((used)) =  {BANK_VALID_APP};

官方论坛

https://devzone.nordicsemi.com/question/60745/nrfgo-studio-and-bootloader-programming/

BLE-NRF51822教程17-DFU使用手机升级

修改后编译下载

为了和之前的app区别我们将名字修改,编译下载

BLE-NRF51822教程17-DFU使用手机升级

这次我们看到在手机中设备名为

BLE-NRF51822教程17-DFU使用手机升级

更多信息可以参考

https://devzone.nordicsemi.com/blogs/685/common-faq-on-dfu/

https://devzone.nordicsemi.com/tutorials/9/