diff --git a/firmware/console/connector_uart_dma.cpp b/firmware/console/connector_uart_dma.cpp index b1feb4c310..5767a51e72 100644 --- a/firmware/console/connector_uart_dma.cpp +++ b/firmware/console/connector_uart_dma.cpp @@ -5,16 +5,20 @@ * @author Andrey Belomutskiy, (c) 2012-2020 */ +#include "connector_uart_dma.h" + #if TS_UART_DMA_MODE || PRIMARY_UART_DMA_MODE +EXTERN_CONFIG; + // Async. FIFO buffer takes some RAM... uart_dma_s tsUartDma; /* Common function for all DMA-UART IRQ handlers. */ -static void tsCopyDataFromDMA() { +static void tsCopyDataFromDMA(UARTDriver *uartp) { chSysLockFromISR(); // get 0-based DMA buffer position - int dmaPos = TS_DMA_BUFFER_SIZE - dmaStreamGetTransactionSize(TS_UART_DEVICE->dmarx); + int dmaPos = TS_DMA_BUFFER_SIZE - dmaStreamGetTransactionSize(uartp->dmarx); // if the position is wrapped (circular DMA-mode enabled) if (dmaPos < tsUartDma.readPos) dmaPos += TS_DMA_BUFFER_SIZE; @@ -35,13 +39,13 @@ static void tsCopyDataFromDMA() { static void tsRxIRQHalfHandler(UARTDriver *uartp, uartflags_t full) { UNUSED(uartp); UNUSED(full); - tsCopyDataFromDMA(); + tsCopyDataFromDMA(uartp); } /* This handler is called right after the UART receiver has finished its work. */ static void tsRxIRQIdleHandler(UARTDriver *uartp) { UNUSED(uartp); - tsCopyDataFromDMA(); + tsCopyDataFromDMA(uartp); } /* Note: This structure is modified from the default ChibiOS layout! */ @@ -58,7 +62,7 @@ void startUartDmaConnector(UARTDriver *uartp DECLARE_CONFIG_PARAMETER_SUFFIX) { // start DMA driver tsDmaUartConfig.speed = CONFIG(tunerStudioSerialSpeed); - uartStart(TS_UART_DEVICE, &tsDmaUartConfig); + uartStart(uartp, &tsDmaUartConfig); // start continuous DMA transfer using our circular buffer tsUartDma.readPos = 0; diff --git a/firmware/console/connector_uart_dma.h b/firmware/console/connector_uart_dma.h index 62d112e17f..271952b799 100644 --- a/firmware/console/connector_uart_dma.h +++ b/firmware/console/connector_uart_dma.h @@ -7,6 +7,7 @@ #pragma once #include "global.h" +#include "engine_configuration.h" // See uart_dma_s #define TS_FIFO_BUFFER_SIZE (BLOCKING_FACTOR + 30) diff --git a/firmware/console/console_io.cpp b/firmware/console/console_io.cpp index c55734a80a..b73e0fdf3a 100644 --- a/firmware/console/console_io.cpp +++ b/firmware/console/console_io.cpp @@ -38,6 +38,7 @@ #include "console_io.h" #include "os_util.h" #include "tunerstudio.h" +#include "connector_uart_dma.h" #if EFI_SIMULATOR #include "rusEfiFunctionalTest.h" @@ -232,7 +233,7 @@ BaseChannel * getConsoleChannel(void) { #if HAL_USE_SERIAL_USB return (BaseChannel *) &CONSOLE_USB_DEVICE; #else - return NULL; + return nullptr; #endif /* HAL_USE_SERIAL_USB */ } @@ -250,7 +251,10 @@ static THD_FUNCTION(consoleThreadEntryPoint, arg) { (void) arg; chRegSetThreadName("console thread"); +#if !PRIMARY_UART_DMA_MODE primaryChannel.channel = (BaseChannel *) getConsoleChannel(); +#endif + if (primaryChannel.channel != NULL) { #if EFI_TUNER_STUDIO runBinaryProtocolLoop(&primaryChannel); @@ -283,7 +287,11 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p) #endif -#if (defined(EFI_CONSOLE_SERIAL_DEVICE) && ! EFI_SIMULATOR) +#if (defined(CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR) + primaryChannel.uartp = CONSOLE_UART_DEVICE; + startUartDmaConnector(primaryChannel.uartp PASS_CONFIG_PARAMETER_SUFFIX); + +#elif (defined(EFI_CONSOLE_SERIAL_DEVICE) && ! EFI_SIMULATOR) /* * Activates the serial * it is important to set 'NONE' as flow control! in terminal application on the PC diff --git a/firmware/console/eficonsole.cpp b/firmware/console/eficonsole.cpp index 4f1d101a82..3d01e95818 100644 --- a/firmware/console/eficonsole.cpp +++ b/firmware/console/eficonsole.cpp @@ -169,9 +169,13 @@ void print(const char *format, ...) { if (!isCommandLineConsoleReady()) { return; } + BaseSequentialStream * channel = (BaseSequentialStream*) getConsoleChannel(); + if (channel == nullptr) { + return; + } va_list ap; va_start(ap, format); - chvprintf((BaseSequentialStream*) getConsoleChannel(), format, ap); + chvprintf(channel, format, ap); va_end(ap); #else UNUSED(format);