KW41 - Reprogramming a FRDM-KW41 board using the OTAP Client Software

cancel
Showing results for 
Search instead for 
Did you mean: 

KW41 - Reprogramming a FRDM-KW41 board using the OTAP Client Software

KW41 - Reprogramming a FRDM-KW41 board using the OTAP Client Software

Introduction

This document guides to load a new software image in a KW41 device through Over The Air Programming bootloader. Also, are explained the details of how to set up the client software to change the storage method of the image.

Software Requirements

  1. IAR Embedded Workbench IDE or MCUXpresso IDE
  2. Download both, SDK FRDM-KW41Z and SDK USB-KW41Z.

Hardware Requirements

  1. FRDM-KW41Z board

OTAP Memory Management During the Update Process

The KW41 has a 512KB Program Flash with a flash address range from 0x0000_0000 to 0x0007_FFFF.

 

pastedImage_6.png

 

  1. The OTAP application splits the flash into two independent parts, the OTAP Bootloader, and the OTAP Client. The OTAP Bootloader verifies if there is a new image available at the OTAP Client to reprogram the device. The OTAP Client software provides the Bluetooth LE custom service needed to communicate the OTAP Client device with the OTAP Server that contains the new image file (The OTAP Server device could be another FRDM-KW41Z connected to a PC with Test Tool or a Smartphone with IoT Toolbox app). Therefore, the OTAP Client device needs to be programmed twice, first with the OTAP Bootloader, then with the Bluetooth LE application supporting OTAP Client. The mechanism created to have two different software coexisting in the same device is storing each one in different memory regions. This functionality is implemented by the linker file. In the KW41 device, the bootloader has reserved a 16 KB slot of memory from 0x0000_0000 to 0x0003_FFFF, thus the left memory is reserved among other things, by the OTAP Client demo.pastedImage_11.png
  2. To create a new image file for the client device, the developer needs to specify to the linker file that the code will be built with an offset of 16 KB since the first addresses must be reserved for the OTAP Bootloader.pastedImage_13.png
  3. In connection state, the OTAP server sends the image packets (known as chunks) to the OTAP Client device via Bluetooth LE. The OTAP Client device can store these chunks, in first instance, at the external SPI flash or the On-Chip Flash. The destination of the code is selectable in the OTAP Client software.pastedImage_15.png
  4. When the connection has finished and all chunks were sent from the OTAP Server to the OTAP Client device, the OTAP Client software writes information, such as the source of the image update (external flash or internal flash) in a portion of memory known as Bootloader Flags and then resets the MCU to execute the OTAP Bootloader code. The OTAP Bootloader reads the Bootloader Flags to get the information needed to program the device and triggers a commando to reprogram the MCU with the new application. Due to the new application was built with an offset of 16 KB, the OTAP Bootloader programs the device starting from the 0x0000_4000 address and the OTAP Client application is overwritten by the new image, therefore, after the device has been reprogrammed through this method, cannot be programmed a second time as same. Finally, the OTAP Bootloader triggers a command to start the execution of the new code automatically.

 

pastedImage_18.png

 

Preparing the Software to Test the OTAP Client for KW41Z Device Using IAR Embedded Workbench

  • Program the OTAP Bootloader on the FRDM-KW41Z. Program the OTAP Bootloader software from the project included in the SDK FRDM-KW41Z at the following path, or you can simply drag and drop the pre-built binary from the following path.

 

        OTAP Bootloader Project:

         <SDK_2.2.0_FRDM-KW41Z_download_path>\boards\frdmkw41z\wireless_examples\framework\bootloader_otap\bm\iar\bootloader_otap_bm.eww

 

         OTAP Bootloader pre-built binary:

           <SDK_2.2.0_FRDM-KW41Z_download_path>\tools\wireless\binaries\bootloader_otap_frdmkw41z.bin

 

  • Open the OTAP Client project included in the SDK FRDM-KW41Z located in the following path.

         <SDK_2.2.0_FRDM-KW41Z_download_path>\boards\frdmkw41z\wireless_examples\bluetooth\otap_client_att\freertos\iar\otap_client_att_freertos.eww

 

  • Customize the OTAP Client software to select the storage method. Locate the app_preinclude.h header file inside the source folder at the workspace.
  1. To select the External Flash storage method, set the "gEepromType_d" define to "gEepromDevice_AT45DB041E_c                    
  2. To select the Internal Flash storage method, set the "gEepromType_d" define to "gEepromDevice_InternalFlash_c"

 

  • Configure the linker flags. Open the project options window (Alt + F7). In "Linker->Config" window, locate the "Configuration file symbol definitions" pane.
  1. To select the External Flash storage method, remove the "gUseInternalStorageLink_d=1" linker flag
  2. To select the Internal Flash storage method, add the "gUseInternalStorageLink_d=1" linker flag

 

