From dbb8cdbf7c3d4df02cbcf0ac3530f5b908942e17 Mon Sep 17 00:00:00 2001
From: Frederic Pillon <frederic.pillon@st.com>
Date: Mon, 29 Apr 2024 17:13:55 +0200
Subject: [PATCH 1/5] chore: update STM32_WPAN from Cube version v1.19.0

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
---
 src/utility/STM32_WPAN/README.md          |   4 +-
 src/utility/STM32_WPAN/app_conf_default.h | 105 +++++-----------------
 src/utility/STM32_WPAN/ble_bufsize.h      |  51 ++++++-----
 src/utility/STM32_WPAN/hw.h               |  13 +--
 src/utility/STM32_WPAN/hw_ipcc.c          |   4 +-
 src/utility/STM32_WPAN/shci.c             |   2 -
 src/utility/STM32_WPAN/shci_tl.c          |  27 +-----
 src/utility/STM32_WPAN/stm_list.c         |   6 +-
 src/utility/STM32_WPAN/tl.h               |   2 +-
 src/utility/STM32_WPAN/tl_mbox.c          |   6 --
 10 files changed, 60 insertions(+), 160 deletions(-)

diff --git a/src/utility/STM32_WPAN/README.md b/src/utility/STM32_WPAN/README.md
index 97c4ceba..b8b7d7ed 100644
--- a/src/utility/STM32_WPAN/README.md
+++ b/src/utility/STM32_WPAN/README.md
@@ -1,6 +1,6 @@
 
 ## Source
 
