app_debug.c 12 KB

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