app_debug.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : app_debug.c
  5. * Description : Debug capabilities source file for STM32WPAN Middleware
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under Ultimate Liberty license
  13. * SLA0044, the "License"; You may not use this file except in compliance with
  14. * the License. You may obtain a copy of the License at:
  15. * www.st.com/SLA0044
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. /* USER CODE BEGIN Includes */
  22. #include "utilities_common.h"
  23. #include "app_common.h"
  24. #include "app_debug.h"
  25. #include "shci.h"
  26. #include "tl.h"
  27. #include "dbg_trace.h"
  28. #include <furi_hal.h>
  29. /* USER CODE END Includes */
  30. /* Private typedef -----------------------------------------------------------*/
  31. /* USER CODE BEGIN PTD */
  32. typedef PACKED_STRUCT {
  33. GPIO_TypeDef* port;
  34. uint16_t pin;
  35. uint8_t enable;
  36. uint8_t reserved;
  37. }
  38. APPD_GpioConfig_t;
  39. /* USER CODE END PTD */
  40. /* Private defines -----------------------------------------------------------*/
  41. /* USER CODE BEGIN PD */
  42. #define GPIO_NBR_OF_RF_SIGNALS 9
  43. #define GPIO_CFG_NBR_OF_FEATURES 34
  44. #define NBR_OF_TRACES_CONFIG_PARAMETERS 4
  45. #define NBR_OF_GENERAL_CONFIG_PARAMETERS 4
  46. /**
  47. * THIS SHALL BE SET TO A VALUE DIFFERENT FROM 0 ONLY ON REQUEST FROM ST SUPPORT
  48. */
  49. #define BLE_DTB_CFG 7
  50. #define SYS_DBG_CFG1 (SHCI_C2_DEBUG_OPTIONS_IPCORE_LP | SHCI_C2_DEBUG_OPTIONS_CPU2_STOP_EN)
  51. /* USER CODE END PD */
  52. /* Private variables ---------------------------------------------------------*/
  53. /* USER CODE BEGIN PV */
  54. PLACE_IN_SECTION("MB_MEM2")
  55. ALIGN(4) static SHCI_C2_DEBUG_TracesConfig_t APPD_TracesConfig = {0, 0, 0, 0};
  56. PLACE_IN_SECTION("MB_MEM2")
  57. ALIGN(4)
  58. static SHCI_C2_DEBUG_GeneralConfig_t APPD_GeneralConfig = {BLE_DTB_CFG, SYS_DBG_CFG1, {0, 0}};
  59. /**
  60. * THE DEBUG ON GPIO FOR CPU2 IS INTENDED TO BE USED ONLY ON REQUEST FROM ST SUPPORT
  61. * It provides timing information on the CPU2 activity.
  62. * All configuration of (port, pin) is supported for each features and can be selected by the user
  63. * depending on the availability
  64. */
  65. static const APPD_GpioConfig_t aGpioConfigList[GPIO_CFG_NBR_OF_FEATURES] = {
  66. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_ISR - Set on Entry / Reset on Exit */
  67. {GPIOA, LL_GPIO_PIN_7, 1, 0}, /* BLE_STACK_TICK - Set on Entry / Reset on Exit */
  68. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_CMD_PROCESS - Set on Entry / Reset on Exit */
  69. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_ACL_DATA_PROCESS - Set on Entry / Reset on Exit */
  70. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* SYS_CMD_PROCESS - Set on Entry / Reset on Exit */
  71. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* RNG_PROCESS - Set on Entry / Reset on Exit */
  72. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVM_PROCESS - Set on Entry / Reset on Exit */
  73. {GPIOB, LL_GPIO_PIN_3, 1, 0}, /* IPCC_GENERAL - Set on Entry / Reset on Exit */
  74. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_BLE_CMD_RX - Set on Entry / Reset on Exit */
  75. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_BLE_EVT_TX - Set on Entry / Reset on Exit */
  76. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_BLE_ACL_DATA_RX - Set on Entry / Reset on Exit */
  77. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_SYS_CMD_RX - Set on Entry / Reset on Exit */
  78. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_SYS_EVT_TX - Set on Entry / Reset on Exit */
  79. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_CLI_CMD_RX - Set on Entry / Reset on Exit */
  80. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_OT_CMD_RX - Set on Entry / Reset on Exit */
  81. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_OT_ACK_TX - Set on Entry / Reset on Exit */
  82. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_CLI_ACK_TX - Set on Entry / Reset on Exit */
  83. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_MEM_MANAGER_RX - Set on Entry / Reset on Exit */
  84. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_TRACES_TX - Set on Entry / Reset on Exit */
  85. {GPIOA, LL_GPIO_PIN_6, 1, 0}, /* HARD_FAULT - Set on Entry / Reset on Exit */
  86. /* From v1.1.1 */
  87. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IP_CORE_LP_STATUS - Set on Entry / Reset on Exit */
  88. /* From v1.2.0 */
  89. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* END_OF_CONNECTION_EVENT - Set on Entry / Reset on Exit */
  90. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* TIMER_SERVER_CALLBACK - Toggle on Entry */
  91. {GPIOA, LL_GPIO_PIN_4, 1, 0}, /* PES_ACTIVITY - Set on Entry / Reset on Exit */
  92. {GPIOB, LL_GPIO_PIN_2, 1, 0}, /* MB_BLE_SEND_EVT - Set on Entry / Reset on Exit */
  93. /* From v1.3.0 */
  94. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_NO_DELAY - Set on Entry / Reset on Exit */
  95. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_STACK_STORE_NVM_CB - Set on Entry / Reset on Exit */
  96. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVMA_WRITE_ONGOING - Set on Entry / Reset on Exit */
  97. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVMA_WRITE_COMPLETE - Set on Entry / Reset on Exit */
  98. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVMA_CLEANUP - Set on Entry / Reset on Exit */
  99. /* From v1.4.0 */
  100. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVMA_START - Set on Entry / Reset on Exit */
  101. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* FLASH_EOP - Set on Entry / Reset on Exit */
  102. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* FLASH_WRITE - Set on Entry / Reset on Exit */
  103. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* FLASH_ERASE - Set on Entry / Reset on Exit */
  104. };
  105. /**
  106. * THE DEBUG ON GPIO FOR CPU2 IS INTENDED TO BE USED ONLY ON REQUEST FROM ST SUPPORT
  107. * This table is relevant only for BLE
  108. * It provides timing information on BLE RF activity.
  109. * New signals may be allocated at any location when requested by ST
  110. * The GPIO allocated to each signal depend on the BLE_DTB_CFG value and cannot be changed
  111. */
  112. #if(BLE_DTB_CFG == 7)
  113. static const APPD_GpioConfig_t aRfConfigList[GPIO_NBR_OF_RF_SIGNALS] = {
  114. {GPIOB, LL_GPIO_PIN_2, 0, 0}, /* DTB10 - Tx/Rx SPI */
  115. {GPIOB, LL_GPIO_PIN_7, 0, 0}, /* DTB11 - Tx/Tx SPI Clk */
  116. {GPIOA, LL_GPIO_PIN_8, 0, 0}, /* DTB12 - Tx/Rx Ready & SPI Select */
  117. {GPIOA, LL_GPIO_PIN_9, 0, 0}, /* DTB13 - Tx/Rx Start */
  118. {GPIOA, LL_GPIO_PIN_10, 0, 0}, /* DTB14 - FSM0 */
  119. {GPIOA, LL_GPIO_PIN_11, 0, 0}, /* DTB15 - FSM1 */
  120. {GPIOB, LL_GPIO_PIN_8, 0, 0}, /* DTB16 - FSM2 */
  121. {GPIOB, LL_GPIO_PIN_11, 0, 0}, /* DTB17 - FSM3 */
  122. {GPIOB, LL_GPIO_PIN_10, 0, 0}, /* DTB18 - FSM4 */
  123. };
  124. #endif
  125. /* USER CODE END PV */
  126. /* Global variables ----------------------------------------------------------*/
  127. /* USER CODE BEGIN GV */
  128. /* USER CODE END GV */
  129. /* Private function prototypes -----------------------------------------------*/
  130. /* USER CODE BEGIN PFP */
  131. static void APPD_SetCPU2GpioConfig(void);
  132. static void APPD_BleDtbCfg(void);
  133. /* USER CODE END PFP */
  134. /* Functions Definition ------------------------------------------------------*/
  135. void APPD_Init(void) {
  136. /* USER CODE BEGIN APPD_Init */
  137. #if(CFG_DEBUGGER_SUPPORTED == 1)
  138. /**
  139. * Keep debugger enabled while in any low power mode
  140. */
  141. HAL_DBGMCU_EnableDBGSleepMode();
  142. HAL_DBGMCU_EnableDBGStopMode();
  143. /***************** ENABLE DEBUGGER *************************************/
  144. LL_EXTI_EnableIT_32_63(LL_EXTI_LINE_48);
  145. #else
  146. GPIO_InitTypeDef gpio_config = {0};
  147. gpio_config.Pull = GPIO_NOPULL;
  148. gpio_config.Mode = GPIO_MODE_ANALOG;
  149. gpio_config.Pin = GPIO_PIN_15 | GPIO_PIN_14 | GPIO_PIN_13;
  150. __HAL_RCC_GPIOA_CLK_ENABLE();
  151. HAL_GPIO_Init(GPIOA, &gpio_config);
  152. gpio_config.Pin = GPIO_PIN_4 | GPIO_PIN_3;
  153. __HAL_RCC_GPIOB_CLK_ENABLE();
  154. HAL_GPIO_Init(GPIOB, &gpio_config);
  155. HAL_DBGMCU_DisableDBGSleepMode();
  156. HAL_DBGMCU_DisableDBGStopMode();
  157. HAL_DBGMCU_DisableDBGStandbyMode();
  158. #endif /* (CFG_DEBUGGER_SUPPORTED == 1) */
  159. #if(CFG_DEBUG_TRACE != 0)
  160. DbgTraceInit();
  161. #endif
  162. APPD_SetCPU2GpioConfig();
  163. APPD_BleDtbCfg();
  164. /* USER CODE END APPD_Init */
  165. return;
  166. }
  167. void APPD_EnableCPU2(void) {
  168. /* USER CODE BEGIN APPD_EnableCPU2 */
  169. SHCI_C2_DEBUG_Init_Cmd_Packet_t DebugCmdPacket = {
  170. {{0, 0, 0}}, /**< Does not need to be initialized */
  171. {(uint8_t*)aGpioConfigList,
  172. (uint8_t*)&APPD_TracesConfig,
  173. (uint8_t*)&APPD_GeneralConfig,
  174. GPIO_CFG_NBR_OF_FEATURES,
  175. NBR_OF_TRACES_CONFIG_PARAMETERS,
  176. NBR_OF_GENERAL_CONFIG_PARAMETERS}};
  177. /**< Traces channel initialization */
  178. TL_TRACES_Init();
  179. /** GPIO DEBUG Initialization */
  180. SHCI_C2_DEBUG_Init(&DebugCmdPacket);
  181. // GPIO_InitTypeDef GPIO_InitStruct;
  182. // GPIO_InitStruct.Pull = GPIO_NOPULL;
  183. // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  184. // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  185. // GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
  186. // HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  187. // SHCI_C2_ExtpaConfig((uint32_t)GPIOC, LL_GPIO_PIN_3, EXT_PA_ENABLED_LOW, EXT_PA_ENABLED);
  188. /* USER CODE END APPD_EnableCPU2 */
  189. return;
  190. }
  191. /*************************************************************
  192. *
  193. * LOCAL FUNCTIONS
  194. *
  195. *************************************************************/
  196. static void APPD_SetCPU2GpioConfig(void) {
  197. /* USER CODE BEGIN APPD_SetCPU2GpioConfig */
  198. GPIO_InitTypeDef gpio_config = {0};
  199. uint8_t local_loop;
  200. uint16_t gpioa_pin_list;
  201. uint16_t gpiob_pin_list;
  202. uint16_t gpioc_pin_list;
  203. gpioa_pin_list = 0;
  204. gpiob_pin_list = 0;
  205. gpioc_pin_list = 0;
  206. for(local_loop = 0; local_loop < GPIO_CFG_NBR_OF_FEATURES; local_loop++) {
  207. if(aGpioConfigList[local_loop].enable != 0) {
  208. switch((uint32_t)aGpioConfigList[local_loop].port) {
  209. case(uint32_t)GPIOA:
  210. gpioa_pin_list |= aGpioConfigList[local_loop].pin;
  211. break;
  212. case(uint32_t)GPIOB:
  213. gpiob_pin_list |= aGpioConfigList[local_loop].pin;
  214. break;
  215. case(uint32_t)GPIOC:
  216. gpioc_pin_list |= aGpioConfigList[local_loop].pin;
  217. break;
  218. default:
  219. break;
  220. }
  221. }
  222. }
  223. gpio_config.Pull = GPIO_NOPULL;
  224. gpio_config.Mode = GPIO_MODE_OUTPUT_PP;
  225. gpio_config.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  226. if(gpioa_pin_list != 0) {
  227. gpio_config.Pin = gpioa_pin_list;
  228. __HAL_RCC_GPIOA_CLK_ENABLE();
  229. __HAL_RCC_C2GPIOA_CLK_ENABLE();
  230. HAL_GPIO_Init(GPIOA, &gpio_config);
  231. HAL_GPIO_WritePin(GPIOA, gpioa_pin_list, GPIO_PIN_RESET);
  232. }
  233. if(gpiob_pin_list != 0) {
  234. gpio_config.Pin = gpiob_pin_list;
  235. __HAL_RCC_GPIOB_CLK_ENABLE();
  236. __HAL_RCC_C2GPIOB_CLK_ENABLE();
  237. HAL_GPIO_Init(GPIOB, &gpio_config);
  238. HAL_GPIO_WritePin(GPIOB, gpiob_pin_list, GPIO_PIN_RESET);
  239. }
  240. if(gpioc_pin_list != 0) {
  241. gpio_config.Pin = gpioc_pin_list;
  242. __HAL_RCC_GPIOC_CLK_ENABLE();
  243. __HAL_RCC_C2GPIOC_CLK_ENABLE();
  244. HAL_GPIO_Init(GPIOC, &gpio_config);
  245. HAL_GPIO_WritePin(GPIOC, gpioc_pin_list, GPIO_PIN_RESET);
  246. }
  247. /* USER CODE END APPD_SetCPU2GpioConfig */
  248. return;
  249. }
  250. static void APPD_BleDtbCfg(void) {
  251. /* USER CODE BEGIN APPD_BleDtbCfg */
  252. #if(BLE_DTB_CFG != 0)
  253. GPIO_InitTypeDef gpio_config = {0};
  254. uint8_t local_loop;
  255. uint16_t gpioa_pin_list;
  256. uint16_t gpiob_pin_list;
  257. gpioa_pin_list = 0;
  258. gpiob_pin_list = 0;
  259. for(local_loop = 0; local_loop < GPIO_NBR_OF_RF_SIGNALS; local_loop++) {
  260. if(aRfConfigList[local_loop].enable != 0) {
  261. switch((uint32_t)aRfConfigList[local_loop].port) {
  262. case(uint32_t)GPIOA:
  263. gpioa_pin_list |= aRfConfigList[local_loop].pin;
  264. break;
  265. case(uint32_t)GPIOB:
  266. gpiob_pin_list |= aRfConfigList[local_loop].pin;
  267. break;
  268. default:
  269. break;
  270. }
  271. }
  272. }
  273. gpio_config.Pull = GPIO_NOPULL;
  274. gpio_config.Mode = GPIO_MODE_AF_PP;
  275. gpio_config.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  276. gpio_config.Alternate = GPIO_AF6_RF_DTB7;
  277. if(gpioa_pin_list != 0) {
  278. gpio_config.Pin = gpioa_pin_list;
  279. __HAL_RCC_GPIOA_CLK_ENABLE();
  280. __HAL_RCC_C2GPIOA_CLK_ENABLE();
  281. HAL_GPIO_Init(GPIOA, &gpio_config);
  282. }
  283. if(gpiob_pin_list != 0) {
  284. gpio_config.Pin = gpiob_pin_list;
  285. __HAL_RCC_GPIOB_CLK_ENABLE();
  286. __HAL_RCC_C2GPIOB_CLK_ENABLE();
  287. HAL_GPIO_Init(GPIOB, &gpio_config);
  288. }
  289. #endif
  290. /* USER CODE END APPD_BleDtbCfg */
  291. return;
  292. }
  293. /*************************************************************
  294. *
  295. * WRAP FUNCTIONS
  296. *
  297. *************************************************************/
  298. #if(CFG_DEBUG_TRACE != 0)
  299. void DbgOutputInit(void) {
  300. }
  301. void DbgOutputTraces(uint8_t* p_data, uint16_t size, void (*cb)(void)) {
  302. furi_hal_console_tx(p_data, size);
  303. cb();
  304. }
  305. #endif
  306. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/