app_debug.c 13 KB

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