Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Projects/STM32WB5MM-DK/Applications/BLE/BLE_HeartRate/Core/Src/app_entry.c')
-rw-r--r--Projects/STM32WB5MM-DK/Applications/BLE/BLE_HeartRate/Core/Src/app_entry.c243
1 files changed, 195 insertions, 48 deletions
diff --git a/Projects/STM32WB5MM-DK/Applications/BLE/BLE_HeartRate/Core/Src/app_entry.c b/Projects/STM32WB5MM-DK/Applications/BLE/BLE_HeartRate/Core/Src/app_entry.c
index 98fb79035..95cfcced7 100644
--- a/Projects/STM32WB5MM-DK/Applications/BLE/BLE_HeartRate/Core/Src/app_entry.c
+++ b/Projects/STM32WB5MM-DK/Applications/BLE/BLE_HeartRate/Core/Src/app_entry.c
@@ -1,21 +1,21 @@
/* USER CODE BEGIN Header */
/**
- ******************************************************************************
- * File Name : app_entry.c
- * Description : Entry application source file for STM32WPAN Middleware
- ******************************************************************************
+ ******************************************************************************
+ * @file app_entry.c
+ * @author MCD Application Team
+ * @brief Entry point of the Application
+ ******************************************************************************
* @attention
*
- * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
- * All rights reserved.</center></h2>
+ * Copyright (c) 2021 STMicroelectronics.
+ * All rights reserved.
*
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * www.st.com/SLA0044
+ * This software is licensed under terms that can be found in the LICENSE file
+ * in the root directory of this software component.
+ * If no LICENSE file comes with this software, it is provided AS-IS.
*
- ******************************************************************************
- */
+ ******************************************************************************
+ */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
@@ -29,6 +29,8 @@
#include "shci_tl.h"
#include "stm32_lpm.h"
#include "app_debug.h"
+#include "dbg_trace.h"
+#include "shci.h"
#include "otp.h"
/* Private includes -----------------------------------------------------------*/
@@ -66,16 +68,18 @@ PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t BleSpareEvtBuffer[sizeof(TL_
/* Private functions prototypes-----------------------------------------------*/
static void Config_HSE(void);
static void Reset_Device( void );
+#if ( CFG_HW_RESET_BY_FW == 1 )
static void Reset_IPCC( void );
static void Reset_BackupDomain( void );
+#endif /* CFG_HW_RESET_BY_FW */
static void System_Init( void );
static void SystemPower_Config( void );
static void appe_Tl_Init( void );
static void APPE_SysStatusNot( SHCI_TL_CmdStatus_t status );
static void APPE_SysUserEvtRx( void * pPayload );
-static void Init_Exti( void );
+static void APPE_SysEvtReadyProcessing( void * pPayload );
+static void APPE_SysEvtError( void * pPayload);
static void Init_Rtc( void );
-static void Init_Smps( void );
/* USER CODE BEGIN PFP */
static void Button_Init( void );
@@ -154,6 +158,33 @@ void MX_APPE_Init( void )
/* USER CODE END APPE_Init_2 */
return;
}
+
+void Init_Smps( void )
+{
+#if (CFG_USE_SMPS != 0)
+ /**
+ * Configure and enable SMPS
+ *
+ * The SMPS configuration is not yet supported by CubeMx
+ * when SMPS output voltage is set to 1.4V, the RF output power is limited to 3.7dBm
+ * the SMPS output voltage shall be increased for higher RF output power
+ */
+ LL_PWR_SMPS_SetStartupCurrent(LL_PWR_SMPS_STARTUP_CURRENT_80MA);
+ LL_PWR_SMPS_SetOutputVoltageLevel(LL_PWR_SMPS_OUTPUT_VOLTAGE_1V40);
+ LL_PWR_SMPS_Enable();
+#endif
+
+ return;
+}
+
+void Init_Exti( void )
+{
+ /* Enable IPCC(36), HSEM(38) wakeup interrupts on CPU1 */
+ LL_EXTI_EnableIT_32_63( LL_EXTI_LINE_36 & LL_EXTI_LINE_38 );
+
+ return;
+}
+
/* USER CODE BEGIN FD */
void LED_Deinit(void)
@@ -199,11 +230,12 @@ static void Reset_Device( void )
Reset_BackupDomain();
Reset_IPCC();
-#endif
+#endif /* CFG_HW_RESET_BY_FW */
return;
}
+#if ( CFG_HW_RESET_BY_FW == 1 )
static void Reset_BackupDomain( void )
{
if ((LL_RCC_IsActiveFlag_PINRST() != FALSE) && (LL_RCC_IsActiveFlag_SFTRST() == FALSE))
@@ -259,6 +291,7 @@ static void Reset_IPCC( void )
return;
}
+#endif /* CFG_HW_RESET_BY_FW */
static void Config_HSE(void)
{
@@ -287,33 +320,6 @@ static void System_Init( void )
return;
}
-static void Init_Smps( void )
-{
-#if (CFG_USE_SMPS != 0)
- /**
- * Configure and enable SMPS
- *
- * The SMPS configuration is not yet supported by CubeMx
- * when SMPS output voltage is set to 1.4V, the RF output power is limited to 3.7dBm
- * the SMPS output voltage shall be increased for higher RF output power
- */
- LL_PWR_SMPS_SetStartupCurrent(LL_PWR_SMPS_STARTUP_CURRENT_80MA);
- LL_PWR_SMPS_SetOutputVoltageLevel(LL_PWR_SMPS_OUTPUT_VOLTAGE_1V40);
- LL_PWR_SMPS_Enable();
-#endif
-
- return;
-}
-
-static void Init_Exti( void )
-{
- /**< Disable all wakeup interrupt on CPU1 except IPCC(36), HSEM(38) */
- LL_EXTI_DisableIT_0_31(~0);
- LL_EXTI_DisableIT_32_63( (~0) & (~(LL_EXTI_LINE_36 | LL_EXTI_LINE_38)) );
-
- return;
-}
-
static void Init_Rtc( void )
{
/* Disable RTC registers write protection */
@@ -326,6 +332,7 @@ static void Init_Rtc( void )
return;
}
+
/**
* @brief Configure the system for power optimization
*
@@ -398,12 +405,151 @@ static void APPE_SysStatusNot( SHCI_TL_CmdStatus_t status )
*/
static void APPE_SysUserEvtRx( void * pPayload )
{
- UNUSED(pPayload);
- /* Traces channel initialization */
- APPD_EnableCPU2( );
+ TL_AsynchEvt_t *p_sys_event;
+ WirelessFwInfo_t WirelessInfo;
+
+ p_sys_event = (TL_AsynchEvt_t*)(((tSHCI_UserEvtRxParam*)pPayload)->pckt->evtserial.evt.payload);
+
+ /* Read the firmware version of both the wireless firmware and the FUS */
+ SHCI_GetWirelessFwInfo( &WirelessInfo );
+ APP_DBG_MSG("Wireless Firmware version %d.%d.%d\n", WirelessInfo.VersionMajor, WirelessInfo.VersionMinor, WirelessInfo.VersionSub);
+ APP_DBG_MSG("Wireless Firmware build %d\n", WirelessInfo.VersionReleaseType);
+ APP_DBG_MSG("FUS version %d.%d.%d\n\n", WirelessInfo.FusVersionMajor, WirelessInfo.FusVersionMinor, WirelessInfo.FusVersionSub);
+
+ switch(p_sys_event->subevtcode)
+ {
+ case SHCI_SUB_EVT_CODE_READY:
+ APPE_SysEvtReadyProcessing(pPayload);
+ break;
+
+ case SHCI_SUB_EVT_ERROR_NOTIF:
+ APPE_SysEvtError(pPayload);
+ break;
+
+ case SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE:
+ APP_DBG_MSG("-- BLE NVM RAM HAS BEEN UPDATED BY CMO+ \n");
+ APP_DBG_MSG("SHCI_SUB_EVT_BLE_NVM_RAM_UPDATE : StartAddress = %lx , Size = %ld\n",
+ ((SHCI_C2_BleNvmRamUpdate_Evt_t*)p_sys_event->payload)->StartAddress,
+ ((SHCI_C2_BleNvmRamUpdate_Evt_t*)p_sys_event->payload)->Size);
+ break;
+
+ case SHCI_SUB_EVT_NVM_START_WRITE:
+ APP_DBG_MSG("SHCI_SUB_EVT_NVM_START_WRITE : NumberOfWords = %ld\n",
+ ((SHCI_C2_NvmStartWrite_Evt_t*)p_sys_event->payload)->NumberOfWords);
+ break;
+
+ case SHCI_SUB_EVT_NVM_END_WRITE:
+ APP_DBG_MSG("SHCI_SUB_EVT_NVM_END_WRITE\n");
+ break;
+
+ case SHCI_SUB_EVT_NVM_START_ERASE:
+ APP_DBG_MSG("SHCI_SUB_EVT_NVM_START_ERASE : NumberOfSectors = %ld\n",
+ ((SHCI_C2_NvmStartErase_Evt_t*)p_sys_event->payload)->NumberOfSectors);
+ break;
+
+ case SHCI_SUB_EVT_NVM_END_ERASE:
+ APP_DBG_MSG("SHCI_SUB_EVT_NVM_END_ERASE\n");
+ break;
+
+ default:
+ break;
+ }
+
+ return;
+}
+
+/**
+ * @brief Notify a system error coming from the M0 firmware
+ * @param ErrorCode : errorCode detected by the M0 firmware
+ *
+ * @retval None
+ */
+static void APPE_SysEvtError( void * pPayload)
+{
+ TL_AsynchEvt_t *p_sys_event;
+ SCHI_SystemErrCode_t *p_sys_error_code;
+
+ p_sys_event = (TL_AsynchEvt_t*)(((tSHCI_UserEvtRxParam*)pPayload)->pckt->evtserial.evt.payload);
+ p_sys_error_code = (SCHI_SystemErrCode_t*) p_sys_event->payload;
+
+ APP_DBG_MSG("SHCI_SUB_EVT_ERROR_NOTIF WITH REASON %x \n",(*p_sys_error_code));
+
+ if ((*p_sys_error_code) == ERR_BLE_INIT)
+ {
+ /* Error during BLE stack initialization */
+ APP_DBG_MSG("SHCI_SUB_EVT_ERROR_NOTIF WITH REASON - ERR_BLE_INIT \n");
+ }
+ else
+ {
+ APP_DBG_MSG("SHCI_SUB_EVT_ERROR_NOTIF WITH REASON - BLE ERROR \n");
+ }
+ return;
+}
+
+static void APPE_SysEvtReadyProcessing( void * pPayload )
+{
+ TL_AsynchEvt_t *p_sys_event;
+ SHCI_C2_Ready_Evt_t *p_sys_ready_event;
+
+ SHCI_C2_CONFIG_Cmd_Param_t config_param = {0};
+ uint32_t RevisionID=0;
+
+ p_sys_event = (TL_AsynchEvt_t*)(((tSHCI_UserEvtRxParam*)pPayload)->pckt->evtserial.evt.payload);
+ p_sys_ready_event = (SHCI_C2_Ready_Evt_t*) p_sys_event->payload;
+
+ if(p_sys_ready_event->sysevt_ready_rsp == WIRELESS_FW_RUNNING)
+ {
+ /**
+ * The wireless firmware is running on the CPU2
+ */
+ APP_DBG_MSG("SHCI_SUB_EVT_CODE_READY - WIRELESS_FW_RUNNING \n");
+
+ /* Traces channel initialization */
+ APPD_EnableCPU2( );
+
+ /* Enable all events Notification */
+ config_param.PayloadCmdSize = SHCI_C2_CONFIG_PAYLOAD_CMD_SIZE;
+ config_param.EvtMask1 = SHCI_C2_CONFIG_EVTMASK1_BIT0_ERROR_NOTIF_ENABLE
+ + SHCI_C2_CONFIG_EVTMASK1_BIT1_BLE_NVM_RAM_UPDATE_ENABLE
+ + SHCI_C2_CONFIG_EVTMASK1_BIT2_THREAD_NVM_RAM_UPDATE_ENABLE
+ + SHCI_C2_CONFIG_EVTMASK1_BIT3_NVM_START_WRITE_ENABLE
+ + SHCI_C2_CONFIG_EVTMASK1_BIT4_NVM_END_WRITE_ENABLE
+ + SHCI_C2_CONFIG_EVTMASK1_BIT5_NVM_START_ERASE_ENABLE
+ + SHCI_C2_CONFIG_EVTMASK1_BIT6_NVM_END_ERASE_ENABLE;
+
+ /* Read revision identifier */
+ /**
+ * @brief Return the device revision identifier
+ * @note This field indicates the revision of the device.
+ * @rmtoll DBGMCU_IDCODE REV_ID LL_DBGMCU_GetRevisionID
+ * @retval Values between Min_Data=0x00 and Max_Data=0xFFFF
+ */
+ RevisionID = LL_DBGMCU_GetRevisionID();
+
+ APP_DBG_MSG("DBGMCU_GetRevisionID= %lx \n\n", RevisionID);
+
+ config_param.RevisionID = RevisionID;
+ (void)SHCI_C2_Config(&config_param);
+
+ APP_BLE_Init( );
+ UTIL_LPM_SetOffMode(1U << CFG_LPM_APP, UTIL_LPM_ENABLE);
+ }
+ else if (p_sys_ready_event->sysevt_ready_rsp == FUS_FW_RUNNING)
+ {
+ /**
+ * The FUS firmware is running on the CPU2
+ * In the scope of this application, there should be no case when we get here
+ */
+ APP_DBG_MSG("SHCI_SUB_EVT_CODE_READY - FUS_FW_RUNNING \n");
+
+ /* The packet shall not be released as this is not supported by the FUS */
+ ((tSHCI_UserEvtRxParam*)pPayload)->status = SHCI_TL_UserEventFlow_Disable;
+ }
+ else
+ {
+ APP_DBG_MSG("SHCI_SUB_EVT_CODE_READY - UNEXPECTED CASE \n");
+ }
- APP_BLE_Init( );
- UTIL_LPM_SetOffMode(1U << CFG_LPM_APP, UTIL_LPM_ENABLE);
return;
}
@@ -487,6 +633,8 @@ void UTIL_SEQ_Idle( void )
void UTIL_SEQ_EvtIdle( UTIL_SEQ_bm_t task_id_bm, UTIL_SEQ_bm_t evt_waited_bm )
{
UTIL_SEQ_Run( UTIL_SEQ_DEFAULT );
+
+ return;
}
void shci_notify_asynch_evt(void* pdata)
@@ -528,4 +676,3 @@ void HAL_GPIO_EXTI_Callback( uint16_t GPIO_Pin )
}
/* USER CODE END FD_WRAP_FUNCTIONS */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/