pastedImage_321.png

 

  • Load the OTAP Client software on the FRDM-KW41Z board (Ctrl + D). Stop the debug session (Ctrl + Shift + D). The default linker configurations of the project allow the OTAP Client application to be stored with the proper memory offset.

 

Preparing the Software to Test the OTAP Client for KW41Z Device Using MCUXpresso IDE

  • Program the OTAP Bootloader on the FRDM-KW41Z. Program the OTAP Bootloader software from the project included in the SDK FRDM-KW41Z at the following path, or you can simply drag and drop the pre-built binary from the following path.

 

        OTAP Bootloader Project:

         wireless_examples->framework->bootloader_otap->bm

 

         OTAP Bootloader pre-built binary:

           <SDK_2.2.0_FRDM-KW41Z_download_path>\tools\wireless\binaries\bootloader_otap_frdmkw41z.bin

 

  • Click on "Import SDK examples(s)" option in the "Quickstart Panel" view.
  • Click twice on the frdmkw41z icon.

 

pastedImage_319.png

 

  • Open the OTAP Client project included in the SDK FRDM-KW41Z located in the following path.wireless_examples->bluetooth->otap_client_att->freertos

 

pastedImage_320.png

 

  • Customize the OTAP Client software to select the storage method. Locate the app_preinclude.h header file inside the source folder at the workspace.
  1. To select the External Flash storage method, set the "gEepromType_d" define to "gEepromDevice_AT45DB041E_c                    
  2. To select the Internal Flash storage method, set the "gEepromType_d" define to "gEepromDevice_InternalFlash_c"

 

  • Configure the linker file.
  1. To select the External Flash storage method, are not required any changes in the project from this point. You can skip this step.
  2. To select the Internal Flash storage method, search the linker file located in the SDK USB-KW41Z at the following path and replace instead of the default linker file at the source folder in the OTAP Client project. You can copy (Ctrl + C) the linker file from SDK USB-KW41Z and paste (Ctrl + V) on the workspace directly. A warning message will be displayed, select "Overwrite". 

 

       Linker file at the SDK USB-KW41Z:

       <SDK_2.2.0_USB-KW41Z_download_path>\boards\usbkw41z_kw41z\wireless_examples\bluetooth\otap_client_att\freertos\MKW41Z512xxx4_connectivity.ld

 

pastedImage_413.png

 

  • Save the changes in the project. Select "Debug" in the "Quickstart Panel". Once the project is already loaded on the device, stop the debug session.

 

Creating an S-Record Image File for FRDM-KW41Z OTAP Client in IAR Embedded Workbench

  • Open the connectivity project that you want to program using the OTAP Bootloader from your SDK FRDM-KW41Z. This example will make use of the glucose sensor project, this is located at the following path.

    <SDK_2.2.0_FRDM-KW41Z_download_path>\boards\frdmkw41z\wireless_examples\bluetooth\glucose_sensor\freertos\iar\glucose_sensor_freertos.eww

 

  • Open the project options window (Alt+F7). In Linker->Config window, add the following linker flag in the “Configuration file symbol definitions” textbox.

        gUseBootloaderLink_d=1

 

pastedImage_5.png

 

  • Go to the “Output Converter” window. Deselect the “Override default" checkbox, expand the “Output format” combo box and select Motorola S-records format. Click the OK button.

 

pastedImage_6.png

 

  • Rebuild the project.
  • Search the S-Record file (.srec) in the following path.<SDK_2.2.0_FRDM-KW41Z_download_path>\boards\frdmkw41z\wireless_examples\bluetooth\glucose_sensor\freertos\iar\debug

 

Creating an S-Record Image File for FRDM-KW41Z OTAP Client in MCUXpresso IDE

  • Open the connectivity project that you want to program using the OTAP Bootloader from MCUXpresso IDE. This example will make use of the glucose sensor project, this is located at the following path.

       wireless_examples->bluetooth->glucose_sensor->freertos

 

  • Search the linker file located in the SDK FRDM-KW41Z at the path below and replace instead of the default linker file at the source folder in the Glucose Sensor project. You can copy (Ctrl + C) the linker file from SDK FRDM-KW41Z and paste (Ctrl + V) on the workspace directly. A warning message will be displayed, select "Overwrite".

 

       Linker file at the SDK FRDM-KW41Z:

       <SDK_2.2.0_FRDM-KW41Z_download_path>\boards\frdmkw41z\wireless_examples\bluetooth\otap_client_att\freertos\MKW41Z512xxx4_connectivity.ld

 

