app_debug.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 "app_common.h"
  23. #include "app_debug.h"
  24. #include "utilities_common.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. {
  34. GPIO_TypeDef* port;
  35. uint16_t pin;
  36. uint8_t enable;
  37. uint8_t reserved;
  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 0
  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") ALIGN(4) static SHCI_C2_DEBUG_TracesConfig_t APPD_TracesConfig={0, 0, 0, 0};
  55. PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static SHCI_C2_DEBUG_GeneralConfig_t APPD_GeneralConfig={BLE_DTB_CFG, SYS_DBG_CFG1, {0, 0}};
  56. /**
  57. * THE DEBUG ON GPIO FOR CPU2 IS INTENDED TO BE USED ONLY ON REQUEST FROM ST SUPPORT
  58. * It provides timing information on the CPU2 activity.
  59. * All configuration of (port, pin) is supported for each features and can be selected by the user
  60. * depending on the availability
  61. */
  62. static const APPD_GpioConfig_t aGpioConfigList[GPIO_CFG_NBR_OF_FEATURES] =
  63. {
  64. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_ISR - Set on Entry / Reset on Exit */
  65. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_STACK_TICK - Set on Entry / Reset on Exit */
  66. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_CMD_PROCESS - Set on Entry / Reset on Exit */
  67. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_ACL_DATA_PROCESS - Set on Entry / Reset on Exit */
  68. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* SYS_CMD_PROCESS - Set on Entry / Reset on Exit */
  69. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* RNG_PROCESS - Set on Entry / Reset on Exit */
  70. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVM_PROCESS - Set on Entry / Reset on Exit */
  71. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_GENERAL - Set on Entry / Reset on Exit */
  72. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_BLE_CMD_RX - Set on Entry / Reset on Exit */
  73. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_BLE_EVT_TX - Set on Entry / Reset on Exit */
  74. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_BLE_ACL_DATA_RX - Set on Entry / Reset on Exit */
  75. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_SYS_CMD_RX - Set on Entry / Reset on Exit */
  76. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_SYS_EVT_TX - Set on Entry / Reset on Exit */
  77. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_CLI_CMD_RX - Set on Entry / Reset on Exit */
  78. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_OT_CMD_RX - Set on Entry / Reset on Exit */
  79. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_OT_ACK_TX - Set on Entry / Reset on Exit */
  80. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_CLI_ACK_TX - Set on Entry / Reset on Exit */
  81. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_MEM_MANAGER_RX - Set on Entry / Reset on Exit */
  82. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_TRACES_TX - Set on Entry / Reset on Exit */
  83. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* HARD_FAULT - Set on Entry / Reset on Exit */
  84. /* From v1.1.1 */
  85. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IP_CORE_LP_STATUS - Set on Entry / Reset on Exit */
  86. /* From v1.2.0 */
  87. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* END_OF_CONNECTION_EVENT - Set on Entry / Reset on Exit */
  88. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* TIMER_SERVER_CALLBACK - Toggle on Entry */
  89. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* PES_ACTIVITY - Set on Entry / Reset on Exit */
  90. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* MB_BLE_SEND_EVT - Set on Entry / Reset on Exit */
  91. /* From v1.3.0 */
  92. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_NO_DELAY - Set on Entry / Reset on Exit */
  93. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_STACK_STORE_NVM_CB - Set on Entry / Reset on Exit */
  94. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVMA_WRITE_ONGOING - Set on Entry / Reset on Exit */
  95. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVMA_WRITE_COMPLETE - Set on Entry / Reset on Exit */
  96. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVMA_CLEANUP - Set on Entry / Reset on Exit */
  97. /* From v1.4.0 */
  98. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVMA_START - Set on Entry / Reset on Exit */
  99. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* FLASH_EOP - Set on Entry / Reset on Exit */
  100. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* FLASH_WRITE - Set on Entry / Reset on Exit */
  101. { GPIOA, LL_GPIO_PIN_0, 0, 0}, /* FLASH_ERASE - Set on Entry / Reset on Exit */
  102. };
  103. /**
  104. * THE DEBUG ON GPIO FOR CPU2 IS INTENDED TO BE USED ONLY ON REQUEST FROM ST SUPPORT
  105. * This table is relevant only for BLE
  106. * It provides timing information on BLE RF activity.
  107. * New signals may be allocated at any location when requested by ST
  108. * The GPIO allocated to each signal depend on the BLE_DTB_CFG value and cannot be changed
  109. */
  110. #if( BLE_DTB_CFG == 7)
  111. static const APPD_GpioConfig_t aRfConfigList[GPIO_NBR_OF_RF_SIGNALS] =
  112. {
  113. { GPIOB, LL_GPIO_PIN_2, 0, 0}, /* DTB10 - Tx/Rx SPI */
  114. { GPIOB, LL_GPIO_PIN_7, 0, 0}, /* DTB11 - Tx/Tx SPI Clk */
  115. { GPIOA, LL_GPIO_PIN_8, 0, 0}, /* DTB12 - Tx/Rx Ready & SPI Select */
  116. { GPIOA, LL_GPIO_PIN_9, 0, 0}, /* DTB13 - Tx/Rx Start */
  117. { GPIOA, LL_GPIO_PIN_10, 0, 0}, /* DTB14 - FSM0 */
  118. { GPIOA, LL_GPIO_PIN_11, 0, 0}, /* DTB15 - FSM1 */
  119. { GPIOB, LL_GPIO_PIN_8, 0, 0}, /* DTB16 - FSM2 */
  120. { GPIOB, LL_GPIO_PIN_11, 0, 0}, /* DTB17 - FSM3 */
  121. { GPIOB, LL_GPIO_PIN_10, 0, 0}, /* DTB18 - FSM4 */
  122. };
  123. #endif
  124. /* USER CODE END PV */
  125. /* Global variables ----------------------------------------------------------*/
  126. /* USER CODE BEGIN GV */
  127. /* USER CODE END GV */
  128. /* Private function prototypes -----------------------------------------------*/
  129. /* USER CODE BEGIN PFP */
  130. static void APPD_SetCPU2GpioConfig( void );
  131. static void APPD_BleDtbCfg( void );
  132. /* USER CODE END PFP */
  133. /* Functions Definition ------------------------------------------------------*/
  134. void APPD_Init( void )
  135. {
  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. __HAL_RCC_GPIOA_CLK_DISABLE();
  153. gpio_config.Pin = GPIO_PIN_4 | GPIO_PIN_3;
  154. __HAL_RCC_GPIOB_CLK_ENABLE();
  155. HAL_GPIO_Init(GPIOB, &gpio_config);
  156. __HAL_RCC_GPIOB_CLK_DISABLE();
  157. HAL_DBGMCU_DisableDBGSleepMode();
  158. HAL_DBGMCU_DisableDBGStopMode();
  159. HAL_DBGMCU_DisableDBGStandbyMode();
  160. #endif /* (CFG_DEBUGGER_SUPPORTED == 1) */
  161. #if(CFG_DEBUG_TRACE != 0)
  162. DbgTraceInit();
  163. #endif
  164. APPD_SetCPU2GpioConfig( );
  165. APPD_BleDtbCfg( );
  166. /* USER CODE END APPD_Init */
  167. return;
  168. }
  169. void APPD_EnableCPU2( void )
  170. {
  171. /* USER CODE BEGIN APPD_EnableCPU2 */
  172. SHCI_C2_DEBUG_Init_Cmd_Packet_t DebugCmdPacket =
  173. {
  174. {{0,0,0}}, /**< Does not need to be initialized */
  175. {(uint8_t *)aGpioConfigList,
  176. (uint8_t *)&APPD_TracesConfig,
  177. (uint8_t *)&APPD_GeneralConfig,
  178. GPIO_CFG_NBR_OF_FEATURES,
  179. NBR_OF_TRACES_CONFIG_PARAMETERS,
  180. NBR_OF_GENERAL_CONFIG_PARAMETERS}
  181. };
  182. /**< Traces channel initialization */
  183. TL_TRACES_Init( );
  184. /** GPIO DEBUG Initialization */
  185. SHCI_C2_DEBUG_Init( &DebugCmdPacket );
  186. /* USER CODE END APPD_EnableCPU2 */
  187. return;
  188. }
  189. /*************************************************************
  190. *
  191. * LOCAL FUNCTIONS
  192. *
  193. *************************************************************/
  194. static void APPD_SetCPU2GpioConfig( void )
  195. {
  196. /* USER CODE BEGIN APPD_SetCPU2GpioConfig */
  197. GPIO_InitTypeDef gpio_config = {0};
  198. uint8_t local_loop;
  199. uint16_t gpioa_pin_list;
  200. uint16_t gpiob_pin_list;
  201. uint16_t gpioc_pin_list;
  202. gpioa_pin_list = 0;
  203. gpiob_pin_list = 0;
  204. gpioc_pin_list = 0;
  205. for(local_loop = 0 ; local_loop < GPIO_CFG_NBR_OF_FEATURES; local_loop++)
  206. {
  207. if( aGpioConfigList[local_loop].enable != 0)
  208. {
  209. switch((uint32_t)aGpioConfigList[local_loop].port)
  210. {
  211. case (uint32_t)GPIOA:
  212. gpioa_pin_list |= aGpioConfigList[local_loop].pin;
  213. break;
  214. case (uint32_t)GPIOB:
  215. gpiob_pin_list |= aGpioConfigList[local_loop].pin;
  216. break;
  217. case (uint32_t)GPIOC:
  218. gpioc_pin_list |= aGpioConfigList[local_loop].pin;
  219. break;
  220. default:
  221. break;
  222. }
  223. }
  224. }
  225. gpio_config.Pull = GPIO_NOPULL;
  226. gpio_config.Mode = GPIO_MODE_OUTPUT_PP;
  227. gpio_config.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  228. if(gpioa_pin_list != 0)
  229. {
  230. gpio_config.Pin = gpioa_pin_list;
  231. __HAL_RCC_GPIOA_CLK_ENABLE();
  232. __HAL_RCC_C2GPIOA_CLK_ENABLE();
  233. HAL_GPIO_Init(GPIOA, &gpio_config);
  234. HAL_GPIO_WritePin(GPIOA, gpioa_pin_list, GPIO_PIN_RESET);
  235. }
  236. if(gpiob_pin_list != 0)
  237. {
  238. gpio_config.Pin = gpiob_pin_list;
  239. __HAL_RCC_GPIOB_CLK_ENABLE();
  240. __HAL_RCC_C2GPIOB_CLK_ENABLE();
  241. HAL_GPIO_Init(GPIOB, &gpio_config);
  242. HAL_GPIO_WritePin(GPIOB, gpiob_pin_list, GPIO_PIN_RESET);
  243. }
  244. if(gpioc_pin_list != 0)
  245. {
  246. gpio_config.Pin = gpioc_pin_list;
  247. __HAL_RCC_GPIOC_CLK_ENABLE();
  248. __HAL_RCC_C2GPIOC_CLK_ENABLE();
  249. HAL_GPIO_Init(GPIOC, &gpio_config);
  250. HAL_GPIO_WritePin(GPIOC, gpioc_pin_list, GPIO_PIN_RESET);
  251. }
  252. /* USER CODE END APPD_SetCPU2GpioConfig */
  253. return;
  254. }
  255. static void APPD_BleDtbCfg( void )
  256. {
  257. /* USER CODE BEGIN APPD_BleDtbCfg */
  258. #if (BLE_DTB_CFG != 0)
  259. GPIO_InitTypeDef gpio_config = {0};
  260. uint8_t local_loop;
  261. uint16_t gpioa_pin_list;
  262. uint16_t gpiob_pin_list;
  263. gpioa_pin_list = 0;
  264. gpiob_pin_list = 0;
  265. for(local_loop = 0 ; local_loop < GPIO_NBR_OF_RF_SIGNALS; local_loop++)
  266. {
  267. if( aRfConfigList[local_loop].enable != 0)
  268. {
  269. switch((uint32_t)aRfConfigList[local_loop].port)
  270. {
  271. case (uint32_t)GPIOA:
  272. gpioa_pin_list |= aRfConfigList[local_loop].pin;
  273. break;
  274. case (uint32_t)GPIOB:
  275. gpiob_pin_list |= aRfConfigList[local_loop].pin;
  276. break;
  277. default:
  278. break;
  279. }
  280. }
  281. }
  282. gpio_config.Pull = GPIO_NOPULL;
  283. gpio_config.Mode = GPIO_MODE_AF_PP;
  284. gpio_config.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  285. gpio_config.Alternate = GPIO_AF6_RF_DTB7;
  286. if(gpioa_pin_list != 0)
  287. {
  288. gpio_config.Pin = gpioa_pin_list;
  289. __HAL_RCC_GPIOA_CLK_ENABLE();
  290. __HAL_RCC_C2GPIOA_CLK_ENABLE();
  291. HAL_GPIO_Init(GPIOA, &gpio_config);
  292. }
  293. if(gpiob_pin_list != 0)
  294. {
  295. gpio_config.Pin = gpiob_pin_list;
  296. __HAL_RCC_GPIOB_CLK_ENABLE();
  297. __HAL_RCC_C2GPIOB_CLK_ENABLE();
  298. HAL_GPIO_Init(GPIOB, &gpio_config);
  299. }
  300. #endif
  301. /* USER CODE END APPD_BleDtbCfg */
  302. return;
  303. }
  304. /*************************************************************
  305. *
  306. * WRAP FUNCTIONS
  307. *
  308. *************************************************************/
  309. #if(CFG_DEBUG_TRACE != 0)
  310. void DbgOutputInit( void )
  311. {
  312. }
  313. void DbgOutputTraces( uint8_t *p_data, uint16_t size, void (*cb)(void) )
  314. {
  315. furi_hal_console_tx(p_data, size);
  316. cb();
  317. }
  318. #endif
  319. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/