4.闪烁和升级固件

在本节中,我们将使用多端映像进行编程SPI Flash并在空中升级它,但是,在我们这样做之前,让我们快速查看升级过程的工作原理。

4.1. Explanation of memory management

There are three memory locations that are of particular importance for the SUOTA procedure: the start offset of the first image, the one for the second image, and the location for the product header. These variables define where the binary images and the product header reside. In the figure below you can see the fields of the multipart-image header, the header of each single image, and the product header.

标题

Figure 4多部分图像,单图像和产品标题

二级引导加载程序驻留在我们的多级图像的标题之后。当设备启动时,它会检查产品标题的偏移字段以确定固件图像启动的位置,还执行一些检查以验证图像的完整性。然后,它将每个固件的版本进行比较,以评估哪些图像是最近最近的图像,然后继续启动最新图像。开发人员应该处理代码大小,以便升级的图像将有足够的空间驻留在其适当的内存段中。另请注意,在您希望产品标题驻留在不同位置的情况下,您必须通过更改辅助引导加载程序提供该位置product_header_position.macro definition.

4.2. Programming the SPI flash (DA145xx Pro Development Kit)

  • Open SmartSnippets Toolbox. Select your device family and the JTAG interface and Open the profile. If you need more details on how to use the SmartSnippets Toolbox, you can consult theSmartSnippets工具箱的用户手册.
SSToolbox home

Figure 5SmartSnippets Toolbox home screen

  • On the ribbon, choose the SPI Flash/EEPROM utility.
SSToolbox ribbon

Figure 6SPI Flash/EEPROM utility

  • Push the “Load hex/bin file” button. In the pop-up window, select the “Make single image” radio button and then browse through your files and select the first firmware image. This will create the first single image that we need for the multipart firmware. Press “Next”.
选择单个映像

Figure 7Select the first firmware image

  • In the next screen you will be asked about the encryption key and initialization vector, as was the string array that we discussed previously. We will use the defaults in this case, but you can provide yours to better suit your needs. After that, press “Next”.
Encryption key and initialization vector

Figure 8Encryption key and initialization vector

  • 然后选取ect the output folder in which you want to save the single image.
Select output folder of single image

Figure 9Select output folder of single image

  • Repeat the above procedure for the second image file. After that, you will have two output files,fw_1.imgfw_2.img.
  • Push the “Load hex/bin file” button. In the pop-up window, select the “Make multi image” radio button this time, and then browse through your files and select thefw_1.img. Press “Next”.
Select multi image

Figure 10Create multi image

  • In the next screen, select thefw_2.img. Press “Next”.
Select second image

Figure 11Select the second image file

  • Provide the secondary bootloader that we have compiled earlier.
Secondary bootloader

Figure 12Secondary bootloader

  • 在下一个屏幕中,您可以选择固件映像将驻留的内存位置。一个重要的一点是产品标题位置必须是我们之前在辅助引导加载程序中定义的位置。
Memory offsets

Figure 13Memory offsets for firmware images and product header

  • Choose the output folder for the multi image. Go through your settings one more time, and if you are satisfied, click finish. The SPI Flash Programmer will be updated and it’s ready to burn our multi image.
Multi image summary

Figure 14Summary of multi image

  • Press “Connect” to connect to device, then “Erase” to erase your flash contents and then “Burn & Verify”. Push the Reset button on your board. The active image will be now running on your device.

4.3。编程SPI Flash(DA14531模块)

本节介绍了用户需要进行的更改,以便在DA14531模块上运行Suota。这些变化是由于DA14531模块中嵌入的闪存大小为128千字节(1-Mbit)。DA145xx Pro开发套件在2-Mbit SPI数据闪存中。

在下图中显示了模块连接到DA145x开发套件时的硬件连接:

Multi image summary

Figure 15The DA14531 module connected to the DA14531 mother Board

  1. Change the SPI Flash memory size ((HEX, in Bytes) to20000
Multi image summary

Figure 16SPI Flash memory size

  1. 生成新的辅助引导加载程序映像

Here you can follow the same steps as it is already described in thesection 3.1.4, then do the following changes:

  • Go intobootloader.h并改变product_header_position.to0x1F000
#define product_header_position 0x1f000.
  • Go intoperiph_setup.h并改变SPI_FLASH_DEV_SIZEto(128 * 1024)
  • The memory location that the firmware images will reside should be changed to:
Multi image summary

Figure 17Memory offsets for firmware images and product header when the DA14531 Module is used

  • In the application (project file) change the following inapp_suotar.h:
#define product_header_position 0x38000

To

#define product_header_position 0x1f000.

4.4. Upgrading the firmware with the Dialog’s SUOTA App

You can easily upgrade the firmware over-the-air with Dialog’s SUOTA app, available on Android and iOS devices. Download it on your phone through the Apple App Store or Google Play.

  • In theoutput/folder you will find each firmware output in a.img文件格式。在手机上复制第二个图像文件Suota/folder by any means you are comfortable with (e.g. USB cable, download over the internet, etc.)
  • 打开对话框的Suota应用程序。确保嵌入式设备正在运行并按“扫描”按钮。
SUOTA home

Figure 18Dialog’s SUOTA home screen

  • You should quickly see your device advertising. Click on your device’s name to begin the upgrade process.
SUOTA find device

Figure 19Device selection screen

  • Some basic information, like your device family and the SDK version it is using will be presented for you to check. Hit the “Update Device” button to continue.
SUOTA device info

Figure 20Device information

  • 选择第二个固件。
SUOTA select firmware

Figure 21Firmware selection

  • Configure the pins according to your device and select “Send to device”.
SUOTA select firmware

Figure 22SPI pin configuration

  • The upload process will begin. When it complete, a message will prompt you to reboot your device. Push “Yes”. You can verify that the update process succeeded by checking the advertised device name.
SUOTA select firmware

Figure 23SUOTA upgrade complete