Spi fixes (#1083)
* spi: add support for SPI4 * mpu_util: spi: add 8BIT mode definitions for F4, F7 and kineris (?)
This commit is contained in:
parent
feae6f95f2
commit
1b42748e60
|
@ -82,8 +82,11 @@ void printFloatArray(const char *prefix, float array[], int size) {
|
|||
}
|
||||
|
||||
void printSpiState(Logging *logger, const engine_configuration_s *engineConfiguration) {
|
||||
scheduleMsg(logger, "spi 1=%s/2=%s/3=%s", boolToString(engineConfiguration->is_enabled_spi_1),
|
||||
boolToString(engineConfiguration->is_enabled_spi_2), boolToString(engineConfiguration->is_enabled_spi_3));
|
||||
scheduleMsg(logger, "spi 1=%s/2=%s/3=%s/4=%s",
|
||||
boolToString(engineConfiguration->is_enabled_spi_1),
|
||||
boolToString(engineConfiguration->is_enabled_spi_2),
|
||||
boolToString(engineConfiguration->is_enabled_spi_3),
|
||||
boolToString(engineConfiguration->is_enabled_spi_4));
|
||||
}
|
||||
|
||||
extern engine_configuration_s *engineConfiguration;
|
||||
|
|
|
@ -113,6 +113,9 @@ static void initSpiModules(engine_configuration_s *engineConfiguration) {
|
|||
if (CONFIG(is_enabled_spi_3)) {
|
||||
turnOnSpi(SPI_DEVICE_3);
|
||||
}
|
||||
if (CONFIG(is_enabled_spi_4)) {
|
||||
turnOnSpi(SPI_DEVICE_4);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -335,6 +338,9 @@ void applyNewHardwareSettings(void) {
|
|||
if (isConfigurationChanged(is_enabled_spi_3))
|
||||
stopSpi(SPI_DEVICE_3);
|
||||
|
||||
if (isConfigurationChanged(is_enabled_spi_4))
|
||||
stopSpi(SPI_DEVICE_4);
|
||||
|
||||
#if EFI_HD44780_LCD
|
||||
stopHD44780_pins();
|
||||
#endif /* #if EFI_HD44780_LCD */
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
|
||||
#if EFI_PROD_CODE
|
||||
#include "pin_repository.h"
|
||||
#include "mpu_util.h"
|
||||
#endif
|
||||
|
||||
#if EFI_HIP_9011
|
||||
|
@ -84,14 +85,20 @@ static Logging *logger;
|
|||
// todo: nicer method which would mention SPI speed explicitly?
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
static SPIConfig hipSpiCfg = { .circular = false,
|
||||
.end_cb = NULL,
|
||||
.ssport = NULL,
|
||||
.sspad = 0,
|
||||
.cr1 = SPI_CR1_MSTR |
|
||||
//SPI_CR1_BR_1 // 5MHz
|
||||
SPI_CR1_CPHA | SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_BR_2,
|
||||
.cr2 = 0};
|
||||
static SPIConfig hipSpiCfg = {
|
||||
.circular = false,
|
||||
.end_cb = NULL,
|
||||
.ssport = NULL,
|
||||
.sspad = 0,
|
||||
.cr1 =
|
||||
SPI_CR1_MSTR |
|
||||
SPI_CR1_CPHA |
|
||||
//SPI_CR1_BR_1 // 5MHz
|
||||
SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_BR_2 |
|
||||
SPI_CR1_8BIT_MODE,
|
||||
.cr2 =
|
||||
SPI_CR2_8BIT_MODE
|
||||
};
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
static void checkResponse(void) {
|
||||
|
|
|
@ -41,6 +41,9 @@ BOR_Result_t BOR_Set(BOR_Level_t BORValue);
|
|||
#define ADC_CR2_SWSTART ((uint32_t)0x40000000)
|
||||
#endif
|
||||
|
||||
#define SPI_CR1_8BIT_MODE 0
|
||||
#define SPI_CR2_8BIT_MODE 0
|
||||
|
||||
#define SPI_CR1_16BIT_MODE SPI_CR1_DFF
|
||||
#define SPI_CR2_16BIT_MODE 0
|
||||
|
||||
|
|
|
@ -318,6 +318,13 @@ void turnOnSpi(spi_device_e device) {
|
|||
engineConfiguration->spi3MisoMode);
|
||||
#endif /* STM32_SPI_USE_SPI3 */
|
||||
}
|
||||
if (device == SPI_DEVICE_4) {
|
||||
#if STM32_SPI_USE_SPI4
|
||||
// scheduleMsg(&logging, "Turning on SPI4 pins");
|
||||
/* there is no cofiguration fields for SPI4 in engineConfiguration, rely on board init code
|
||||
* it should set proper functions for SPI4 pins */
|
||||
#endif /* STM32_SPI_USE_SPI4 */
|
||||
}
|
||||
}
|
||||
|
||||
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
|
||||
|
|
|
@ -54,6 +54,9 @@
|
|||
#define ADC_CR2_SWSTART ((uint32_t)0x40000000)
|
||||
#endif
|
||||
|
||||
#define SPI_CR1_8BIT_MODE 0
|
||||
#define SPI_CR2_8BIT_MODE 0
|
||||
|
||||
#define SPI_CR1_16BIT_MODE SPI_CR1_DFF
|
||||
#define SPI_CR2_16BIT_MODE 0
|
||||
|
||||
|
|
|
@ -313,6 +313,13 @@ void turnOnSpi(spi_device_e device) {
|
|||
engineConfiguration->spi3MisoMode);
|
||||
#endif /* STM32_SPI_USE_SPI3 */
|
||||
}
|
||||
if (device == SPI_DEVICE_4) {
|
||||
#if STM32_SPI_USE_SPI4
|
||||
// scheduleMsg(&logging, "Turning on SPI4 pins");
|
||||
/* there is no cofiguration fields for SPI4 in engineConfiguration, rely on board init code
|
||||
* it should set proper functions for SPI4 pins */
|
||||
#endif /* STM32_SPI_USE_SPI4 */
|
||||
}
|
||||
}
|
||||
|
||||
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
|
||||
|
|
|
@ -55,11 +55,14 @@
|
|||
#define ADC_CR2_SWSTART ((uint32_t)0x40000000)
|
||||
#endif
|
||||
|
||||
#define SPI_CR1_8BIT_MODE 0
|
||||
#define SPI_CR2_8BIT_MODE (SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0)
|
||||
|
||||
#define SPI_CR1_16BIT_MODE 0
|
||||
#define SPI_CR2_16BIT_MODE SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0
|
||||
|
||||
#define SPI_CR1_24BIT_MODE 0
|
||||
/* 3 x 8-bit transfer */
|
||||
#define SPI_CR1_24BIT_MODE 0
|
||||
#define SPI_CR2_24BIT_MODE SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0
|
||||
|
||||
|
||||
|
|
|
@ -34,11 +34,13 @@ static SPIDriver *driver;
|
|||
* The slave select line is the pin GPIOE_CS_SPI on the port GPIOE.
|
||||
*/
|
||||
static const SPIConfig accelerometerCfg = {
|
||||
NULL,
|
||||
/* HW dependent part.*/
|
||||
GPIOE,
|
||||
GPIOE_PIN3,
|
||||
SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_CPOL | SPI_CR1_CPHA
|
||||
.spi_bus = NULL,
|
||||
/* HW dependent part.*/
|
||||
.ssport = GPIOE,
|
||||
.sspad = GPIOE_PIN3,
|
||||
.cr1 = SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_CPOL | SPI_CR1_CPHA |
|
||||
SPI_CR1_8BIT_MODE,
|
||||
.cr2 = SPI_CR2_8BIT_MODE
|
||||
};
|
||||
#endif /* EFI_MEMS */
|
||||
|
||||
|
|
|
@ -15,6 +15,10 @@
|
|||
|
||||
#include "adc_inputs.h"
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
#include "mpu_util.h"
|
||||
#endif
|
||||
|
||||
//#define CJ125_DEBUG
|
||||
//#define CJ125_DEBUG_SPI
|
||||
|
||||
|
@ -39,8 +43,12 @@ static SPIConfig cj125spicfg = {
|
|||
.end_cb = NULL,
|
||||
.ssport = NULL,
|
||||
.sspad = 0,
|
||||
.cr1 = SPI_CR1_MSTR | SPI_CR1_CPHA,
|
||||
.cr2 = 0 };
|
||||
.cr1 =
|
||||
SPI_CR1_MSTR | SPI_CR1_CPHA |
|
||||
SPI_CR1_8BIT_MODE,
|
||||
.cr2 =
|
||||
SPI_CR2_8BIT_MODE
|
||||
};
|
||||
|
||||
static volatile int lastSlowAdcCounter = 0;
|
||||
|
||||
|
|
|
@ -85,6 +85,7 @@ struct mc33972_config mc33972 = {
|
|||
.ssport = NULL,
|
||||
.sspad = 0,
|
||||
.cr1 =
|
||||
SPI_CR1_24BIT_MODE |
|
||||
SPI_CR1_SSM |
|
||||
SPI_CR1_SSI |
|
||||
/* SPI_CR1_LSBFIRST | */
|
||||
|
|
Loading…
Reference in New Issue