-[STMicroelectronics/STM32CubeWB Release v1.18.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.18.0)
-- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.18.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode)
+[STMicroelectronics/STM32CubeWB Release v1.19.0](https://github.com/STMicroelectronics/STM32CubeWB/releases/tag/v1.19.0)
+- Application: [BLE_TransparentMode](https://github.com/STMicroelectronics/STM32CubeWB/tree/v1.19.0/Projects/P-NUCLEO-WB55.Nucleo/Applications/BLE/BLE_TransparentMode)
 
diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h
index 9509a0f5..846be3c9 100644
--- a/src/utility/STM32_WPAN/app_conf_default.h
+++ b/src/utility/STM32_WPAN/app_conf_default.h
@@ -1,9 +1,9 @@
 /* USER CODE BEGIN Header */
 /**
   ******************************************************************************
-  * @file    app_conf_default.h
+  * @file    app_conf.h
   * @author  MCD Application Team
-  * @brief   Default application configuration file for STM32WPAN Middleware.
+  * @brief   Application configuration file for STM32WPAN Middleware.
   ******************************************************************************
   * @attention
   *
@@ -19,42 +19,18 @@
 /* USER CODE END Header */
 
 /* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef APP_CONF_DEFAULT_H
-#define APP_CONF_DEFAULT_H
+#ifndef APP_CONF_H
+#define APP_CONF_H
 
-#if 0
 #include "hw.h"
 #include "hw_conf.h"
 #include "hw_if.h"
 #include "ble_bufsize.h"
-#endif
 
 /******************************************************************************
  * Application Config
  ******************************************************************************/
 
-/**< generic parameters ******************************************************/
-/* HCI related defines */
-
-#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F
-#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C
-#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D
-#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251)
-#define HCI_RESET 0x0C03
-
-#ifndef BLE_SHARED_MEM_BYTE_ORDER
-  #define BLE_SHARED_MEM_BYTE_ORDER  MSBFIRST
-#endif
-#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128
-
-/**
- * Define Tx Power
- */
-#ifndef CFG_TX_POWER
-  #define CFG_TX_POWER                        (0x18) /* -0.15dBm */
-#endif
-
-#if 0
 /**
  * Define Secure Connections Support
  */
@@ -128,7 +104,6 @@
 #define CFG_FW_SUBVERSION         (1)
 #define CFG_FW_BRANCH             (0)
 #define CFG_FW_BUILD              (0)
-#endif
 
 /******************************************************************************
  * BLE Stack
@@ -137,25 +112,13 @@
  * Maximum number of simultaneous connections that the device will support.
  * Valid values are from 1 to 8
  */
-#ifndef CFG_BLE_NUM_LINK
-#ifdef STM32WB15xx
-  #define CFG_BLE_NUM_LINK            3
-#else
-  #define CFG_BLE_NUM_LINK            8
-#endif
-#endif
+#define CFG_BLE_NUM_LINK            8
 
 /**
  * Maximum number of Services that can be stored in the GATT database.
  * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services
  */
-#ifndef CFG_BLE_NUM_GATT_SERVICES
-#ifdef STM32WB15xx
-  #define CFG_BLE_NUM_GATT_SERVICES   4
-#else
-  #define CFG_BLE_NUM_GATT_SERVICES   8
-#endif
-#endif
+#define CFG_BLE_NUM_GATT_SERVICES   8
 
 /**
  * Maximum number of Attributes
@@ -164,13 +127,7 @@
  * Note that certain characteristics and relative descriptors are added automatically during device initialization
  * so this parameters should be 9 plus the number of user Attributes
  */
-#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES
-#ifdef STM32WB15xx
-  #define CFG_BLE_NUM_GATT_ATTRIBUTES 30
-#else
-  #define CFG_BLE_NUM_GATT_ATTRIBUTES 68
-#endif
-#endif
+#define CFG_BLE_NUM_GATT_ATTRIBUTES 68
 
 /**
  * Maximum supported ATT_MTU size
@@ -206,16 +163,12 @@
 /**
  * Enable or disable the Extended Packet length feature. Valid values are 0 or 1.
  */
-#ifndef CFG_BLE_DATA_LENGTH_EXTENSION
-  #define CFG_BLE_DATA_LENGTH_EXTENSION   1
-#endif
+#define CFG_BLE_DATA_LENGTH_EXTENSION   1
 
 /**
  * Sleep clock accuracy in Peripheral mode (ppm value)
  */
-#ifndef CFG_BLE_PERIPHERAL_SCA
-  #define CFG_BLE_PERIPHERAL_SCA   500
-#endif
+#define CFG_BLE_PERIPHERAL_SCA   500
 
 /**
  * Sleep clock accuracy in Central mode
@@ -228,9 +181,7 @@
  * 6 : 21 ppm to 30 ppm
  * 7 : 0 ppm to 20 ppm
  */
-#ifndef CFG_BLE_CENTRAL_SCA
-  #define CFG_BLE_CENTRAL_SCA   0
-#endif
+#define CFG_BLE_CENTRAL_SCA   0
 
 /**
  * LsSource
@@ -239,27 +190,21 @@
  * - bit 1:   1: STM32WB5M Module device                             0: Other devices as STM32WBxx SOC, STM32WB1M module
  * - bit 2:   1: HSE/1024 Clock config                               0: LSE Clock config
  */
-#ifndef CFG_BLE_LS_SOURCE
-  #if defined(STM32WB5Mxx)
-    #define CFG_BLE_LS_SOURCE  (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE)
-  #else
-    #define CFG_BLE_LS_SOURCE  (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE)
-  #endif
+#if defined(STM32WB5Mxx)
+  #define CFG_BLE_LS_SOURCE  (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE)
+#else
+  #define CFG_BLE_LS_SOURCE  (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE)
 #endif
 
 /**
  * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us)
  */
-#ifndef CFG_BLE_HSE_STARTUP_TIME
-  #define CFG_BLE_HSE_STARTUP_TIME  0x148
-#endif
+#define CFG_BLE_HSE_STARTUP_TIME  0x148
 
 /**
  * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us)
  */
-#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH
-  #define CFG_BLE_MAX_CONN_EVENT_LENGTH  (0xFFFFFFFF)
-#endif
+#define CFG_BLE_MAX_CONN_EVENT_LENGTH  (0xFFFFFFFF)
 
 /**
  * Viterbi Mode
@@ -305,7 +250,7 @@
  *          0: LE Power Class 2-3
  * other bits: complete with Options_extension flag
  */
-#define CFG_BLE_OPTIONS  (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3)
+#define CFG_BLE_OPTIONS  (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3)
 
 /**
  * BLE stack Options_extension flags to be configured with:
@@ -347,11 +292,7 @@
  * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set
  */
 
-#if defined(STM32WB15xx)
-  #define CFG_BLE_MAX_ADV_SET_NBR     (3)
-#else
-  #define CFG_BLE_MAX_ADV_SET_NBR     (8)
-#endif
+#define CFG_BLE_MAX_ADV_SET_NBR     (8)
 
  /* Maximum advertising data length (in bytes)
  * Range: 31 .. 1650 with limitation:
@@ -360,11 +301,7 @@
  * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set
  */
 
-#if defined(STM32WB15xx)
-  #define CFG_BLE_MAX_ADV_DATA_LEN    (414)
-#else
-  #define CFG_BLE_MAX_ADV_DATA_LEN    (207)
-#endif
+#define CFG_BLE_MAX_ADV_DATA_LEN    (207)
 
  /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB.
   * Range: -1280 .. 1280
@@ -387,7 +324,6 @@
 
 #define CFG_BLE_CORE_VERSION   (SHCI_C2_BLE_INIT_BLE_CORE_5_4)
 
-#if 0
 /******************************************************************************
  * Transport Layer
  ******************************************************************************/
@@ -723,5 +659,4 @@ typedef enum
 
 #define CFG_OTP_END_ADRESS      OTP_AREA_END_ADDR
 
-#endif
-#endif /*APP_CONF_DEFAULT_H */
+#endif /*APP_CONF_H */
diff --git a/src/utility/STM32_WPAN/ble_bufsize.h b/src/utility/STM32_WPAN/ble_bufsize.h
index b9935c0b..66cc2a5a 100644
--- a/src/utility/STM32_WPAN/ble_bufsize.h
+++ b/src/utility/STM32_WPAN/ble_bufsize.h
@@ -5,7 +5,7 @@
  *****************************************************************************
  * @attention
  *
- * Copyright (c) 2018-2023 STMicroelectronics.
+ * Copyright (c) 2018-2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
@@ -35,13 +35,13 @@
  * equal to BLE_DEFAULT_ATT_MTU (23).
  */
 #define BLE_PREP_WRITE_X_ATT(max_att) \
-          (DIVC(max_att, BLE_DEFAULT_ATT_MTU - 5) * 2)
+        (DIVC(max_att, BLE_DEFAULT_ATT_MTU - 5) * 2)
 
 /*
  * BLE_DEFAULT_PREP_WRITE_LIST_SIZE: default minimum Prepare Write List size.
  */
 #define BLE_DEFAULT_PREP_WRITE_LIST_SIZE \
-          BLE_PREP_WRITE_X_ATT(BLE_DEFAULT_MAX_ATT_SIZE)
+        BLE_PREP_WRITE_X_ATT(BLE_DEFAULT_MAX_ATT_SIZE)
 
 /*
  * BLE_MEM_BLOCK_X_MTU: compute how many memory blocks are needed to compose
@@ -49,14 +49,21 @@
  */
 #define BLE_MEM_BLOCK_SIZE                   32
 
+#if (SLAVE_ONLY != 0) ||(BASIC_FEATURES != 0)
+#define BLE_MEM_BLOCK_X_PTX(n_link)           0
+#else
+#define BLE_MEM_BLOCK_X_PTX(n_link)           (n_link)
+#endif
+
 #define BLE_MEM_BLOCK_X_TX(mtu) \
-          (DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 1U)
+        (DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 1)
 
 #define BLE_MEM_BLOCK_X_RX(mtu, n_link) \
-          ((DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 2U) * (n_link) + 1)
+        ((DIVC((mtu) + 4U, BLE_MEM_BLOCK_SIZE) + 2U) * (n_link) + 1)
 
 #define BLE_MEM_BLOCK_X_MTU(mtu, n_link) \
-          (BLE_MEM_BLOCK_X_TX(mtu) + BLE_MEM_BLOCK_X_RX(mtu, n_link))
+        (BLE_MEM_BLOCK_X_TX(mtu) + BLE_MEM_BLOCK_X_PTX(n_link) + \
+         BLE_MEM_BLOCK_X_RX(mtu, n_link))
 
 /*
  * BLE_MBLOCKS_SECURE_CONNECTIONS: minimum number of blocks required for
@@ -72,8 +79,8 @@
  *  - n_link: maximum number of simultaneous connections
  */
 #define BLE_MBLOCKS_CALC(pw, mtu, n_link) \
-          ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \
-                      BLE_MBLOCKS_SECURE_CONNECTIONS))
+        ((pw) + MAX(BLE_MEM_BLOCK_X_MTU(mtu, n_link), \
+                    BLE_MBLOCKS_SECURE_CONNECTIONS))
 
 /*
  * BLE_FIXED_BUFFER_SIZE_BYTES:
@@ -90,30 +97,30 @@
  *   mentioned parameters.
 */
 #if (BEACON_ONLY != 0)
