app_debug.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. {
  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 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") 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_7, 1, 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. { GPIOB, LL_GPIO_PIN_3, 1, 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_6, 1, 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_4, 1, 0}, /* PES_ACTIVITY - Set on Entry / Reset on Exit */
  90. { GPIOB, LL_GPIO_PIN_2, 1, 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. // GPIO_InitTypeDef GPIO_InitStruct;
  187. // GPIO_InitStruct.Pull = GPIO_NOPULL;
  188. // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  189. // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  190. // GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
  191. // HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  192. // SHCI_C2_ExtpaConfig((uint32_t)GPIOC, LL_GPIO_PIN_3, EXT_PA_ENABLED_LOW, EXT_PA_ENABLED);
  193. /* USER CODE END APPD_EnableCPU2 */
  194. return;
  195. }
  196. /*************************************************************
  197. *
  198. * LOCAL FUNCTIONS
  199. *
  200. *************************************************************/
  201. static void APPD_SetCPU2GpioConfig( void )
  202. {
  203. /* USER CODE BEGIN APPD_SetCPU2GpioConfig */
  204. GPIO_InitTypeDef gpio_config = {0};
  205. uint8_t local_loop;
  206. uint16_t gpioa_pin_list;
  207. uint16_t gpiob_pin_list;
  208. uint16_t gpioc_pin_list;
  209. gpioa_pin_list = 0;
  210. gpiob_pin_list = 0;
  211. gpioc_pin_list = 0;
  212. for(local_loop = 0 ; local_loop < GPIO_CFG_NBR_OF_FEATURES; local_loop++)
  213. {
  214. if( aGpioConfigList[local_loop].enable != 0)
  215. {
  216. switch((uint32_t)aGpioConfigList[local_loop].port)
  217. {
  218. case (uint32_t)GPIOA:
  219. gpioa_pin_list |= aGpioConfigList[local_loop].pin;
  220. break;
  221. case (uint32_t)GPIOB:
  222. gpiob_pin_list |= aGpioConfigList[local_loop].pin;
  223. break;
  224. case (uint32_t)GPIOC:
  225. gpioc_pin_list |= aGpioConfigList[local_loop].pin;
  226. break;
  227. default:
  228. break;
  229. }
  230. }
  231. }
  232. gpio_config.Pull = GPIO_NOPULL;
  233. gpio_config.Mode = GPIO_MODE_OUTPUT_PP;
  234. gpio_config.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  235. if(gpioa_pin_list != 0)
  236. {
  237. gpio_config.Pin = gpioa_pin_list;
  238. __HAL_RCC_GPIOA_CLK_ENABLE();
  239. __HAL_RCC_C2GPIOA_CLK_ENABLE();
  240. HAL_GPIO_Init(GPIOA, &gpio_config);
  241. HAL_GPIO_WritePin(GPIOA, gpioa_pin_list, GPIO_PIN_RESET);
  242. }
  243. if(gpiob_pin_list != 0)
  244. {
  245. gpio_config.Pin = gpiob_pin_list;
  246. __HAL_RCC_GPIOB_CLK_ENABLE();
  247. __HAL_RCC_C2GPIOB_CLK_ENABLE();
  248. HAL_GPIO_Init(GPIOB, &gpio_config);
  249. HAL_GPIO_WritePin(GPIOB, gpiob_pin_list, GPIO_PIN_RESET);
  250. }
  251. if(gpioc_pin_list != 0)
  252. {
  253. gpio_config.Pin = gpioc_pin_list;
  254. __HAL_RCC_GPIOC_CLK_ENABLE();
  255. __HAL_RCC_C2GPIOC_CLK_ENABLE();
  256. HAL_GPIO_Init(GPIOC, &gpio_config);
  257. HAL_GPIO_WritePin(GPIOC, gpioc_pin_list, GPIO_PIN_RESET);
  258. }
  259. /* USER CODE END APPD_SetCPU2GpioConfig */
  260. return;
  261. }
  262. static void APPD_BleDtbCfg( void )
  263. {
  264. /* USER CODE BEGIN APPD_BleDtbCfg */
  265. #if (BLE_DTB_CFG != 0)
  266. GPIO_InitTypeDef gpio_config = {0};
  267. uint8_t local_loop;
  268. uint16_t gpioa_pin_list;
  269. uint16_t gpiob_pin_list;
  270. gpioa_pin_list = 0;
  271. gpiob_pin_list = 0;
  272. for(local_loop = 0 ; local_loop < GPIO_NBR_OF_RF_SIGNALS; local_loop++)
  273. {
  274. if( aRfConfigList[local_loop].enable != 0)
  275. {
  276. switch((uint32_t)aRfConfigList[local_loop].port)
  277. {
  278. case (uint32_t)GPIOA:
  279. gpioa_pin_list |= aRfConfigList[local_loop].pin;
  280. break;
  281. case (uint32_t)GPIOB:
  282. gpiob_pin_list |= aRfConfigList[local_loop].pin;
  283. break;
  284. default:
  285. break;
  286. }
  287. }
  288. }
  289. gpio_config.Pull = GPIO_NOPULL;
  290. gpio_config.Mode = GPIO_MODE_AF_PP;
  291. gpio_config.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  292. gpio_config.Alternate = GPIO_AF6_RF_DTB7;
  293. if(gpioa_pin_list != 0)
  294. {
  295. gpio_config.Pin = gpioa_pin_list;
  296. __HAL_RCC_GPIOA_CLK_ENABLE();
  297. __HAL_RCC_C2GPIOA_CLK_ENABLE();
  298. HAL_GPIO_Init(GPIOA, &gpio_config);
  299. }
  300. if(gpiob_pin_list != 0)
  301. {
  302. gpio_config.Pin = gpiob_pin_list;
  303. __HAL_RCC_GPIOB_CLK_ENABLE();
  304. __HAL_RCC_C2GPIOB_CLK_ENABLE();
  305. HAL_GPIO_Init(GPIOB, &gpio_config);
  306. }
  307. #endif
  308. /* USER CODE END APPD_BleDtbCfg */
  309. return;
  310. }
  311. /*************************************************************
  312. *
  313. * WRAP FUNCTIONS
  314. *
  315. *************************************************************/
  316. #if(CFG_DEBUG_TRACE != 0)
  317. void DbgOutputInit( void )
  318. {
  319. }
  320. void DbgOutputTraces( uint8_t *p_data, uint16_t size, void (*cb)(void) )
  321. {
  322. furi_hal_console_tx(p_data, size);
  323. cb();
  324. }
  325. #endif
  326. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/