1 /* USER CODE BEGIN Header */ 2 /** 3 ****************************************************************************** 4 * @file miscutils.c 5 * @author GPM WBL Application Team 6 * @brief Miscellaneous utilities for interfacing to HW. 7 ****************************************************************************** 8 * @attention 9 * 10 * Copyright (c) 2024 STMicroelectronics. 11 * All rights reserved. 12 * 13 * This software is licensed under terms that can be found in the LICENSE file 14 * in the root directory of this software component. 15 * If no LICENSE file comes with this software, it is provided AS-IS. 16 * 17 ****************************************************************************** 18 */ 19 /* USER CODE END Header */ 20 21 /* Includes ------------------------------------------------------------------*/ 22 #include "miscutil.h" 23 #include "RADIO_utils.h" 24 #include "compiler.h" 25 #include "stm32wb0x_ll_system.h" 26 #include "stm32wb0x_ll_utils.h" 27 #include "stm32wb0x_ll_pwr.h" 28 #include "stm32wb0x_ll_bus.h" 29 #include "stm32wb0x_ll_usart.h" 30 #include "stm32wb0x_hal_conf.h" 31 32 NO_INIT_SECTION(crash_info_t CrashInfoRam, ".crash_info_ram_vr"); 33 34 /** @addtogroup Miscellaneous_Utilities 35 * @{ 36 */ 37 38 /* Private typedef -----------------------------------------------------------*/ 39 /* Private define ------------------------------------------------------------*/ 40 41 /* Private macro -------------------------------------------------------------*/ 42 /* Private variables ---------------------------------------------------------*/ 43 44 /*---------------------------------------------------------------------------*/ 45 GetPartInfo(PartInfoType * partInfo)46void GetPartInfo(PartInfoType *partInfo) 47 { 48 uint32_t jtag_id; 49 50 partInfo->die_id = DIE_SW_ID_UNKOWN; 51 52 jtag_id = LL_SYSCFG_GetDeviceJTAG_ID(); 53 54 #if defined(STM32WB09) 55 if(jtag_id == JTAG_ID_CODE_STM32WB09XX) 56 { 57 partInfo->die_id = DIE_SW_ID_STM32WB09XX; 58 } 59 #elif defined(STM32WB07) || defined(STM32WB06) 60 if(jtag_id == JTAG_ID_CODE_STM32WB07XX) 61 { 62 partInfo->die_id = DIE_SW_ID_STM32WB07XX; 63 } 64 #elif defined(STM32WB05) 65 if(jtag_id == JTAG_ID_CODE_STM32WB05XX) 66 { 67 partInfo->die_id = DIE_SW_ID_STM32WB05XX; 68 } 69 #endif 70 71 partInfo->die_major = LL_SYSCFG_GetDeviceVersion(); 72 partInfo->die_cut = LL_SYSCFG_GetDeviceRevision(); 73 partInfo->jtag_id_code = LL_SYSCFG_GetDeviceJTAG_ID(); // Duplicated 74 partInfo->flash_size = (LL_GetFlashSize() + 1) * 4; 75 76 if (LL_GetRAMSize() != LL_UTILS_RAMSIZE_24K) 77 { 78 partInfo->ram_size = (LL_GetRAMSize() + 1) * 16 * 1024; 79 } 80 else 81 { 82 partInfo->ram_size = 24*1024; 83 } 84 85 } 86 87 /** 88 * @brief Get Crash Information utility 89 */ GetCrashInfo(crash_info_t * crashInfo)90void GetCrashInfo(crash_info_t *crashInfo) 91 { 92 *crashInfo = CrashInfoRam; 93 /* Reset crash info value */ 94 CrashInfoRam.signature = 0; 95 } CrashHandler(uint32_t msp,uint32_t signature)96void CrashHandler(uint32_t msp, uint32_t signature) 97 { 98 volatile uint32_t * crash_info = (volatile uint32_t *)&CrashInfoRam; 99 register uint32_t reg_content; 100 /* Init to zero the crash_info RAM locations */ 101 for (reg_content=0; reg_content<NMB_OF_EXCEP_RAM_WORD; reg_content++) { 102 crash_info[reg_content] = 0; 103 } 104 /* Store Crash Signature */ 105 CrashInfoRam.signature = signature; 106 /* Store SP register */ 107 CrashInfoRam.SP = msp; 108 for (reg_content=2; reg_content<NMB_OF_EXCEP_RAM_WORD; reg_content++) { 109 uint32_t *ptr = ((uint32_t *)msp)+(reg_content-2); 110 if ((ptr >= ((uint32_t *) _MEMORY_RAM_BEGIN_)) && 111 (ptr <= ((uint32_t *) _MEMORY_RAM_END_))) 112 crash_info[reg_content] = *ptr; 113 } 114 NVIC_SystemReset(); 115 } 116 GetDemodCI(void)117uint8_t GetDemodCI(void) 118 { 119 /* Read the CI from the demodulator register */ 120 uint8_t demod_ci = (RRM->DEMOD_DIG_OUT) & 0x03U; 121 122 /* Remap to the standard compliant values */ 123 uint8_t std_ci = (demod_ci == 0x02U ? 0x01U : 0x00U); 124 125 return std_ci; 126 } 127 128 /** 129 *@ 130 } */ /* End of group Miscellaneous_Utilities */ 131 132