cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB, what might cause CPU2 to FAIL and stuck during initialization?

Micha Valach
Associate III

Hello,

I have a project which contains both: Bootloader (BL) and Application (App.)

The BL is based on minimal devices without interrupts, mainly RS485 - and worked Fine!

The App. is based on "BLE_PERIPHERAL_LITE" example by ST, with my additional freeRTOS integration - Also worked Fine!

After Reset, the control is transferred to the BL then it Jumps successfully to my App. (which is located at address 0x08008000), most of the times App. initialization goes - Fine, and the App. is working OK!!

However sometimes (20% of the cases) the App. initialization doesn't succeed and it stuck in endless loop, but do recover after IWDT timeout.

Below please find my main() code, on 20% of the times, the App. performs the CPU2_Init(); procedure (at line#42) and then stuck at line#48 until next IWDT occur, then my App. successfully recover and RUN!!!

My question are:

  1. What might cause APP_FLAG_CPU2_INITIALIZED and APP_FLAG_WIRELESS_FW_RUNNING, M0+ flags (at lines #44-45) to remain "0" after Reset, at 20% of the times ?
  2. What shell I add in order to improve the App. running after reset, to 100%?

Thanks In Advance,

Micha

  1.  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  2.  HAL_Init();
  3.  
  4.  /* USER CODE BEGIN Init */
  5.  
  6.  /* Tune the HSE internal load capacitors - P-NUCLEO-WB55.Nucleo board */
  7.  // micha removed Tune_HSE();
  8.   
  9. // Reset_Device();
  10.  
  11.  /* Configure the debug support if needed */
  12.  APPD_Init();
  13.   
  14.  /* USER CODE END Init */
  15.  
  16.  /* Configure the system clock */
  17.  SystemClock_Config();
  18.  
  19.  /* USER CODE END SysInit */
  20.  
  21.  /* Initialize all configured peripherals */
  22.  MX_GPIO_Init();
  23.  MX_DMA_Init();
  24.  MX_USART1_UART_Init();
  25.  MX_RTC_Init();
  26.  MX_RF_Init();
  27.  MX_LPUART1_UART_Init();
  28.  MX_SPI1_Init();
  29.  MX_TIM2_Init();
  30.  MX_TIM1_Init();
  31.  MX_TIM16_Init();
  32. #ifdef __ENABLE_TOUCH_PAD__
  33.  MX_TSC_Init();
  34. #endif
  35. #ifdef __WATCHDOG__
  36.  MX_IWDG_Init(); // already done in BL (bootloader)
  37. #endif
  38.  /* USER CODE BEGIN 2 */
  39.   
  40.  /* Initialize all transport layers */
  41. #ifdef __ENABLE_BLE__
  42.  CPU2_Init();
  43.  /* Wait until the CPU2 gets initialized */  // Micha 2020-12-08 this is a critical trap, after Boot loader initialization!!!
  44.  while((APP_FLAG_GET(APP_FLAG_CPU2_INITIALIZED) == 0) \
  45.     || (APP_FLAG_GET(APP_FLAG_WIRELESS_FW_RUNNING) == 0))
  46.  {
  47.   /* Process pending SYSTEM event coming from CPU2 (if any) */
  48.   SYS_ProcessEvent(); <== Sometimes code stuck here
  49.  }
  50.  
  51.  /* Configure the CPU2 Debug (Optional) */
  52.  APPD_EnableCPU2();
  53.  

2 REPLIES 2
Vincent H
Associate III

Hi,

did you get any explanation/relief for this ?

It looks like I get caught in the same situation :

No boot-loader. My code works fine on Nucleo (WB55) but get stuck on custom board WB35.

When I debug it (single step through the code), CPU gets initialized.

Before I open a ticket, I'd like to know is anyone came up with a suggestion or a fix.

Thx.

Vincent

Micha Valach
Associate III

Hi Vincent,

I don't have this issue anymore, I changed a bit the order and add some small delays

I'll Not be able to comment in the coming month (overseas vacation)

Make sure you use HAL_Delay(xx); at this stage and NOT osDelay(xx) in case of freeRTOS usage

Below please find my current new main() procedure:

Give it a try, Good Luck

Kind Regards,

Micha

int main(void)

{

 /* USER CODE BEGIN 1 */

 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* USER CODE BEGIN Init */

 /* Tune the HSE internal load capacitors AYK35 */

 Tune_HSE();

  

 /* Configure the debug support if needed */

 APPD_Init();

 // Reset_Device();

  

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

// Init_Exti(); /**< Configure the system Power Mode */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_USART1_UART_Init();

 MX_RTC_Init();

 MX_RF_Init();

 MX_LPUART1_UART_Init();

 MX_SPI1_Init();

 MX_TIM2_Init();

 MX_TIM1_Init();

 MX_TIM16_Init();

 MX_TSC_Init();

 MX_IWDG_Init();

 /* USER CODE BEGIN 2 */

 /*## Start the TIM Base generation in interrupt mode ####################*/

 /* Initialize all transport layers */

#ifdef __ENABLE_BLE__

 CPU2_Init();

 // ST support advice 2021-01-13

// hci_reset();

// HAL_Delay(3);

// SHCI_C2_Reinit();

 /**

  * This is a safe clear in case the engi bytes are not all written

  * The error flag should be cleared before moving forward

  */

 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);

 HAL_Delay(3);

 while((APP_FLAG_GET(APP_FLAG_CPU2_INITIALIZED) == 0) \

|| (APP_FLAG_GET(APP_FLAG_WIRELESS_FW_RUNNING) == 0))

 {

 SYS_ProcessEvent();

 }

 /* Configure the CPU2 Debug (Optional) */

 APPD_EnableCPU2();

 /* At this point it is still unknown from the app perspective, which wireless stack

and which version is installed on CPU2. It is expected that a BLE stack is installed.

In order to check that, SHCI_GetWirelessFwInfo(...) can be used to read out

the information about the CM0+ wireless stack FW running since the Device Information Table

is initialized. For more information on this topic, please refer to AN5289 and AN5185. */

 WirelessFwInfo_t WirelessInfo;

 /* Read the firmware version of both the wireless firmware and the FUS */

 SHCI_GetWirelessFwInfo( &WirelessInfo );

 /* Initialize BLE (BLE TL, BLE stack, HAL, HCI, GATT, GAP) */

 BLE_Init();

 /* Initialize My Very Own GATT Service - user may also implement SVCCTL_InitCustomSvc()

interface function as explained in AN5289. SVCCTL_InitCustomSvc() is called at the end of

SVCCTL_Init() called from BLE_Init() */

 MyVeryOwnService_Init();

 /* Start BLE advertising */

 BLE_Advertising(SET);