pastedImage_7.png

 

  • Open the new "MKW41Z512xxx4_connectivity.ld" linker file. Locate the section placement of the figure below and remove the "FILL" and the "BYTE" statements.

 

   pastedImage_2.png

 

  • Build the project.
  • Deploy the “Binaries” icon in the workspace. Click the right mouse button on the “.axf” file. Select the “Binary Utilities/Create S-Record” option. The S-Record file will be saved at “Debug” folder in the workspace with “.s19” extension.

 

pastedImage_8.png

 

Testing OTAP Client Demo Using IoT Toolbox App

  1. Save the S-Record file created with the steps in the last section in your smartphone at a known location.
  2. Open the IoT Toolbox App and select OTAP demo. Press “SCAN” to start scanning for a suitable advertiser.
  3. Press the “SW4” button on the FRDM-KW41Z board to start advertising.
  4. Create a connection with the found device.pastedImage_9.png
  5. Press “Open” and search the S-Record file.pastedImage_10.png
  6. Press “Upload” to start the transfer.
  7. Once the transfer is complete, wait a few seconds until the bootloader has finished programming the new image. The new application will start automatically. 
Labels (3)
Tags (1)
Comments

Hi,

I'm porting the OTOP client example into my HRS modified program.

Compilation seems to passe now, but i have an error during Linking step.