-#define BLE_FIXED_BUFFER_SIZE_BYTES  4092   /* Beacon only */
+#define BLE_FIXED_BUFFER_SIZE_BYTES  4100   /* Beacon only */
 #elif (LL_ONLY_BASIC != 0)
-#define BLE_FIXED_BUFFER_SIZE_BYTES  5788   /* LL only Basic*/
+#define BLE_FIXED_BUFFER_SIZE_BYTES  6040   /* LL only Basic*/
 #elif (LL_ONLY != 0)
-#define BLE_FIXED_BUFFER_SIZE_BYTES  6036   /* LL only Full */
+#define BLE_FIXED_BUFFER_SIZE_BYTES  6288   /* LL only Full */
 #elif (SLAVE_ONLY != 0)
-#define BLE_FIXED_BUFFER_SIZE_BYTES  6300   /* Peripheral only */
+#define BLE_FIXED_BUFFER_SIZE_BYTES  6408   /* Peripheral only */
 #elif (BASIC_FEATURES != 0)
-#define BLE_FIXED_BUFFER_SIZE_BYTES  6632   /* Basic Features */
+#define BLE_FIXED_BUFFER_SIZE_BYTES  7184   /* Basic Features */
 #else
-#define BLE_FIXED_BUFFER_SIZE_BYTES  7152   /* Full stack */
+#define BLE_FIXED_BUFFER_SIZE_BYTES  7468   /* Full stack */
 #endif
 
 /*
  * BLE_PER_LINK_SIZE_BYTES: additional memory size used per link
  */
 #if (BEACON_ONLY != 0)
-#define BLE_PER_LINK_SIZE_BYTES       112   /* Beacon only */
+#define BLE_PER_LINK_SIZE_BYTES       108   /* Beacon only */
 #elif (LL_ONLY_BASIC != 0)
 #define BLE_PER_LINK_SIZE_BYTES       244   /* LL only Basic */
 #elif (LL_ONLY != 0)
 #define BLE_PER_LINK_SIZE_BYTES       244   /* LL only Full */
 #elif (SLAVE_ONLY != 0)
-#define BLE_PER_LINK_SIZE_BYTES       344   /* Peripheral only */
+#define BLE_PER_LINK_SIZE_BYTES       392   /* Peripheral only */
 #elif (BASIC_FEATURES != 0)
 #define BLE_PER_LINK_SIZE_BYTES       420   /* Basic Features */
 #else
@@ -131,9 +138,9 @@
  * @param mblocks_count: Number of memory blocks allocated for packets.
  */
 #define BLE_TOTAL_BUFFER_SIZE(n_link, mblocks_count) \
-          (16 + BLE_FIXED_BUFFER_SIZE_BYTES + \
-           (BLE_PER_LINK_SIZE_BYTES * (n_link)) + \
-           ((BLE_MEM_BLOCK_SIZE + 12) * (mblocks_count)))
+        (16 + BLE_FIXED_BUFFER_SIZE_BYTES + \
+         (BLE_PER_LINK_SIZE_BYTES * (n_link)) + \
+         ((BLE_MEM_BLOCK_SIZE + 8) * (mblocks_count)))
 
 /*
  * BLE_EXT_ADV_BUFFER_SIZE
@@ -148,7 +155,7 @@
  * Valid values are from 31 to 1650.
  */
 #define BLE_EXT_ADV_BUFFER_SIZE(set_nbr, data_len) \
-          (2512 + ((892 + (DIVC(data_len, 207) * 244)) * (set_nbr)))
+        (2512 + ((892 + (DIVC(data_len, 207) * 244)) * (set_nbr)))
 
 /*
  * BLE_TOTAL_BUFFER_SIZE_GATT: this macro returns the amount of memory,
@@ -168,8 +175,8 @@
  * @param att_value_array_size: Size of the storage area for Attribute values.
   */
 #define BLE_TOTAL_BUFFER_SIZE_GATT(num_gatt_attributes, num_gatt_services, att_value_array_size) \
