cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB5MMGHx custom app couldn't go back to OTA Loader App

Jtron.11
Senior

I am following this video link showing step by step to create OTA app.

https://www.youtube.com/watch?v=mRzZOa3jmuM.

I am successfully to create the custom application, download the OTA loader app at 0x08000000, and the custom's app at 0x08007000. The problem I am facing is whenever I sent some data to OTA Reboot characteristic, the custom app is just reset, then go back to the custom app. It didn't enter the OTA loader app. Am I missing something like the erase current app function? I also notice in my custom app, once the ST BLE tool box or ST BLE Sensor app connects to my device, it didn't show the OTA reboot option like when I tried the BLE_p2pServer_ota.

1 ACCEPTED SOLUTION

Accepted Solutions
Jtron.11
Senior

Thank you Axel.

I found the bug. My copied and pasted code mistake so I used the Notification characteristic for the Reboot Mode characteristic which is the problem I will never got the command sent in from ST ToolBox BLE app.

View solution in original post

11 REPLIES 11
Jtron.11
Senior


_legacyfs_online_stmicro_images_0693W00000bjfdaQAA.png 

So I found this info,

When my device is up, it has the option "OTA Reboot Request" when I use ST Ble Toolbox,

I write Hex "000702" but nothing is happening

My code has

  case CUSTOM_STM_BOOT_REQUEST_EVT:

   *(uint32_t*)(SRAM1_BASE) = *(uint32_t*)pNotification->DataTransfered.pPayload;

   NVIC_SystemReset();

   break;

