Skip to main content
SAli.8
Associate II
March 8, 2023
Solved

Issue in BLE stack advertisement after jumping with bootloader. Context: We have two binaries: a custom bootloader/ota app and user app with BLE capabilities. After jump from bootloader to app binary, BLE advertisement does not work.

  • March 8, 2023
  • 3 replies
  • 1921 views

..

This topic has been closed for replies.
Best answer by SAli.8

This issue has been resolved by me as follows:

Before jumping:

Pause any tasks registered with sequencer especially CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID

Then call SHCI_C2_Reinit()

This will de-init BLE and it can be re-init with different services in other binary smoothly.

 // De-init BLE stack run by CPU 2, this is needed as we are not doing system reset but jumping to another binary and we were sing BLE stack in this binary as well
 UTIL_SEQ_PauseTask(1<< CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID); // tell sequencer to pause all registered tasks, in our case advertisement only
 
 SHCI_CmdStatus_t shci_response = SHCI_C2_Reinit(); // fake reset CPU2 as per AN5289 Application Note "Building wireless applications with STM32WB Series microcontrollers"
 

3 replies

SAli.8
SAli.8Author
Associate II
March 8, 2023

0693W00000aISW0QAO.pngDetails:

The bootloader binary has BLE stack initialized with generated code and also user app used BLE stack as well with different GAP profile.

The function APPE_SysUserEvtRx is not called after jump from bootloader to user app binary.

Here is the jump function of bootloader:

// Implementation of long jump from one binary in flash to another
__attribute__ ((optimize(0))) void Jump(uint32_t firmware_address) {
 // De-init BLE of CPU 2, commented as these keep bootloader blocked if any of them are called
	// SHCI_C2_802_15_4_DeInit();
	// LL_C2_PWR_SetPowerMode(LL_PWR_MODE_STOP1);
 // __SEV();
 
 // Set VTOR register which contains vector table with reset interrupt handler etc. addresses
 SCB->VTOR = (uint32_t)(firmware_address);
 
 // Block memory access until above command finishes, as it may not be atomic operation
 __DSB();
 
 // Reset control register
 __set_CONTROL(0);
 
 // De-init all peripherals of CPU 1 used in bootloader
 HAL_UART_MspDeInit(&hlpuart1);
	 __HAL_RCC_GPIOC_CLK_DISABLE();
	 __HAL_RCC_GPIOD_CLK_DISABLE();
	 __HAL_RCC_GPIOB_CLK_DISABLE();
	 __HAL_RCC_GPIOA_CLK_DISABLE();
	HAL_RCC_DeInit();
	HAL_DeInit();
 
	// Prepare to jump
 // Set Main Stack Pointer to image start address
 __set_MSP(*(uint32_t *)firmware_address);
 
 // Set program counter to image address + 4 where reset vector of image lies, jumping from bootloader to image here
 __set_PC(*(uint32_t *)(firmware_address + 4));
}

The jump is successful if I do not use any commented out shci.h functions but BLE advertisement does not work then in user application binary.

If I use shci.h functions to stop BLE in hopes of stopping the stack to re-init later then that keeps sequencer waiting. Means stuck forever in bootloader.

There is related issue to this but it is unresolved so please help:

Related Issue of BL Jump and BLE Stack

SAli.8
SAli.8Author
Associate II
March 8, 2023

The BLE stack works fine only if one of the binary uses it for that binary presently.

SAli.8
SAli.8AuthorBest answer
Associate II
March 31, 2023

This issue has been resolved by me as follows:

Before jumping:

Pause any tasks registered with sequencer especially CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID

Then call SHCI_C2_Reinit()

This will de-init BLE and it can be re-init with different services in other binary smoothly.

 // De-init BLE stack run by CPU 2, this is needed as we are not doing system reset but jumping to another binary and we were sing BLE stack in this binary as well
 UTIL_SEQ_PauseTask(1<< CFG_TASK_SYSTEM_HCI_ASYNCH_EVT_ID); // tell sequencer to pause all registered tasks, in our case advertisement only
 
 SHCI_CmdStatus_t shci_response = SHCI_C2_Reinit(); // fake reset CPU2 as per AN5289 Application Note "Building wireless applications with STM32WB Series microcontrollers"