Invoking: MCU Linker
arm-none-eabi-gcc -L"D:\OTS\Firmware\prototm\libs" -Xlinker -Map="OTS_v1.map" -Xlinker --gc-sections -Xlinker -print-memory-usage -mcpu=cortex-m0 -mthumb -T MKW41Z512xxx4_connectivity.ld -L ../source -o "OTS_v1.axf" ./utilities/fsl_debug_console.o ./startup/startup_MKW41Z4.o ./source/common/gatt_db/gatt_database.o ./source/common/ApplMain.o ./source/common/ble_conn_manager.o ./source/common/ble_controller_task.o ./source/common/ble_host_tasks.o ./source/common/ble_init.o ./source/app_config.o ./source/global.o ./source/heart_rate_sensor.o ./source/i2cGPIO.o ./source/mlx90621.o ./source/mlx91804.o ./source/mtb.o ./source/semihost_hardfault.o ./freertos/croutine.o ./freertos/event_groups.o ./freertos/fsl_tickless_lptmr.o ./freertos/fsl_tickless_systick.o ./freertos/heap_4.o ./freertos/list.o ./freertos/port.o ./freertos/queue.o ./freertos/tasks.o ./freertos/timers.o ./framework/XCVR/MKW41Z4/cfgs_kw4x_3x_2x/fsl_xcvr_ant_config.o ./framework/XCVR/MKW41Z4/cfgs_kw4x_3x_2x/fsl_xcvr_ble_config.o ./framework/XCVR/MKW41Z4/cfgs_kw4x_3x_2x/fsl_xcvr_common_config.o ./framework/XCVR/MKW41Z4/cfgs_kw4x_3x_2x/fsl_xcvr_gfsk_bt_0p3_h_0p5_config.o ./framework/XCVR/MKW41Z4/cfgs_kw4x_3x_2x/fsl_xcvr_gfsk_bt_0p5_h_0p32_config.o ./framework/XCVR/MKW41Z4/cfgs_kw4x_3x_2x/fsl_xcvr_gfsk_bt_0p5_h_0p5_config.o ./framework/XCVR/MKW41Z4/cfgs_kw4x_3x_2x/fsl_xcvr_gfsk_bt_0p5_h_0p7_config.o ./framework/XCVR/MKW41Z4/cfgs_kw4x_3x_2x/fsl_xcvr_gfsk_bt_0p5_h_1p0_config.o ./framework/XCVR/MKW41Z4/cfgs_kw4x_3x_2x/fsl_xcvr_gfsk_bt_0p7_h_0p5_config.o ./framework/XCVR/MKW41Z4/cfgs_kw4x_3x_2x/fsl_xcvr_mode_datarate_config.o ./framework/XCVR/MKW41Z4/cfgs_kw4x_3x_2x/fsl_xcvr_msk_config.o ./framework/XCVR/MKW41Z4/cfgs_kw4x_3x_2x/fsl_xcvr_zgbe_config.o ./framework/XCVR/MKW41Z4/dbg_ram_capture.o ./framework/XCVR/MKW41Z4/fsl_xcvr.o ./framework/XCVR/MKW41Z4/fsl_xcvr_trim.o ./framework/XCVR/MKW41Z4/ifr_radio.o ./framework/TimersManager/Source/TMR_Adapter.o ./framework/TimersManager/Source/TimersManager.o ./framework/SerialManager/Source/UART_Adapter/UART_Adapter.o ./framework/SerialManager/Source/SPI_Adapter/SPI_Adapter.o ./framework/SerialManager/Source/I2C_Adapter/I2C_Adapter.o ./framework/SerialManager/Source/SerialManager.o ./framework/SecLib/SecLib.o ./framework/Reset/Reset.o ./framework/RNG/Source/RNG.o ./framework/Panic/Source/Panic.o ./framework/OtaSupport/Source/OtaSupport.o ./framework/OSAbstraction/Source/fsl_os_abstraction_free_rtos.o ./framework/NVM/Source/NV_Flash.o ./framework/NVM/Source/NV_FsciCommands.o ./framework/ModuleInfo/ModuleInfo.o ./framework/Messaging/Source/Messaging.o ./framework/MemManager/Source/MemManager.o ./framework/MWSCoexistence/Source/MWS.o ./framework/LowPower/Source/MKW41Z/PWR.o ./framework/LowPower/Source/MKW41Z/PWRLib.o ./framework/LowPower/Source/MKW41Z/PWR_BLE.o ./framework/Lists/GenericList.o ./framework/LED/Source/LED.o ./framework/Keyboard/Source/Keyboard.o ./framework/GPIO/GPIO_Adapter.o ./framework/FunctionLib/FunctionLib.o ./framework/Flash/Internal/Flash_Adapter.o ./framework/Flash/External/Source/Eeprom_AT26DF081A.o ./framework/Flash/External/Source/Eeprom_AT45DB021E.o ./framework/Flash/External/Source/Eeprom_AT45DB041E.o ./framework/Flash/External/Source/Eeprom_AT45DB161E.o ./framework/Flash/External/Source/Eeprom_InternalFlash.o ./framework/DCDC/Source/DCDC.o ./drivers/fsl_adc16.o ./drivers/fsl_clock.o ./drivers/fsl_common.o ./drivers/fsl_dspi.o ./drivers/fsl_dspi_freertos.o ./drivers/fsl_flash.o ./drivers/fsl_gpio.o ./drivers/fsl_i2c.o ./drivers/fsl_i2c_freertos.o ./drivers/fsl_llwu.o ./drivers/fsl_lptmr.o ./drivers/fsl_lpuart.o ./drivers/fsl_lpuart_freertos.o ./drivers/fsl_ltc.o ./drivers/fsl_pmc.o ./drivers/fsl_rtc.o ./drivers/fsl_smc.o ./drivers/fsl_tpm.o ./drivers/fsl_trng.o ./board/board.o ./board/clock_config.o ./board/gpio_pins.o ./board/peripherals.o ./board/pin_mux.o ./bluetooth/profiles/tpms/tpms_service.o ./bluetooth/profiles/otap/otap_service.o ./bluetooth/profiles/ircam/ircam_service.o ./bluetooth/profiles/heart_rate/heart_rate_service.o ./bluetooth/profiles/device_info/device_info_service.o ./bluetooth/profiles/battery/battery_service.o ./bluetooth/host/config/ble_globals.o ./bluetooth/hci_transport/source/hcit_serial_interface.o ./CMSIS/system_MKW41Z4.o -lm -lc -lgcc -lnosys -l_ble_kw41z_controller -l_ble_4-2_host_peripheral_cm0p -l_crypto_m0
Memory region Used Size Region Size %age Used
Bootloader_region: 0 GB 16383 B 0.00%
TEXT_region1: 192 B 192 B 100.00%
BootFlags_region: 4 B 7 B 57.14%
TEXT_region2: 206644 B 239416 B 86.31%
InternalStorage: 0 GB 258047 B 0.00%
NVM_region: 0 GB 8191 B 0.00%
DATA_region: 33304 B 128 KB 25.41%
c:/nxp/mcuxpressoide_11.0.0_2516/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.0.0.201905131304/tools/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld.exe: section .dummy VMA [1ffffffb,20000002] overlaps section .stack VMA [1ffffe18,20000217]
collect2.exe: error: ld returned 1 exit status
PRODUCT_INFO_region: 0 GB 2047 B 0.00%
make: *** [makefile:75: OTS_v1.axf] Error 1
"make -r -j12 all" terminated with exit code 2. Build might be incomplete.