-          (((((att_value_array_size) - 1) | 3) + 1) + \
-           (40 * (num_gatt_attributes)) + (48 * (num_gatt_services)))
+        (((((att_value_array_size) - 1) | 3) + 1) + \
+         (40 * (num_gatt_attributes)) + (48 * (num_gatt_services)))
 
 
 #endif /* BLE_BUFSIZE_H__ */
diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h
index 1472a5e8..651e1f17 100644
--- a/src/utility/STM32_WPAN/hw.h
+++ b/src/utility/STM32_WPAN/hw.h
@@ -26,23 +26,14 @@ extern "C" {
 #endif
 
   /* Includes ------------------------------------------------------------------*/
-#include "stm32_def.h"
-#include "stm32wbxx_ll_bus.h"
-#include "stm32wbxx_ll_exti.h"
-#include "stm32wbxx_ll_system.h"
-#include "stm32wbxx_ll_rcc.h"
-#include "stm32wbxx_ll_ipcc.h"
-#include "stm32wbxx_ll_cortex.h"
-#include "stm32wbxx_ll_utils.h"
-#include "stm32wbxx_ll_pwr.h"
 
   /******************************************************************************
    * HW IPCC
    ******************************************************************************/
   void HW_IPCC_Enable( void );
   void HW_IPCC_Init( void );
-#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler
-#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler
+  void HW_IPCC_Rx_Handler( void );
+  void HW_IPCC_Tx_Handler( void );
 
   void HW_IPCC_BLE_Init( void );
   void HW_IPCC_BLE_SendCmd( void );
diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c
index 3461cbed..fd620b85 100644
--- a/src/utility/STM32_WPAN/hw_ipcc.c
+++ b/src/utility/STM32_WPAN/hw_ipcc.c
@@ -18,9 +18,8 @@
   */
 /* USER CODE END Header */
 
-#if defined(STM32WBxx)
 /* Includes ------------------------------------------------------------------*/
-#include "hw.h"
+#include "app_common.h"
 #include "mbox_def.h"
 
 /* Global variables ---------------------------------------------------------*/
@@ -668,4 +667,3 @@ static void HW_IPCC_TRACES_EvtHandler( void )
 }
 
 __weak void HW_IPCC_TRACES_EvtNot( void ){};
-#endif /* STM32WBxx */
diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c
index 40110f42..5c32555e 100644
--- a/src/utility/STM32_WPAN/shci.c
+++ b/src/utility/STM32_WPAN/shci.c
@@ -17,7 +17,6 @@
  */
 
 
-#if defined(STM32WBxx)
 /* Includes ------------------------------------------------------------------*/
 #include "stm32_wpan_common.h"
 
@@ -760,4 +759,3 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo )
 
   return (SHCI_Success);
 }
-#endif /* STM32WBxx */
diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c
index 25e1a214..0f604300 100644
--- a/src/utility/STM32_WPAN/shci_tl.c
+++ b/src/utility/STM32_WPAN/shci_tl.c
@@ -17,14 +17,11 @@
  */
 
 
-#if defined(STM32WBxx)
 /* Includes ------------------------------------------------------------------*/
 #include "stm32_wpan_common.h"
 
 #include "stm_list.h"
 #include "shci_tl.h"
-#include "stm32_def.h"
-#include "wiring_time.h"
 
 /* Private typedef -----------------------------------------------------------*/
 typedef enum
@@ -171,20 +168,6 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl
   return;
 }
 
-void shci_notify_asynch_evt(void *pdata)
-{
-  UNUSED(pdata);
-  /* Need to parse data in future version */
-  shci_user_evt_proc();
-}
-
-void shci_register_io_bus(tSHciIO *fops)
-{
-  /* Register IO bus services */
-  fops->Init    = TL_SYS_Init;
-  fops->Send    = TL_SYS_SendCmd;
-}
-
 /* Private functions ---------------------------------------------------------*/
 static void TlInit( TL_CmdPacket_t * p_cmdbuffer )
 {
@@ -252,11 +235,10 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt)
 /* Weak implementation ----------------------------------------------------------------*/
 __WEAK void shci_cmd_resp_wait(uint32_t timeout)
 {
-  for (unsigned long start = millis(); (millis() - start) < timeout;) {
-    if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) {
-      break;
-    }
-  }
+  (void)timeout;
+
+  while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE);
+
   return;
 }
 
@@ -268,4 +250,3 @@ __WEAK void shci_cmd_resp_release(uint32_t flag)
 
   return;
 }
-#endif /* STM32WBxx */
diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c
index df6c2155..4c928647 100644
--- a/src/utility/STM32_WPAN/stm_list.c
+++ b/src/utility/STM32_WPAN/stm_list.c
@@ -17,13 +17,10 @@
   */
 
 
-#if defined(STM32WBxx)
 /******************************************************************************
  * Include Files
  ******************************************************************************/
-#include "stdint.h"
-#include "cmsis_gcc.h"
-#include "stm32_wpan_common.h"
+#include "utilities_common.h"
 
 #include "stm_list.h"
 
@@ -207,4 +204,3 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node)
 
   __set_PRIMASK(primask_bit);      /**< Restore PRIMASK bit*/
 }
