-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uart receiving data via dma and selecting speed and UART for logging output #3078
Closed
Closed
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e332b46
furi_hal: add selecting speed and USART for logging output
Skorpionm 5cb1954
furi_hal: fix syntax
Skorpionm d58adbd
Furi_Hal: add DMA RX in LPUART
Skorpionm 5ed59d9
Furi_Hal: add LPUART receiving data via dma
Skorpionm 94efc86
Furi_Hal: add USART1 receiving data via dma
Skorpionm bd9c5bb
usb_uart_bridge: add Rx DMA
Skorpionm 7d8aa41
furi_hal_usart: delete comments
Skorpionm 65a16d9
API: api_symbols F18
Skorpionm 83927af
Merge branch 'dev' into skorp/furi_hal_usart_console
Skorpionm 52dd414
furi_hal_uart: fix syntax
Skorpionm 0112169
Merge branch 'skorp/furi_hal_usart_console' of github.com:Flipper-Zer…
Skorpionm ee79a30
Merge branch 'dev' into skorp/furi_hal_usart_console
Skorpionm 0e0cbc7
API: fix api_symbols version
Skorpionm 334e869
Merge branch 'dev' into skorp/furi_hal_usart_console
Skorpionm 83d6496
furi_hal_uart: add description of functions
Skorpionm a85aa9e
free-dap: delete submodule
Skorpionm 99b6556
furi_hal: fix uart callback
Skorpionm e2be364
Merge branch 'dev' into skorp/furi_hal_usart_console
skotopes 4ed9b97
FuriHal: remove unused includes
skotopes bb430bc
FuriHal: cleanup UART API naming
skotopes 6e88845
Format sources and fix uart api usae by usb uart bridge
skotopes 8bc91ef
FuriHal: more naming chnages in uart api
skotopes bc22992
FuriHal: fix comments
Skorpionm 6c9cfbc
Merge remote-tracking branch 'origin/dev' into skorp/furi_hal_usart_c…
skotopes 6bee333
UsbUartBridge: slightly more readable usb_uart_on_irq_rx_dma_cb routi…
skotopes a706d21
FuriHal: cleaup uart and console code
skotopes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,17 +24,18 @@ typedef enum { | |
|
||
WorkerEvtTxStop = (1 << 2), | ||
WorkerEvtCdcRx = (1 << 3), | ||
WorkerEvtCdcTxComplete = (1 << 4), | ||
|
||
WorkerEvtCfgChange = (1 << 4), | ||
WorkerEvtCfgChange = (1 << 5), | ||
|
||
WorkerEvtLineCfgSet = (1 << 5), | ||
WorkerEvtCtrlLineSet = (1 << 6), | ||
WorkerEvtLineCfgSet = (1 << 6), | ||
WorkerEvtCtrlLineSet = (1 << 7), | ||
|
||
} WorkerEvtFlags; | ||
|
||
#define WORKER_ALL_RX_EVENTS \ | ||
(WorkerEvtStop | WorkerEvtRxDone | WorkerEvtCfgChange | WorkerEvtLineCfgSet | \ | ||
WorkerEvtCtrlLineSet) | ||
WorkerEvtCtrlLineSet | WorkerEvtCdcTxComplete) | ||
#define WORKER_ALL_TX_EVENTS (WorkerEvtTxStop | WorkerEvtCdcRx) | ||
|
||
struct UsbUartBridge { | ||
|
@@ -75,13 +76,18 @@ static const CdcCallbacks cdc_cb = { | |
|
||
static int32_t usb_uart_tx_thread(void* context); | ||
|
||
static void usb_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) { | ||
static void usb_uart_on_irq_rx_dma_cb( | ||
FuriHalUartDmaEvent ev, | ||
FuriHalUartId id_uart, | ||
size_t data_len, | ||
void* context) { | ||
UsbUartBridge* usb_uart = (UsbUartBridge*)context; | ||
|
||
if(ev == UartIrqEventRXNE) { | ||
furi_stream_buffer_send(usb_uart->rx_stream, &data, 1, 0); | ||
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtRxDone); | ||
} | ||
UNUSED(ev); | ||
uint8_t data[data_len]; | ||
furi_hal_uart_dma_rx(id_uart, data, data_len); | ||
furi_stream_buffer_send(usb_uart->rx_stream, data, data_len, 100); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no timeouts in interrupts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix |
||
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtRxDone); | ||
} | ||
|
||
static void usb_uart_vcp_init(UsbUartBridge* usb_uart, uint8_t vcp_ch) { | ||
|
@@ -112,20 +118,17 @@ static void usb_uart_vcp_deinit(UsbUartBridge* usb_uart, uint8_t vcp_ch) { | |
|
||
static void usb_uart_serial_init(UsbUartBridge* usb_uart, uint8_t uart_ch) { | ||
if(uart_ch == FuriHalUartIdUSART1) { | ||
furi_hal_console_disable(); | ||
} else if(uart_ch == FuriHalUartIdLPUART1) { | ||
furi_hal_uart_init(uart_ch, 115200); | ||
furi_hal_console_deinit(); | ||
} | ||
furi_hal_uart_set_irq_cb(uart_ch, usb_uart_on_irq_cb, usb_uart); | ||
furi_hal_uart_init(uart_ch, 115200); | ||
furi_hal_uart_dma_start(uart_ch, usb_uart_on_irq_rx_dma_cb, usb_uart); | ||
} | ||
|
||
static void usb_uart_serial_deinit(UsbUartBridge* usb_uart, uint8_t uart_ch) { | ||
UNUSED(usb_uart); | ||
furi_hal_uart_set_irq_cb(uart_ch, NULL, NULL); | ||
furi_hal_uart_deinit(uart_ch); | ||
if(uart_ch == FuriHalUartIdUSART1) | ||
furi_hal_console_enable(); | ||
else if(uart_ch == FuriHalUartIdLPUART1) | ||
furi_hal_uart_deinit(uart_ch); | ||
furi_hal_console_init(FuriHalUartIdUSART1, CONSOLE_BAUDRATE); | ||
} | ||
|
||
static void usb_uart_set_baudrate(UsbUartBridge* usb_uart, uint32_t baudrate) { | ||
|
@@ -186,7 +189,7 @@ static int32_t usb_uart_worker(void* context) { | |
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, FuriFlagWaitAny, FuriWaitForever); | ||
furi_check(!(events & FuriFlagError)); | ||
if(events & WorkerEvtStop) break; | ||
if(events & WorkerEvtRxDone) { | ||
if(events & WorkerEvtRxDone || events & WorkerEvtCdcTxComplete) { | ||
size_t len = furi_stream_buffer_receive( | ||
usb_uart->rx_stream, usb_uart->rx_buf, USB_CDC_PKT_LEN, 0); | ||
if(len > 0) { | ||
|
@@ -196,8 +199,6 @@ static int32_t usb_uart_worker(void* context) { | |
furi_mutex_acquire(usb_uart->usb_mutex, FuriWaitForever) == FuriStatusOk); | ||
furi_hal_cdc_send(usb_uart->cfg.vcp_ch, usb_uart->rx_buf, len); | ||
furi_check(furi_mutex_release(usb_uart->usb_mutex) == FuriStatusOk); | ||
} else { | ||
furi_stream_buffer_reset(usb_uart->rx_stream); | ||
} | ||
} | ||
} | ||
|
@@ -310,6 +311,7 @@ static int32_t usb_uart_tx_thread(void* context) { | |
static void vcp_on_cdc_tx_complete(void* context) { | ||
UsbUartBridge* usb_uart = (UsbUartBridge*)context; | ||
furi_semaphore_release(usb_uart->tx_sem); | ||
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtCdcTxComplete); | ||
} | ||
|
||
static void vcp_on_cdc_rx(void* context) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't allocate data on stack with variable passed from outside
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix