Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing cpu overclock bricking issue. #28

Merged
merged 4 commits into from
Mar 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion make/mcu/STM32F4.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ else
CMSIS_DIR := $(ROOT)/lib/main/CMSIS/CM4
STDPERIPH_DIR = $(ROOT)/lib/main/STM32F4/Drivers/STM32F4xx_StdPeriph_Driver
STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
EXCLUDES = stm32f4xx_can.c \
EXCLUDES = stm32f4xx_crc.c \
stm32f4xx_can.c \
stm32f4xx_fmc.c \
stm32f4xx_sai.c \
stm32f4xx_cec.c \
Expand Down
10 changes: 9 additions & 1 deletion src/main/drivers/accgyro/accgyro_mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
#include "drivers/sensor.h"
#include "drivers/system.h"
#include "drivers/time.h"
#include "drivers/dma_spi.h"

#ifdef USE_DMA_SPI_DEVICE
#include "drivers/dma_spi.h"
#include "sensors/gyro.h"
#include "sensors/acceleration.h"
#endif //USE_DMA_SPI_DEVICE

#include "drivers/accgyro/accgyro.h"
#include "drivers/accgyro/accgyro_mpu3050.h"
Expand All @@ -53,11 +55,17 @@
#include "drivers/accgyro/accgyro_spi_mpu6000.h"
#include "drivers/accgyro/accgyro_spi_mpu6500.h"
#include "drivers/accgyro/accgyro_spi_mpu9250.h"
#ifdef USE_GYRO_IMUF9001
#include "drivers/accgyro/accgyro_imuf9001.h"
#endif //USE_GYRO_IMUF9001
#include "drivers/accgyro/accgyro_mpu.h"


#ifdef USE_DMA_SPI_DEVICE
volatile int dmaSpiGyroDataReady = 0;
volatile uint32_t imufCrcErrorCount = 0;
#endif //USE_DMA_SPI_DEVICE

mpuResetFnPtr mpuResetFn;
#ifdef USE_GYRO_IMUF9001
imufData_t imufData;
Expand Down
7 changes: 1 addition & 6 deletions src/main/drivers/accgyro/accgyro_mpu6500.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ bool mpu6500GyroDetect(gyroDev_t *gyro)
}

gyro->initFn = mpu6500GyroInit;

#ifdef USE_DMA_SPI_DEVICE
gyro->readFn = mpuGyroDmaSpiReadStart;
#else
gyro->readFn = mpuGyroRead;
#endif
gyro->readFn = mpuGyroRead;

// 16.4 dps/lsb scalefactor
gyro->scale = 1.0f / 16.4f;
Expand Down
17 changes: 4 additions & 13 deletions src/main/drivers/accgyro/accgyro_spi_mpu6500.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,15 @@ bool mpu6500SpiGyroDetect(gyroDev_t *gyro)
case MPU_9250_SPI:
case ICM_20608_SPI:
case ICM_20602_SPI:
// 16.4 dps/lsb scalefactor
gyro->scale = 1.0f / 16.4f;
break;
case ICM_20601_SPI:
// 8.2 dps/lsb scalefactor
gyro->scale = 1.0f / 8.2f;
break;
default:
return false;
}

gyro->initFn = mpu6500SpiGyroInit;
#ifdef USE_DMA_SPI_DEVICE
gyro->readFn = mpuGyroDmaSpiReadStart;
#else
gyro->readFn = mpuGyroReadSPI;
#endif


gyro->readFn = mpuGyroReadSPI;
// 16.4 dps/lsb scalefactor
gyro->scale = 1.0f / 16.4f;

return true;
}
3 changes: 3 additions & 0 deletions src/main/drivers/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ typedef struct busDevice_s {
SPI_HandleTypeDef* handle; // cached here for efficiency
#endif
IO_t csnPin;

#if defined(USE_GYRO_IMUF9001)
IO_t rstPin;
#endif
} spi;
struct deviceI2C_s {
I2CDevice device;
Expand Down
13 changes: 7 additions & 6 deletions src/main/drivers/bus_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@
#include <platform.h>

#ifdef USE_SPI
#ifndef GYRO_READ_TIMEOUT
#define GYRO_READ_TIMEOUT 20
#endif

#include "drivers/bus.h"
#include "drivers/bus_spi.h"
#include "drivers/bus_spi_impl.h"
#include "drivers/exti.h"
#include "drivers/io.h"
#include "drivers/rcc.h"
#ifdef USE_DMA_SPI_DEVICE
#ifndef GYRO_READ_TIMEOUT
#define GYRO_READ_TIMEOUT 20
#endif //GYRO_READ_TIMEOUT
#include "drivers/dma_spi.h"
#include "drivers/time.h"
#endif //USE_DMA_SPI_DEVICE

spiDevice_t spiDevice[SPIDEV_COUNT];

Expand Down Expand Up @@ -118,10 +120,10 @@ uint32_t spiTimeoutUserCallback(SPI_TypeDef *instance)
return spiDevice[device].errorCount;
}