-#endif /* STM32WBxx */
diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h
index 74520878..8e8c6cbc 100644
--- a/src/utility/STM32_WPAN/tl.h
+++ b/src/utility/STM32_WPAN/tl.h
@@ -108,7 +108,7 @@ typedef PACKED_STRUCT
 {
   uint8_t   evtcode;
   uint8_t   plen;
-  uint8_t   payload[4];
+  uint8_t   payload[2];
 } TL_Evt_t;
 
 typedef PACKED_STRUCT
diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c
index 40c96793..27a998a3 100644
--- a/src/utility/STM32_WPAN/tl_mbox.c
+++ b/src/utility/STM32_WPAN/tl_mbox.c
@@ -16,7 +16,6 @@
  ******************************************************************************
  */
 
-#if defined(STM32WBxx)
 /* Includes ------------------------------------------------------------------*/
 #include "stm32_wpan_common.h"
 #include "hw.h"
@@ -52,10 +51,8 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable;
 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable;
 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable;
 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable;
-#if 0
 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table;
 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table;
-#endif
 
 /**< tables */
 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode  FreeBufQueue;
@@ -100,10 +97,8 @@ void TL_Init( void )
   TL_RefTable.p_sys_table = &TL_SysTable;
   TL_RefTable.p_mem_manager_table = &TL_MemManagerTable;
   TL_RefTable.p_traces_table = &TL_TracesTable;
-#if 0
   TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table;
   TL_RefTable.p_zigbee_table = &TL_Zigbee_Table;
-#endif
   HW_IPCC_Init();
 
   return;
@@ -851,4 +846,3 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer)
 
   return;
 }
-#endif /* STM32WBxx */

From 277526456bf95c2e8181aa50268e0e4965d8e8f6 Mon Sep 17 00:00:00 2001
From: Frederic Pillon <frederic.pillon@st.com>
Date: Wed, 10 Jan 2024 18:16:01 +0100
Subject: [PATCH 2/5] chore: adapt STM32_WPAN sources

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
---
 src/utility/STM32_WPAN/app_conf_default.h | 49 +++++++++++++++++++----
 src/utility/STM32_WPAN/hw.h               | 13 +++++-
 src/utility/STM32_WPAN/hw_ipcc.c          |  4 +-
 src/utility/STM32_WPAN/shci.c             |  2 +
 src/utility/STM32_WPAN/shci_tl.c          | 17 ++++++++
 src/utility/STM32_WPAN/stm_list.c         |  6 ++-
 src/utility/STM32_WPAN/tl_mbox.c          |  6 +++
 7 files changed, 85 insertions(+), 12 deletions(-)

diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h
index 846be3c9..6c9beb3b 100644
--- a/src/utility/STM32_WPAN/app_conf_default.h
+++ b/src/utility/STM32_WPAN/app_conf_default.h
@@ -1,9 +1,9 @@
 /* USER CODE BEGIN Header */
 /**
   ******************************************************************************
-  * @file    app_conf.h
+  * @file    app_conf_default.h
   * @author  MCD Application Team
-  * @brief   Application configuration file for STM32WPAN Middleware.
+  * @brief   Default application configuration file for STM32WPAN Middleware.
   ******************************************************************************
   * @attention
   *
@@ -19,18 +19,40 @@
 /* USER CODE END Header */
 
 /* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef APP_CONF_H
-#define APP_CONF_H
+#ifndef APP_CONF_DEFAULT_H
+#define APP_CONF_DEFAULT_H
 
+#if 0
 #include "hw.h"
 #include "hw_conf.h"
 #include "hw_if.h"
 #include "ble_bufsize.h"
+#endif
 
 /******************************************************************************
  * Application Config
  ******************************************************************************/
 
+/**< generic parameters ******************************************************/
+/* HCI related defines */
+
+#define ACI_HAL_SET_TX_POWER_LEVEL 0xFC0F
+#define ACI_WRITE_CONFIG_DATA_OPCODE 0xFC0C
+#define ACI_READ_CONFIG_DATA_OPCODE 0xFC0D
+#define MAX_HCI_ACL_PACKET_SIZE (sizeof(TL_PacketHeader_t) + 5 + 251)
+#define HCI_RESET 0x0C03
+
+#ifndef BLE_SHARED_MEM_BYTE_ORDER
+  #define BLE_SHARED_MEM_BYTE_ORDER  MSBFIRST
+#endif
+#define BLE_MODULE_SHARED_MEM_BUFFER_SIZE 128
+
+/**
+ * Define Tx Power
+ */
+#define CFG_TX_POWER                      (0x18) /* -0.15dBm */
+
+#if 0
 /**
  * Define Secure Connections Support
  */
@@ -104,6 +126,7 @@
 #define CFG_FW_SUBVERSION         (1)
 #define CFG_FW_BRANCH             (0)
 #define CFG_FW_BUILD              (0)
+#endif
 
 /******************************************************************************
  * BLE Stack
@@ -250,7 +273,7 @@
  *          0: LE Power Class 2-3
  * other bits: complete with Options_extension flag
  */
-#define CFG_BLE_OPTIONS  (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3)
+#define CFG_BLE_OPTIONS  (SHCI_C2_BLE_INIT_OPTIONS_LL_ONLY | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RW | SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_CS_ALGO2 | SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3)
 
 /**
  * BLE stack Options_extension flags to be configured with:
@@ -292,7 +315,11 @@
  * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set
  */
 
-#define CFG_BLE_MAX_ADV_SET_NBR     (8)
+#if defined(STM32WB15xx)
+  #define CFG_BLE_MAX_ADV_SET_NBR     (3)
+#else
+  #define CFG_BLE_MAX_ADV_SET_NBR     (8)
+#endif
 
  /* Maximum advertising data length (in bytes)
  * Range: 31 .. 1650 with limitation:
@@ -301,7 +328,11 @@
  * This parameter is considered by the CPU2 when CFG_BLE_OPTIONS has SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV flag set
  */
 
