From cde26ac1a22cc211d3518437e19e1f916ccc2514 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Fri, 25 Apr 2014 03:50:33 +0100 Subject: [PATCH] Fix eeprom writing. Update some clocks. Add fake implementation of acc and gyro to allow the main loop to run. --- src/config.c | 8 +++++--- src/drivers/system_common.c | 4 ++-- src/sensors_acceleration.h | 3 ++- src/sensors_initialisation.c | 37 ++++++++++++++++++++++++++++++++++++ src/serial_cli.c | 2 +- 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/config.c b/src/config.c index 0d993cbab..5780f4743 100755 --- a/src/config.c +++ b/src/config.c @@ -144,7 +144,6 @@ void copyCurrentProfileToProfileSlot(uint8_t profileSlotIndex) void writeEEPROM(void) { -#ifndef STM32F3DISCOVERY FLASH_Status status = 0; uint32_t wordOffset; int8_t attemptsRemaining = 3; @@ -160,8 +159,12 @@ void writeEEPROM(void) // write it FLASH_Unlock(); while (attemptsRemaining--) { +#ifdef STM32F3DISCOVERY + FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPERR); +#endif +#ifdef STM32F10X_MD FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); - +#endif status = FLASH_ErasePage(FLASH_WRITE_ADDR); for (wordOffset = 0; wordOffset < sizeof(master_t) && status == FLASH_COMPLETE; wordOffset += 4) { status = FLASH_ProgramWord(FLASH_WRITE_ADDR + wordOffset, *(uint32_t *) ((char *)&masterConfig + wordOffset)); @@ -176,7 +179,6 @@ void writeEEPROM(void) if (status != FLASH_COMPLETE || !isEEPROMContentValid()) { failureMode(10); } -#endif } void ensureEEPROMContainsValidData(void) diff --git a/src/drivers/system_common.c b/src/drivers/system_common.c index 3db300dcf..3e34fe799 100755 --- a/src/drivers/system_common.c +++ b/src/drivers/system_common.c @@ -100,13 +100,13 @@ void systemInit(bool overclock) #ifdef STM32F303xC RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4 | RCC_APB1Periph_I2C2, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 | RCC_APB2Periph_USART1, ENABLE); - RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_ADC12, ENABLE); + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 | RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_ADC12, ENABLE); #endif #ifdef STM32F10X_MD RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4 | RCC_APB1Periph_I2C2, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_TIM1 | RCC_APB2Periph_ADC1 | RCC_APB2Periph_USART1, ENABLE); -#endif RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); +#endif RCC_ClearFlag(); // Make all GPIO in by default to save power and reduce noise diff --git a/src/sensors_acceleration.h b/src/sensors_acceleration.h index 241b18d1e..d974a21c8 100644 --- a/src/sensors_acceleration.h +++ b/src/sensors_acceleration.h @@ -7,7 +7,8 @@ typedef enum AccelSensors { ACC_MPU6050 = 2, ACC_MMA8452 = 3, ACC_BMA280 = 4, - ACC_NONE = 5 + ACC_FAKE = 5, + ACC_NONE = 6 } AccelSensors; extern uint8_t accHardware; diff --git a/src/sensors_initialisation.c b/src/sensors_initialisation.c index f1f57c95c..12fb5f8f7 100755 --- a/src/sensors_initialisation.c +++ b/src/sensors_initialisation.c @@ -43,6 +43,30 @@ extern gyro_t gyro; extern baro_t baro; extern acc_t acc; +static void fakeGyroInit(void) {} +static void fakeGyroRead(int16_t *gyroData) {} +static void fakeGyroReadTemp(int16_t *tempData) {} + +bool fakeGyroDetect(gyro_t *gyro, uint16_t lpf) +{ + gyro->init = fakeGyroInit; + gyro->read = fakeGyroRead; + gyro->temperature = fakeGyroReadTemp; + return true; +} + +static void fakeAccInit(void) {} +static void fakeAccRead(int16_t *gyroData) {} + +bool fakeAccDetect(acc_t *acc) +{ + acc->init = fakeAccInit; + acc->read = fakeAccRead; + acc->revisionCode = 0; + return true; +} + + #ifdef FY90Q // FY90Q analog gyro/acc void sensorsAutodetect(sensorAlignmentConfig_t *sensorAlignmentConfig, uint16_t gyroLpf, uint8_t accHardwareToUse, int16_t magDeclinationFromConfig) @@ -69,6 +93,10 @@ void sensorsAutodetect(sensorAlignmentConfig_t *sensorAlignmentConfig, uint16_t gyroAlign = CW0_DEG; } else if (mpu3050Detect(&gyro, gyroLpf)) { gyroAlign = CW0_DEG; +#ifdef STM32F3DISCOVERY + } else if (fakeGyroDetect(&gyro, gyroLpf)) { + gyroAlign = ALIGN_DEFAULT; +#endif } else { // if this fails, we get a beep + blink pattern. we're doomed, no gyro or i2c error. failureMode(3); @@ -116,6 +144,15 @@ retry: if (accHardwareToUse == ACC_BMA280) break; } +#endif +#ifdef STM32F3DISCOVERY + default: + if (fakeAccDetect(&acc)) { + accHardware = ACC_BMA280; + accAlign = CW0_DEG; // + if (accHardwareToUse == ACC_FAKE) + break; + } #endif } diff --git a/src/serial_cli.c b/src/serial_cli.c index abe787636..23532018e 100644 --- a/src/serial_cli.c +++ b/src/serial_cli.c @@ -92,7 +92,7 @@ static const char * const sensorNames[] = { }; static const char * const accNames[] = { - "", "ADXL345", "MPU6050", "MMA845x", "BMA280", "None", NULL + "", "ADXL345", "MPU6050", "MMA845x", "BMA280", "FAKE", "None", NULL }; typedef struct {