#pragma GCC push_options
#pragma GCC optimize ("O0")

bool spiBusTransfer(const busDevice_t *bus, const uint8_t *txData, uint8_t *rxData, int length)
{

#ifdef USE_DMA_SPI_DEVICE
(void)(bus);
uint32_t timeoutCheck = millis();
Expand All @@ -146,7 +148,6 @@ bool spiBusTransfer(const busDevice_t *bus, const uint8_t *txData, uint8_t *rxDa

return true;
}
#pragma GCC pop_options

uint16_t spiGetErrorCounter(SPI_TypeDef *instance)
{
Expand Down
2 changes: 2 additions & 0 deletions src/main/fc/fc_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
#include "drivers/usb_io.h"
#include "drivers/vtx_rtc6705.h"
#include "drivers/vtx_common.h"
#ifdef USE_DMA_SPI_DEVICE
#include "drivers/dma_spi.h"
#endif //USE_DMA_SPI_DEVICE

#include "fc/config.h"
#include "fc/fc_init.h"
Expand Down
2 changes: 1 addition & 1 deletion src/main/flight/imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ static bool imuIsAccelerometerHealthy(void)

static void imuCalculateEstimatedAttitude(timeUs_t currentTimeUs)
{
static timeUs_t previousIMUUpdateTime = 0;
static timeUs_t previousIMUUpdateTime;
float rawYawError = 0;
bool useAcc = false;
bool useMag = false;
Expand Down
4 changes: 2 additions & 2 deletions src/main/interface/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -3795,7 +3795,7 @@ static void cliImufUpdate(char *cmdline)
UNUSED(cmdline);
cliPrint("I muff, you muff, we all muff for IMU-F!");
cliPrintLinefeed();
(*((uint32_t *)0x2001FFF4)) = 0xF431FA77;
(*((uint32_t *)0x2001FFEC)) = 0xF431FA77;
delay(1000);
cliReboot();
}
Expand All @@ -3808,7 +3808,7 @@ static void cliMsd(char *cmdline)

cliPrint("Loading as USB drive!");
cliPrintLinefeed();
(*((uint32_t *)0x2001FFF8)) = 0xF431FA11;
(*((uint32_t *)0x2001FFF0)) = 0xF431FA11;
delay(1000);
cliReboot();
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/sensors/acceleration.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
#include "drivers/accgyro/accgyro_spi_mpu6000.h"
#include "drivers/accgyro/accgyro_spi_mpu6500.h"
#include "drivers/accgyro/accgyro_spi_mpu9250.h"
#ifdef USE_GYRO_IMUF9001
#include "drivers/accgyro/accgyro_imuf9001.h"
#endif //USE_GYRO_IMUF9001
#include "drivers/bus_spi.h"

#include "fc/config.h"
Expand Down
80 changes: 36 additions & 44 deletions src/main/sensors/gyro.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
#include "drivers/accgyro/accgyro_spi_mpu6000.h"
#include "drivers/accgyro/accgyro_spi_mpu6500.h"
#include "drivers/accgyro/accgyro_spi_mpu9250.h"
#ifdef USE_GYRO_IMUF9001
#include "drivers/accgyro/accgyro_imuf9001.h"
#endif //USE_GYRO_IMUF9001
#include "drivers/accgyro/gyro_sync.h"
#include "drivers/bus_spi.h"
#include "drivers/io.h"
Expand Down Expand Up @@ -119,20 +121,18 @@ typedef struct gyroSensor_s {
biquadFilter_t notchFilterDyn[XYZ_AXIS_COUNT];
timeUs_t overflowTimeUs;
bool overflowDetected;
#if defined(USE_GYRO_IMUF9001)
// do nothing
#else
#if defined(USE_GYRO_FAST_KALMAN)
// gyro kalman filter
filterApplyFnPtr fastKalmanApplyFn;
fastKalman_t fastKalman[XYZ_AXIS_COUNT];
#endif // USE_GYRO_FAST_KALMAN
#if defined(USE_GYRO_BIQUAD_RC_FIR2)
// gyro biquad RC FIR2 filter
filterApplyFnPtr biquadRCFIR2ApplyFn;
biquadFilter_t biquadRCFIR2[XYZ_AXIS_COUNT];
#endif // USE_GYRO_BIQUAD_RC_FIR2
#endif //USE_GYRO_IMUF9001
#ifndef USE_GYRO_IMUF9001
#if defined(USE_GYRO_FAST_KALMAN)
// gyro kalman filter
filterApplyFnPtr fastKalmanApplyFn;
fastKalman_t fastKalman[XYZ_AXIS_COUNT];
#endif // USE_GYRO_FAST_KALMAN
#if defined(USE_GYRO_BIQUAD_RC_FIR2)
// gyro biquad RC FIR2 filter
filterApplyFnPtr biquadRCFIR2ApplyFn;
biquadFilter_t biquadRCFIR2[XYZ_AXIS_COUNT];
#endif // USE_GYRO_BIQUAD_RC_FIR2
#endif //!USE_GYRO_IMUF9001
} gyroSensor_t;

STATIC_UNIT_TESTED FAST_RAM gyroSensor_t gyroSensor1;
Expand All @@ -141,16 +141,14 @@ STATIC_UNIT_TESTED gyroSensor_t * const gyroSensorPtr = &gyroSensor1;
STATIC_UNIT_TESTED gyroDev_t * const gyroDevPtr = &gyroSensor1.gyroDev;
#endif

#if defined(USE_GYRO_IMUF9001)
// do nothing
#else
#if defined(USE_GYRO_FAST_KALMAN)
static void gyroInitFilterKalman(gyroSensor_t *gyroSensor, uint16_t gyro_filter_q, uint16_t gyro_filter_r, uint16_t gyro_filter_p);
#endif // USE_GYRO_FAST_KALMAN
#if defined(USE_GYRO_BIQUAD_RC_FIR2)
static void gyroInitFilterBiquadRCFIR2(gyroSensor_t *gyroSensor, uint16_t lpfHz);
#endif // USE_GYRO_BIQUAD_RC_FIR2
#endif // USE_GYRO_FAST_KALMAN
#ifndef USE_GYRO_IMUF9001
#if defined(USE_GYRO_FAST_KALMAN)
static void gyroInitFilterKalman(gyroSensor_t *gyroSensor, uint16_t gyro_filter_q, uint16_t gyro_filter_r, uint16_t gyro_filter_p);
#endif // USE_GYRO_FAST_KALMAN
#if defined(USE_GYRO_BIQUAD_RC_FIR2)
static void gyroInitFilterBiquadRCFIR2(gyroSensor_t *gyroSensor, uint16_t lpfHz);
#endif // USE_GYRO_BIQUAD_RC_FIR2
#endif //!USE_GYRO_IMUF9001

static void gyroInitSensorFilters(gyroSensor_t *gyroSensor);

Expand Down Expand Up @@ -189,9 +187,9 @@ PG_RESET_TEMPLATE(gyroConfig_t, gyroConfig,
.imuf_mode = 32,
.imuf_pitch_q = 2500,
.imuf_pitch_r = 88,
.imuf_roll_q = 3500,
.imuf_roll_q = 2500,
.imuf_roll_r = 88,
.imuf_yaw_q = 1500,
.imuf_yaw_q = 1250,
.imuf_yaw_r = 88,
.imuf_pitch_lpf_cutoff_hz = 120.0f,
.imuf_roll_lpf_cutoff_hz = 120.0f,
Expand Down Expand Up @@ -620,9 +618,7 @@ static void gyroInitFilterDynamicNotch(gyroSensor_t *gyroSensor)
}
#endif

#if defined(USE_GYRO_IMUF9001)
// do nothing
#else
#ifndef USE_GYRO_IMUF9001
#if defined(USE_GYRO_FAST_KALMAN)
static void gyroInitFilterKalman(gyroSensor_t *gyroSensor, uint16_t gyro_filter_q, uint16_t gyro_filter_r, uint16_t gyro_filter_p)
{
Expand Down Expand Up @@ -651,23 +647,21 @@ static void gyroInitFilterBiquadRCFIR2(gyroSensor_t *gyroSensor, uint16_t lpfHz)
}
}
#endif // USE_GYRO_BIQUAD_RC_FIR2
#endif // USE_GYRO_IMUF9001
#endif //!USE_GYRO_IMUF9001

static void gyroInitSensorFilters(gyroSensor_t *gyroSensor)
{
#if defined(USE_GYRO_SLEW_LIMITER)
gyroInitSlewLimiter(gyroSensor);
#endif
#if defined(USE_GYRO_IMUF9001)
// do nothing
#else
#if defined(USE_GYRO_FAST_KALMAN)
gyroInitFilterKalman(gyroSensor, gyroConfig()->gyro_filter_q, gyroConfig()->gyro_filter_r, gyroConfig()->gyro_filter_p);
#endif // USE_GYRO_FAST_KALMAN
#if defined(USE_GYRO_BIQUAD_RC_FIR2)
gyroInitFilterBiquadRCFIR2(gyroSensor, gyroConfig()->gyro_soft_lpf_hz_2);
#endif // USE_GYRO_BIQUAD_RC_FIR2
#endif // USE_GYRO_IMUF9001
#ifndef USE_GYRO_IMUF9001
#if defined(USE_GYRO_FAST_KALMAN)
gyroInitFilterKalman(gyroSensor, gyroConfig()->gyro_filter_q, gyroConfig()->gyro_filter_r, gyroConfig()->gyro_filter_p);
#endif // USE_GYRO_FAST_KALMAN
#if defined(USE_GYRO_BIQUAD_RC_FIR2)
gyroInitFilterBiquadRCFIR2(gyroSensor, gyroConfig()->gyro_soft_lpf_hz_2);
#endif // USE_GYRO_BIQUAD_RC_FIR2
#endif //!USE_GYRO_IMUF9001
#ifndef USE_GYRO_IMUF9001
gyroInitFilterLpf(gyroSensor, gyroConfig()->gyro_soft_lpf_hz);
gyroInitFilterNotch1(gyroSensor, gyroConfig()->gyro_soft_notch_hz_1, gyroConfig()->gyro_soft_notch_cutoff_1);
Expand Down Expand Up @@ -939,9 +933,7 @@ static FAST_CODE void gyroUpdateSensor(gyroSensor_t *gyroSensor, timeUs_t curren
// NOTE: this branch optimized for when there is no gyro debugging, ensure it is kept in step with non-optimized branch
float gyroADCf = gyroSensor->gyroDev.gyroADC[axis] * gyroSensor->gyroDev.scale;

#if defined(USE_GYRO_IMUF9001)
// do nothing
#else
#ifndef USE_GYRO_IMUF9001
#if defined(USE_GYRO_BIQUAD_RC_FIR2)
#if defined(USE_GYRO_FAST_KALMAN)
switch(gyroConfig()->gyro_stage2_filter_type){
Expand All @@ -958,7 +950,7 @@ static FAST_CODE void gyroUpdateSensor(gyroSensor_t *gyroSensor, timeUs_t curren
break;
}
#endif // USE_GYRO_BIQUAD_RC_FIR2
#endif // USE_GYRO_IMUF9001
#endif //USE_GYRO_IMUF9001
#ifdef USE_GYRO_DATA_ANALYSE
gyroADCf = gyroSensor->notchFilterDynApplyFn((filter_t *)&gyroSensor->notchFilterDyn[axis], gyroADCf);
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/main/startup/startup_stm32f40xx.s
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ Reset_Handler:
dsb

// Check for imufUpdate reboot
ldr r0, =0x2001FFF4 // rs2k
ldr r0, =0x2001FFEC // rs2k
ldr r1, =0xF431FA77 // rs2k
ldr r2, [r0, #0] // rs2k
str r0, [r0, #0] // rs2k
cmp r2, r1 // rs2k
beq rebootUpdater // rs2k

// Check for msd reboot
ldr r0, =0x2001FFF8 // rs2k
ldr r0, =0x2001FFF0 // rs2k
ldr r1, =0xF431FA11 // rs2k
ldr r2, [r0, #0] // rs2k
str r0, [r0, #0] // rs2k
Expand Down
2 changes: 1 addition & 1 deletion src/main/target/HELIOSPRING/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void targetConfiguration(void) {
// pidProfile->dterm_lpf_hz = 0;
// pidProfile->dterm_notch_hz = 0;
// pidProfile->dterm_notch_cutoff = 0;
pidProfile->dterm_filter_type = FILTER_BIQUAD;
pidProfile->dterm_filter_type = FILTER_PT1;
}
}

2 changes: 1 addition & 1 deletion src/main/target/HELIOSPRING/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
#define DEFAULT_CURRENT_METER_SOURCE CURRENT_METER_ADC
#define CURRENT_METER_ADC_PIN PA1
#define VBAT_ADC_PIN PA0
#define CURRENT_METER_SCALE_DEFAULT 16000
#define CURRENT_METER_SCALE_DEFAULT 400
#define VBAT_SCALE 109

#define CAMERA_CONTROL_PIN PB6 // define dedicated camera_osd_control pin
8 changes: 4 additions & 4 deletions src/main/target/HELIOSPRING/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
F405_TARGETS += $(TARGET)
FEATURES += VCP ONBOARDFLASH

TARGET_SRC = \
drivers/dma_spi.c \
drivers/accgyro/accgyro_imuf9001.c \
drivers/max7456.c
TARGET_SRC = stm32f4xx_crc.c \
drivers/dma_spi.c \
drivers/accgyro/accgyro_imuf9001.c \
drivers/max7456.c