-#define CFG_BLE_MAX_ADV_DATA_LEN    (207)
+#if defined(STM32WB15xx)
+  #define CFG_BLE_MAX_ADV_DATA_LEN    (414)
+#else
+  #define CFG_BLE_MAX_ADV_DATA_LEN    (207)
+#endif
 
  /* RF TX Path Compensation Value (16-bit signed integer). Units: 0.1 dB.
   * Range: -1280 .. 1280
@@ -324,6 +355,7 @@
 
 #define CFG_BLE_CORE_VERSION   (SHCI_C2_BLE_INIT_BLE_CORE_5_4)
 
+#if 0
 /******************************************************************************
  * Transport Layer
  ******************************************************************************/
@@ -659,4 +691,5 @@ typedef enum
 
 #define CFG_OTP_END_ADRESS      OTP_AREA_END_ADDR
 
-#endif /*APP_CONF_H */
+#endif
+#endif /*APP_CONF_DEFAULT_H */
diff --git a/src/utility/STM32_WPAN/hw.h b/src/utility/STM32_WPAN/hw.h
index 651e1f17..1472a5e8 100644
--- a/src/utility/STM32_WPAN/hw.h
+++ b/src/utility/STM32_WPAN/hw.h
@@ -26,14 +26,23 @@ extern "C" {
 #endif
 
   /* Includes ------------------------------------------------------------------*/
+#include "stm32_def.h"
+#include "stm32wbxx_ll_bus.h"
+#include "stm32wbxx_ll_exti.h"
+#include "stm32wbxx_ll_system.h"
+#include "stm32wbxx_ll_rcc.h"
+#include "stm32wbxx_ll_ipcc.h"
+#include "stm32wbxx_ll_cortex.h"
+#include "stm32wbxx_ll_utils.h"
+#include "stm32wbxx_ll_pwr.h"
 
   /******************************************************************************
    * HW IPCC
    ******************************************************************************/
   void HW_IPCC_Enable( void );
   void HW_IPCC_Init( void );
-  void HW_IPCC_Rx_Handler( void );
-  void HW_IPCC_Tx_Handler( void );
+#define HW_IPCC_Rx_Handler IPCC_C1_RX_IRQHandler
+#define HW_IPCC_Tx_Handler IPCC_C1_TX_IRQHandler
 
   void HW_IPCC_BLE_Init( void );
   void HW_IPCC_BLE_SendCmd( void );
diff --git a/src/utility/STM32_WPAN/hw_ipcc.c b/src/utility/STM32_WPAN/hw_ipcc.c
index fd620b85..3461cbed 100644
--- a/src/utility/STM32_WPAN/hw_ipcc.c
+++ b/src/utility/STM32_WPAN/hw_ipcc.c
@@ -18,8 +18,9 @@
   */
 /* USER CODE END Header */
 
+#if defined(STM32WBxx)
 /* Includes ------------------------------------------------------------------*/
-#include "app_common.h"
+#include "hw.h"
 #include "mbox_def.h"
 
 /* Global variables ---------------------------------------------------------*/
@@ -667,3 +668,4 @@ static void HW_IPCC_TRACES_EvtHandler( void )
 }
 
 __weak void HW_IPCC_TRACES_EvtNot( void ){};
+#endif /* STM32WBxx */
diff --git a/src/utility/STM32_WPAN/shci.c b/src/utility/STM32_WPAN/shci.c
index 5c32555e..40110f42 100644
--- a/src/utility/STM32_WPAN/shci.c
+++ b/src/utility/STM32_WPAN/shci.c
@@ -17,6 +17,7 @@
  */
 
 
+#if defined(STM32WBxx)
 /* Includes ------------------------------------------------------------------*/
 #include "stm32_wpan_common.h"
 
@@ -759,3 +760,4 @@ SHCI_CmdStatus_t SHCI_GetWirelessFwInfo( WirelessFwInfo_t* pWirelessInfo )
 
   return (SHCI_Success);
 }
+#endif /* STM32WBxx */
diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c
index 0f604300..daa988c1 100644
--- a/src/utility/STM32_WPAN/shci_tl.c
+++ b/src/utility/STM32_WPAN/shci_tl.c
@@ -17,11 +17,13 @@
  */
 
 
+#if defined(STM32WBxx)
 /* Includes ------------------------------------------------------------------*/
 #include "stm32_wpan_common.h"
 
 #include "stm_list.h"
 #include "shci_tl.h"
+#include "stm32_def.h"
 
 /* Private typedef -----------------------------------------------------------*/
 typedef enum
@@ -168,6 +170,20 @@ void shci_send( uint16_t cmd_code, uint8_t len_cmd_payload, uint8_t * p_cmd_payl
   return;
 }
 
+void shci_notify_asynch_evt(void *pdata)
+{
+  UNUSED(pdata);
+  /* Need to parse data in future version */
+  shci_user_evt_proc();
+}
+
+void shci_register_io_bus(tSHciIO *fops)
+{
+  /* Register IO bus services */
+  fops->Init    = TL_SYS_Init;
+  fops->Send    = TL_SYS_SendCmd;
+}
+
 /* Private functions ---------------------------------------------------------*/
 static void TlInit( TL_CmdPacket_t * p_cmdbuffer )
 {
@@ -250,3 +266,4 @@ __WEAK void shci_cmd_resp_release(uint32_t flag)
 
   return;
 }