Do I understand the logic is OTA loader will use the information from SRAM1_BASE (which is define at 0x20000000UL, to erase my 2 sector starting at 0x08007000?

#define SRAM_BASE       (0x20000000UL)/*!< SRAM(up to 256 KB) base address */

#define SRAM1_BASE       SRAM_BASE         /*!< SRAM1(up to 192 KB) base address */

If I used the programmer, and manually erased 2 sectors starting from 0x08007000, after the power cycle, my device always comes up with STM_OTA which is the OTA loader application was loaded at 0x08000000.

Please suggest where should I need to double check or my errors.

Hello @Jtron.1​ ,

Please not that I am not an expert of BLE or OTA, but from my own experience I could give you some advises. 

First of all, may I have for information about your configuration?

What MCU are you using, running on an EVAL board ? What binary OTA application do you flash ? It is the last release ?

For the following I am assuming that your are running an custom BLE application.

Here is the general idea of procedure for OTA application:

  • {Ensure your BLE stack is update and running}
  • Flash OTA application at @0x08000000
  • Add OTA reboot characteristic to one of your BLE service
  • Managed the OTA reboot characteristic
In custom_app.c:
...
    case CUSTOM_STM_OTA_REBOOT_REQUEST_WRITE_EVT:
     /* USER CODE BEGIN CUSTOM_STM_OTA_REBOOT_REQUEST_WRITE_EVT */
   	APP_DBG_MSG("\r\n\r** OTA Reboot event!\n");
   	/* Write reboot reason at 0x20000000 (SRAM1):
   	 * Boot Mode: 0x00-> User Application (0x08007000), 0x01-> OTA application (0x08000000)
   	 * Sector index: 0x07 (7 sectors is the first to be program)
   	 * Number of sector to be erase (4K granulation): Filesize/4K + 1
   	 * Total: 3bytes (octets).
   	 *  */
   	*(uint32_t *)SRAM1_BASE = *(uint32_t*)pNotification->DataTransfered.pPayload;
   	NVIC_SystemReset();
   	while(1);
     /* USER CODE END CUSTOM_STM_OTA_REBOOT_REQUEST_WRITE_EVT */
     break;
...
  • Managed the vector table relocation (or not?)
In /Core/Src/system_stm32wbxx.c
...
 
#define USER_VECT_TAB_ADDRESS
#if defined(USER_VECT_TAB_ADDRESS)
/*!< Uncomment this line for user vector table remap in Sram else user remap
     will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS   SRAM1_BASE      /*!< Vector Table base address field.
                                                     This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET         0x00000000U     /*!< Vector Table base offset field.
                                                     This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS   FLASH_BASE      /*!< Vector Table base address field.
                                                     This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET         0x00007000U     /*!< Vector Table base offset field.
                                                     This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
  • Modify linkerscript (STM32WB5xx_FLASH.ld file) to add the magic keyword section
...
    .ota_region 0x08007140:
  {
	KEEP(*(TAG_OTA_START))
	. = ALIGN(4);
  } >FLASH
 
...
 
  .ota_region_end :
  {
	. = ALIGN(4);
	KEEP(*(TAG_OTA_END))
	. = ALIGN(4);
  } >FLASH
 
...

  • In app_ble.c
/**
 * These are the two tags used to manage a power failure during OTA
 * The MagicKeywordAdress shall be mapped @0x140 from start of the binary image
 * The MagicKeywordvalue is checked in the ble_ota application
 */
PLACE_IN_SECTION("TAG_OTA_END") const uint32_t MagicKeywordValue = 0x94448A29 ;
PLACE_IN_SECTION("TAG_OTA_START") const uint32_t MagicKeywordAddress = (uint32_t)&MagicKeywordValue;

  • Ensure your MagicKeyword is correctly written (using STM32CubeProgrammer for exemple)

You may see the OTA procedure describe in this figure


_legacyfs_online_stmicro_images_0693W00000bjrUgQAI.png 

AN5247 may be usefull for you.

BeST Regards,

Axel L.

Jtron.11
Senior

Thank you Axel.

I found the bug. My copied and pasted code mistake so I used the Notification characteristic for the Reboot Mode characteristic which is the problem I will never got the command sent in from ST ToolBox BLE app.

Glad that you resolve your problem.

May you flag this question as answer, this can help other people.

BeST Regards,

Axel L.

Jtron.11
Senior

Axel,

May I ask you couple questions regarding the ST BLE toolbox or Sensor app?

  1. When I tested either with HeartRate_ota or P2P_Server_ota, the 2 app nicely provide more button and calculate the parameters in the background to send to the application to back to STM_OTA.

Is this proprietary from ST? Or there are any App Note that share the information.

Is the feature depending on the specific UUID it receives?

In my custom template app, I have 1 service: 2 characters: write and notification. Doesn't matter what UUID I assigned but when I used FULL 128 bits, my write characteristic always show the same UUID as the notification characteristic.

If I changed them back to reduce, I then see 2 different UUID (2 bytes) for each of characteristics.

Do you know why?

Or do you know any App Note to elaborate the UUIDs?

Sure, if I can help,

From what I experience:

  1. ST BLE Toolbox/sensor are develop by ST. I thinks that the app managed alone the command because the UUID is standard for OTA procedure so the app recognize it. I don't know well about theses two apps.
  2. When creating services you have two options:
    1. Use standards UUID publied and reference by the SIG, so you can use the reduce for on 16-bits (for exemple Heart rate service is 0x180D). I attach for you a document that describe the standards UUID.
    2. Generate random UUID for you own custom services/caracteristics. Please not that is it mandatory to not use a standard service UUID for your custom services UUID. You can find online custom UUID generator.
Jtron.11
Senior

Thank you Axel,

That is my problem. I generate 128 bit of UUID for my own, I used it for Service, Write, and Notification characteristics but ST BLE tool box pickup and use the same UUID for Write and Notification. I don't understand this.

Please pay attention that you need to generate a custom UUID for you #Service1 then generate customs UUIDs for you characteristic #CharA, and #CharB.

As a result of the previous example, you will have a custom service #Service1 that contain two characteristics: #CharA and #CharB.

Jtron.11
Senior

Thank you so much for your help. I might not clear in my previously post.

I generated for example EEAABB01-0000-0000.., I used for Service 1 then I just change EEAABB02- 0000-0000.., and EEAABB02-0000-0000.., for CharA and CharB respectively.

Still the ST BLE toolbox app pick only EEAABB02-0000-0000.., to show on the app for both Char.