17:13:22 Build Failed. 2 errors, 13 warnings. (took 8s.618ms)

I followed the tutorial by using the .ld files from SDK USB-KW41Z.

My programe was a bit too big : 105% of the 512/2 -16 Ko of bootloader. So i had to enable the compilation optimisation option "for size". I don' t think it can have an impact but i give this input in case of ....

What is this dummy partition it point for please ?

Is there a workaround to solve the issue please ?

I removed the dummy section and it build and link too. But when i run in Debug mode the program can not start and doesn' go till the Hardware first init breakpoint.

dummy __dummy_start :
{
. += 8;
} =0x90909090

I laso notice that  inb your tutorial, gEepromType_d sould be in app_preinclude.h header file but for me it is in board.h in sdk.

I tried to check to change ld file in otap client example by the one in usb sdk and change gEepromType_d  for internal storage, there is also error at linking step with bootlader section this time.

What are the step the properly migrate source code from otap client into hrs example for example please? i did by colmparing the two projects and incorporing line by line from otap client to hrs. It build but there is probleme with linking step. I regret that it is the own step missing for my project to be complete.

Thanks for support, i'm a bit stuck here :smileyhappy:

Hello florian.lebrun59@gmail.com‌,

Could you please confirm which version of SDK do you have?  You can verify it in the installed SDKs perspective in MCUXpresso IDE (or simply you can go to https://mcuxpresso.nxp.com/en/dashboard and check for updates).

We recommend to download and install the newest SDK package (SDK 2.2.1) to discard some issues related to version compatibility. My suspect is that you have older software due DATA_region linker section does not match with the new release that splits this section into two parts: DATA1_region and DATA2_region. Did you modify the linker file to create this section?. 

We are already working on release an application note explaining the details of OTAP integration on the HRS demo for FRDM-KW36. I will inform you in a few weeks when we planned to release the document.

Best regards.

Hi nxf46726,

Thanks for your help.

Sdk version is at the moment 2.2.0

pastedImage_1.png

Thanks for writting the tutorial.

1. Do you have an idea if it will be done? for this month or next one may be ? Just to organize my self and see if i can progress anyway.

What i did was to merge OTAP example into HRS : file missing, add the Timer callback and pieces of code here and there . It build but not linked with USB ld file

2. Do you advise to start from hrs and import otap code into it or start from otap nd move hrs into it ?

I have compared otap client demo code from sdk 2.2.0 and 2.2.1. I see some correction on complete transfert flag etc so yes , it will be better to restart from sdk 2.2.1 it seems.

3. Why should we use the USB ld file and not the OTAP client for internal flash memory ota ?

I really look forword your nice tutorial to do this properly.

Thank you so much

Hello florian.lebrun59@gmail.com‌,

1. The application note will be released around half of the next month.

2. The best way to integrate OTAP is first basing on your application and then include the OTAP service on it. In other words, using the HRS as a starting point and then integrate the OTAP into it. This is done in this way because if in the future you need to integrate OTAP on another application, for example, the Glucose Sensor, the steps required are similar (probably, the same steps).  

3. The linker file decides how the code must be stored on the device, also, it has the ability to reserve slots of memory for other purposes, in this case, we need to reserve a section for internal storage. The USB-KW41 board does not have an external flash, instead, it uses the internal storage method as default, so, the USB-KW41 linker already contains the proper linker memory sections for internal storage enablement. We recommend to use it because is the easiest and fastest way to get the example working (which is the purpose of this document), another way, the programmer would edit and customize the linker file to reserve the memory slot needed.

Regards.

Ok 100% clear,

I will then update all my tools and put OTA into HRS, then if all works fine, integrated my code into it.

GO back to 0 :smileysad: lol.

Thanks a lot i hope i will succeed in it, worth case in one month i will be able to compare with your method.

Thanks a lot Edgar for your precious help.

Version history
Revision #:
3 of 3
Last update:
2 weeks ago
Updated by:
 
Contributors