app_debug.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. LL_DBGMCU_EnableDBGSleepMode();
  142. LL_DBGMCU_EnableDBGStopMode();
  143. /***************** ENABLE DEBUGGER *************************************/
  144. LL_EXTI_EnableIT_32_63(LL_EXTI_LINE_48);
  145. #else
  146. LL_GPIO_InitTypeDef gpio_config = {0};
  147. LL_PWR_EnableVddUSB();
  148. gpio_config.Mode = LL_GPIO_MODE_ANALOG;
  149. gpio_config.Speed = LL_GPIO_SPEED_FREQ_LOW;
  150. // gpio_config.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  151. // gpio_config.Pull = LL_GPIO_PULL_NO;
  152. // gpio_config.Alternate = LL_GPIO_AF_10;
  153. gpio_config.Pin = LL_GPIO_PIN_15 | LL_GPIO_PIN_14 | LL_GPIO_PIN_13;
  154. LL_GPIO_Init(GPIOA, &gpio_config);
  155. gpio_config.Pin = LL_GPIO_PIN_4 | LL_GPIO_PIN_3;
  156. LL_GPIO_Init(GPIOB, &gpio_config);
  157. LL_DBGMCU_DisableDBGSleepMode();
  158. LL_DBGMCU_DisableDBGStopMode();
  159. LL_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. /* USER CODE BEGIN APPD_EnableCPU2 */
  171. SHCI_C2_DEBUG_Init_Cmd_Packet_t DebugCmdPacket = {
  172. {{0, 0, 0}}, /**< Does not need to be initialized */
  173. {(uint8_t*)aGpioConfigList,
  174. (uint8_t*)&APPD_TracesConfig,
  175. (uint8_t*)&APPD_GeneralConfig,
  176. GPIO_CFG_NBR_OF_FEATURES,
  177. NBR_OF_TRACES_CONFIG_PARAMETERS,
  178. NBR_OF_GENERAL_CONFIG_PARAMETERS}};
  179. /**< Traces channel initialization */
  180. TL_TRACES_Init();
  181. /** GPIO DEBUG Initialization */
  182. SHCI_C2_DEBUG_Init(&DebugCmdPacket);
  183. // LL_GPIO_InitTypeDef gpio_config;
  184. // gpio_config.Pull = GPIO_NOPULL;
  185. // gpio_config.Mode = GPIO_MODE_OUTPUT_PP;
  186. // gpio_config.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  187. // gpio_config.Pin = LL_GPIO_PIN_3;
  188. // HAL_GPIO_Init(GPIOC, &gpio_config);
  189. // SHCI_C2_ExtpaConfig((uint32_t)GPIOC, LL_GPIO_PIN_3, EXT_PA_ENABLED_LOW, EXT_PA_ENABLED);
  190. /* USER CODE END APPD_EnableCPU2 */
  191. return;
  192. }
  193. /*************************************************************
  194. *
  195. * LOCAL FUNCTIONS
  196. *
  197. *************************************************************/
  198. static void APPD_SetCPU2GpioConfig(void) {
  199. /* USER CODE BEGIN APPD_SetCPU2GpioConfig */
  200. LL_GPIO_InitTypeDef gpio_config = {0};
  201. uint8_t local_loop;
  202. uint16_t gpioa_pin_list;
  203. uint16_t gpiob_pin_list;
  204. uint16_t gpioc_pin_list;
  205. gpioa_pin_list = 0;
  206. gpiob_pin_list = 0;
  207. gpioc_pin_list = 0;
  208. for(local_loop = 0; local_loop < GPIO_CFG_NBR_OF_FEATURES; local_loop++) {
  209. if(aGpioConfigList[local_loop].enable != 0) {
  210. switch((uint32_t)aGpioConfigList[local_loop].port) {
  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.Mode = LL_GPIO_MODE_OUTPUT;
  226. gpio_config.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
  227. gpio_config.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  228. gpio_config.Pull = LL_GPIO_PULL_NO;
  229. gpio_config.Pin = LL_GPIO_PIN_15 | LL_GPIO_PIN_14 | LL_GPIO_PIN_13;
  230. LL_GPIO_Init(GPIOA, &gpio_config);
  231. if(gpioa_pin_list != 0) {
  232. gpio_config.Pin = gpioa_pin_list;
  233. LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOA);
  234. LL_GPIO_Init(GPIOA, &gpio_config);
  235. LL_GPIO_ResetOutputPin(GPIOA, gpioa_pin_list);
  236. }
  237. if(gpiob_pin_list != 0) {
  238. gpio_config.Pin = gpiob_pin_list;
  239. LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOB);
  240. LL_GPIO_Init(GPIOB, &gpio_config);
  241. LL_GPIO_ResetOutputPin(GPIOB, gpioa_pin_list);
  242. }
  243. if(gpioc_pin_list != 0) {
  244. gpio_config.Pin = gpioc_pin_list;
  245. LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOC);
  246. LL_GPIO_Init(GPIOC, &gpio_config);
  247. LL_GPIO_ResetOutputPin(GPIOC, gpioa_pin_list);
  248. }
  249. /* USER CODE END APPD_SetCPU2GpioConfig */
  250. return;
  251. }
  252. static void APPD_BleDtbCfg(void) {
  253. /* USER CODE BEGIN APPD_BleDtbCfg */
  254. #if(BLE_DTB_CFG != 0)
  255. LL_GPIO_InitTypeDef gpio_config = {0};
  256. uint8_t local_loop;
  257. uint16_t gpioa_pin_list;
  258. uint16_t gpiob_pin_list;
  259. gpioa_pin_list = 0;
  260. gpiob_pin_list = 0;
  261. for(local_loop = 0; local_loop < GPIO_NBR_OF_RF_SIGNALS; local_loop++) {
  262. if(aRfConfigList[local_loop].enable != 0) {
  263. switch((uint32_t)aRfConfigList[local_loop].port) {
  264. case(uint32_t)GPIOA:
  265. gpioa_pin_list |= aRfConfigList[local_loop].pin;
  266. break;
  267. case(uint32_t)GPIOB:
  268. gpiob_pin_list |= aRfConfigList[local_loop].pin;
  269. break;
  270. default:
  271. break;
  272. }
  273. }
  274. }
  275. gpio_config.Mode = LL_GPIO_MODE_ALTERNATE;
  276. gpio_config.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
  277. gpio_config.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  278. gpio_config.Pull = LL_GPIO_PULL_NO;
  279. gpio_config.Alternate = LL_GPIO_AF_6;
  280. gpio_config.Pin = LL_GPIO_PIN_15 | LL_GPIO_PIN_14 | LL_GPIO_PIN_13;
  281. if(gpioa_pin_list != 0) {
  282. gpio_config.Pin = gpioa_pin_list;
  283. LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOA);
  284. LL_GPIO_Init(GPIOA, &gpio_config);
  285. }
  286. if(gpiob_pin_list != 0) {
  287. gpio_config.Pin = gpiob_pin_list;
  288. LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOB);
  289. LL_GPIO_Init(GPIOB, &gpio_config);
  290. }
  291. #endif
  292. /* USER CODE END APPD_BleDtbCfg */
  293. return;
  294. }
  295. /*************************************************************
  296. *
  297. * WRAP FUNCTIONS
  298. *
  299. *************************************************************/
  300. #if(CFG_DEBUG_TRACE != 0)
  301. void DbgOutputInit(void) {
  302. }
  303. void DbgOutputTraces(uint8_t* p_data, uint16_t size, void (*cb)(void)) {
  304. furi_hal_console_tx(p_data, size);
  305. cb();
  306. }
  307. #endif
  308. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/