dap_link.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. #include <dap.h>
  2. #include <furi.h>
  3. #include <furi_hal_version.h>
  4. #include <furi_hal_gpio.h>
  5. #include <furi_hal_serial_control.h>
  6. #include <furi_hal_serial.h>
  7. #include <furi_hal_resources.h>
  8. #include <furi_hal_power.h>
  9. #include <stm32wbxx_ll_usart.h>
  10. #include <stm32wbxx_ll_lpuart.h>
  11. #include <expansion/expansion.h>
  12. #include "dap_link.h"
  13. #include "dap_config.h"
  14. #include "gui/dap_gui.h"
  15. #include "usb/dap_v2_usb.h"
  16. #include <dialogs/dialogs.h>
  17. #include "dap_link_icons.h"
  18. #include <assets_icons.h>
  19. /***************************************************************************/
  20. /****************************** DAP COMMON *********************************/
  21. /***************************************************************************/
  22. struct DapApp {
  23. FuriThread* dap_thread;
  24. FuriThread* cdc_thread;
  25. FuriThread* gui_thread;
  26. DapState state;
  27. DapConfig config;
  28. };
  29. void dap_app_get_state(DapApp* app, DapState* state) {
  30. *state = app->state;
  31. }
  32. #define DAP_PROCESS_THREAD_TICK 500
  33. typedef enum {
  34. DapEventStop = (1 << 0),
  35. } DapEvent;
  36. void dap_thread_send_stop(FuriThread* thread) {
  37. furi_thread_flags_set(furi_thread_get_id(thread), DapEventStop);
  38. }
  39. GpioPin flipper_dap_swclk_pin;
  40. GpioPin flipper_dap_swdio_pin;
  41. GpioPin flipper_dap_reset_pin;
  42. GpioPin flipper_dap_tdo_pin;
  43. GpioPin flipper_dap_tdi_pin;
  44. /***************************************************************************/
  45. /****************************** DAP PROCESS ********************************/
  46. /***************************************************************************/
  47. typedef struct {
  48. uint8_t data[DAP_CONFIG_PACKET_SIZE];
  49. uint8_t size;
  50. } DapPacket;
  51. typedef enum {
  52. DapThreadEventStop = DapEventStop,
  53. DapThreadEventRxV1 = (1 << 1),
  54. DapThreadEventRxV2 = (1 << 2),
  55. DapThreadEventUsbConnect = (1 << 3),
  56. DapThreadEventUsbDisconnect = (1 << 4),
  57. DapThreadEventApplyConfig = (1 << 5),
  58. DapThreadEventAll = DapThreadEventStop | DapThreadEventRxV1 | DapThreadEventRxV2 |
  59. DapThreadEventUsbConnect | DapThreadEventUsbDisconnect |
  60. DapThreadEventApplyConfig,
  61. } DapThreadEvent;
  62. #define USB_SERIAL_NUMBER_LEN 16
  63. char usb_serial_number[USB_SERIAL_NUMBER_LEN] = {0};
  64. const char* dap_app_get_serial(DapApp* app) {
  65. UNUSED(app);
  66. return usb_serial_number;
  67. }
  68. static void dap_app_rx1_callback(void* context) {
  69. furi_assert(context);
  70. FuriThreadId thread_id = (FuriThreadId)context;
  71. furi_thread_flags_set(thread_id, DapThreadEventRxV1);
  72. }
  73. static void dap_app_rx2_callback(void* context) {
  74. furi_assert(context);
  75. FuriThreadId thread_id = (FuriThreadId)context;
  76. furi_thread_flags_set(thread_id, DapThreadEventRxV2);
  77. }
  78. static void dap_app_usb_state_callback(bool state, void* context) {
  79. furi_assert(context);
  80. FuriThreadId thread_id = (FuriThreadId)context;
  81. if(state) {
  82. furi_thread_flags_set(thread_id, DapThreadEventUsbConnect);
  83. } else {
  84. furi_thread_flags_set(thread_id, DapThreadEventUsbDisconnect);
  85. }
  86. }
  87. static void dap_app_process_v1() {
  88. DapPacket tx_packet;
  89. DapPacket rx_packet;
  90. memset(&tx_packet, 0, sizeof(DapPacket));
  91. rx_packet.size = dap_v1_usb_rx(rx_packet.data, DAP_CONFIG_PACKET_SIZE);
  92. dap_process_request(rx_packet.data, rx_packet.size, tx_packet.data, DAP_CONFIG_PACKET_SIZE);
  93. dap_v1_usb_tx(tx_packet.data, DAP_CONFIG_PACKET_SIZE);
  94. }
  95. static void dap_app_process_v2() {
  96. DapPacket tx_packet;
  97. DapPacket rx_packet;
  98. memset(&tx_packet, 0, sizeof(DapPacket));
  99. rx_packet.size = dap_v2_usb_rx(rx_packet.data, DAP_CONFIG_PACKET_SIZE);
  100. size_t len = dap_process_request(
  101. rx_packet.data, rx_packet.size, tx_packet.data, DAP_CONFIG_PACKET_SIZE);
  102. dap_v2_usb_tx(tx_packet.data, len);
  103. }
  104. void dap_app_vendor_cmd(uint8_t cmd) {
  105. // openocd -c "cmsis-dap cmd 81"
  106. if(cmd == 0x01) {
  107. furi_hal_power_reset();
  108. }
  109. }
  110. void dap_app_target_reset() {
  111. FURI_LOG_I("DAP", "Target reset");
  112. }
  113. static void dap_init_gpio(DapSwdPins swd_pins) {
  114. switch(swd_pins) {
  115. case DapSwdPinsPA7PA6:
  116. flipper_dap_swclk_pin = gpio_ext_pa7;
  117. flipper_dap_swdio_pin = gpio_ext_pa6;
  118. break;
  119. case DapSwdPinsPA14PA13:
  120. flipper_dap_swclk_pin = (GpioPin){.port = GPIOA, .pin = LL_GPIO_PIN_14};
  121. flipper_dap_swdio_pin = (GpioPin){.port = GPIOA, .pin = LL_GPIO_PIN_13};
  122. break;
  123. }
  124. flipper_dap_reset_pin = gpio_ext_pa4;
  125. flipper_dap_tdo_pin = gpio_ext_pb3;
  126. flipper_dap_tdi_pin = gpio_ext_pb2;
  127. }
  128. static void dap_deinit_gpio(DapSwdPins swd_pins) {
  129. // setup gpio pins to default state
  130. furi_hal_gpio_init(&flipper_dap_reset_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
  131. furi_hal_gpio_init(&flipper_dap_tdo_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
  132. furi_hal_gpio_init(&flipper_dap_tdi_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
  133. if(DapSwdPinsPA14PA13 == swd_pins) {
  134. // PA14 and PA13 are used by SWD
  135. furi_hal_gpio_init_ex(
  136. &flipper_dap_swclk_pin,
  137. GpioModeAltFunctionPushPull,
  138. GpioPullDown,
  139. GpioSpeedLow,
  140. GpioAltFn0JTCK_SWCLK);
  141. furi_hal_gpio_init_ex(
  142. &flipper_dap_swdio_pin,
  143. GpioModeAltFunctionPushPull,
  144. GpioPullUp,
  145. GpioSpeedVeryHigh,
  146. GpioAltFn0JTMS_SWDIO);
  147. } else {
  148. furi_hal_gpio_init(&flipper_dap_swclk_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
  149. furi_hal_gpio_init(&flipper_dap_swdio_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
  150. }
  151. }
  152. static int32_t dap_process(void* p) {
  153. DapApp* app = p;
  154. DapState* dap_state = &(app->state);
  155. // allocate resources
  156. FuriHalUsbInterface* usb_config_prev;
  157. app->config.swd_pins = DapSwdPinsPA7PA6;
  158. DapSwdPins swd_pins_prev = app->config.swd_pins;
  159. // init pins
  160. dap_init_gpio(swd_pins_prev);
  161. // init dap
  162. dap_init();
  163. // get name
  164. const char* name = furi_hal_version_get_name_ptr();
  165. if(!name) {
  166. name = "Flipper";
  167. }
  168. snprintf(usb_serial_number, USB_SERIAL_NUMBER_LEN, "DAP_%s", name);
  169. // init usb
  170. usb_config_prev = furi_hal_usb_get_config();
  171. dap_common_usb_alloc_name(usb_serial_number);
  172. dap_common_usb_set_context(furi_thread_get_id(furi_thread_get_current()));
  173. dap_v1_usb_set_rx_callback(dap_app_rx1_callback);
  174. dap_v2_usb_set_rx_callback(dap_app_rx2_callback);
  175. dap_common_usb_set_state_callback(dap_app_usb_state_callback);
  176. furi_hal_usb_set_config(&dap_v2_usb_hid, NULL);
  177. // work
  178. uint32_t events;
  179. while(1) {
  180. events = furi_thread_flags_wait(DapThreadEventAll, FuriFlagWaitAny, FuriWaitForever);
  181. if(!(events & FuriFlagError)) {
  182. if(events & DapThreadEventRxV1) {
  183. dap_app_process_v1();
  184. dap_state->dap_counter++;
  185. dap_state->dap_version = DapVersionV1;
  186. }
  187. if(events & DapThreadEventRxV2) {
  188. dap_app_process_v2();
  189. dap_state->dap_counter++;
  190. dap_state->dap_version = DapVersionV2;
  191. }
  192. if(events & DapThreadEventUsbConnect) {
  193. dap_state->usb_connected = true;
  194. }
  195. if(events & DapThreadEventUsbDisconnect) {
  196. dap_state->usb_connected = false;
  197. dap_state->dap_version = DapVersionUnknown;
  198. }
  199. if(events & DapThreadEventApplyConfig) {
  200. if(swd_pins_prev != app->config.swd_pins) {
  201. dap_deinit_gpio(swd_pins_prev);
  202. swd_pins_prev = app->config.swd_pins;
  203. dap_init_gpio(swd_pins_prev);
  204. }
  205. }
  206. if(events & DapThreadEventStop) {
  207. break;
  208. }
  209. }
  210. }
  211. // deinit usb
  212. furi_hal_usb_set_config(usb_config_prev, NULL);
  213. dap_common_usb_free_name();
  214. dap_deinit_gpio(swd_pins_prev);
  215. return 0;
  216. }
  217. /***************************************************************************/
  218. /****************************** CDC PROCESS ********************************/
  219. /***************************************************************************/
  220. typedef enum {
  221. CdcThreadEventStop = DapEventStop,
  222. CdcThreadEventUartRx = (1 << 1),
  223. CdcThreadEventCdcRx = (1 << 2),
  224. CdcThreadEventCdcConfig = (1 << 3),
  225. CdcThreadEventApplyConfig = (1 << 4),
  226. CdcThreadEventCdcDtrHigh = (1 << 5),
  227. CdcThreadEventCdcDtrLow = (1 << 6),
  228. CdcThreadEventCdcTxComplete = (1 << 7),
  229. CdcThreadEventAll = CdcThreadEventStop | CdcThreadEventUartRx | CdcThreadEventCdcRx |
  230. CdcThreadEventCdcConfig | CdcThreadEventApplyConfig |
  231. CdcThreadEventCdcDtrHigh | CdcThreadEventCdcDtrLow |
  232. CdcThreadEventCdcTxComplete,
  233. } CdcThreadEvent;
  234. typedef struct {
  235. FuriStreamBuffer* rx_stream;
  236. FuriThreadId thread_id;
  237. FuriHalSerialHandle* serial_handle;
  238. struct usb_cdc_line_coding line_coding;
  239. } CDCProcess;
  240. static void cdc_uart_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent event, void* ctx) {
  241. CDCProcess* app = ctx;
  242. if(event == FuriHalSerialRxEventData) {
  243. uint8_t data = furi_hal_serial_async_rx(handle);
  244. furi_stream_buffer_send(app->rx_stream, &data, 1, 0);
  245. furi_thread_flags_set(app->thread_id, CdcThreadEventUartRx);
  246. }
  247. }
  248. static void cdc_usb_rx_callback(void* context) {
  249. CDCProcess* app = context;
  250. furi_thread_flags_set(app->thread_id, CdcThreadEventCdcRx);
  251. }
  252. static void cdc_usb_tx_complete_callback(void* context) {
  253. CDCProcess* app = context;
  254. furi_thread_flags_set(app->thread_id, CdcThreadEventCdcTxComplete);
  255. }
  256. static void cdc_usb_control_line_callback(uint8_t state, void* context) {
  257. CDCProcess* app = context;
  258. // bit 0: DTR state, bit 1: RTS state
  259. bool dtr = state & (1 << 0);
  260. if(dtr == true) {
  261. furi_thread_flags_set(app->thread_id, CdcThreadEventCdcDtrHigh);
  262. } else {
  263. furi_thread_flags_set(app->thread_id, CdcThreadEventCdcDtrLow);
  264. }
  265. }
  266. static void cdc_usb_config_callback(struct usb_cdc_line_coding* config, void* context) {
  267. CDCProcess* app = context;
  268. app->line_coding = *config;
  269. furi_thread_flags_set(app->thread_id, CdcThreadEventCdcConfig);
  270. }
  271. static void cdc_init_uart(
  272. CDCProcess* app,
  273. DapUartType type,
  274. DapUartTXRX swap,
  275. uint32_t baudrate,
  276. void (*cb)(FuriHalSerialHandle* handle, FuriHalSerialRxEvent event, void* ctx),
  277. void* ctx) {
  278. if(baudrate == 0) baudrate = 115200;
  279. switch(type) {
  280. case DapUartTypeUSART1:
  281. app->serial_handle = furi_hal_serial_control_acquire(FuriHalSerialIdUsart);
  282. furi_check(app->serial_handle);
  283. if(swap == DapUartTXRXSwap) {
  284. LL_USART_SetTXRXSwap(USART1, LL_USART_TXRX_SWAPPED);
  285. } else {
  286. LL_USART_SetTXRXSwap(USART1, LL_USART_TXRX_STANDARD);
  287. }
  288. furi_hal_serial_init(app->serial_handle, baudrate);
  289. furi_hal_serial_async_rx_start(app->serial_handle, cb, ctx, false);
  290. break;
  291. case DapUartTypeLPUART1:
  292. app->serial_handle = furi_hal_serial_control_acquire(FuriHalSerialIdLpuart);
  293. furi_check(app->serial_handle);
  294. if(swap == DapUartTXRXSwap) {
  295. LL_LPUART_SetTXRXSwap(LPUART1, LL_LPUART_TXRX_SWAPPED);
  296. } else {
  297. LL_LPUART_SetTXRXSwap(LPUART1, LL_LPUART_TXRX_STANDARD);
  298. }
  299. furi_hal_serial_init(app->serial_handle, baudrate);
  300. furi_hal_serial_async_rx_start(app->serial_handle, cb, ctx, false);
  301. break;
  302. }
  303. }
  304. static void cdc_deinit_uart(CDCProcess* app, DapUartType type) {
  305. switch(type) {
  306. case DapUartTypeUSART1:
  307. furi_hal_serial_async_rx_stop(app->serial_handle);
  308. furi_hal_serial_deinit(app->serial_handle);
  309. LL_USART_SetTXRXSwap(USART1, LL_USART_TXRX_STANDARD);
  310. furi_hal_serial_control_release(app->serial_handle);
  311. break;
  312. case DapUartTypeLPUART1:
  313. furi_hal_serial_async_rx_stop(app->serial_handle);
  314. furi_hal_serial_deinit(app->serial_handle);
  315. LL_LPUART_SetTXRXSwap(LPUART1, LL_LPUART_TXRX_STANDARD);
  316. furi_hal_serial_control_release(app->serial_handle);
  317. break;
  318. }
  319. }
  320. static int32_t dap_cdc_process(void* p) {
  321. DapApp* dap_app = p;
  322. DapState* dap_state = &(dap_app->state);
  323. dap_app->config.uart_pins = DapUartTypeLPUART1;
  324. dap_app->config.uart_swap = DapUartTXRXNormal;
  325. DapUartType uart_pins_prev = dap_app->config.uart_pins;
  326. DapUartTXRX uart_swap_prev = dap_app->config.uart_swap;
  327. CDCProcess* app = malloc(sizeof(CDCProcess));
  328. app->thread_id = furi_thread_get_id(furi_thread_get_current());
  329. app->rx_stream = furi_stream_buffer_alloc(512, 1);
  330. const uint8_t rx_buffer_size = 64;
  331. uint8_t* rx_buffer = malloc(rx_buffer_size);
  332. cdc_init_uart(
  333. app, uart_pins_prev, uart_swap_prev, dap_state->cdc_baudrate, cdc_uart_irq_cb, app);
  334. dap_cdc_usb_set_context(app);
  335. dap_cdc_usb_set_rx_callback(cdc_usb_rx_callback);
  336. dap_cdc_usb_set_tx_complete_callback(cdc_usb_tx_complete_callback);
  337. dap_cdc_usb_set_control_line_callback(cdc_usb_control_line_callback);
  338. dap_cdc_usb_set_config_callback(cdc_usb_config_callback);
  339. bool cdc_connect = false;
  340. uint32_t events;
  341. while(1) {
  342. events = furi_thread_flags_wait(CdcThreadEventAll, FuriFlagWaitAny, FuriWaitForever);
  343. if(!(events & FuriFlagError)) {
  344. if(events & CdcThreadEventCdcConfig) {
  345. if(dap_state->cdc_baudrate != app->line_coding.dwDTERate) {
  346. dap_state->cdc_baudrate = app->line_coding.dwDTERate;
  347. if(dap_state->cdc_baudrate > 0) {
  348. furi_hal_serial_set_br(app->serial_handle, dap_state->cdc_baudrate);
  349. }
  350. }
  351. }
  352. if(events & (CdcThreadEventUartRx | CdcThreadEventCdcTxComplete)) {
  353. size_t len =
  354. furi_stream_buffer_receive(app->rx_stream, rx_buffer, rx_buffer_size, 0);
  355. if(cdc_connect) {
  356. if(len > 0) {
  357. dap_cdc_usb_tx(rx_buffer, len);
  358. }
  359. dap_state->cdc_rx_counter += len;
  360. }
  361. }
  362. if(events & CdcThreadEventCdcRx) {
  363. size_t len = dap_cdc_usb_rx(rx_buffer, rx_buffer_size);
  364. if(len > 0) {
  365. furi_hal_serial_tx(app->serial_handle, rx_buffer, len);
  366. }
  367. dap_state->cdc_tx_counter += len;
  368. }
  369. if(events & CdcThreadEventApplyConfig) {
  370. if(uart_pins_prev != dap_app->config.uart_pins ||
  371. uart_swap_prev != dap_app->config.uart_swap) {
  372. cdc_deinit_uart(app, uart_pins_prev);
  373. uart_pins_prev = dap_app->config.uart_pins;
  374. uart_swap_prev = dap_app->config.uart_swap;
  375. cdc_init_uart(
  376. app,
  377. uart_pins_prev,
  378. uart_swap_prev,
  379. dap_state->cdc_baudrate,
  380. cdc_uart_irq_cb,
  381. app);
  382. }
  383. }
  384. if(events & CdcThreadEventStop) {
  385. break;
  386. }
  387. if(events & CdcThreadEventCdcDtrHigh) {
  388. cdc_connect = true;
  389. }
  390. if(events & CdcThreadEventCdcDtrLow) {
  391. cdc_connect = false;
  392. }
  393. }
  394. }
  395. cdc_deinit_uart(app, uart_pins_prev);
  396. free(rx_buffer);
  397. furi_stream_buffer_free(app->rx_stream);
  398. free(app);
  399. return 0;
  400. }
  401. /***************************************************************************/
  402. /******************************* MAIN APP **********************************/
  403. /***************************************************************************/
  404. static DapApp* dap_app_alloc() {
  405. DapApp* dap_app = malloc(sizeof(DapApp));
  406. dap_app->dap_thread = furi_thread_alloc_ex("DapProcess", 1024, dap_process, dap_app);
  407. dap_app->cdc_thread = furi_thread_alloc_ex("DapCdcProcess", 1024, dap_cdc_process, dap_app);
  408. dap_app->gui_thread = furi_thread_alloc_ex("DapGui", 1024, dap_gui_thread, dap_app);
  409. return dap_app;
  410. }
  411. static void dap_app_free(DapApp* dap_app) {
  412. furi_assert(dap_app);
  413. furi_thread_free(dap_app->dap_thread);
  414. furi_thread_free(dap_app->cdc_thread);
  415. furi_thread_free(dap_app->gui_thread);
  416. free(dap_app);
  417. }
  418. static DapApp* app_handle = NULL;
  419. void dap_app_disconnect() {
  420. app_handle->state.dap_mode = DapModeDisconnected;
  421. }
  422. void dap_app_connect_swd() {
  423. app_handle->state.dap_mode = DapModeSWD;
  424. }
  425. void dap_app_connect_jtag() {
  426. app_handle->state.dap_mode = DapModeJTAG;
  427. }
  428. void dap_app_set_config(DapApp* app, DapConfig* config) {
  429. app->config = *config;
  430. furi_thread_flags_set(furi_thread_get_id(app->dap_thread), DapThreadEventApplyConfig);
  431. furi_thread_flags_set(furi_thread_get_id(app->cdc_thread), CdcThreadEventApplyConfig);
  432. }
  433. DapConfig* dap_app_get_config(DapApp* app) {
  434. return &app->config;
  435. }
  436. int32_t dap_link_app(void* p) {
  437. UNUSED(p);
  438. // Disable expansion protocol to avoid interference with UART Handle
  439. Expansion* expansion = furi_record_open(RECORD_EXPANSION);
  440. expansion_disable(expansion);
  441. if(furi_hal_usb_is_locked()) {
  442. DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
  443. DialogMessage* message = dialog_message_alloc();
  444. dialog_message_set_header(message, "Connection\nis active!", 3, 2, AlignLeft, AlignTop);
  445. dialog_message_set_text(
  446. message,
  447. "Disconnect from\nPC or phone to\nuse this function.",
  448. 3,
  449. 30,
  450. AlignLeft,
  451. AlignTop);
  452. dialog_message_set_icon(message, &I_ActiveConnection_50x64, 78, 0);
  453. dialog_message_show(dialogs, message);
  454. dialog_message_free(message);
  455. furi_record_close(RECORD_DIALOGS);
  456. // Return previous state of expansion
  457. expansion_enable(expansion);
  458. furi_record_close(RECORD_EXPANSION);
  459. return -1;
  460. }
  461. // alloc app
  462. DapApp* app = dap_app_alloc();
  463. app_handle = app;
  464. furi_thread_start(app->dap_thread);
  465. furi_thread_start(app->cdc_thread);
  466. furi_thread_start(app->gui_thread);
  467. // wait until gui thread is finished
  468. furi_thread_join(app->gui_thread);
  469. // send stop event to threads
  470. dap_thread_send_stop(app->dap_thread);
  471. dap_thread_send_stop(app->cdc_thread);
  472. // wait for threads to stop
  473. furi_thread_join(app->dap_thread);
  474. furi_thread_join(app->cdc_thread);
  475. // free app
  476. dap_app_free(app);
  477. // Return previous state of expansion
  478. expansion_enable(expansion);
  479. furi_record_close(RECORD_EXPANSION);
  480. return 0;
  481. }