app_debug.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. #include "app_common.h"
  2. #include "app_debug.h"
  3. #include <interface/patterns/ble_thread/tl/tl.h>
  4. #include <interface/patterns/ble_thread/tl/mbox_def.h>
  5. #include <interface/patterns/ble_thread/shci/shci.h>
  6. #include <utilities/dbg_trace.h>
  7. #include <utilities/utilities_common.h>
  8. #include <furi_hal.h>
  9. typedef PACKED_STRUCT {
  10. GPIO_TypeDef* port;
  11. uint16_t pin;
  12. uint8_t enable;
  13. uint8_t reserved;
  14. }
  15. APPD_GpioConfig_t;
  16. #define GPIO_NBR_OF_RF_SIGNALS 9
  17. #define GPIO_CFG_NBR_OF_FEATURES 34
  18. #define NBR_OF_TRACES_CONFIG_PARAMETERS 4
  19. #define NBR_OF_GENERAL_CONFIG_PARAMETERS 4
  20. /**
  21. * THIS SHALL BE SET TO A VALUE DIFFERENT FROM 0 ONLY ON REQUEST FROM ST SUPPORT
  22. */
  23. #define BLE_DTB_CFG 0
  24. // #define BLE_DTB_CFG 7
  25. #define SYS_DBG_CFG1 (SHCI_C2_DEBUG_OPTIONS_IPCORE_LP | SHCI_C2_DEBUG_OPTIONS_CPU2_STOP_EN)
  26. /* Private variables ---------------------------------------------------------*/
  27. PLACE_IN_SECTION("MB_MEM2")
  28. ALIGN(4) static SHCI_C2_DEBUG_TracesConfig_t APPD_TracesConfig = {0, 0, 0, 0};
  29. PLACE_IN_SECTION("MB_MEM2")
  30. ALIGN(4)
  31. static SHCI_C2_DEBUG_GeneralConfig_t APPD_GeneralConfig =
  32. {BLE_DTB_CFG, SYS_DBG_CFG1, {0, 0}, 0, 0, 0, 0, 0};
  33. /**
  34. * THE DEBUG ON GPIO FOR CPU2 IS INTENDED TO BE USED ONLY ON REQUEST FROM ST SUPPORT
  35. * It provides timing information on the CPU2 activity.
  36. * All configuration of (port, pin) is supported for each features and can be selected by the user
  37. * depending on the availability
  38. */
  39. static const APPD_GpioConfig_t aGpioConfigList[GPIO_CFG_NBR_OF_FEATURES] = {
  40. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_ISR - Set on Entry / Reset on Exit */
  41. {GPIOA, LL_GPIO_PIN_7, 1, 0}, /* BLE_STACK_TICK - Set on Entry / Reset on Exit */
  42. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_CMD_PROCESS - Set on Entry / Reset on Exit */
  43. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_ACL_DATA_PROCESS - Set on Entry / Reset on Exit */
  44. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* SYS_CMD_PROCESS - Set on Entry / Reset on Exit */
  45. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* RNG_PROCESS - Set on Entry / Reset on Exit */
  46. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVM_PROCESS - Set on Entry / Reset on Exit */
  47. {GPIOB, LL_GPIO_PIN_3, 1, 0}, /* IPCC_GENERAL - Set on Entry / Reset on Exit */
  48. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_BLE_CMD_RX - Set on Entry / Reset on Exit */
  49. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_BLE_EVT_TX - Set on Entry / Reset on Exit */
  50. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_BLE_ACL_DATA_RX - Set on Entry / Reset on Exit */
  51. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_SYS_CMD_RX - Set on Entry / Reset on Exit */
  52. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_SYS_EVT_TX - Set on Entry / Reset on Exit */
  53. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_CLI_CMD_RX - Set on Entry / Reset on Exit */
  54. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_OT_CMD_RX - Set on Entry / Reset on Exit */
  55. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_OT_ACK_TX - Set on Entry / Reset on Exit */
  56. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_CLI_ACK_TX - Set on Entry / Reset on Exit */
  57. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_MEM_MANAGER_RX - Set on Entry / Reset on Exit */
  58. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* IPCC_TRACES_TX - Set on Entry / Reset on Exit */
  59. {GPIOA, LL_GPIO_PIN_6, 1, 0}, /* HARD_FAULT - Set on Entry / Reset on Exit */
  60. /* From v1.1.1 */
  61. {GPIOC, LL_GPIO_PIN_1, 1, 0}, /* IP_CORE_LP_STATUS - Set on Entry / Reset on Exit */
  62. /* From v1.2.0 */
  63. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* END_OF_CONNECTION_EVENT - Set on Entry / Reset on Exit */
  64. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* TIMER_SERVER_CALLBACK - Toggle on Entry */
  65. {GPIOA, LL_GPIO_PIN_4, 1, 0}, /* PES_ACTIVITY - Set on Entry / Reset on Exit */
  66. {GPIOC, LL_GPIO_PIN_0, 1, 0}, /* MB_BLE_SEND_EVT - Set on Entry / Reset on Exit */
  67. /* From v1.3.0 */
  68. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_NO_DELAY - Set on Entry / Reset on Exit */
  69. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* BLE_STACK_STORE_NVM_CB - Set on Entry / Reset on Exit */
  70. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVMA_WRITE_ONGOING - Set on Entry / Reset on Exit */
  71. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVMA_WRITE_COMPLETE - Set on Entry / Reset on Exit */
  72. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVMA_CLEANUP - Set on Entry / Reset on Exit */
  73. /* From v1.4.0 */
  74. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* NVMA_START - Set on Entry / Reset on Exit */
  75. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* FLASH_EOP - Set on Entry / Reset on Exit */
  76. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* FLASH_WRITE - Set on Entry / Reset on Exit */
  77. {GPIOA, LL_GPIO_PIN_0, 0, 0}, /* FLASH_ERASE - Set on Entry / Reset on Exit */
  78. };
  79. /**
  80. * THE DEBUG ON GPIO FOR CPU2 IS INTENDED TO BE USED ONLY ON REQUEST FROM ST SUPPORT
  81. * This table is relevant only for BLE
  82. * It provides timing information on BLE RF activity.
  83. * New signals may be allocated at any location when requested by ST
  84. * The GPIO allocated to each signal depend on the BLE_DTB_CFG value and cannot be changed
  85. */
  86. #if(BLE_DTB_CFG == 7)
  87. static const APPD_GpioConfig_t aRfConfigList[GPIO_NBR_OF_RF_SIGNALS] = {
  88. {GPIOB, LL_GPIO_PIN_2, 0, 0}, /* DTB10 - Tx/Rx SPI */
  89. {GPIOB, LL_GPIO_PIN_7, 0, 0}, /* DTB11 - Tx/Tx SPI Clk */
  90. {GPIOA, LL_GPIO_PIN_8, 0, 0}, /* DTB12 - Tx/Rx Ready & SPI Select */
  91. {GPIOA, LL_GPIO_PIN_9, 0, 0}, /* DTB13 - Tx/Rx Start */
  92. {GPIOA, LL_GPIO_PIN_10, 0, 0}, /* DTB14 - FSM0 */
  93. {GPIOA, LL_GPIO_PIN_11, 0, 0}, /* DTB15 - FSM1 */
  94. {GPIOB, LL_GPIO_PIN_8, 0, 0}, /* DTB16 - FSM2 */
  95. {GPIOB, LL_GPIO_PIN_11, 0, 0}, /* DTB17 - FSM3 */
  96. {GPIOB, LL_GPIO_PIN_10, 0, 0}, /* DTB18 - FSM4 */
  97. };
  98. #endif
  99. static void APPD_SetCPU2GpioConfig(void);
  100. static void APPD_BleDtbCfg(void);
  101. void APPD_Init() {
  102. #if(CFG_DEBUG_TRACE != 0)
  103. DbgTraceInit();
  104. #endif
  105. APPD_SetCPU2GpioConfig();
  106. APPD_BleDtbCfg();
  107. }
  108. void APPD_EnableCPU2(void) {
  109. SHCI_C2_DEBUG_Init_Cmd_Packet_t DebugCmdPacket = {
  110. {{0, 0, 0}}, /**< Does not need to be initialized */
  111. {(uint8_t*)aGpioConfigList,
  112. (uint8_t*)&APPD_TracesConfig,
  113. (uint8_t*)&APPD_GeneralConfig,
  114. GPIO_CFG_NBR_OF_FEATURES,
  115. NBR_OF_TRACES_CONFIG_PARAMETERS,
  116. NBR_OF_GENERAL_CONFIG_PARAMETERS}};
  117. /**< Traces channel initialization */
  118. TL_TRACES_Init();
  119. /** GPIO DEBUG Initialization */
  120. SHCI_C2_DEBUG_Init(&DebugCmdPacket);
  121. // We don't need External Power Amplifier
  122. // LL_GPIO_InitTypeDef gpio_config;
  123. // gpio_config.Pull = GPIO_NOPULL;
  124. // gpio_config.Mode = GPIO_MODE_OUTPUT_PP;
  125. // gpio_config.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  126. // gpio_config.Pin = LL_GPIO_PIN_3;
  127. // HAL_GPIO_Init(GPIOC, &gpio_config);
  128. // SHCI_C2_ExtpaConfig((uint32_t)GPIOC, LL_GPIO_PIN_3, EXT_PA_ENABLED_LOW, EXT_PA_ENABLED);
  129. return;
  130. }
  131. static void APPD_SetCPU2GpioConfig(void) {
  132. LL_GPIO_InitTypeDef gpio_config = {0};
  133. uint8_t local_loop;
  134. uint16_t gpioa_pin_list;
  135. uint16_t gpiob_pin_list;
  136. uint16_t gpioc_pin_list;
  137. gpioa_pin_list = 0;
  138. gpiob_pin_list = 0;
  139. gpioc_pin_list = 0;
  140. for(local_loop = 0; local_loop < GPIO_CFG_NBR_OF_FEATURES; local_loop++) {
  141. if(aGpioConfigList[local_loop].enable != 0) {
  142. switch((uint32_t)aGpioConfigList[local_loop].port) {
  143. case(uint32_t)GPIOA:
  144. gpioa_pin_list |= aGpioConfigList[local_loop].pin;
  145. break;
  146. case(uint32_t)GPIOB:
  147. gpiob_pin_list |= aGpioConfigList[local_loop].pin;
  148. break;
  149. case(uint32_t)GPIOC:
  150. gpioc_pin_list |= aGpioConfigList[local_loop].pin;
  151. break;
  152. default:
  153. break;
  154. }
  155. }
  156. }
  157. gpio_config.Mode = LL_GPIO_MODE_OUTPUT;
  158. gpio_config.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
  159. gpio_config.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  160. gpio_config.Pull = LL_GPIO_PULL_NO;
  161. // Never disable SWD, why would you?
  162. // gpio_config.Pin = LL_GPIO_PIN_15 | LL_GPIO_PIN_14 | LL_GPIO_PIN_13;
  163. // LL_GPIO_Init(GPIOA, &gpio_config);
  164. if(gpioa_pin_list != 0) {
  165. gpio_config.Pin = gpioa_pin_list;
  166. LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOA);
  167. LL_GPIO_Init(GPIOA, &gpio_config);
  168. LL_GPIO_ResetOutputPin(GPIOA, gpioa_pin_list);
  169. }
  170. if(gpiob_pin_list != 0) {
  171. gpio_config.Pin = gpiob_pin_list;
  172. LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOB);
  173. LL_GPIO_Init(GPIOB, &gpio_config);
  174. LL_GPIO_ResetOutputPin(GPIOB, gpioa_pin_list);
  175. }
  176. if(gpioc_pin_list != 0) {
  177. gpio_config.Pin = gpioc_pin_list;
  178. LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOC);
  179. LL_GPIO_Init(GPIOC, &gpio_config);
  180. LL_GPIO_ResetOutputPin(GPIOC, gpioa_pin_list);
  181. }
  182. }
  183. static void APPD_BleDtbCfg(void) {
  184. #if(BLE_DTB_CFG != 0)
  185. LL_GPIO_InitTypeDef gpio_config = {0};
  186. uint8_t local_loop;
  187. uint16_t gpioa_pin_list;
  188. uint16_t gpiob_pin_list;
  189. gpioa_pin_list = 0;
  190. gpiob_pin_list = 0;
  191. for(local_loop = 0; local_loop < GPIO_NBR_OF_RF_SIGNALS; local_loop++) {
  192. if(aRfConfigList[local_loop].enable != 0) {
  193. switch((uint32_t)aRfConfigList[local_loop].port) {
  194. case(uint32_t)GPIOA:
  195. gpioa_pin_list |= aRfConfigList[local_loop].pin;
  196. break;
  197. case(uint32_t)GPIOB:
  198. gpiob_pin_list |= aRfConfigList[local_loop].pin;
  199. break;
  200. default:
  201. break;
  202. }
  203. }
  204. }
  205. gpio_config.Mode = LL_GPIO_MODE_ALTERNATE;
  206. gpio_config.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
  207. gpio_config.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  208. gpio_config.Pull = LL_GPIO_PULL_NO;
  209. gpio_config.Alternate = LL_GPIO_AF_6;
  210. gpio_config.Pin = LL_GPIO_PIN_15 | LL_GPIO_PIN_14 | LL_GPIO_PIN_13;
  211. if(gpioa_pin_list != 0) {
  212. gpio_config.Pin = gpioa_pin_list;
  213. LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOA);
  214. LL_GPIO_Init(GPIOA, &gpio_config);
  215. }
  216. if(gpiob_pin_list != 0) {
  217. gpio_config.Pin = gpiob_pin_list;
  218. LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOB);
  219. LL_GPIO_Init(GPIOB, &gpio_config);
  220. }
  221. #endif
  222. }
  223. #if(CFG_DEBUG_TRACE != 0)
  224. void DbgOutputInit(void) {
  225. }
  226. void DbgOutputTraces(uint8_t* p_data, uint16_t size, void (*cb)(void)) {
  227. furi_hal_console_tx(p_data, size);
  228. cb();
  229. }
  230. #endif