diff --git a/firmware/.cproject b/firmware/.cproject
index 119404730f..67f890cc89 100644
--- a/firmware/.cproject
+++ b/firmware/.cproject
@@ -205,7 +205,7 @@
-
+
@@ -288,7 +288,7 @@
-
+
diff --git a/firmware/config/stm32f1egt/mpu_util.h b/firmware/config/stm32f1egt/mpu_util.h
deleted file mode 100644
index 9741c01397..0000000000
--- a/firmware/config/stm32f1egt/mpu_util.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * mpu_util.h
- *
- * Created on: Jan 8, 2015
- * Author: Andrey
- */
-
-#ifndef CONFIG_STM32F1EGT_MPU_UTIL_H_
-#define CONFIG_STM32F1EGT_MPU_UTIL_H_
-
-#define baseHardwareInit() {}
-
-#endif /* CONFIG_STM32F1EGT_MPU_UTIL_H_ */
diff --git a/firmware/development/hw_layer/poten.c b/firmware/development/hw_layer/poten.c
index 2fe08bcab0..97b1a7880e 100644
--- a/firmware/development/hw_layer/poten.c
+++ b/firmware/development/hw_layer/poten.c
@@ -12,6 +12,7 @@
#include "pin_repository.h"
#include "engine_configuration.h"
#include "hardware.h"
+#include "mpu_util.h"
/**
* MCP42010 digital potentiometer driver
diff --git a/firmware/egt2can.cpp b/firmware/egt2can.cpp
index 6a98bf8280..19f6499a7f 100644
--- a/firmware/egt2can.cpp
+++ b/firmware/egt2can.cpp
@@ -7,8 +7,6 @@ egt_cs_array_t max31855_cs;
int main_loop_started;
-int maxNesting = 0;
-
void firmwareError(const char *fmt, ...) {
}
@@ -30,18 +28,6 @@ static msg_t Thread1(void *arg) {
return 0;
}
-
-void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin) {
- spiConfig->end_cb = NULL;
-// ioportid_t port = getHwPort(csPin);
-// ioportmask_t pin = getHwPin(csPin);
-// spiConfig->ssport = port;
-// spiConfig->sspad = pin;
-// mySetPadMode("chip select", port, pin, PAL_STM32_MODE_OUTPUT);
-}
-
-
-
void runRusEfi(void) {
#if EFI_USE_UART_FOR_CONSOLE
diff --git a/firmware/hw_layer/HIP9011.cpp b/firmware/hw_layer/HIP9011.cpp
index 0ae8a96840..12f35c68df 100644
--- a/firmware/hw_layer/HIP9011.cpp
+++ b/firmware/hw_layer/HIP9011.cpp
@@ -153,7 +153,7 @@ static void showHipInfo(void) {
printSpiState(&logger, boardConfiguration);
scheduleMsg(&logger, "bore=%f freq=%f", engineConfiguration->cylinderBore, BAND(engineConfiguration->cylinderBore));
- scheduleMsg(&logger, "band_index=%d gain_index=%d", bandIndex, currentGainIndex);
+ scheduleMsg(&logger, "band_index=%d gain %f/index=%d", bandIndex, boardConfiguration->hip9011Gain, currentGainIndex);
scheduleMsg(&logger, "integrator index=%d", currentIntergratorIndex);
scheduleMsg(&logger, "spi= int=%s response count=%d", hwPortname(boardConfiguration->hip9011IntHoldPin), nonZeroResponse);
diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp
index e7aea94dad..aae244fb90 100644
--- a/firmware/hw_layer/hardware.cpp
+++ b/firmware/hw_layer/hardware.cpp
@@ -57,15 +57,6 @@ int maxNesting = 0;
#if HAL_USE_SPI || defined(__DOXYGEN__)
static bool isSpiInitialized[5] = { false, false, false, false, false };
-static void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
- brain_pin_e mosi, int af) {
-
- mySetPadMode2("SPI clock", sck, PAL_MODE_ALTERNATE(af));
-
- mySetPadMode2("SPI master out", mosi, PAL_MODE_ALTERNATE(af));
- mySetPadMode2("SPI master in ", miso, PAL_MODE_ALTERNATE(af));
-}
-
/**
* Only one consumer can use SPI bus at a given time
*/
@@ -78,39 +69,6 @@ void unlockSpi(void) {
chMtxUnlock();
}
-void turnOnSpi(spi_device_e device) {
- if (isSpiInitialized[device])
- return; // already initialized
- isSpiInitialized[device] = true;
- if (device == SPI_DEVICE_1) {
-#if STM32_SPI_USE_SPI1
-// scheduleMsg(&logging, "Turning on SPI1 pins");
- initSpiModule(&SPID1, boardConfiguration->spi1sckPin,
- boardConfiguration->spi1misoPin,
- boardConfiguration->spi1mosiPin,
- EFI_SPI1_AF);
-#endif /* STM32_SPI_USE_SPI1 */
- }
- if (device == SPI_DEVICE_2) {
-#if STM32_SPI_USE_SPI2
-// scheduleMsg(&logging, "Turning on SPI2 pins");
- initSpiModule(&SPID2, boardConfiguration->spi2sckPin,
- boardConfiguration->spi2misoPin,
- boardConfiguration->spi2mosiPin,
- EFI_SPI2_AF);
-#endif /* STM32_SPI_USE_SPI2 */
- }
- if (device == SPI_DEVICE_3) {
-#if STM32_SPI_USE_SPI3
-// scheduleMsg(&logging, "Turning on SPI3 pins");
- initSpiModule(&SPID3, boardConfiguration->spi3sckPin,
- boardConfiguration->spi3misoPin,
- boardConfiguration->spi3mosiPin,
- EFI_SPI3_AF);
-#endif /* STM32_SPI_USE_SPI3 */
- }
-}
-
static void initSpiModules(board_configuration_s *boardConfiguration) {
if (boardConfiguration->is_enabled_spi_2) {
turnOnSpi(SPI_DEVICE_2);
@@ -142,15 +100,6 @@ SPIDriver * getSpiDevice(spi_device_e spiDevice) {
firmwareError("Unexpected SPI device: %d", spiDevice);
return NULL;
}
-
-void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin) {
- spiConfig->end_cb = NULL;
- ioportid_t port = getHwPort(csPin);
- ioportmask_t pin = getHwPin(csPin);
- spiConfig->ssport = port;
- spiConfig->sspad = pin;
- mySetPadMode("chip select", port, pin, PAL_STM32_MODE_OUTPUT);
-}
#endif
#if HAL_USE_I2C || defined(__DOXYGEN__)
diff --git a/firmware/hw_layer/hardware.h b/firmware/hw_layer/hardware.h
index 8ecaaedad1..a1672ab97f 100644
--- a/firmware/hw_layer/hardware.h
+++ b/firmware/hw_layer/hardware.h
@@ -37,7 +37,6 @@ extern "C"
#endif /* __cplusplus */
SPIDriver * getSpiDevice(spi_device_e spiDevice);
-void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin);
void turnOnSpi(spi_device_e device);
void lockSpi(spi_device_e device);
void unlockSpi(void);
diff --git a/firmware/hw_layer/max31855.cpp b/firmware/hw_layer/max31855.cpp
index 37be5cf1be..f2369e7ab8 100644
--- a/firmware/hw_layer/max31855.cpp
+++ b/firmware/hw_layer/max31855.cpp
@@ -16,6 +16,7 @@
#include "max31855.h"
#include "hardware.h"
+#include "mpu_util.h"
#if EFI_PROD_CODE
#include "settings.h"
diff --git a/firmware/hw_layer/stm32f1/mpu_util.h b/firmware/hw_layer/stm32f1/mpu_util.h
new file mode 100644
index 0000000000..65b3088bbd
--- /dev/null
+++ b/firmware/hw_layer/stm32f1/mpu_util.h
@@ -0,0 +1,17 @@
+/*
+ * @file mpu_util.h
+ *
+ * @date Jan 8, 2015
+ * @author Andrey Belomutskiy, (c) 2012-2014
+ */
+
+#ifndef CONFIG_STM32F1EGT_MPU_UTIL_H_
+#define CONFIG_STM32F1EGT_MPU_UTIL_H_
+
+#include "main.h"
+
+#define baseHardwareInit() {}
+
+void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin);
+
+#endif /* CONFIG_STM32F1EGT_MPU_UTIL_H_ */
diff --git a/firmware/hw_layer/stm32f4/mpu_util.cpp b/firmware/hw_layer/stm32f4/mpu_util.cpp
index 591cb19735..207aa9ac96 100644
--- a/firmware/hw_layer/stm32f4/mpu_util.cpp
+++ b/firmware/hw_layer/stm32f4/mpu_util.cpp
@@ -8,6 +8,10 @@
#include "main.h"
#include "mpu_util.h"
#include "error_handling.h"
+#include "engine.h"
+#include "pin_repository.h"
+
+EXTERN_ENGINE;
extern "C" {
int getRemainingStack(Thread *otp);
@@ -197,3 +201,74 @@ void HardFaultVector(void) {
}
}
+#if HAL_USE_SPI || defined(__DOXYGEN__)
+static bool isSpiInitialized[5] = { false, false, false, false, false };
+
+static int getSpiAf(SPIDriver *driver) {
+#if STM32_SPI_USE_SPI1
+ if (driver == &SPID1) {
+ return EFI_SPI1_AF;
+ }
+#endif
+#if STM32_SPI_USE_SPI2
+ if (driver == &SPID2) {
+ return EFI_SPI2_AF;
+ }
+#endif
+#if STM32_SPI_USE_SPI3
+ if (driver == &SPID3) {
+ return EFI_SPI3_AF;
+ }
+#endif
+ return -1;
+}
+
+void turnOnSpi(spi_device_e device) {
+ if (isSpiInitialized[device])
+ return; // already initialized
+ isSpiInitialized[device] = true;
+ if (device == SPI_DEVICE_1) {
+#if STM32_SPI_USE_SPI1
+// scheduleMsg(&logging, "Turning on SPI1 pins");
+ initSpiModule(&SPID1, boardConfiguration->spi1sckPin,
+ boardConfiguration->spi1misoPin,
+ boardConfiguration->spi1mosiPin);
+#endif /* STM32_SPI_USE_SPI1 */
+ }
+ if (device == SPI_DEVICE_2) {
+#if STM32_SPI_USE_SPI2
+// scheduleMsg(&logging, "Turning on SPI2 pins");
+ initSpiModule(&SPID2, boardConfiguration->spi2sckPin,
+ boardConfiguration->spi2misoPin,
+ boardConfiguration->spi2mosiPin);
+#endif /* STM32_SPI_USE_SPI2 */
+ }
+ if (device == SPI_DEVICE_3) {
+#if STM32_SPI_USE_SPI3
+// scheduleMsg(&logging, "Turning on SPI3 pins");
+ initSpiModule(&SPID3, boardConfiguration->spi3sckPin,
+ boardConfiguration->spi3misoPin,
+ boardConfiguration->spi3mosiPin);
+#endif /* STM32_SPI_USE_SPI3 */
+ }
+}
+
+void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
+ brain_pin_e mosi) {
+
+ mySetPadMode2("SPI clock", sck, PAL_MODE_ALTERNATE(getSpiAf(driver)));
+
+ mySetPadMode2("SPI master out", mosi, PAL_MODE_ALTERNATE(getSpiAf(driver)));
+ mySetPadMode2("SPI master in ", miso, PAL_MODE_ALTERNATE(getSpiAf(driver)));
+}
+
+void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin) {
+ spiConfig->end_cb = NULL;
+ ioportid_t port = getHwPort(csPin);
+ ioportmask_t pin = getHwPin(csPin);
+ spiConfig->ssport = port;
+ spiConfig->sspad = pin;
+ mySetPadMode("chip select", port, pin, PAL_STM32_MODE_OUTPUT);
+}
+
+#endif
diff --git a/firmware/hw_layer/stm32f4/mpu_util.h b/firmware/hw_layer/stm32f4/mpu_util.h
index c8d31e4c33..e5d60f3aec 100644
--- a/firmware/hw_layer/stm32f4/mpu_util.h
+++ b/firmware/hw_layer/stm32f4/mpu_util.h
@@ -57,6 +57,11 @@ void DebugMonitorVector(void);
void UsageFaultVector(void);
void BusFaultVector(void);
void HardFaultVector(void);
+void turnOnSpi(spi_device_e device);
+void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
+ brain_pin_e mosi);
+void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin);
+void turnOnSpi(spi_device_e device);
#ifdef __cplusplus
}
diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp
index 81d409d747..0e9434e4c9 100644
--- a/firmware/rusefi.cpp
+++ b/firmware/rusefi.cpp
@@ -268,5 +268,5 @@ int getRusEfiVersion(void) {
return 1; // this is here to make the compiler happy about the unused array
if (UNUSED_CCM_SIZE == 0)
return 1; // this is here to make the compiler happy about the unused array
- return 20150109;
+ return 20150110;
}
diff --git a/firmware/svnversion.h b/firmware/svnversion.h
index 476ff06cf8..3a72cf2a2b 100644
--- a/firmware/svnversion.h
+++ b/firmware/svnversion.h
@@ -1,5 +1,5 @@
// This file was generated by Version2Header
-// Thu Jan 01 15:21:19 EST 2015
+// Sat Jan 10 10:38:47 EST 2015
#ifndef VCS_VERSION
-#define VCS_VERSION "6083"
+#define VCS_VERSION "6259"
#endif