+#endif /* STM32WBxx */
diff --git a/src/utility/STM32_WPAN/stm_list.c b/src/utility/STM32_WPAN/stm_list.c
index 4c928647..df6c2155 100644
--- a/src/utility/STM32_WPAN/stm_list.c
+++ b/src/utility/STM32_WPAN/stm_list.c
@@ -17,10 +17,13 @@
   */
 
 
+#if defined(STM32WBxx)
 /******************************************************************************
  * Include Files
  ******************************************************************************/
-#include "utilities_common.h"
+#include "stdint.h"
+#include "cmsis_gcc.h"
+#include "stm32_wpan_common.h"
 
 #include "stm_list.h"
 
@@ -204,3 +207,4 @@ void LST_get_prev_node (tListNode * ref_node, tListNode ** node)
 
   __set_PRIMASK(primask_bit);      /**< Restore PRIMASK bit*/
 }
+#endif /* STM32WBxx */
diff --git a/src/utility/STM32_WPAN/tl_mbox.c b/src/utility/STM32_WPAN/tl_mbox.c
index 27a998a3..40c96793 100644
--- a/src/utility/STM32_WPAN/tl_mbox.c
+++ b/src/utility/STM32_WPAN/tl_mbox.c
@@ -16,6 +16,7 @@
  ******************************************************************************
  */
 
+#if defined(STM32WBxx)
 /* Includes ------------------------------------------------------------------*/
 #include "stm32_wpan_common.h"
 #include "hw.h"
@@ -51,8 +52,10 @@ PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_BleLldTable_t TL_BleLldTable;
 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_SysTable_t TL_SysTable;
 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_MemManagerTable_t TL_MemManagerTable;
 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_TracesTable_t TL_TracesTable;
+#if 0
 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_Mac_802_15_4_t TL_Mac_802_15_4_Table;
 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static MB_ZigbeeTable_t TL_Zigbee_Table;
+#endif
 
 /**< tables */
 PLACE_IN_SECTION("MB_MEM1") ALIGN(4) static tListNode  FreeBufQueue;
@@ -97,8 +100,10 @@ void TL_Init( void )
   TL_RefTable.p_sys_table = &TL_SysTable;
   TL_RefTable.p_mem_manager_table = &TL_MemManagerTable;
   TL_RefTable.p_traces_table = &TL_TracesTable;
+#if 0
   TL_RefTable.p_mac_802_15_4_table = &TL_Mac_802_15_4_Table;
   TL_RefTable.p_zigbee_table = &TL_Zigbee_Table;
+#endif
   HW_IPCC_Init();
 
   return;
@@ -846,3 +851,4 @@ static void OutputDbgTrace(TL_MB_PacketType_t packet_type, uint8_t* buffer)
 
   return;
 }
+#endif /* STM32WBxx */

From 6cb3b4208553284d24d99412bf44b2cfd00b85dc Mon Sep 17 00:00:00 2001
From: Frederic Pillon <frederic.pillon@st.com>
Date: Thu, 13 Jul 2023 17:16:40 +0200
Subject: [PATCH 3/5] fix: include a timeout when waiting for the cmd_resp

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
---
 src/utility/STM32_WPAN/shci_tl.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/utility/STM32_WPAN/shci_tl.c b/src/utility/STM32_WPAN/shci_tl.c
index daa988c1..25e1a214 100644
--- a/src/utility/STM32_WPAN/shci_tl.c
+++ b/src/utility/STM32_WPAN/shci_tl.c
@@ -24,6 +24,7 @@
 #include "stm_list.h"
 #include "shci_tl.h"
 #include "stm32_def.h"
+#include "wiring_time.h"
 
 /* Private typedef -----------------------------------------------------------*/
 typedef enum
@@ -251,10 +252,11 @@ static void TlUserEvtReceived(TL_EvtPacket_t *shcievt)
 /* Weak implementation ----------------------------------------------------------------*/
 __WEAK void shci_cmd_resp_wait(uint32_t timeout)
 {
-  (void)timeout;
-
-  while(CmdRspStatusFlag != SHCI_TL_CMD_RESP_RELEASE);
-
+  for (unsigned long start = millis(); (millis() - start) < timeout;) {
+    if (CmdRspStatusFlag == SHCI_TL_CMD_RESP_RELEASE) {
+      break;
+    }
+  }
   return;
 }
 

From 790d928aabca9a4507f569c20b57b5609a8c83aa Mon Sep 17 00:00:00 2001
From: Frederic Pillon <frederic.pillon@st.com>
Date: Wed, 10 Jan 2024 18:45:17 +0100
Subject: [PATCH 4/5] chore: add support for customize app_conf_default.h

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
---
 src/utility/STM32_WPAN/app_conf_default.h | 58 ++++++++++++++++++-----
 1 file changed, 45 insertions(+), 13 deletions(-)

diff --git a/src/utility/STM32_WPAN/app_conf_default.h b/src/utility/STM32_WPAN/app_conf_default.h
index 6c9beb3b..9509a0f5 100644
--- a/src/utility/STM32_WPAN/app_conf_default.h
+++ b/src/utility/STM32_WPAN/app_conf_default.h
@@ -50,7 +50,9 @@
 /**
  * Define Tx Power
  */
-#define CFG_TX_POWER                      (0x18) /* -0.15dBm */
+#ifndef CFG_TX_POWER
+  #define CFG_TX_POWER                        (0x18) /* -0.15dBm */
+#endif
 
 #if 0
 /**
@@ -135,13 +137,25 @@
  * Maximum number of simultaneous connections that the device will support.
  * Valid values are from 1 to 8
  */
