From b80806182ff64b17b8ffcb8e4dd12e064d6d6bc9 Mon Sep 17 00:00:00 2001 From: andreika-git Date: Fri, 29 Mar 2019 16:29:01 +0200 Subject: [PATCH] More portability & small fixes (#719) * Use hw_stm32.mk * Fix bootloader * Use more common hw_ports.mk filename instead of hw_stm32.mk * More CPU compatibility for Makefile * TS_UART_MODE & rename TS_SERIAL_UART_DEVICE->TS_SERIAL_DEVICE * Move lockAnyContext()/unlockAnyContext() to rfiutil.c * USE_FATFS * EFI_LCD * Less compilation errors * STATUS_LOGGING_BUFFER_SIZE & SETTINGS_LOGGING_BUFFER_SIZE * EFI_ALTERNATOR_CONTROL, EFI_SERVO, EFI_DISABLE_CONSOLE_ACTIONS * #ifndef PWM_PHASE_MAX_COUNT & more flexible GPIO inside portname() * merge * EFI_ALTERNATOR_CONTROL, EFI_ELECTRONIC_THROTTLE_BODY --- firmware/Makefile | 26 +++++++++----- firmware/compile_and_program.bat | 1 - .../boards/prometheus/board_configuration.cpp | 12 +++---- .../config/boards/prometheus/efifeatures.h | 11 +++--- firmware/config/boards/prometheus/halconf.h | 2 +- firmware/config/boards/prometheus/mcuconf.h | 2 +- firmware/config/engines/custom_engine.cpp | 4 +-- firmware/config/engines/mazda_miata.cpp | 1 + firmware/config/engines/mitsubishi.cpp | 1 + firmware/config/stm32f0egt/efifeatures.h | 2 +- firmware/config/stm32f4ems/efifeatures.h | 10 ++++-- firmware/config/stm32f4ems/halconf.h | 4 +-- firmware/config/stm32f7ems/efifeatures.h | 13 ++++--- firmware/config/stm32f7ems/halconf.h | 4 +-- firmware/console/binary/tunerstudio_io.cpp | 36 +++++++++++++------ firmware/console/console_io.cpp | 35 +----------------- firmware/console/status_loop.cpp | 9 ++++- .../controllers/algo/engine_configuration.cpp | 8 ++--- firmware/controllers/core/efi_wave.h | 2 ++ firmware/controllers/settings.cpp | 10 ++++-- firmware/controllers/system/efi_gpio.cpp | 18 ++++++---- .../system/pwm_generator_logic.cpp | 1 + firmware/hw_layer/drivers/gpio/core.c | 2 +- firmware/hw_layer/hw_layer.mk | 5 ++- .../stm32f0/{hw_stm32.mk => hw_ports.mk} | 0 .../stm32f1/{hw_stm32.mk => hw_ports.mk} | 0 .../stm32f4/{hw_stm32.mk => hw_ports.mk} | 0 .../stm32f7/{hw_stm32.mk => hw_ports.mk} | 0 firmware/hw_layer/servo.cpp | 5 ++- firmware/rusefi.mk | 10 ++++++ firmware/util/cli_registry.cpp | 2 ++ firmware/util/rfiutil.c | 36 +++++++++++++++++++ hardware/rusefi_lib | 2 +- unit_tests/Makefile | 5 ++- 34 files changed, 175 insertions(+), 104 deletions(-) rename firmware/hw_layer/ports/stm32/stm32f0/{hw_stm32.mk => hw_ports.mk} (100%) rename firmware/hw_layer/ports/stm32/stm32f1/{hw_stm32.mk => hw_ports.mk} (100%) rename firmware/hw_layer/ports/stm32/stm32f4/{hw_stm32.mk => hw_ports.mk} (100%) rename firmware/hw_layer/ports/stm32/stm32f7/{hw_stm32.mk => hw_ports.mk} (100%) diff --git a/firmware/Makefile b/firmware/Makefile index e8a0987db5..318e6f5a5f 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -7,6 +7,13 @@ CHIBIOS = ChibiOS RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC RULESFILE = $(RULESPATH)/rules.mk +# Define project name here +PROJECT = rusefi +PROJECT_DIR = . + +# Imported source files and paths +CHIBIOS_CONTRIB = ChibiOS-Contrib + include rusefi.mk # by default EXTRA_PARAMS is empty and we create 'debug' version of the firmware with additional assertions and statistics @@ -69,6 +76,10 @@ ifeq ($(USE_BOOTLOADER),) USE_BOOTLOADER = no endif +ifeq ($(USE_FATFS),) + USE_FATFS = yes +endif + # # Build global options ############################################################################## @@ -108,28 +119,25 @@ MAKEFLAGS += ${NUMJOBS} # Project, sources and paths # -# Define project name here -PROJECT = rusefi -PROJECT_DIR = . - -# Imported source files and paths -CHIBIOS_CONTRIB = ChibiOS-Contrib - # Startup files. -include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/$(CPU_STARTUP) +include $(CPU_STARTUP_DIR) # HAL-OSAL files (optional). include $(CHIBIOS_CONTRIB)/os/hal/hal.mk -include $(CHIBIOS)/os/hal/ports/STM32/$(CPU_PLATFORM) +include $(CPU_PLATFORM_DIR) include $(CHIBIOS)/os/hal/osal/rt/osal.mk # RTOS files (optional). include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk +ifeq ($(USE_FATFS),yes) include $(CHIBIOS)/os/various/fatfs_bindings/fatfs.mk +endif include $(CHIBIOS)/os/various/cpp_wrappers/chcpp.mk include console/binary/tunerstudio.mk +ifeq ($(USE_FATFS),yes) include $(PROJECT_DIR)/ext/fatfs.mk +endif include $(PROJECT_DIR)/hw_layer/hw_layer.mk include $(PROJECT_DIR)/hw_layer/drivers/drivers.mk diff --git a/firmware/compile_and_program.bat b/firmware/compile_and_program.bat index a21b37b23d..d8e77af141 100644 --- a/firmware/compile_and_program.bat +++ b/firmware/compile_and_program.bat @@ -1,5 +1,4 @@ @echo off -rm -rf .dep/ rm -rf build\rusefi.hex rm -rf build\rusefi.bin diff --git a/firmware/config/boards/prometheus/board_configuration.cpp b/firmware/config/boards/prometheus/board_configuration.cpp index c166e493cb..4632a58c0c 100644 --- a/firmware/config/boards/prometheus/board_configuration.cpp +++ b/firmware/config/boards/prometheus/board_configuration.cpp @@ -229,18 +229,18 @@ void setBoardConfigurationOverrides(void) { boardConfiguration->is_enabled_spi_3 = true; boardConfiguration->spi1mosiPin = GPIOB_5; - engineConfiguration->spi1MosiMode = 0; // PAL_STM32_OTYPE_PUSHPULL + engineConfiguration->spi1MosiMode = PO_DEFAULT; // PAL_STM32_OTYPE_PUSHPULL boardConfiguration->spi1misoPin = GPIOB_4; - engineConfiguration->spi1MisoMode = 0; // PAL_STM32_OTYPE_PUSHPULL + engineConfiguration->spi1MisoMode = PO_DEFAULT; // PAL_STM32_OTYPE_PUSHPULL boardConfiguration->spi1sckPin = GPIOB_3; - engineConfiguration->spi1SckMode = 0; // PAL_STM32_OTYPE_PUSHPULL + engineConfiguration->spi1SckMode = PO_DEFAULT; // PAL_STM32_OTYPE_PUSHPULL boardConfiguration->spi3mosiPin = GPIOC_12; - engineConfiguration->spi3MosiMode = PAL_STM32_OTYPE_OPENDRAIN; // 4 + engineConfiguration->spi3MosiMode = PO_OPENDRAIN; // 4 boardConfiguration->spi3misoPin = GPIOC_11; - engineConfiguration->spi3MisoMode = PAL_STM32_PUPDR_PULLUP; // 32 + engineConfiguration->spi3MisoMode = PO_PULLUP; // 32 boardConfiguration->spi3sckPin = GPIOC_10; - engineConfiguration->spi3SckMode = PAL_STM32_OTYPE_OPENDRAIN; // 4 + engineConfiguration->spi3SckMode = PO_OPENDRAIN; // 4 engineConfiguration->hip9011SpiDevice = SPI_DEVICE_3; boardConfiguration->hip9011CsPin = is469 ? GPIOD_1 : GPIOD_2; diff --git a/firmware/config/boards/prometheus/efifeatures.h b/firmware/config/boards/prometheus/efifeatures.h index b5b21e4a93..41a77124cc 100644 --- a/firmware/config/boards/prometheus/efifeatures.h +++ b/firmware/config/boards/prometheus/efifeatures.h @@ -24,6 +24,9 @@ #undef EFI_HD44780_LCD #define EFI_HD44780_LCD FALSE +#undef EFI_LCD +#define EFI_LCD FALSE + #undef EFI_USB_SERIAL #define EFI_USB_SERIAL FALSE @@ -42,11 +45,11 @@ #undef TS_UART_DMA_MODE #define TS_UART_DMA_MODE TRUE -#undef TS_DMA_UART_DEVICE -#define TS_DMA_UART_DEVICE (&UARTD4) +#undef TS_UART_DEVICE +#define TS_UART_DEVICE (&UARTD4) -#undef TS_SERIAL_UART_DEVICE -#define TS_SERIAL_UART_DEVICE (&SD4) +#undef TS_SERIAL_DEVICE +#define TS_SERIAL_DEVICE (&SD4) #undef EFI_BLUETOOTH_SETUP #define EFI_BLUETOOTH_SETUP TRUE diff --git a/firmware/config/boards/prometheus/halconf.h b/firmware/config/boards/prometheus/halconf.h index ac4ae8e361..e4e1ead174 100644 --- a/firmware/config/boards/prometheus/halconf.h +++ b/firmware/config/boards/prometheus/halconf.h @@ -24,7 +24,7 @@ #define HAL_USE_SERIAL FALSE #undef HAL_USE_UART -#if TS_UART_DMA_MODE +#if (TS_UART_DMA_MODE || TS_UART_MODE) #define HAL_USE_UART TRUE #else #define HAL_USE_UART FALSE diff --git a/firmware/config/boards/prometheus/mcuconf.h b/firmware/config/boards/prometheus/mcuconf.h index f959416954..3f8c8d5cc7 100644 --- a/firmware/config/boards/prometheus/mcuconf.h +++ b/firmware/config/boards/prometheus/mcuconf.h @@ -43,7 +43,7 @@ #define STM32_SERIAL_USE_USART3 FALSE #undef STM32_SERIAL_USE_UART4 -#if TS_UART_DMA_MODE +#if (TS_UART_DMA_MODE || TS_UART_MODE) #define STM32_SERIAL_USE_UART4 FALSE #else #define STM32_SERIAL_USE_UART4 TRUE diff --git a/firmware/config/engines/custom_engine.cpp b/firmware/config/engines/custom_engine.cpp index 995fe22cbf..a286629ccd 100644 --- a/firmware/config/engines/custom_engine.cpp +++ b/firmware/config/engines/custom_engine.cpp @@ -283,12 +283,12 @@ void setEtbTestConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { CONFIGB(etb1.directionPin2) = GPIOC_9; CONFIGB(etb1.controlPin1) = GPIOE_14; -#if EFI_PROD_CODE || defined(__DOXYGEN__) +#if EFI_ELECTRONIC_THROTTLE_BODY || defined(__DOXYGEN__) setDefaultEtbParameters(PASS_ENGINE_PARAMETER_SIGNATURE); // values are above 100% since we have feedforward part of the total summation engineConfiguration->etb.minValue = -200; engineConfiguration->etb.maxValue = 200; -#endif +#endif /* EFI_ELECTRONIC_THROTTLE_BODY */ engineConfiguration->tpsAdcChannel = EFI_ADC_2; // PA2 engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_9; // PB1 diff --git a/firmware/config/engines/mazda_miata.cpp b/firmware/config/engines/mazda_miata.cpp index dcd02aca3e..16bb90220b 100644 --- a/firmware/config/engines/mazda_miata.cpp +++ b/firmware/config/engines/mazda_miata.cpp @@ -15,6 +15,7 @@ * @author Andrey Belomutskiy, (c) 2012-2018 */ +#include "global.h" #include "fsio_impl.h" #include "mazda_miata.h" #include "engine_math.h" diff --git a/firmware/config/engines/mitsubishi.cpp b/firmware/config/engines/mitsubishi.cpp index 5b66e2c7d6..6b0995abe5 100644 --- a/firmware/config/engines/mitsubishi.cpp +++ b/firmware/config/engines/mitsubishi.cpp @@ -9,6 +9,7 @@ * @author Andrey Belomutskiy, (c) 2012-2018 */ +#include "global.h" #include "fsio_impl.h" #include "mitsubishi.h" #include "allsensors.h" diff --git a/firmware/config/stm32f0egt/efifeatures.h b/firmware/config/stm32f0egt/efifeatures.h index 67feff44f0..050bb19c90 100644 --- a/firmware/config/stm32f0egt/efifeatures.h +++ b/firmware/config/stm32f0egt/efifeatures.h @@ -18,7 +18,7 @@ #define EFI_CONSOLE_UART_DEVICE (&SD1) -#define TS_SERIAL_UART_DEVICE (&SD3) +#define TS_SERIAL_DEVICE (&SD3) #define EFI_CONSOLE_TX_PORT GPIOC #define EFI_CONSOLE_TX_PIN 10 diff --git a/firmware/config/stm32f4ems/efifeatures.h b/firmware/config/stm32f4ems/efifeatures.h index be13acc428..b1585d729e 100644 --- a/firmware/config/stm32f4ems/efifeatures.h +++ b/firmware/config/stm32f4ems/efifeatures.h @@ -163,6 +163,10 @@ #define EFI_HD44780_LCD TRUE #endif +#ifndef EFI_LCD +#define EFI_LCD TRUE +#endif + #ifndef EFI_IDLE_CONTROL #define EFI_IDLE_CONTROL TRUE #endif @@ -318,11 +322,11 @@ */ #define TS_UART_DMA_MODE FALSE -#define TS_DMA_UART_DEVICE (&UARTD3) -#define TS_SERIAL_UART_DEVICE (&SD3) +#define TS_UART_DEVICE (&UARTD3) +#define TS_SERIAL_DEVICE (&SD3) // todo: add DMA-mode for Console? -#if TS_UART_DMA_MODE +#if (TS_UART_DMA_MODE || TS_UART_MODE) #undef EFI_CONSOLE_UART_DEVICE #endif diff --git a/firmware/config/stm32f4ems/halconf.h b/firmware/config/stm32f4ems/halconf.h index 3b02c7ad21..1efea2015c 100644 --- a/firmware/config/stm32f4ems/halconf.h +++ b/firmware/config/stm32f4ems/halconf.h @@ -154,7 +154,7 @@ */ #if !defined(HAL_USE_UART) || defined(__DOXYGEN__) /* Configured in efifeatures.h */ -#if TS_UART_DMA_MODE +#if (TS_UART_DMA_MODE || TS_UART_MODE) #define HAL_USE_UART TRUE #else #define HAL_USE_UART FALSE @@ -359,7 +359,7 @@ */ #if !defined(UART_USE_WAIT) || defined(__DOXYGEN__) /* Configured in efifeatures.h */ -#if TS_UART_DMA_MODE +#if (TS_UART_DMA_MODE || TS_UART_MODE) #define UART_USE_WAIT TRUE #else #define UART_USE_WAIT FALSE diff --git a/firmware/config/stm32f7ems/efifeatures.h b/firmware/config/stm32f7ems/efifeatures.h index 8ae0e2b3a5..608d0dc560 100644 --- a/firmware/config/stm32f7ems/efifeatures.h +++ b/firmware/config/stm32f7ems/efifeatures.h @@ -52,6 +52,9 @@ #undef EFI_HD44780_LCD #define EFI_HD44780_LCD FALSE +#undef EFI_LCD +#define EFI_LCD FALSE + /** * Do we need file logging (like SD card) logic? */ @@ -75,13 +78,13 @@ #undef TS_UART_DMA_MODE #define TS_UART_DMA_MODE FALSE -#undef TS_DMA_UART_DEVICE -#define TS_DMA_UART_DEVICE (&UARTD3) -#undef TS_SERIAL_UART_DEVICE -#define TS_SERIAL_UART_DEVICE (&SD3) +#undef TS_UART_DEVICE +#define TS_UART_DEVICE (&UARTD3) +#undef TS_SERIAL_DEVICE +#define TS_SERIAL_DEVICE (&SD3) // todo: add DMA-mode for Console? -#if TS_UART_DMA_MODE +#if (TS_UART_DMA_MODE || TS_UART_MODE) #undef EFI_CONSOLE_UART_DEVICE #endif diff --git a/firmware/config/stm32f7ems/halconf.h b/firmware/config/stm32f7ems/halconf.h index 3944c47cd7..778a5340b2 100644 --- a/firmware/config/stm32f7ems/halconf.h +++ b/firmware/config/stm32f7ems/halconf.h @@ -161,7 +161,7 @@ */ #if !defined(HAL_USE_UART) || defined(__DOXYGEN__) /* Configured in efifeatures.h */ -#if TS_UART_DMA_MODE +#if (TS_UART_DMA_MODE || TS_UART_MODE) #define HAL_USE_UART TRUE #else #define HAL_USE_UART FALSE @@ -366,7 +366,7 @@ */ #if !defined(UART_USE_WAIT) || defined(__DOXYGEN__) /* Configured in efifeatures.h */ -#if TS_UART_DMA_MODE +#if (TS_UART_DMA_MODE || TS_UART_MODE) #define UART_USE_WAIT TRUE #else #define UART_USE_WAIT FALSE diff --git a/firmware/console/binary/tunerstudio_io.cpp b/firmware/console/binary/tunerstudio_io.cpp index dc075ec6ae..6b7a72c2ee 100644 --- a/firmware/console/binary/tunerstudio_io.cpp +++ b/firmware/console/binary/tunerstudio_io.cpp @@ -34,7 +34,7 @@ static uart_dma_s tsUartDma; static void tsCopyDataFromDMA() { chSysLockFromISR(); // get 0-based DMA buffer position - int dmaPos = TS_DMA_BUFFER_SIZE - dmaStreamGetTransactionSize(TS_DMA_UART_DEVICE->dmarx); + int dmaPos = TS_DMA_BUFFER_SIZE - dmaStreamGetTransactionSize(TS_UART_DEVICE->dmarx); // if the position is wrapped (circular DMA-mode enabled) if (dmaPos < tsUartDma.readPos) dmaPos += TS_DMA_BUFFER_SIZE; @@ -70,6 +70,12 @@ static UARTConfig tsDmaUartConfig = { 0, 0, 0/*USART_CR2_STOP1_BITS*/ | USART_CR2_LINEN, 0, /*timeout_cb*/tsRxIRQIdleHandler, /*rxhalf_cb*/tsRxIRQHalfHandler }; +#elif TS_UART_MODE +/* Note: This structure is modified from the default ChibiOS layout! */ +static UARTConfig tsUartConfig = { + NULL, NULL, NULL, NULL, NULL, + 0, 0, 0/*USART_CR2_STOP1_BITS*/ | USART_CR2_LINEN, 0 +}; #else static SerialConfig tsSerialConfig = { 0, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 }; #endif /* TS_UART_DMA_MODE */ @@ -103,18 +109,23 @@ void startTsPort(ts_channel_s *tsChannel) { // start DMA driver tsDmaUartConfig.speed = CONFIGB(tunerStudioSerialSpeed); - uartStart(TS_DMA_UART_DEVICE, &tsDmaUartConfig); + uartStart(TS_UART_DEVICE, &tsDmaUartConfig); // start continuous DMA transfer using our circular buffer tsUartDma.readPos = 0; - uartStartReceive(TS_DMA_UART_DEVICE, sizeof(tsUartDma.dmaBuffer), tsUartDma.dmaBuffer); + uartStartReceive(TS_UART_DEVICE, sizeof(tsUartDma.dmaBuffer), tsUartDma.dmaBuffer); +#elif TS_UART_MODE + print("Using UART mode"); + // start DMA driver + tsUartConfig.speed = CONFIGB(tunerStudioSerialSpeed); + uartStart(TS_UART_DEVICE, &tsUartConfig); #else print("Using Serial mode"); tsSerialConfig.speed = CONFIGB(tunerStudioSerialSpeed); - sdStart(TS_SERIAL_UART_DEVICE, &tsSerialConfig); + sdStart(TS_SERIAL_DEVICE, &tsSerialConfig); - tsChannel->channel = (BaseChannel *) TS_SERIAL_UART_DEVICE; + tsChannel->channel = (BaseChannel *) TS_SERIAL_DEVICE; #endif /* TS_UART_DMA_MODE */ } else tsChannel->channel = (BaseChannel *) NULL; // actually not used @@ -138,10 +149,10 @@ bool stopTsPort(ts_channel_s *tsChannel) { { if (CONFIGB(useSerialPort)) { // todo: disable Rx/Tx pads? -#if TS_UART_DMA_MODE - uartStop(TS_DMA_UART_DEVICE); +#if (TS_UART_DMA_MODE || TS_UART_MODE) + uartStop(TS_UART_DEVICE); #else - sdStop(TS_SERIAL_UART_DEVICE); + sdStop(TS_SERIAL_DEVICE); #endif /* TS_UART_DMA_MODE */ } } @@ -160,10 +171,10 @@ void sr5WriteData(ts_channel_s *tsChannel, const uint8_t * buffer, int size) { logMsg("chSequentialStreamWrite [%d]\r\n", size); #endif -#if TS_UART_DMA_MODE && EFI_PROD_CODE +#if (TS_UART_DMA_MODE || TS_UART_MODE) && EFI_PROD_CODE UNUSED(tsChannel); int transferred = size; - uartSendTimeout(TS_DMA_UART_DEVICE, (size_t *)&transferred, buffer, BINARY_IO_TIMEOUT); + uartSendTimeout(TS_UART_DEVICE, (size_t *)&transferred, buffer, BINARY_IO_TIMEOUT); #else if (tsChannel->channel == NULL) return; @@ -197,6 +208,11 @@ int sr5ReadDataTimeout(ts_channel_s *tsChannel, uint8_t * buffer, int size, int #if TS_UART_DMA_MODE || defined(__DOXYGEN__) UNUSED(tsChannel); return (int)iqReadTimeout(&tsUartDma.fifoRxQueue, (uint8_t * )buffer, (size_t)size, timeout); +#elif TS_UART_MODE + UNUSED(tsChannel); + size_t received = (size_t)size; + uartReceiveTimeout(TS_UART_DEVICE, &received, buffer, timeout); + return (int)received; #else /* TS_UART_DMA_MODE */ if (tsChannel->channel == NULL) return 0; diff --git a/firmware/console/console_io.cpp b/firmware/console/console_io.cpp index 95db7cf7e0..5cf917abae 100644 --- a/firmware/console/console_io.cpp +++ b/firmware/console/console_io.cpp @@ -19,6 +19,7 @@ */ #include "global.h" +#include "engine.h" #include "console_io.h" #include "rfiutil.h" #include "tunerstudio.h" @@ -293,37 +294,3 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p) addConsoleAction(SWITCH_TO_BINARY_COMMAND, switchToBinaryProtocol); } -/** - * @return TRUE if already in locked context - */ -bool lockAnyContext(void) { - int alreadyLocked = isLocked(); - if (alreadyLocked) - return true; -#if USE_PORT_LOCK - port_lock(); -#else /* #if USE_PORT_LOCK */ - if (isIsrContext()) { - chSysLockFromISR() - ; - } else { - chSysLock() - ; - } -#endif /* #if USE_PORT_LOCK */ - return false; -} - -void unlockAnyContext(void) { -#if USE_PORT_LOCK - port_unlock(); -#else /* #if USE_PORT_LOCK */ - if (isIsrContext()) { - chSysUnlockFromISR() - ; - } else { - chSysUnlock() - ; - } -#endif /* #if USE_PORT_LOCK */ -} diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index b671da2f8b..9ed0ef4e8a 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -102,8 +102,11 @@ extern int maxTriggerReentraint; extern uint32_t maxLockedDuration; #define FULL_LOGGING_KEY "fl" +#if !defined(STATUS_LOGGING_BUFFER_SIZE) || defined(__DOXYGEN__) +#define STATUS_LOGGING_BUFFER_SIZE 1800 +#endif /* STATUS_LOGGING_BUFFER_SIZE */ -static char LOGGING_BUFFER[1800] CCM_OPTIONAL; +static char LOGGING_BUFFER[STATUS_LOGGING_BUFFER_SIZE] CCM_OPTIONAL; static Logging logger("status loop", LOGGING_BUFFER, sizeof(LOGGING_BUFFER)); static void setWarningEnabled(int value) { @@ -650,6 +653,7 @@ static void blinkingThread(void *arg) { #endif /* EFI_PROD_CODE */ +#if EFI_LCD || defined(__DOXYGEN__) class LcdController : public PeriodicController { public: LcdController() : PeriodicController("BenchThread") { } @@ -666,6 +670,7 @@ private: }; static LcdController lcdInstance; +#endif /* EFI_LCD */ #if EFI_HIP_9011 || defined(__DOXYGEN__) extern HIP9011 instance; @@ -984,7 +989,9 @@ void startStatusThreads(void) { initStatusLeds(); chThdCreateStatic(blinkingStack, sizeof(blinkingStack), NORMALPRIO, (tfunc_t) blinkingThread, NULL); #endif /* EFI_PROD_CODE */ +#if EFI_LCD || defined(__DOXYGEN__) lcdInstance.Start(); +#endif /* EFI_LCD */ } void setFullLog(int value) { diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 6d643fc635..4066a87f10 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -339,16 +339,16 @@ void prepareVoidConfiguration(engine_configuration_s *engineConfiguration) { boardConfiguration->acRelayPin = GPIO_UNASSIGNED; boardConfiguration->acRelayPinMode = OM_DEFAULT; -#if EFI_PROD_CODE || defined(__DOXYGEN__) +#if EFI_ALTERNATOR_CONTROL || defined(__DOXYGEN__) setDefaultAlternatorParameters(); -#endif +#endif /* EFI_ALTERNATOR_CONTROL */ #if EFI_ELECTRONIC_THROTTLE_BODY || defined(__DOXYGEN__) setDefaultEtbParameters(PASS_ENGINE_PARAMETER_SIGNATURE); setDefaultEtbBiasCurve(PASS_ENGINE_PARAMETER_SIGNATURE); -#endif +#endif /* EFI_ELECTRONIC_THROTTLE_BODY */ #if EFI_IDLE_CONTROL || defined(__DOXYGEN__) setDefaultIdleParameters(); -#endif +#endif /* EFI_IDLE_CONTROL */ boardConfiguration->wboHeaterPin = GPIO_UNASSIGNED; boardConfiguration->cj125CsPin = GPIO_UNASSIGNED; diff --git a/firmware/controllers/core/efi_wave.h b/firmware/controllers/core/efi_wave.h index 2705654dcb..e402992d8a 100644 --- a/firmware/controllers/core/efi_wave.h +++ b/firmware/controllers/core/efi_wave.h @@ -9,7 +9,9 @@ #include "global.h" +#ifndef PWM_PHASE_MAX_COUNT #define PWM_PHASE_MAX_COUNT 252 +#endif /* PWM_PHASE_MAX_COUNT */ #define PWM_PHASE_MAX_WAVE_PER_PWM 3 /** diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 44872db768..b20e89bf2e 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -47,7 +47,11 @@ extern int waveChartUsedSize; extern WaveChart waveChart; #endif /* EFI_ENGINE_SNIFFER */ -static char LOGGING_BUFFER[1000]; +#if !defined(SETTINGS_LOGGING_BUFFER_SIZE) || defined(__DOXYGEN__) +#define SETTINGS_LOGGING_BUFFER_SIZE 1000 +#endif /* SETTINGS_LOGGING_BUFFER_SIZE */ + +static char LOGGING_BUFFER[SETTINGS_LOGGING_BUFFER_SIZE]; static Logging logger("settings control", LOGGING_BUFFER, sizeof(LOGGING_BUFFER)); extern int maxNesting; @@ -1276,7 +1280,7 @@ static void setValue(const char *paramStr, const char *valueStr) { if (strEqualCaseInsensitive(paramStr, "vsscoeff")) { engineConfiguration->vehicleSpeedCoef = valueF; -#if EFI_PROD_CODE || defined(__DOXYGEN__) +#if EFI_ALTERNATOR_CONTROL || defined(__DOXYGEN__) } else if (strEqualCaseInsensitive(paramStr, "alt_t")) { if (valueI > 10) { engineConfiguration->alternatorControl.periodMs = valueI; @@ -1286,7 +1290,7 @@ static void setValue(const char *paramStr, const char *valueStr) { engineConfiguration->alternatorControl.offset = valueI; } else if (strEqualCaseInsensitive(paramStr, "alt_p")) { setAltPFactor(valueF); -#endif +#endif /* EFI_ALTERNATOR_CONTROL */ // } else if (strEqualCaseInsensitive(paramStr, "cranking_rpm")) { // } else if (strEqualCaseInsensitive(paramStr, "cranking_rpm")) { // } else if (strEqualCaseInsensitive(paramStr, "cranking_rpm")) { diff --git a/firmware/controllers/system/efi_gpio.cpp b/firmware/controllers/system/efi_gpio.cpp index 9366ab59cb..f809bd2ed6 100644 --- a/firmware/controllers/system/efi_gpio.cpp +++ b/firmware/controllers/system/efi_gpio.cpp @@ -452,16 +452,22 @@ const char *portname(ioportid_t GPIOx) { return "PC"; if (GPIOx == GPIOD) return "PD"; -#if defined(STM32F4XX) || defined(STM32F7XX) +#if STM32_HAS_GPIOE if (GPIOx == GPIOE) return "PE"; - if (GPIOx == GPIOG) - return "PG"; - if (GPIOx == GPIOH) - return "PH"; -#endif +#endif /* STM32_HAS_GPIOE */ +#if STM32_HAS_GPIOF if (GPIOx == GPIOF) return "PF"; +#endif /* STM32_HAS_GPIOF */ +#if STM32_HAS_GPIOG + if (GPIOx == GPIOG) + return "PG"; +#endif /* STM32_HAS_GPIOG */ +#if STM32_HAS_GPIOH + if (GPIOx == GPIOH) + return "PH"; +#endif /* STM32_HAS_GPIOH */ return "unknown"; } diff --git a/firmware/controllers/system/pwm_generator_logic.cpp b/firmware/controllers/system/pwm_generator_logic.cpp index 2a4e38ef79..d73bd84176 100644 --- a/firmware/controllers/system/pwm_generator_logic.cpp +++ b/firmware/controllers/system/pwm_generator_logic.cpp @@ -10,6 +10,7 @@ #include "global.h" #include "pwm_generator_logic.h" +#include "pwm_generator.h" #include "error_handling.h" /** diff --git a/firmware/hw_layer/drivers/gpio/core.c b/firmware/hw_layer/drivers/gpio/core.c index 29848e4ccf..cf1237c983 100644 --- a/firmware/hw_layer/drivers/gpio/core.c +++ b/firmware/hw_layer/drivers/gpio/core.c @@ -151,7 +151,7 @@ int gpiochip_register(const char *name, struct gpiochip_ops *ops, size_t size, v int gpiochips_init(void) { int i; - int ret; + int ret = -1; int pins_added = 0; for (i = 0; i < BOARD_EXT_GPIOCHIPS; i++) { diff --git a/firmware/hw_layer/hw_layer.mk b/firmware/hw_layer/hw_layer.mk index b9fef485db..ea5814fdb5 100644 --- a/firmware/hw_layer/hw_layer.mk +++ b/firmware/hw_layer/hw_layer.mk @@ -36,16 +36,15 @@ HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \ ifeq ($(PROJECT_CPU),ST_STM32F7) HW_LAYER_EMS += $(PROJECT_DIR)/hw_layer/ports/stm32/stm32f7/stm32f7xx_hal_flash.c \ $(PROJECT_DIR)/hw_layer/ports/stm32/stm32f7/stm32f7xx_hal_flash_ex.c -include $(PROJECT_DIR)/hw_layer/$(CPU_HWLAYER)/hw_stm32.mk endif ifeq ($(PROJECT_CPU),ST_STM32F4) HW_LAYER_EMS += $(PROJECT_DIR)/hw_layer/ports/stm32/stm32f4/stm32f4xx_hal_flash.c \ $(PROJECT_DIR)/hw_layer/ports/stm32/stm32f4/stm32f4xx_hal_flash_ex.c -include $(PROJECT_DIR)/hw_layer/$(CPU_HWLAYER)/hw_stm32.mk endif ifeq ($(PROJECT_CPU),ST_STM32F1) -include $(PROJECT_DIR)/hw_layer/$(CPU_HWLAYER)/hw_stm32.mk endif + +-include $(PROJECT_DIR)/hw_layer/$(CPU_HWLAYER)/hw_ports.mk \ No newline at end of file diff --git a/firmware/hw_layer/ports/stm32/stm32f0/hw_stm32.mk b/firmware/hw_layer/ports/stm32/stm32f0/hw_ports.mk similarity index 100% rename from firmware/hw_layer/ports/stm32/stm32f0/hw_stm32.mk rename to firmware/hw_layer/ports/stm32/stm32f0/hw_ports.mk diff --git a/firmware/hw_layer/ports/stm32/stm32f1/hw_stm32.mk b/firmware/hw_layer/ports/stm32/stm32f1/hw_ports.mk similarity index 100% rename from firmware/hw_layer/ports/stm32/stm32f1/hw_stm32.mk rename to firmware/hw_layer/ports/stm32/stm32f1/hw_ports.mk diff --git a/firmware/hw_layer/ports/stm32/stm32f4/hw_stm32.mk b/firmware/hw_layer/ports/stm32/stm32f4/hw_ports.mk similarity index 100% rename from firmware/hw_layer/ports/stm32/stm32f4/hw_stm32.mk rename to firmware/hw_layer/ports/stm32/stm32f4/hw_ports.mk diff --git a/firmware/hw_layer/ports/stm32/stm32f7/hw_stm32.mk b/firmware/hw_layer/ports/stm32/stm32f7/hw_ports.mk similarity index 100% rename from firmware/hw_layer/ports/stm32/stm32f7/hw_stm32.mk rename to firmware/hw_layer/ports/stm32/stm32f7/hw_ports.mk diff --git a/firmware/hw_layer/servo.cpp b/firmware/hw_layer/servo.cpp index 8bad285edc..aa02227bc9 100644 --- a/firmware/hw_layer/servo.cpp +++ b/firmware/hw_layer/servo.cpp @@ -14,8 +14,7 @@ #include "engine.h" -// todo: EFI_SERVO macro -#if EFI_PROD_CODE || EFI_SIMULATOR +#if EFI_SERVO || EFI_SIMULATOR #include "servo.h" #include "pin_repository.h" @@ -84,5 +83,5 @@ void initServo(void) { chThdCreateStatic(seThreadStack, sizeof(seThreadStack), NORMALPRIO, (tfunc_t)(void*) seThread, NULL); } -#endif +#endif /* EFI_SERVO */ diff --git a/firmware/rusefi.mk b/firmware/rusefi.mk index 5e40d3c485..d5c190836d 100644 --- a/firmware/rusefi.mk +++ b/firmware/rusefi.mk @@ -17,6 +17,8 @@ ifeq ($(PROJECT_CPU),) endif DDEFS += -D$(PROJECT_CPU) +-include $(PROJECT_DIR)/config/boards/$(PROJECT_BOARD)/config.mk + # CPU-dependent defs ifeq ($(PROJECT_CPU),ST_STM32F7) CPU_STARTUP = startup_stm32f7xx.mk @@ -36,3 +38,11 @@ CPU_STARTUP = startup_stm32f1xx.mk CPU_PLATFORM = STM32F1xx/platform.mk CPU_HWLAYER = ports/stm32/stm32f1 endif + +ifeq ($(CPU_STARTUP_DIR),) +CPU_STARTUP_DIR = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/$(CPU_STARTUP) +endif + +ifeq ($(CPU_PLATFORM_DIR),) +CPU_PLATFORM_DIR = $(CHIBIOS)/os/hal/ports/STM32/$(CPU_PLATFORM) +endif diff --git a/firmware/util/cli_registry.cpp b/firmware/util/cli_registry.cpp index 3591d6beec..3702e9efcb 100644 --- a/firmware/util/cli_registry.cpp +++ b/firmware/util/cli_registry.cpp @@ -43,6 +43,7 @@ void resetConsoleActions(void) { } static void doAddAction(const char *token, action_type_e type, Void callback, void *param) { +#if !defined(EFI_DISABLE_CONSOLE_ACTIONS) || defined(__DOXYGEN__) for (uint32_t i = 0; i < efiStrlen(token);i++) { char ch = token[i]; if (ch != mytolower(ch)) { @@ -61,6 +62,7 @@ static void doAddAction(const char *token, action_type_e type, Void callback, vo current->parameterType = type; current->callback = callback; current->param = param; +#endif /* EFI_DISABLE_CONSOLE_ACTIONS */ } void addConsoleActionP(const char *token, VoidPtr callback, void *param) { diff --git a/firmware/util/rfiutil.c b/firmware/util/rfiutil.c index c9a7b21616..21e634409c 100644 --- a/firmware/util/rfiutil.c +++ b/firmware/util/rfiutil.c @@ -74,4 +74,40 @@ void chVTSetAny(virtual_timer_t *vtp, systime_t time, vtfunc_t vtfunc, void *par } } +/** + * @return TRUE if already in locked context + */ +bool lockAnyContext(void) { + int alreadyLocked = isLocked(); + if (alreadyLocked) + return true; +#if USE_PORT_LOCK + port_lock(); +#else /* #if USE_PORT_LOCK */ + if (isIsrContext()) { + chSysLockFromISR() + ; + } else { + chSysLock() + ; + } +#endif /* #if USE_PORT_LOCK */ + return false; +} + +void unlockAnyContext(void) { +#if USE_PORT_LOCK + port_unlock(); +#else /* #if USE_PORT_LOCK */ + if (isIsrContext()) { + chSysUnlockFromISR() + ; + } else { + chSysUnlock() + ; + } +#endif /* #if USE_PORT_LOCK */ +} + #endif + diff --git a/hardware/rusefi_lib b/hardware/rusefi_lib index 90ac7b4eba..c965d87b03 160000 --- a/hardware/rusefi_lib +++ b/hardware/rusefi_lib @@ -1 +1 @@ -Subproject commit 90ac7b4eba79a4d7135c935f2ac14c0bac0efc97 +Subproject commit c965d87b0390c20a7d3be13c1d614f180bfb30c3 diff --git a/unit_tests/Makefile b/unit_tests/Makefile index 6977c4a8fc..06bad3c138 100644 --- a/unit_tests/Makefile +++ b/unit_tests/Makefile @@ -177,10 +177,13 @@ INCDIR = . \ #MCU = cortex-m4 ifeq ($(OS),Windows_NT) +ifeq ($(USE_MINGW32_I686),) #this one is 64 bit TRGT = x86_64-w64-mingw32- +else #this one was 32 bit -# TRGT = i686-w64-mingw32- + TRGT = i686-w64-mingw32- +endif else TRGT = endif