Skip to content

Commit

Permalink
Fix UART deinit issues in multiple apps
Browse files Browse the repository at this point in the history
Also thanks to Willy-JL for finding the issue and fixing part of the apps
  • Loading branch information
xMasterX committed Mar 22, 2024
1 parent 7172669 commit 6f19c6d
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 51 deletions.
1 change: 1 addition & 0 deletions apps_source_code/airmon/airmon_pms.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static void airmon_pms_serial_init(AirmonPmsContext* pms_context) {
}

static void airmon_pms_serial_deinit(AirmonPmsContext* pms_context) {
furi_hal_serial_async_rx_stop(pms_context->serial_handle);
furi_hal_serial_deinit(pms_context->serial_handle);
furi_hal_serial_control_release(pms_context->serial_handle);
}
Expand Down
9 changes: 5 additions & 4 deletions base_pack/camera_suite/views/camera_suite_view_camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,11 @@ CameraSuiteViewCamera* camera_suite_view_camera_alloc() {
void camera_suite_view_camera_free(CameraSuiteViewCamera* instance) {
furi_assert(instance);

// Deinitialize the serial handle and release the control.
furi_hal_serial_async_rx_stop(instance->serial_handle);
furi_hal_serial_deinit(instance->serial_handle);
furi_hal_serial_control_release(instance->serial_handle);

// Free the worker thread.
furi_thread_flags_set(furi_thread_get_id(instance->camera_worker_thread), WorkerEventStop);
furi_thread_join(instance->camera_worker_thread);
Expand All @@ -642,10 +647,6 @@ void camera_suite_view_camera_free(CameraSuiteViewCamera* instance) {
// Free the allocated stream buffer.
furi_stream_buffer_free(instance->camera_rx_stream);

// Deinitialize the serial handle and release the control.
furi_hal_serial_deinit(instance->serial_handle);
furi_hal_serial_control_release(instance->serial_handle);

with_view_model(
instance->view, UartDumpModel * model, { UNUSED(model); }, true);
view_free(instance->view);
Expand Down
2 changes: 2 additions & 0 deletions base_pack/dap_link/dap_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,13 @@ static void cdc_init_uart(
static void cdc_deinit_uart(CDCProcess* app, DapUartType type) {
switch(type) {
case DapUartTypeUSART1:
furi_hal_serial_async_rx_stop(app->serial_handle);
furi_hal_serial_deinit(app->serial_handle);
LL_USART_SetTXRXSwap(USART1, LL_USART_TXRX_STANDARD);
furi_hal_serial_control_release(app->serial_handle);
break;
case DapUartTypeLPUART1:
furi_hal_serial_async_rx_stop(app->serial_handle);
furi_hal_serial_deinit(app->serial_handle);
LL_LPUART_SetTXRXSwap(LPUART1, LL_LPUART_TXRX_STANDARD);
furi_hal_serial_control_release(app->serial_handle);
Expand Down
6 changes: 3 additions & 3 deletions base_pack/esp8266_deauth/esp8266_deauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ int32_t esp8266_deauth_app(void* p) {
}

DEAUTH_APP_LOG_I("Start exit app");
furi_hal_serial_async_rx_stop(app->serial_handle);
furi_hal_serial_deinit(app->serial_handle);
furi_hal_serial_control_release(app->serial_handle);

furi_thread_flags_set(furi_thread_get_id(app->m_worker_thread), WorkerEventStop);
furi_thread_join(app->m_worker_thread);
Expand All @@ -516,9 +519,6 @@ int32_t esp8266_deauth_app(void* p) {
furi_hal_gpio_init(&gpio_ext_pb3, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_ext_pa4, GpioModeAnalog, GpioPullNo, GpioSpeedLow);

furi_hal_serial_deinit(app->serial_handle);
furi_hal_serial_control_release(app->serial_handle);

//*app->m_originalBufferLocation = app->m_originalBuffer;

view_port_enabled_set(view_port, false);
Expand Down
1 change: 1 addition & 0 deletions base_pack/gps_nmea_uart/gps_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static void gps_uart_serial_init(GpsUart* gps_uart) {

static void gps_uart_serial_deinit(GpsUart* gps_uart) {
UNUSED(gps_uart);
furi_hal_serial_async_rx_stop(gps_uart->serial_handle);
furi_hal_serial_deinit(gps_uart->serial_handle);
furi_hal_serial_control_release(gps_uart->serial_handle);
}
Expand Down
9 changes: 5 additions & 4 deletions base_pack/uart_terminal/uart_terminal_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ UART_TerminalUart* uart_terminal_uart_init(UART_TerminalApp* app) {
void uart_terminal_uart_free(UART_TerminalUart* uart) {
furi_assert(uart);

furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtStop);
furi_thread_join(uart->rx_thread);
furi_thread_free(uart->rx_thread);

furi_hal_serial_async_rx_stop(uart->serial_handle);
furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtStop);
furi_thread_join(uart->rx_thread);
furi_thread_free(uart->rx_thread);

free(uart);
}
7 changes: 4 additions & 3 deletions base_pack/wifi_marauder_companion/wifi_marauder_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,13 @@ WifiMarauderUart* wifi_marauder_usart_init(WifiMarauderApp* app) {
void wifi_marauder_uart_free(WifiMarauderUart* uart) {
furi_assert(uart);

furi_hal_serial_async_rx_stop(uart->serial_handle);
furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtStop);
furi_thread_join(uart->rx_thread);
furi_thread_free(uart->rx_thread);

furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

free(uart);
}
6 changes: 3 additions & 3 deletions base_pack/wifi_scanner/wifi_scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,9 @@ int32_t wifi_scanner_app(void* p) {
}

WIFI_APP_LOG_I("Start exit app");
furi_hal_serial_async_rx_stop(app->serial_handle);
furi_hal_serial_deinit(app->serial_handle);
furi_hal_serial_control_release(app->serial_handle);

furi_thread_flags_set(furi_thread_get_id(app->m_worker_thread), WorkerEventStop);
furi_thread_join(app->m_worker_thread);
Expand All @@ -1038,9 +1041,6 @@ int32_t wifi_scanner_app(void* p) {
// Reset GPIO pins to default state
furi_hal_gpio_init(&gpio_ext_pc0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);

furi_hal_serial_deinit(app->serial_handle);
furi_hal_serial_control_release(app->serial_handle);

view_port_enabled_set(view_port, false);

gui_remove_view_port(app->m_gui, view_port);
Expand Down
7 changes: 4 additions & 3 deletions non_catalog_apps/LORA_term/uart_terminal_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ UART_TerminalUart* uart_terminal_uart_init(UART_TerminalApp* app) {
void uart_terminal_uart_free(UART_TerminalUart* uart) {
furi_assert(uart);

furi_hal_serial_async_rx_stop(uart->serial_handle);
furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtStop);
furi_thread_join(uart->rx_thread);
furi_thread_free(uart->rx_thread);

furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

free(uart);
}
7 changes: 4 additions & 3 deletions non_catalog_apps/esp32_gravity/uart_terminal_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ UART_TerminalUart* uart_terminal_uart_init(UART_TerminalApp* app) {
void uart_terminal_uart_free(UART_TerminalUart* uart) {
furi_assert(uart);

furi_hal_serial_async_rx_stop(uart->serial_handle);
furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtStop);
furi_thread_join(uart->rx_thread);
furi_thread_free(uart->rx_thread);

furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

free(uart);
}
7 changes: 4 additions & 3 deletions non_catalog_apps/esp_flasher/esp_flasher_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ EspFlasherUart* esp_flasher_usart_init(EspFlasherApp* app) {
void esp_flasher_uart_free(EspFlasherUart* uart) {
furi_assert(uart);

furi_hal_serial_async_rx_stop(uart->serial_handle);
furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtStop);
furi_thread_join(uart->rx_thread);
furi_thread_free(uart->rx_thread);

furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

free(uart);
}
7 changes: 4 additions & 3 deletions non_catalog_apps/flipagotchi/src/flipagotchi.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,14 @@ static FlipagotchiApp* flipagotchi_app_alloc() {
static void flipagotchi_app_free(FlipagotchiApp* app) {
furi_assert(app);

furi_hal_serial_async_rx_stop(app->serial_handle);
furi_hal_serial_deinit(app->serial_handle);
furi_hal_serial_control_release(app->serial_handle);

furi_thread_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventStop);
furi_thread_join(app->worker_thread);
furi_thread_free(app->worker_thread);

furi_hal_serial_deinit(app->serial_handle);
furi_hal_serial_control_release(app->serial_handle);

// Free views
view_dispatcher_remove_view(app->view_dispatcher, 0);

Expand Down
7 changes: 4 additions & 3 deletions non_catalog_apps/flipper_evil_portal/evil_portal_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,13 @@ Evil_PortalUart* evil_portal_uart_init(Evil_PortalApp* app) {
void evil_portal_uart_free(Evil_PortalUart* uart) {
furi_assert(uart);

furi_hal_serial_async_rx_stop(uart->serial_handle);
furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtStop);
furi_thread_join(uart->rx_thread);
furi_thread_free(uart->rx_thread);

furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

free(uart);
}
1 change: 1 addition & 0 deletions non_catalog_apps/flipperzero-camera/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ static UartEchoApp* camera_app_alloc() {
static void camera_app_free(UartEchoApp* app) {
furi_assert(app);

furi_hal_serial_async_rx_stop(app->serial_handle);
furi_hal_serial_deinit(app->serial_handle);
furi_hal_serial_control_release(app->serial_handle);

Expand Down
1 change: 1 addition & 0 deletions non_catalog_apps/flipperzero_gpioreader/usb_uart_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ static void usb_uart_serial_init(UsbUartBridge* usb_uart, uint8_t uart_ch) {

static void usb_uart_serial_deinit(UsbUartBridge* usb_uart, uint8_t uart_ch) {
UNUSED(uart_ch);
furi_hal_serial_async_rx_stop(usb_uart->serial_handle);
furi_hal_serial_deinit(usb_uart->serial_handle);
furi_hal_serial_control_release(usb_uart->serial_handle);
}
Expand Down
1 change: 1 addition & 0 deletions non_catalog_apps/ifttt/ifttt_virtual_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ void ifttt_virtual_button_app_free(VirtualButtonApp* app) {
furi_record_close(RECORD_POWER);
furi_record_close(RECORD_GUI);

furi_hal_serial_async_rx_stop(app->serial_handle);
furi_hal_serial_deinit(app->serial_handle);
furi_hal_serial_control_release(app->serial_handle);

Expand Down
7 changes: 4 additions & 3 deletions non_catalog_apps/magspoof_flipper/scenes/mag_scene_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,16 @@ void mag_scene_read_on_exit(void* context) {

// Stop UART worker
FURI_LOG_D(TAG, "Stopping UART worker");
furi_hal_serial_async_rx_stop(mag->serial_handle);
furi_hal_serial_deinit(mag->serial_handle);
furi_hal_serial_control_release(mag->serial_handle);

furi_thread_flags_set(furi_thread_get_id(mag->uart_rx_thread), WorkerEvtStop);
furi_thread_join(mag->uart_rx_thread);
furi_thread_free(mag->uart_rx_thread);
FURI_LOG_D(TAG, "UART worker stopped");

furi_string_free(mag->uart_text_box_store);

furi_hal_serial_deinit(mag->serial_handle);
furi_hal_serial_control_release(mag->serial_handle);

notification_message(mag->notifications, &sequence_blink_stop);
}
18 changes: 6 additions & 12 deletions non_catalog_apps/uhf_rfid/uhf_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,10 @@ UHFUart* uhf_uart_alloc() {
uart->bus = FuriHalBusUSART1;
uart->handle = furi_hal_serial_control_acquire(FuriHalSerialIdUsart);
// uart->rx_buff_stream = furi_stream_buffer_alloc(UHF_UART_RX_BUFFER_SIZE, 1);
uart->init_by_app = !furi_hal_bus_is_enabled(uart->bus);
uart->tick = UHF_UART_WAIT_TICK;
uart->baudrate = UHF_UART_DEFAULT_BAUDRATE;
// expansion_disable();
if(uart->init_by_app) {
FURI_LOG_E("UHF_UART", "UHF UART INIT BY APP");
furi_hal_serial_init(uart->handle, uart->baudrate);
} else {
FURI_LOG_E("UHF_UART", "UHF UART INIT BY HAL");
}
// expansion_disable -> is done at app start already
furi_hal_serial_init(uart->handle, uart->baudrate);
uart->buffer = uhf_buffer_alloc(UHF_UART_RX_BUFFER_SIZE);
// uart->thread = furi_thread_alloc_ex("UHFUartWorker", UHF_UART_WORKER_STACK_SIZE, uhf_uart_worker_callback, uart);
// furi_thread_start(uart->thread);
Expand All @@ -86,11 +80,11 @@ void uhf_uart_free(UHFUart* uart) {
// furi_thread_join(uart->thread);
// furi_thread_free(uart->thread);
// furi_stream_buffer_free(uart->rx_buff_stream);
uhf_buffer_free(uart->buffer);
if(uart->init_by_app) {
furi_hal_serial_deinit(uart->handle);
}
furi_hal_serial_async_rx_stop(uart->handle);
furi_hal_serial_deinit(uart->handle);
furi_hal_serial_control_release(uart->handle);

uhf_buffer_free(uart->buffer);
free(uart);
}

Expand Down
1 change: 0 additions & 1 deletion non_catalog_apps/uhf_rfid/uhf_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ typedef struct {
CallbackFunction callback;
Buffer* buffer;
uint32_t baudrate;
bool init_by_app;
void* ctx;
volatile int tick;
} UHFUart;
Expand Down
1 change: 1 addition & 0 deletions non_catalog_apps/wifi-map/wifi_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ static WiFiMapApp* uart_echo_app_alloc() {
static void uart_echo_app_free(WiFiMapApp* app) {
furi_assert(app);

furi_hal_serial_async_rx_stop(app->serial_handle);
furi_hal_serial_deinit(app->serial_handle);
furi_hal_serial_control_release(app->serial_handle);

Expand Down
7 changes: 4 additions & 3 deletions non_catalog_apps/wifi_deauther/wifi_deauther_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ WifideautherUart* wifi_deauther_uart_init(WifideautherApp* app) {
void wifi_deauther_uart_free(WifideautherUart* uart) {
furi_assert(uart);

furi_hal_serial_async_rx_stop(uart->serial_handle);
furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtStop);
furi_thread_join(uart->rx_thread);
furi_thread_free(uart->rx_thread);

furi_hal_serial_deinit(uart->serial_handle);
furi_hal_serial_control_release(uart->serial_handle);

free(uart);
}

0 comments on commit 6f19c6d

Please sign in to comment.