-#define CFG_BLE_NUM_LINK            8
+#ifndef CFG_BLE_NUM_LINK
+#ifdef STM32WB15xx
+  #define CFG_BLE_NUM_LINK            3
+#else
+  #define CFG_BLE_NUM_LINK            8
+#endif
+#endif
 
 /**
  * Maximum number of Services that can be stored in the GATT database.
  * Note that the GAP and GATT services are automatically added so this parameter should be 2 plus the number of user services
  */
-#define CFG_BLE_NUM_GATT_SERVICES   8
+#ifndef CFG_BLE_NUM_GATT_SERVICES
+#ifdef STM32WB15xx
+  #define CFG_BLE_NUM_GATT_SERVICES   4
+#else
+  #define CFG_BLE_NUM_GATT_SERVICES   8
+#endif
+#endif
 
 /**
  * Maximum number of Attributes
@@ -150,7 +164,13 @@
  * Note that certain characteristics and relative descriptors are added automatically during device initialization
  * so this parameters should be 9 plus the number of user Attributes
  */
-#define CFG_BLE_NUM_GATT_ATTRIBUTES 68
+#ifndef CFG_BLE_NUM_GATT_ATTRIBUTES
+#ifdef STM32WB15xx
+  #define CFG_BLE_NUM_GATT_ATTRIBUTES 30
+#else
+  #define CFG_BLE_NUM_GATT_ATTRIBUTES 68
+#endif
+#endif
 
 /**
  * Maximum supported ATT_MTU size
@@ -186,12 +206,16 @@
 /**
  * Enable or disable the Extended Packet length feature. Valid values are 0 or 1.
  */
-#define CFG_BLE_DATA_LENGTH_EXTENSION   1
+#ifndef CFG_BLE_DATA_LENGTH_EXTENSION
+  #define CFG_BLE_DATA_LENGTH_EXTENSION   1
+#endif
 
 /**
  * Sleep clock accuracy in Peripheral mode (ppm value)
  */
-#define CFG_BLE_PERIPHERAL_SCA   500
+#ifndef CFG_BLE_PERIPHERAL_SCA
+  #define CFG_BLE_PERIPHERAL_SCA   500
+#endif
 
 /**
  * Sleep clock accuracy in Central mode
@@ -204,7 +228,9 @@
  * 6 : 21 ppm to 30 ppm
  * 7 : 0 ppm to 20 ppm
  */
-#define CFG_BLE_CENTRAL_SCA   0
+#ifndef CFG_BLE_CENTRAL_SCA
+  #define CFG_BLE_CENTRAL_SCA   0
+#endif
 
 /**
  * LsSource
@@ -213,21 +239,27 @@
  * - bit 1:   1: STM32WB5M Module device                             0: Other devices as STM32WBxx SOC, STM32WB1M module
  * - bit 2:   1: HSE/1024 Clock config                               0: LSE Clock config
  */
-#if defined(STM32WB5Mxx)
-  #define CFG_BLE_LS_SOURCE  (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE)
-#else
-  #define CFG_BLE_LS_SOURCE  (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE)
+#ifndef CFG_BLE_LS_SOURCE
+  #if defined(STM32WB5Mxx)
+    #define CFG_BLE_LS_SOURCE  (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_MOD5MM_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE)
+  #else
+    #define CFG_BLE_LS_SOURCE  (SHCI_C2_BLE_INIT_CFG_BLE_LS_NOCALIB | SHCI_C2_BLE_INIT_CFG_BLE_LS_OTHER_DEV | SHCI_C2_BLE_INIT_CFG_BLE_LS_CLK_LSE)
+  #endif
 #endif
 
 /**
  * Start up time of the high speed (16 or 32 MHz) crystal oscillator in units of 625/256 us (~2.44 us)
  */
-#define CFG_BLE_HSE_STARTUP_TIME  0x148
+#ifndef CFG_BLE_HSE_STARTUP_TIME
+  #define CFG_BLE_HSE_STARTUP_TIME  0x148
+#endif
 
 /**
  * Maximum duration of the connection event when the device is in Peripheral mode in units of 625/256 us (~2.44 us)
  */
-#define CFG_BLE_MAX_CONN_EVENT_LENGTH  (0xFFFFFFFF)
+#ifndef CFG_BLE_MAX_CONN_EVENT_LENGTH
+  #define CFG_BLE_MAX_CONN_EVENT_LENGTH  (0xFFFFFFFF)
+#endif
 
 /**
  * Viterbi Mode

From 676a3ccdd6fb4b20642316ad24dc7dbd8cef89b8 Mon Sep 17 00:00:00 2001
From: Frederic Pillon <frederic.pillon@st.com>
Date: Mon, 24 Jul 2023 10:55:20 +0200
Subject: [PATCH 5/5] fix: TL_Evt_t payload size for reset

Within STM32CubeWB v1.17.0 update TL_Evt_t payload size was reduced.
This produce a warning -Warray-bounds due to the reset management
which require 4 bytes.

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
---
 src/utility/STM32_WPAN/tl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/utility/STM32_WPAN/tl.h b/src/utility/STM32_WPAN/tl.h
index 8e8c6cbc..74520878 100644
--- a/src/utility/STM32_WPAN/tl.h
+++ b/src/utility/STM32_WPAN/tl.h
@@ -108,7 +108,7 @@ typedef PACKED_STRUCT
 {
   uint8_t   evtcode;
   uint8_t   plen;
-  uint8_t   payload[2];
+  uint8_t   payload[4];
 } TL_Evt_t;
 
 typedef PACKED_STRUCT