Expose console over serial port for H7 proc (#3578)

This way you can use the console/TunerStudio with the ST-Link

In the process, combine TS_PRIMARY_UART and TS_PRIMARY_SERIAL into TS_PRIMARY_PORT, to make UART vs
SERIAL selection more robus.  Ditto for TS_SECONDARY_*.  Also change use of TS_NO_PRIMARY to be #if
not #ifdef, so that it can be properly set as a compile flag and not be overwritten by various
header files.
This commit is contained in:
Scott Smith 2021-11-19 21:39:08 -08:00 committed by GitHub
parent fcc2b780e9
commit 1fe26f55fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 76 additions and 60 deletions

View File

@ -7,7 +7,7 @@
#include "dfu.h"
// Communication vars
static UartTsChannel blTsChannel(TS_PRIMARY_UART);
static UartTsChannel blTsChannel(TS_PRIMARY_PORT);
static uint8_t buffer[DFU_BUFFER_SIZE];
// Use short timeout for the first data packet, and normal timeout for the rest
static int sr5Timeout = DFU_SR5_TIMEOUT_FIRST;

View File

@ -11,7 +11,7 @@ DDEFS += -DFIRMWARE_ID=\"atlas\" -DDEFAULT_ENGINE_TYPE=MINIMAL_PINS
# DEFS += -DEFI_SOFTWARE_KNOCK=TRUE
# disable hardware serial ports on H7
# DDEFS += -DTS_NO_PRIMARY -DTS_NO_SECONDARY
# DDEFS += -DTS_NO_PRIMARY=1 -DTS_NO_SECONDARY=1
# We are running on Atlas hardware!
DDEFS += -DHW_ATLAS=1

View File

@ -279,16 +279,13 @@
*/
#define EFI_USE_UART_DMA FALSE
#undef TS_SECONDARY_UART
#undef TS_SECONDARY_SERIAL
// todo: add CAN support
//#define TS_CAN_DEVICE CAND1
#define TS_CAN_AF PAL_MODE_ALTERNATIVE_CAN
#define TS_CAN_DEVICE_SHORT_PACKETS_IN_ONE_FRAME
#undef TS_PRIMARY_SERIAL
#undef TS_PRIMARY_UART
#undef TS_PRIMARY_PORT
#undef TS_SECONDARY_PORT
#define EFI_USB_SERIAL TRUE
#define EFI_CONSOLE_USB_DEVICE SDU1

View File

@ -31,7 +31,7 @@ DDEFS += -DEFI_ICU_INPUTS=FALSE -DHAL_TRIGGER_USE_PAL=TRUE
DDEFS += -DEFI_LOGIC_ANALYZER=FALSE
# Enable serial pins on expansion header
DDEFS += -DEFI_CONSOLE_TX_BRAIN_PIN=GPIOD_6 -DEFI_CONSOLE_RX_BRAIN_PIN=GPIOD_5 -DTS_PRIMARY_UART=UARTD2 -DSTM32_UART_USE_USART2=1
DDEFS += -DEFI_CONSOLE_TX_BRAIN_PIN=GPIOD_6 -DEFI_CONSOLE_RX_BRAIN_PIN=GPIOD_5 -DTS_PRIMARY_PORT=UARTD2 -DSTM32_UART_USE_USART2=1
# We are running on Hellen-One hardware!
DDEFS += -DHW_HELLEN=1

View File

@ -22,7 +22,7 @@ DDEFS += -DLED_WARNING_BRAIN_PIN_MODE=INVERTED_OUTPUT
DDEFS += -DLED_COMMUNICATION_BRAIN_PIN_MODE=INVERTED_OUTPUT
# Disable serial ports on this board as UART3 causes a DMA conflict with the SD card
DDEFS += -DTS_NO_PRIMARY -DTS_NO_SECONDARY
DDEFS += -DTS_NO_PRIMARY=1 -DTS_NO_SECONDARY=1
# Add them all together
DDEFS += -DEFI_USE_OSC=TRUE -DFIRMWARE_ID=\"hellen121nissan\" $(DEFAULT_ENGINE_TYPE) $(LED_CRITICAL_ERROR_BRAIN_PIN) $(LED_COMMUNICATION_BRAIN_PIN)

View File

@ -22,7 +22,7 @@ DDEFS += -DLED_WARNING_BRAIN_PIN_MODE=INVERTED_OUTPUT
DDEFS += -DLED_COMMUNICATION_BRAIN_PIN_MODE=INVERTED_OUTPUT
# Disable serial ports on this board as UART3 causes a DMA conflict with the SD card
DDEFS += -DTS_NO_PRIMARY -DTS_NO_SECONDARY
DDEFS += -DTS_NO_PRIMARY=1 -DTS_NO_SECONDARY=1
# Add them all together
DDEFS += -DEFI_USE_OSC=TRUE -DFIRMWARE_ID=\"hellen121vag\" $(DEFAULT_ENGINE_TYPE) $(LED_CRITICAL_ERROR_BRAIN_PIN) $(LED_COMMUNICATION_BRAIN_PIN)

View File

@ -22,7 +22,7 @@ DDEFS += -DLED_WARNING_BRAIN_PIN_MODE=INVERTED_OUTPUT
DDEFS += -DLED_COMMUNICATION_BRAIN_PIN_MODE=INVERTED_OUTPUT
# Disable serial ports on this board as UART3 causes a DMA conflict with the SD card
DDEFS += -DTS_NO_PRIMARY -DTS_NO_SECONDARY
DDEFS += -DTS_NO_PRIMARY=1 -DTS_NO_SECONDARY=1
# Add them all together
DDEFS += -DEFI_USE_OSC=TRUE -DFIRMWARE_ID=\"hellen128\" $(DEFAULT_ENGINE_TYPE) $(LED_CRITICAL_ERROR_BRAIN_PIN) $(LED_COMMUNICATION_BRAIN_PIN)

View File

@ -22,7 +22,7 @@ DDEFS += -DLED_WARNING_BRAIN_PIN_MODE=INVERTED_OUTPUT
DDEFS += -DLED_COMMUNICATION_BRAIN_PIN_MODE=INVERTED_OUTPUT
# Disable serial ports on this board as UART3 causes a DMA conflict with the SD card
DDEFS += -DTS_NO_PRIMARY -DTS_NO_SECONDARY
DDEFS += -DTS_NO_PRIMARY=1 -DTS_NO_SECONDARY=1
# Add them all together
DDEFS += -DEFI_USE_OSC=TRUE -DFIRMWARE_ID=\"hellen154hyundai\" $(DEFAULT_ENGINE_TYPE) $(LED_CRITICAL_ERROR_BRAIN_PIN) $(LED_COMMUNICATION_BRAIN_PIN)

View File

@ -22,7 +22,7 @@ DDEFS += -DLED_WARNING_BRAIN_PIN_MODE=INVERTED_OUTPUT
DDEFS += -DLED_COMMUNICATION_BRAIN_PIN_MODE=INVERTED_OUTPUT
# Disable serial ports on this board as UART3 causes a DMA conflict with the SD card
DDEFS += -DTS_NO_PRIMARY -DTS_NO_SECONDARY
DDEFS += -DTS_NO_PRIMARY=1 -DTS_NO_SECONDARY=1
# Add them all together
DDEFS += -DEFI_USE_OSC=TRUE -DFIRMWARE_ID=\"hellenNA6\" $(DEFAULT_ENGINE_TYPE) $(LED_CRITICAL_ERROR_BRAIN_PIN) $(LED_COMMUNICATION_BRAIN_PIN)

View File

@ -22,7 +22,7 @@ DDEFS += -DLED_WARNING_BRAIN_PIN_MODE=INVERTED_OUTPUT
DDEFS += -DLED_COMMUNICATION_BRAIN_PIN_MODE=INVERTED_OUTPUT
# Disable serial ports on this board as UART3 causes a DMA conflict with the SD card
DDEFS += -DTS_NO_PRIMARY -DTS_NO_SECONDARY
DDEFS += -DTS_NO_PRIMARY=1 -DTS_NO_SECONDARY=1
# Add them all together
DDEFS += -DEFI_USE_OSC=TRUE -DFIRMWARE_ID=\"hellen72\" $(DEFAULT_ENGINE_TYPE) $(LED_CRITICAL_ERROR_BRAIN_PIN) $(LED_COMMUNICATION_BRAIN_PIN)

View File

@ -25,7 +25,7 @@ DDEFS += -DLED_WARNING_BRAIN_PIN_MODE=INVERTED_OUTPUT
DDEFS += -DLED_COMMUNICATION_BRAIN_PIN_MODE=INVERTED_OUTPUT
# Disable serial ports on this board as UART3 causes a DMA conflict with the SD card
DDEFS += -DTS_NO_PRIMARY -DTS_NO_SECONDARY
DDEFS += -DTS_NO_PRIMARY=1 -DTS_NO_SECONDARY=1
# Add them all together
DDEFS += -DEFI_USE_OSC=TRUE -DFIRMWARE_ID=\"hellen81\" $(DEFAULT_ENGINE_TYPE) $(LED_CRITICAL_ERROR_BRAIN_PIN) $(LED_COMMUNICATION_BRAIN_PIN)

View File

@ -22,7 +22,7 @@ DDEFS += -DLED_WARNING_BRAIN_PIN_MODE=INVERTED_OUTPUT
DDEFS += -DLED_COMMUNICATION_BRAIN_PIN_MODE=INVERTED_OUTPUT
# Disable serial ports on this board as UART3 causes a DMA conflict with the SD card
DDEFS += -DTS_NO_PRIMARY -DTS_NO_SECONDARY
DDEFS += -DTS_NO_PRIMARY=1 -DTS_NO_SECONDARY=1
# Add them all together
DDEFS += -DEFI_USE_OSC=TRUE -DFIRMWARE_ID=\"hellen88bmw\" $(DEFAULT_ENGINE_TYPE) $(LED_CRITICAL_ERROR_BRAIN_PIN) $(LED_COMMUNICATION_BRAIN_PIN)

View File

@ -268,8 +268,8 @@
*/
#define EFI_USE_UART_DMA FALSE
#define TS_PRIMARY_UART UARTD2
#undef TS_SECONDARY_UART
#define TS_PRIMARY_PORT UARTD2
#undef TS_SECONDARY_PORT
#define EFI_CONSOLE_TX_BRAIN_PIN GPIOA_10
#define EFI_CONSOLE_RX_BRAIN_PIN GPIOA_11
@ -360,7 +360,7 @@
if (__debugEnabled) { \
extern char __debugBuffer[80]; \
chsnprintf(__debugBuffer, sizeof(__debugBuffer), fmt, ##__VA_ARGS__); \
uart_lld_blocking_send(TS_PRIMARY_UART, strlen(__debugBuffer), (void *)__debugBuffer); \
uart_lld_blocking_send(TS_PRIMARY_PORT, strlen(__debugBuffer), (void *)__debugBuffer); \
} \
}

View File

@ -1,5 +1,11 @@
# List of all the board related files.
DDEFS = -DTS_NO_PRIMARY=0 \
-DTS_PRIMARY_PORT=SD3 \
-DEFI_CONSOLE_TX_BRAIN_PIN=GPIOD_8 \
-DEFI_CONSOLE_RX_BRAIN_PIN=GPIOD_9 \
# Shared variables
ALLCPPSRC += $(PROJECT_DIR)/config/boards/nucleo_h743/board_configuration.cpp

View File

@ -34,15 +34,13 @@
#define ADC_CHANNEL_VREF ADC_CHANNEL_IN14
#undef TS_PRIMARY_SERIAL
#undef TS_PRIMARY_UART
#define TS_PRIMARY_UART UARTD4
#undef TS_PRIMARY_PORT
#define TS_PRIMARY_PORT UARTD4
#undef EFI_UART_GPS
#define EFI_UART_GPS FALSE
#undef TS_SECONDARY_UART
#undef TS_SECONDARY_SERIAL
#undef TS_SECONDARY_PORT
#undef EFI_BLUETOOTH_SETUP
#define EFI_BLUETOOTH_SETUP TRUE

View File

@ -32,7 +32,7 @@ endif
ifeq ($(PROJECT_CPU),ARCH_STM32F4)
# Hardware serial port on UART 2 -> PD5/PD6
DDEFS += -DSTM32_UART_USE_USART2=TRUE
DDEFS += -DTS_PRIMARY_UART=UARTD2
DDEFS += -DTS_PRIMARY_PORT=UARTD2
DDEFS += -DEFI_CONSOLE_TX_BRAIN_PIN=GPIOD_5 -DEFI_CONSOLE_RX_BRAIN_PIN=GPIOD_6
endif

View File

@ -21,13 +21,11 @@
#define LED_RUNING_BRAIN_PIN_MODE INVERTED_OUTPUT
/* debug console */
#undef TS_PRIMARY_SERIAL
#undef TS_PRIMARY_UART
#define TS_PRIMARY_SERIAL SD1
#undef TS_PRIMARY_PORT
#define TS_PRIMARY_PORT SD1
// no secondary channel
#undef TS_SECONDARY_UART
#undef TS_SECONDARY_SERIAL
#undef TS_SECONDARY_PORT
/* Knock detection */
#undef EFI_HIP_9011
@ -94,7 +92,7 @@
#undef SERIAL_SPEED
#define SERIAL_SPEED 115200
#ifdef TS_PRIMARY_SERIAL
#ifdef TS_PRIMARY_PORT
#undef EFI_CONSOLE_TX_PORT
#define EFI_CONSOLE_TX_PORT GPIOA
#undef EFI_CONSOLE_TX_PIN

View File

@ -360,11 +360,11 @@
#define EFI_USE_UART_DMA TRUE
#endif
#ifndef TS_PRIMARY_UART
#define TS_PRIMARY_UART UARTD3
#ifndef TS_PRIMARY_PORT
#define TS_PRIMARY_PORT UARTD3
#endif
#undef TS_SECONDARY_UART
#undef TS_SECONDARY_PORT
#define AUX_SERIAL_DEVICE (&SD6)

View File

@ -37,8 +37,10 @@
#define EFI_USE_UART_DMA FALSE
// UART driver not implemented on F7
#define TS_NO_PRIMARY
#define TS_NO_SECONDARY
#ifndef TS_NO_PRIMARY
#define TS_NO_PRIMARY 1
#endif
#define TS_NO_SECONDARY 1
#define AUX_SERIAL_DEVICE (&SD6)

View File

@ -9,13 +9,13 @@
#pragma once
#include "global.h"
#if (!defined(TS_NO_PRIMARY) && (defined(TS_PRIMARY_UART) || defined(TS_PRIMARY_SERIAL)))
#if (!TS_NO_PRIMARY && defined(TS_PRIMARY_PORT))
#define HAS_PRIMARY true
#else
#define HAS_PRIMARY false
#endif
#if (!defined(TS_NO_SECONDARY) && (defined(TS_SECONDARY_UART) || defined(TS_SECONDARY_SERIAL)))
#if (!TS_NO_SECONDARY && defined(TS_SECONDARY_PORT))
#define HAS_SECONDARY true
#else
#define HAS_SECONDARY false

View File

@ -11,16 +11,29 @@
#include "tunerstudio_io.h"
#include "connector_uart_dma.h"
// These may not be defined due to the HAL, but they're necessary for the compiler to do it's magic
class UARTDriver;
class UartDmaTsChannel;
class UartTsChannel;
class SerialTsChannel;
#if HAS_PRIMARY
#ifdef TS_PRIMARY_UART
#if EFI_USE_UART_DMA
UartDmaTsChannel primaryChannel(TS_PRIMARY_UART);
#else
UartTsChannel primaryChannel(TS_PRIMARY_UART);
#endif
#elif defined(TS_PRIMARY_SERIAL)
SerialTsChannel primaryChannel(TS_PRIMARY_SERIAL);
#endif
#ifdef TS_PRIMARY_PORT
// We want to instantiate the correct channel type depending on what type of serial port we're
// using. ChibiOS supports two - UART and Serial. We compare the type of the port we're given
// against UartDriver and decide whether to instantiate a UART TS Channel or a Serial version. The
// UART is further subdivided into two depending whether we support DMA or not. We use the right
// combination of std::conditional, std::is_same, and #if to get what we want.
std::conditional_t<
std::is_same_v<decltype(TS_PRIMARY_PORT), UARTDriver>,
#if EFI_USE_UART_DMA
UartDmaTsChannel,
#else // EFI_USE_UART_DMA
UartTsChannel,
#endif // EFI_USE_UART_DMA
SerialTsChannel> primaryChannel(TS_PRIMARY_PORT);
#endif // TS_PRIMARY_PORT
struct PrimaryChannelThread : public TunerstudioThread {
PrimaryChannelThread() : TunerstudioThread("Primary TS Channel") { }
@ -41,15 +54,17 @@
#endif // HAS_PRIMARY
#if HAS_SECONDARY
#ifdef TS_SECONDARY_UART
#if EFI_USE_UART_DMA
UartDmaTsChannel secondaryChannel(TS_SECONDARY_UART);
#else
UartTsChannel secondaryChannel(TS_SECONDARY_UART);
#endif
#elif defined(TS_SECONDARY_SERIAL)
SerialTsChannel secondaryChannel(TS_SECONDARY_SERIAL);
#endif
#ifdef TS_SECONDARY_PORT
std::conditional_t<
std::is_same_v<decltype(TS_SECONDARY_PORT), UARTDriver>,
#if EFI_USE_UART_DMA
UartDmaTsChannel,
#else // EFI_USE_UART_DMA
UartTsChannel,
#endif // EFI_USE_UART_DMA
SerialTsChannel> secondaryChannel(TS_SECONDARY_PORT);
#endif // TS_SECONDARY_PORT
struct SecondaryChannelThread : public TunerstudioThread {
SecondaryChannelThread() : TunerstudioThread("Secondary TS Channel") { }

View File

@ -114,7 +114,7 @@
*/
#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
/* Configured in efifeatures.h */
#if defined(TS_PRIMARY_UART) || defined(TS_PRIMARY_SERIAL)
#if defined(TS_PRIMARY_PORT)
#define HAL_USE_UART TRUE
#else
#define HAL_USE_UART FALSE

View File

@ -121,7 +121,7 @@
*/
#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
/* Configured in efifeatures.h */
#if defined(TS_PRIMARY_UART) || defined(TS_PRIMARY_SERIAL)
#if defined(TS_PRIMARY_PORT)
#define HAL_USE_UART TRUE
#else
#define HAL_USE_UART FALSE
@ -200,7 +200,7 @@
*/
#if !defined(UART_USE_WAIT) || defined(__DOXYGEN__)
/* Configured in efifeatures.h */
#if defined(TS_PRIMARY_UART) || defined(TS_PRIMARY_SERIAL)
#if defined(TS_PRIMARY_PORT)
#define UART_USE_WAIT TRUE
#else
#define UART_USE_WAIT FALSE

View File

@ -385,7 +385,7 @@
*/
#define STM32_SERIAL_USE_USART1 TRUE
#define STM32_SERIAL_USE_USART2 TRUE
#define STM32_SERIAL_USE_USART3 FALSE
#define STM32_SERIAL_USE_USART3 TRUE
#define STM32_SERIAL_USE_UART4 FALSE
#define STM32_SERIAL_USE_UART5 FALSE
#define STM32_SERIAL_USE_USART6 TRUE